Files
CalamityModPublic/NPCs/Abyss/Catfish.cs
T

276 lines
9.1 KiB
C#

using CalamityMod.Items.Placeables.Banners;
using System;
using System.IO;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
namespace CalamityMod.NPCs.Abyss
{
public class Catfish : ModNPC
{
public bool hasBeenHit = false;
public override void SetStaticDefaults()
{
DisplayName.SetDefault("Catfish");
Main.npcFrameCount[npc.type] = 4;
}
public override void SetDefaults()
{
npc.noGravity = true;
npc.damage = 30;
npc.width = 98;
npc.height = 40;
npc.defense = 12;
npc.lifeMax = 120;
npc.aiStyle = -1;
aiType = -1;
for (int k = 0; k < npc.buffImmune.Length; k++)
{
npc.buffImmune[k] = true;
}
npc.value = Item.buyPrice(0, 0, 1, 0);
npc.HitSound = SoundID.NPCHit1;
npc.DeathSound = SoundID.NPCDeath40;
npc.knockBackResist = 0.8f;
banner = npc.type;
bannerItem = ModContent.ItemType<CatfishBanner>();
}
public override void SendExtraAI(BinaryWriter writer)
{
writer.Write(hasBeenHit);
writer.Write(npc.chaseable);
}
public override void ReceiveExtraAI(BinaryReader reader)
{
hasBeenHit = reader.ReadBoolean();
npc.chaseable = reader.ReadBoolean();
}
public override void AI()
{
npc.spriteDirection = (npc.direction > 0) ? 1 : -1;
npc.noGravity = true;
npc.chaseable = hasBeenHit;
if (npc.direction == 0)
{
npc.TargetClosest(true);
}
if (npc.justHit)
{
hasBeenHit = true;
}
if (npc.wet)
{
bool flag14 = hasBeenHit;
npc.TargetClosest(false);
if (Main.player[npc.target].wet && !Main.player[npc.target].dead &&
(Main.player[npc.target].Center - npc.Center).Length() < 200f &&
Collision.CanHit(npc.position, npc.width, npc.height, Main.player[npc.target].position, Main.player[npc.target].width, Main.player[npc.target].height))
{
flag14 = true;
}
if (Main.player[npc.target].dead && flag14)
{
flag14 = false;
}
if (!flag14)
{
if (npc.collideX)
{
npc.velocity.X = npc.velocity.X * -1f;
npc.direction *= -1;
npc.netUpdate = true;
}
if (npc.collideY)
{
npc.netUpdate = true;
if (npc.velocity.Y > 0f)
{
npc.velocity.Y = Math.Abs(npc.velocity.Y) * -1f;
npc.directionY = -1;
npc.ai[0] = -1f;
}
else if (npc.velocity.Y < 0f)
{
npc.velocity.Y = Math.Abs(npc.velocity.Y);
npc.directionY = 1;
npc.ai[0] = 1f;
}
}
}
if (flag14)
{
npc.TargetClosest(true);
npc.velocity.X = npc.velocity.X + (float)npc.direction * 0.25f;
npc.velocity.Y = npc.velocity.Y + (float)npc.directionY * 0.15f;
if (npc.velocity.X > 8f)
{
npc.velocity.X = 8f;
}
if (npc.velocity.X < -8f)
{
npc.velocity.X = -8f;
}
if (npc.velocity.Y > 6f)
{
npc.velocity.Y = 6f;
}
if (npc.velocity.Y < -6f)
{
npc.velocity.Y = -6f;
}
}
else
{
npc.velocity.X = npc.velocity.X + (float)npc.direction * 0.1f;
if (npc.velocity.X < -2.5f || npc.velocity.X > 2.5f)
{
npc.velocity.X = npc.velocity.X * 0.95f;
}
if (npc.ai[0] == -1f)
{
npc.velocity.Y = npc.velocity.Y - 0.01f;
if ((double)npc.velocity.Y < -0.3)
{
npc.ai[0] = 1f;
}
}
else
{
npc.velocity.Y = npc.velocity.Y + 0.01f;
if ((double)npc.velocity.Y > 0.3)
{
npc.ai[0] = -1f;
}
}
}
int num258 = (int)(npc.position.X + (float)(npc.width / 2)) / 16;
int num259 = (int)(npc.position.Y + (float)(npc.height / 2)) / 16;
if (Main.tile[num258, num259 - 1] == null)
{
Main.tile[num258, num259 - 1] = new Tile();
}
if (Main.tile[num258, num259 + 1] == null)
{
Main.tile[num258, num259 + 1] = new Tile();
}
if (Main.tile[num258, num259 + 2] == null)
{
Main.tile[num258, num259 + 2] = new Tile();
}
if (Main.tile[num258, num259 - 1].liquid > 128)
{
if (Main.tile[num258, num259 + 1].active())
{
npc.ai[0] = -1f;
}
else if (Main.tile[num258, num259 + 2].active())
{
npc.ai[0] = -1f;
}
}
if ((double)npc.velocity.Y > 0.4 || (double)npc.velocity.Y < -0.4)
{
npc.velocity.Y = npc.velocity.Y * 0.95f;
}
}
else
{
if (npc.velocity.Y == 0f)
{
npc.velocity.X = npc.velocity.X * 0.94f;
if ((double)npc.velocity.X > -0.2 && (double)npc.velocity.X < 0.2)
{
npc.velocity.X = 0f;
}
}
npc.velocity.Y = npc.velocity.Y + 0.4f;
if (npc.velocity.Y > 12f)
{
npc.velocity.Y = 12f;
}
npc.ai[0] = 1f;
}
npc.rotation = npc.velocity.Y * (float)npc.direction * 0.1f;
if ((double)npc.rotation < -0.2)
{
npc.rotation = -0.2f;
}
if ((double)npc.rotation > 0.2)
{
npc.rotation = 0.2f;
return;
}
}
public override bool? CanBeHitByProjectile(Projectile projectile)
{
if (projectile.minion)
{
return hasBeenHit;
}
return null;
}
public override void FindFrame(int frameHeight)
{
if (!npc.wet)
{
npc.frameCounter = 0.0;
return;
}
npc.frameCounter += hasBeenHit ? 0.15f : 0.075f;
npc.frameCounter %= Main.npcFrameCount[npc.type];
int frame = (int)npc.frameCounter;
npc.frame.Y = frame * frameHeight;
}
public override void OnHitPlayer(Player player, int damage, bool crit)
{
player.AddBuff(BuffID.Bleeding, 180, true);
player.AddBuff(BuffID.Venom, 180, true);
}
public override float SpawnChance(NPCSpawnInfo spawnInfo)
{
if (spawnInfo.playerSafe)
{
return 0f;
}
if (spawnInfo.player.Calamity().ZoneSulphur && spawnInfo.water)
{
return 0.2f;
}
return 0f;
}
public override void NPCLoot()
{
if (Main.rand.NextBool(25))
{
Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, ItemID.DivingHelmet);
}
}
public override void HitEffect(int hitDirection, double damage)
{
for (int k = 0; k < 5; k++)
{
Dust.NewDust(npc.position, npc.width, npc.height, 5, hitDirection, -1f, 0, default, 1f);
}
if (npc.life <= 0)
{
for (int k = 0; k < 25; k++)
{
Dust.NewDust(npc.position, npc.width, npc.height, 5, hitDirection, -1f, 0, default, 1f);
}
}
}
}
}