using CalamityMod.Buffs.StatDebuffs; using CalamityMod.Items.Accessories; using CalamityMod.Items.Materials; using CalamityMod.Items.Placeables.Banners; using CalamityMod.Items.Weapons.Summon; using CalamityMod.World; using Microsoft.Xna.Framework; using System; using Terraria; using Terraria.ID; using Terraria.ModLoader; namespace CalamityMod.NPCs.NormalNPCs { public class IceClasper : ModNPC { public override void SetStaticDefaults() { DisplayName.SetDefault("Ice Clasper"); Main.npcFrameCount[npc.type] = 6; } public override void SetDefaults() { npc.npcSlots = 3f; npc.noGravity = true; npc.damage = 32; npc.width = 40; npc.height = 40; npc.defense = 12; npc.lifeMax = 600; npc.knockBackResist = 0.35f; npc.aiStyle = -1; aiType = -1; npc.value = Item.buyPrice(0, 0, 25, 0); npc.HitSound = SoundID.NPCHit5; npc.DeathSound = SoundID.NPCDeath7; npc.coldDamage = true; npc.rarity = 2; banner = npc.type; bannerItem = ModContent.ItemType(); npc.coldDamage = true; npc.Calamity().VulnerableToHeat = true; npc.Calamity().VulnerableToCold = false; npc.Calamity().VulnerableToSickness = false; } public override void AI() { bool revenge = CalamityWorld.revenge; if (npc.target < 0 || npc.target == 255 || Main.player[npc.target].dead) { npc.TargetClosest(true); } float num = revenge ? 7f : 6f; float num2 = revenge ? 0.07f : 0.06f; if (CalamityWorld.death) { num *= 1.5f; num2 *= 1.5f; } Vector2 vector = new Vector2(npc.position.X + (float)npc.width * 0.5f, npc.position.Y + (float)npc.height * 0.5f); float num4 = Main.player[npc.target].position.X + (float)(Main.player[npc.target].width / 2); float num5 = Main.player[npc.target].position.Y + (float)(Main.player[npc.target].height / 2); num4 = (float)((int)(num4 / 8f) * 8); num5 = (float)((int)(num5 / 8f) * 8); vector.X = (float)((int)(vector.X / 8f) * 8); vector.Y = (float)((int)(vector.Y / 8f) * 8); num4 -= vector.X; num5 -= vector.Y; float num6 = (float)Math.Sqrt((double)(num4 * num4 + num5 * num5)); float num7 = num6; bool flag = false; if (num6 > 600f) { flag = true; } if (num6 == 0f) { num4 = npc.velocity.X; num5 = npc.velocity.Y; } else { num6 = num / num6; num4 *= num6; num5 *= num6; } if (num7 > 100f) { npc.ai[0] += 1f; if (npc.ai[0] > 0f) { npc.velocity.Y = npc.velocity.Y + 0.023f; } else { npc.velocity.Y = npc.velocity.Y - 0.023f; } if (npc.ai[0] < -100f || npc.ai[0] > 100f) { npc.velocity.X = npc.velocity.X + 0.023f; } else { npc.velocity.X = npc.velocity.X - 0.023f; } if (npc.ai[0] > 200f) { npc.ai[0] = -200f; } } if (Main.player[npc.target].dead) { num4 = (float)npc.direction * num / 2f; num5 = -num / 2f; } if (npc.velocity.X < num4) { npc.velocity.X = npc.velocity.X + num2; } else if (npc.velocity.X > num4) { npc.velocity.X = npc.velocity.X - num2; } if (npc.velocity.Y < num5) { npc.velocity.Y = npc.velocity.Y + num2; } else if (npc.velocity.Y > num5) { npc.velocity.Y = npc.velocity.Y - num2; } npc.localAI[0] += 1f; if (Main.netMode != NetmodeID.MultiplayerClient && npc.localAI[0] >= 150f) { npc.localAI[0] = 0f; if (Collision.CanHit(npc.position, npc.width, npc.height, Main.player[npc.target].position, Main.player[npc.target].width, Main.player[npc.target].height)) { int num9 = ProjectileID.FrostBlastHostile; int beam = Projectile.NewProjectile(vector.X, vector.Y, num4, num5, num9, 45, 0f, Main.myPlayer, 0f, 0f); Main.projectile[beam].timeLeft = 300; } } int num10 = (int)npc.position.X + npc.width / 2; int num11 = (int)npc.position.Y + npc.height / 2; num10 /= 16; num11 /= 16; if (!WorldGen.SolidTile(num10, num11)) { Lighting.AddLight((int)((npc.position.X + (float)(npc.width / 2)) / 16f), (int)((npc.position.Y + (float)(npc.height / 2)) / 16f), 0f, 0.6f, 0.75f); } Vector2 vector92 = new Vector2(npc.Center.X, npc.Center.Y); float num740 = Main.player[npc.target].Center.X - vector92.X; float num741 = Main.player[npc.target].Center.Y - vector92.Y; npc.rotation = (float)Math.Atan2((double)num741, (double)num740) - 1.57f; if (Collision.CanHit(npc.position, npc.width, npc.height, Main.player[npc.target].position, Main.player[npc.target].width, Main.player[npc.target].height)) { if (npc.ai[2] > 0f && !Collision.SolidCollision(npc.position, npc.width, npc.height)) { npc.ai[2] = 0f; npc.ai[1] = 0f; npc.netUpdate = true; } } else if (npc.ai[2] == 0f) { npc.ai[1] += 1f; } if (npc.ai[1] >= 150f) { npc.ai[2] = 1f; npc.ai[1] = 0f; npc.netUpdate = true; } if (npc.ai[2] == 0f) { npc.alpha = 0; npc.noTileCollide = false; } else { npc.wet = false; npc.alpha = 200; npc.noTileCollide = true; } float num12 = 0.7f; if (npc.collideX) { npc.netUpdate = true; npc.velocity.X = npc.oldVelocity.X * -num12; if (npc.direction == -1 && npc.velocity.X > 0f && npc.velocity.X < 2f) { npc.velocity.X = 2f; } if (npc.direction == 1 && npc.velocity.X < 0f && npc.velocity.X > -2f) { npc.velocity.X = -2f; } } if (npc.collideY) { npc.netUpdate = true; npc.velocity.Y = npc.oldVelocity.Y * -num12; if (npc.velocity.Y > 0f && (double)npc.velocity.Y < 1.5) { npc.velocity.Y = 2f; } if (npc.velocity.Y < 0f && (double)npc.velocity.Y > -1.5) { npc.velocity.Y = -2f; } } if (flag) { if ((npc.velocity.X > 0f && num4 > 0f) || (npc.velocity.X < 0f && num4 < 0f)) { if (Math.Abs(npc.velocity.X) < 12f) { npc.velocity.X = npc.velocity.X * 1.05f; } } else { npc.velocity.X = npc.velocity.X * 0.9f; } } if (((npc.velocity.X > 0f && npc.oldVelocity.X < 0f) || (npc.velocity.X < 0f && npc.oldVelocity.X > 0f) || (npc.velocity.Y > 0f && npc.oldVelocity.Y < 0f) || (npc.velocity.Y < 0f && npc.oldVelocity.Y > 0f)) && !npc.justHit) { npc.netUpdate = true; } } 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 float SpawnChance(NPCSpawnInfo spawnInfo) { return spawnInfo.player.ZoneSnow && !spawnInfo.player.PillarZone() && !spawnInfo.player.ZoneDungeon && !spawnInfo.player.InSunkenSea() && Main.hardMode && !spawnInfo.playerInTown && !spawnInfo.player.ZoneOldOneArmy && !Main.snowMoon && !Main.pumpkinMoon ? 0.007f : 0f; } public override void OnHitPlayer(Player player, int damage, bool crit) { player.AddBuff(BuffID.Frostburn, 180, true); player.AddBuff(BuffID.Chilled, 120, true); } public override void HitEffect(int hitDirection, double damage) { for (int k = 0; k < 3; k++) { Dust.NewDust(npc.position, npc.width, npc.height, 92, hitDirection, -1f, 0, default, 1f); } if (npc.life <= 0) { for (int k = 0; k < 15; k++) { Dust.NewDust(npc.position, npc.width, npc.height, 92, hitDirection, -1f, 0, default, 1f); } } } public override void NPCLoot() { DropHelper.DropItem(npc, ModContent.ItemType()); DropHelper.DropItemChance(npc, ModContent.ItemType(), 10); DropHelper.DropItemChance(npc, ModContent.ItemType(), 3); } } }