Files
CalamityModPublic/NPCs/Abyss/Viperfish.cs
T

181 lines
7.1 KiB
C#

using CalamityMod.BiomeManagers;
using CalamityMod.Buffs.DamageOverTime;
using CalamityMod.Items.Materials;
using CalamityMod.Items.Placeables.Banners;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System.IO;
using Terraria;
using Terraria.GameContent;
using Terraria.GameContent.Bestiary;
using Terraria.ID;
using Terraria.ModLoader;
using Terraria.ModLoader.Utilities;
namespace CalamityMod.NPCs.Abyss
{
public class Viperfish : ModNPC
{
public override void SetStaticDefaults()
{
DisplayName.SetDefault("Viperfish");
Main.npcFrameCount[NPC.type] = 4;
NPCID.Sets.NPCBestiaryDrawModifiers value = new NPCID.Sets.NPCBestiaryDrawModifiers(0)
{
PortraitPositionXOverride = 0
};
value.Position.X += 15;
NPCID.Sets.NPCBestiaryDrawOffset[Type] = value;
}
public override void SetDefaults()
{
NPC.noGravity = true;
NPC.damage = 75;
NPC.width = 72;
NPC.height = 30;
NPC.defense = 10;
NPC.lifeMax = 320;
NPC.aiStyle = -1;
AIType = -1;
NPC.value = Item.buyPrice(0, 0, 5, 0);
NPC.HitSound = SoundID.NPCHit1;
NPC.DeathSound = SoundID.NPCDeath1;
NPC.knockBackResist = 0.85f;
Banner = NPC.type;
BannerItem = ModContent.ItemType<ViperfishBanner>();
NPC.chaseable = false;
NPC.Calamity().VulnerableToHeat = false;
NPC.Calamity().VulnerableToSickness = true;
NPC.Calamity().VulnerableToElectricity = true;
NPC.Calamity().VulnerableToWater = false;
SpawnModBiomes = new int[3] { ModContent.GetInstance<AbyssLayer1Biome>().Type, ModContent.GetInstance<AbyssLayer2Biome>().Type, ModContent.GetInstance<AbyssLayer3Biome>().Type };
}
public override void SetBestiary(BestiaryDatabase database, BestiaryEntry bestiaryEntry)
{
bestiaryEntry.Info.AddRange(new IBestiaryInfoElement[] {
// Will move to localization whenever that is cleaned up.
new FlavorTextBestiaryInfoElement("A typically docile animal, it spends much of its time meandering about the rocky outcrops of the abyss. When approached it can become quite aggressive.")
});
}
public override void SendExtraAI(BinaryWriter writer)
{
writer.Write(NPC.chaseable);
}
public override void ReceiveExtraAI(BinaryReader reader)
{
NPC.chaseable = reader.ReadBoolean();
}
public override void AI()
{
CalamityAI.PassiveSwimmingAI(NPC, Mod, 0, Main.player[NPC.target].Calamity().GetAbyssAggro(160f), 0.25f, 0.15f, 6f, 6f, 0.1f);
}
public override bool? CanBeHitByProjectile(Projectile projectile)
{
if (projectile.minion && !projectile.Calamity().overridesMinionDamagePrevention)
{
return NPC.chaseable;
}
return null;
}
public override void FindFrame(int frameHeight)
{
if (!NPC.wet && !NPC.IsABestiaryIconDummy)
{
NPC.frameCounter = 0.0;
return;
}
if (NPC.IsABestiaryIconDummy)
{
NPC.frameCounter += 1.0;
if (NPC.frameCounter > 6.0)
{
NPC.frameCounter = 0.0;
NPC.frame.Y += frameHeight;
}
if (NPC.frame.Y >= frameHeight * 4)
{
NPC.frame.Y = 0;
}
}
else
{
NPC.frameCounter += NPC.chaseable ? 0.15f : 0.075f;
NPC.frameCounter %= Main.npcFrameCount[NPC.type];
int frame = (int)NPC.frameCounter;
NPC.frame.Y = frame * frameHeight;
}
}
public override void PostDraw(SpriteBatch spriteBatch, Vector2 screenPos, Color drawColor)
{
SpriteEffects spriteEffects = SpriteEffects.None;
if (NPC.spriteDirection == 1)
{
spriteEffects = SpriteEffects.FlipHorizontally;
}
Vector2 center = new Vector2(NPC.Center.X, NPC.Center.Y);
Vector2 vector11 = new Vector2((float)(TextureAssets.Npc[NPC.type].Value.Width / 2), (float)(TextureAssets.Npc[NPC.type].Value.Height / Main.npcFrameCount[NPC.type] / 2));
Vector2 vector = center - screenPos;
vector -= new Vector2((float)ModContent.Request<Texture2D>("CalamityMod/NPCs/Abyss/ViperfishGlow").Value.Width, (float)(ModContent.Request<Texture2D>("CalamityMod/NPCs/Abyss/ViperfishGlow").Value.Height / Main.npcFrameCount[NPC.type])) * 1f / 2f;
vector += vector11 * 1f + new Vector2(0f, 4f + NPC.gfxOffY);
Color color = new Color(127 - NPC.alpha, 127 - NPC.alpha, 127 - NPC.alpha, 0).MultiplyRGBA(Microsoft.Xna.Framework.Color.Gold);
Main.spriteBatch.Draw(ModContent.Request<Texture2D>("CalamityMod/NPCs/Abyss/ViperfishGlow").Value, vector,
new Microsoft.Xna.Framework.Rectangle?(NPC.frame), color, NPC.rotation, vector11, 1f, spriteEffects, 0f);
}
public override void OnHitPlayer(Player player, int damage, bool crit)
{
if (damage > 0)
player.AddBuff(ModContent.BuffType<CrushDepth>(), 120, true);
}
public override float SpawnChance(NPCSpawnInfo spawnInfo)
{
if (spawnInfo.Player.Calamity().ZoneAbyssLayer1 && spawnInfo.Water)
{
return SpawnCondition.CaveJellyfish.Chance * 0.6f;
}
if (spawnInfo.Player.Calamity().ZoneAbyssLayer2 && spawnInfo.Water)
{
return SpawnCondition.CaveJellyfish.Chance * 1.2f;
}
return 0f;
}
public override void ModifyNPCLoot(NPCLoot npcLoot)
{
var postClone = npcLoot.DefineConditionalDropSet(DropHelper.PostCal());
postClone.Add(DropHelper.NormalVsExpertQuantity(ModContent.ItemType<DepthCells>(), 2, 1, 2, 2, 3));
postClone.Add(ModContent.ItemType<Lumenyl>(), 4);
}
public override void HitEffect(int hitDirection, double damage)
{
for (int k = 0; k < 5; k++)
{
Dust.NewDust(NPC.position, NPC.width, NPC.height, DustID.Blood, hitDirection, -1f, 0, default, 1f);
}
if (NPC.life <= 0)
{
for (int k = 0; k < 25; k++)
{
Dust.NewDust(NPC.position, NPC.width, NPC.height, DustID.Blood, hitDirection, -1f, 0, default, 1f);
}
if (Main.netMode != NetmodeID.Server)
{
Gore.NewGore(NPC.GetSource_Death(), NPC.position, NPC.velocity, Mod.Find<ModGore>("ViperFish").Type, 1f);
Gore.NewGore(NPC.GetSource_Death(), NPC.position, NPC.velocity, Mod.Find<ModGore>("ViperFish2").Type, 1f);
}
}
}
}
}