using CalamityMod.NPCs.NormalNPCs; using CalamityMod.NPCs.NormalNPCs.HorribleHog; using Terraria; using Terraria.ID; using Terraria.ModLoader; namespace CalamityMod.Projectiles { public class PowderTransformationsProjectile : GlobalProjectile { public override bool AppliesToEntity(Projectile entity, bool lateInstantiation) { return entity.type == ProjectileID.VilePowder || entity.type == ProjectileID.ViciousPowder || entity.type == ProjectileID.PurificationPowder; } public override void AI(Projectile projectile) { // Transform certain NPCs into different variants when contact is made with Vile/Vicious Powder or Purification Powder. // Currently only used for Piggy, Divine Swine and Horrible Hog. bool isPurePowder = projectile.type == ProjectileID.PurificationPowder; bool isEvilPowder = projectile.type == ProjectileID.VilePowder || projectile.type == ProjectileID.ViciousPowder; foreach (NPC npc in Main.ActiveNPCs) { bool targetIsPiggy = npc.type == ModContent.NPCType() || npc.type == ModContent.NPCType(); bool targetIsDivineSwine = npc.type == ModContent.NPCType(); bool targetIsHorribleHog = npc.type == ModContent.NPCType(); if (!targetIsPiggy && !targetIsDivineSwine && !targetIsHorribleHog) continue; if (projectile.Hitbox.Intersects(npc.Hitbox)) { if (targetIsPiggy && npc.ModNPC().TryTransformingIntoVariant()) { if (isEvilPowder) npc.ModNPC().TransformIntoVariant(ModContent.NPCType()); else if (isPurePowder) npc.ModNPC().TransformIntoVariant(ModContent.NPCType()); } if (targetIsDivineSwine && isEvilPowder && npc.ModNPC().TryTransformingIntoPiggy()) npc.ModNPC().TransformIntoPiggy(); if (targetIsHorribleHog && isPurePowder && npc.ModNPC().TryTransformingIntoPiggy()) npc.ModNPC().TransformIntoPiggy(); } } } } }