128 lines
4.7 KiB
C#
128 lines
4.7 KiB
C#
using CalamityMod.Items.Materials;
|
|
using Microsoft.Xna.Framework;
|
|
using System;
|
|
using Terraria;
|
|
using Terraria.ID;
|
|
using Terraria.ModLoader;
|
|
|
|
namespace CalamityMod.NPCs.NormalNPCs
|
|
{
|
|
public class Cryocore : ModNPC
|
|
{
|
|
public override void SetStaticDefaults()
|
|
{
|
|
DisplayName.SetDefault("Cryocore");
|
|
Main.npcFrameCount[NPC.type] = 5;
|
|
}
|
|
|
|
public override void SetDefaults()
|
|
{
|
|
NPC.damage = 35;
|
|
NPC.width = 40;
|
|
NPC.height = 40;
|
|
NPC.defense = 6;
|
|
NPC.lifeMax = 220;
|
|
NPC.aiStyle = -1;
|
|
AIType = -1;
|
|
NPC.value = Item.buyPrice(0, 0, 3, 50);
|
|
NPC.knockBackResist = 0.75f;
|
|
NPC.noGravity = true;
|
|
NPC.HitSound = SoundID.NPCHit5;
|
|
NPC.DeathSound = SoundID.NPCDeath15;
|
|
NPC.Calamity().VulnerableToHeat = true;
|
|
NPC.Calamity().VulnerableToCold = false;
|
|
NPC.Calamity().VulnerableToSickness = false;
|
|
}
|
|
|
|
public override void FindFrame(int frameHeight)
|
|
{
|
|
NPC.frameCounter += 0.15f;
|
|
NPC.frameCounter %= Main.npcFrameCount[NPC.type];
|
|
int frame = (int)NPC.frameCounter;
|
|
NPC.frame.Y = frame * frameHeight;
|
|
}
|
|
|
|
public override void AI()
|
|
{
|
|
Lighting.AddLight((int)((NPC.position.X + (float)(NPC.width / 2)) / 16f), (int)((NPC.position.Y + (float)(NPC.height / 2)) / 16f), 0.02f, 0.5f, 0.5f);
|
|
NPC.TargetClosest();
|
|
float speed = 11f;
|
|
Vector2 vector167 = new Vector2(NPC.Center.X + (float)(NPC.direction * 20), NPC.Center.Y + 6f);
|
|
float num1373 = Main.player[NPC.target].position.X + (float)Main.player[NPC.target].width * 0.5f - vector167.X;
|
|
float num1374 = Main.player[NPC.target].Center.Y - vector167.Y;
|
|
float num1375 = (float)Math.Sqrt((double)(num1373 * num1373 + num1374 * num1374));
|
|
float num1376 = speed / num1375;
|
|
num1373 *= num1376;
|
|
num1374 *= num1376;
|
|
NPC.ai[0] -= 1f;
|
|
if (num1375 < 200f || NPC.ai[0] > 0f)
|
|
{
|
|
if (num1375 < 200f)
|
|
{
|
|
NPC.ai[0] = 20f;
|
|
}
|
|
if (NPC.velocity.X < 0f)
|
|
{
|
|
NPC.direction = -1;
|
|
}
|
|
else
|
|
{
|
|
NPC.direction = 1;
|
|
}
|
|
NPC.rotation += (float)NPC.direction * 0.3f;
|
|
return;
|
|
}
|
|
NPC.velocity.X = (NPC.velocity.X * 50f + num1373) / 51f;
|
|
NPC.velocity.Y = (NPC.velocity.Y * 50f + num1374) / 51f;
|
|
if (num1375 < 350f)
|
|
{
|
|
NPC.velocity.X = (NPC.velocity.X * 10f + num1373) / 11f;
|
|
NPC.velocity.Y = (NPC.velocity.Y * 10f + num1374) / 11f;
|
|
}
|
|
if (num1375 < 300f)
|
|
{
|
|
NPC.velocity.X = (NPC.velocity.X * 7f + num1373) / 8f;
|
|
NPC.velocity.Y = (NPC.velocity.Y * 7f + num1374) / 8f;
|
|
}
|
|
NPC.rotation = NPC.velocity.X * 0.15f;
|
|
}
|
|
|
|
public override float SpawnChance(NPCSpawnInfo spawnInfo)
|
|
{
|
|
return spawnInfo.Player.ZoneSnow &&
|
|
spawnInfo.Player.ZoneOverworldHeight &&
|
|
!spawnInfo.Player.PillarZone() &&
|
|
!spawnInfo.Player.ZoneDungeon &&
|
|
!spawnInfo.Player.InSunkenSea() &&
|
|
Main.hardMode && !spawnInfo.PlayerInTown && !spawnInfo.Player.ZoneOldOneArmy && !Main.snowMoon && !Main.pumpkinMoon ? 0.01f : 0f;
|
|
}
|
|
|
|
public override void OnHitPlayer(Player player, int damage, bool crit)
|
|
{
|
|
player.AddBuff(BuffID.Frostburn, 90, true);
|
|
player.AddBuff(BuffID.Chilled, 60, true);
|
|
}
|
|
|
|
public override void HitEffect(int hitDirection, double damage)
|
|
{
|
|
for (int k = 0; k < 5; k++)
|
|
{
|
|
Dust.NewDust(NPC.position, NPC.width, NPC.height, 67, hitDirection, -1f, 0, default, 1f);
|
|
}
|
|
if (NPC.life <= 0)
|
|
{
|
|
for (int k = 0; k < 20; k++)
|
|
{
|
|
Dust.NewDust(NPC.position, NPC.width, NPC.height, 67, hitDirection, -1f, 0, default, 1f);
|
|
}
|
|
if (Main.netMode != NetmodeID.Server)
|
|
{
|
|
Gore.NewGore(NPC.GetSource_Death(), NPC.position, NPC.velocity, Mod.Find<ModGore>("Cryocore").Type, 1f);
|
|
}
|
|
}
|
|
}
|
|
|
|
public override void ModifyNPCLoot(NPCLoot npcLoot) => npcLoot.Add(ModContent.ItemType<EssenceofEleum>(), 3);
|
|
}
|
|
}
|