using CalamityMod.Items.Accessories; using CalamityMod.Items.Placeables.Banners; using System.IO; using Terraria; using Terraria.GameContent.Bestiary; using Terraria.ID; using Terraria.ModLoader; using Terraria.ModLoader.Utilities; namespace CalamityMod.NPCs.NormalNPCs { public class CrawlerRuby : ModNPC { private bool detected = false; public override void SetStaticDefaults() { Main.npcFrameCount[NPC.type] = 5; } public override void SetDefaults() { NPC.npcSlots = 0.3f; NPC.aiStyle = -1; NPC.damage = 23; NPC.width = 44; NPC.height = 34; NPC.defense = 8; NPC.lifeMax = 135; NPC.knockBackResist = 0.45f; AIType = -1; NPC.value = Item.buyPrice(0, 0, 1, 0); NPC.HitSound = SoundID.NPCHit33; NPC.DeathSound = SoundID.NPCDeath36; Banner = NPC.type; BannerItem = ModContent.ItemType(); NPC.Calamity().VulnerableToHeat = true; NPC.Calamity().VulnerableToCold = true; NPC.Calamity().VulnerableToSickness = true; } public override void SetBestiary(BestiaryDatabase database, BestiaryEntry bestiaryEntry) { bestiaryEntry.Info.AddRange(new IBestiaryInfoElement[] { BestiaryDatabaseNPCsPopulator.CommonTags.SpawnConditions.Biomes.UndergroundDesert, new FlavorTextBestiaryInfoElement("Mods.CalamityMod.Bestiary.GemCrawler") }); } public override void SendExtraAI(BinaryWriter writer) { writer.Write(detected); } public override void ReceiveExtraAI(BinaryReader reader) { detected = reader.ReadBoolean(); } public override void FindFrame(int frameHeight) { if (!detected) { NPC.frame.Y = frameHeight * 4; NPC.frameCounter = 0.0; return; } NPC.spriteDirection = -NPC.direction; NPC.frameCounter += (double)(NPC.velocity.Length() / 8f); if (NPC.frameCounter > 2.0) { NPC.frame.Y = NPC.frame.Y + frameHeight; NPC.frameCounter = 0.0; } if (NPC.frame.Y >= frameHeight * 3) { NPC.frame.Y = 0; } } public override void AI() { if (!detected) NPC.TargetClosest(); if (((Main.player[NPC.target].Center - NPC.Center).Length() < 100f && Collision.CanHit(NPC.position, NPC.width, NPC.height, Main.player[NPC.target].position, Main.player[NPC.target].width, Main.player[NPC.target].height)) || NPC.justHit) detected = true; if (!detected) return; CalamityAI.GemCrawlerAI(NPC, Mod, 6f, 0.06f); } public override float SpawnChance(NPCSpawnInfo spawnInfo) { if (spawnInfo.PlayerSafe || spawnInfo.Player.Calamity().ZoneAbyss || spawnInfo.Player.Calamity().ZoneSunkenSea) { return 0f; } return SpawnCondition.Cavern.Chance * 0.025f; } public override void HitEffect(NPC.HitInfo hit) { for (int k = 0; k < 5; k++) { Dust.NewDust(NPC.position, NPC.width, NPC.height, 12, hit.HitDirection, -1f, 0, default, 1f); } if (NPC.life <= 0) { for (int k = 0; k < 20; k++) { Dust.NewDust(NPC.position, NPC.width, NPC.height, 12, hit.HitDirection, -1f, 0, default, 1f); } if (Main.netMode != NetmodeID.Server) { Gore.NewGore(NPC.GetSource_Death(), NPC.position, NPC.velocity, Mod.Find("CrawlerRuby").Type, 1f); Gore.NewGore(NPC.GetSource_Death(), NPC.position, NPC.velocity, Mod.Find("CrawlerRuby2").Type, 1f); Gore.NewGore(NPC.GetSource_Death(), NPC.position, NPC.velocity, Mod.Find("Crawler").Type, 1f); Gore.NewGore(NPC.GetSource_Death(), NPC.position, NPC.velocity, Mod.Find("Crawler2").Type, 1f); } } } public override void ModifyNPCLoot(NPCLoot npcLoot) { npcLoot.Add(ItemID.Ruby, 1, 2, 4); npcLoot.Add(ModContent.ItemType(), 6); } } }