2 - Added weakness and resistance system for debuffs. I'll explain it all later.
148 lines
4.9 KiB
C#
148 lines
4.9 KiB
C#
using CalamityMod.Items.Placeables.Banners;
|
|
using Microsoft.Xna.Framework;
|
|
using Terraria;
|
|
using Terraria.ID;
|
|
using Terraria.ModLoader;
|
|
|
|
namespace CalamityMod.NPCs.Abyss
|
|
{
|
|
public class OarfishBody : ModNPC
|
|
{
|
|
public override void SetStaticDefaults()
|
|
{
|
|
DisplayName.SetDefault("Oarfish");
|
|
}
|
|
|
|
public override void SetDefaults()
|
|
{
|
|
npc.damage = 30; //70
|
|
npc.width = 16; //28
|
|
npc.height = 16; //28
|
|
npc.defense = 20;
|
|
npc.lifeMax = 4000;
|
|
npc.aiStyle = -1; //new
|
|
aiType = -1; //new
|
|
npc.knockBackResist = 0f;
|
|
npc.alpha = 255;
|
|
npc.behindTiles = true;
|
|
npc.noGravity = true;
|
|
npc.noTileCollide = true;
|
|
npc.HitSound = SoundID.NPCHit1;
|
|
npc.DeathSound = SoundID.NPCDeath1;
|
|
npc.netAlways = true;
|
|
npc.dontCountMe = true;
|
|
npc.chaseable = false;
|
|
banner = ModContent.NPCType<OarfishHead>();
|
|
bannerItem = ModContent.ItemType<OarfishBanner>();
|
|
npc.Calamity().VulnerableToHeat = false;
|
|
npc.Calamity().VulnerableToSickness = true;
|
|
npc.Calamity().VulnerableToElectricity = true;
|
|
npc.Calamity().VulnerableToWater = false;
|
|
}
|
|
|
|
public override bool? DrawHealthBar(byte hbPosition, ref float scale, ref Vector2 position)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
public override void AI()
|
|
{
|
|
if (npc.ai[2] > 0f)
|
|
npc.realLife = (int)npc.ai[2];
|
|
|
|
// Check if other segments are still alive, if not, die
|
|
bool shouldDespawn = true;
|
|
for (int i = 0; i < Main.maxNPCs; i++)
|
|
{
|
|
if (Main.npc[i].active && Main.npc[i].type == ModContent.NPCType<OarfishHead>())
|
|
{
|
|
shouldDespawn = false;
|
|
break;
|
|
}
|
|
}
|
|
if (!shouldDespawn)
|
|
{
|
|
if (npc.ai[1] <= 0f)
|
|
shouldDespawn = true;
|
|
else if (Main.npc[(int)npc.ai[1]].life <= 0)
|
|
shouldDespawn = true;
|
|
}
|
|
if (shouldDespawn)
|
|
{
|
|
npc.life = 0;
|
|
npc.HitEffect(0, 10.0);
|
|
npc.checkDead();
|
|
npc.active = false;
|
|
}
|
|
|
|
if (Main.npc[(int)npc.ai[1]].alpha < 128)
|
|
{
|
|
npc.alpha -= 42;
|
|
if (npc.alpha < 0)
|
|
npc.alpha = 0;
|
|
}
|
|
|
|
Vector2 vector18 = new Vector2(npc.position.X + (float)npc.width * 0.5f, npc.position.Y + (float)npc.height * 0.5f);
|
|
float num191 = Main.player[npc.target].position.X + (float)(Main.player[npc.target].width / 2);
|
|
float num192 = Main.player[npc.target].position.Y + (float)(Main.player[npc.target].height / 2);
|
|
num191 = (float)((int)(num191 / 16f) * 16);
|
|
num192 = (float)((int)(num192 / 16f) * 16);
|
|
vector18.X = (float)((int)(vector18.X / 16f) * 16);
|
|
vector18.Y = (float)((int)(vector18.Y / 16f) * 16);
|
|
num191 -= vector18.X;
|
|
num192 -= vector18.Y;
|
|
float num193 = (float)System.Math.Sqrt((double)(num191 * num191 + num192 * num192));
|
|
if (npc.ai[1] > 0f && npc.ai[1] < (float)Main.npc.Length)
|
|
{
|
|
try
|
|
{
|
|
vector18 = new Vector2(npc.position.X + (float)npc.width * 0.5f, npc.position.Y + (float)npc.height * 0.5f);
|
|
num191 = Main.npc[(int)npc.ai[1]].position.X + (float)(Main.npc[(int)npc.ai[1]].width / 2) - vector18.X;
|
|
num192 = Main.npc[(int)npc.ai[1]].position.Y + (float)(Main.npc[(int)npc.ai[1]].height / 2) - vector18.Y;
|
|
} catch
|
|
{
|
|
}
|
|
npc.rotation = (float)System.Math.Atan2((double)num192, (double)num191) + 1.57f;
|
|
num193 = (float)System.Math.Sqrt((double)(num191 * num191 + num192 * num192));
|
|
int num194 = npc.width;
|
|
num193 = (num193 - (float)num194) / num193;
|
|
num191 *= num193;
|
|
num192 *= num193;
|
|
npc.velocity = Vector2.Zero;
|
|
npc.position.X = npc.position.X + num191;
|
|
npc.position.Y = npc.position.Y + num192;
|
|
|
|
if (num191 < 0f)
|
|
npc.spriteDirection = -1;
|
|
else if (num191 > 0f)
|
|
npc.spriteDirection = 1;
|
|
}
|
|
}
|
|
|
|
public override bool CheckActive()
|
|
{
|
|
return false;
|
|
}
|
|
|
|
public override bool PreNPCLoot()
|
|
{
|
|
return false;
|
|
}
|
|
|
|
public override void HitEffect(int hitDirection, double damage)
|
|
{
|
|
for (int k = 0; k < 3; 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 < 10; k++)
|
|
{
|
|
Dust.NewDust(npc.position, npc.width, npc.height, DustID.Blood, hitDirection, -1f, 0, default, 1f);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|