using CalamityMod.Buffs.DamageOverTime; using CalamityMod.Dusts; using CalamityMod.Events; using CalamityMod.Projectiles.Boss; using CalamityMod.World; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using System; using System.IO; using Terraria; using Terraria.ID; using Terraria.ModLoader; namespace CalamityMod.NPCs.Providence { [AutoloadBossHead] public class ProvSpawnOffense : ModNPC { private bool start = true; public override void SetStaticDefaults() { DisplayName.SetDefault("A Profaned Guardian"); Main.npcFrameCount[npc.type] = 6; NPCID.Sets.TrailingMode[npc.type] = 1; } public override void SetDefaults() { npc.Calamity().canBreakPlayerDefense = true; npc.npcSlots = 1f; npc.aiStyle = -1; npc.GetNPCDamage(); npc.width = 100; npc.height = 80; npc.defense = 40; npc.DR_NERD(0.3f); npc.lifeMax = 31875; if (BossRushEvent.BossRushActive) { npc.lifeMax = 40000; } double HPBoost = CalamityConfig.Instance.BossHealthBoost * 0.01; npc.lifeMax += (int)(npc.lifeMax * HPBoost); npc.knockBackResist = 0f; npc.noGravity = true; npc.noTileCollide = true; aiType = -1; npc.HitSound = SoundID.NPCHit52; npc.DeathSound = SoundID.NPCDeath55; npc.Calamity().VulnerableToHeat = false; npc.Calamity().VulnerableToCold = true; npc.Calamity().VulnerableToSickness = false; npc.Calamity().VulnerableToWater = true; } public override void SendExtraAI(BinaryWriter writer) { writer.Write(npc.dontTakeDamage); } public override void ReceiveExtraAI(BinaryReader reader) { npc.dontTakeDamage = reader.ReadBoolean(); } 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() { // Setting this in SetDefaults will disable expert mode scaling, so put it here instead npc.damage = 0; CalamityGlobalNPC.holyBossAttacker = npc.whoAmI; if (CalamityGlobalNPC.holyBoss < 0 || !Main.npc[CalamityGlobalNPC.holyBoss].active) { npc.active = false; npc.netUpdate = true; return; } npc.dontTakeDamage = Main.npc[CalamityGlobalNPC.holyBoss].dontTakeDamage; NPC parent = Main.npc[CalamityGlobalNPC.holyBoss]; if (start) { for (int d = 0; d < 30; d++) Dust.NewDust(npc.position, npc.width, npc.height, (int)CalamityDusts.ProfanedFire, 0f, 0f, 100, default, 2f); npc.ai[1] = npc.ai[0]; start = false; } float playerLocation = npc.Center.X - Main.player[Main.npc[CalamityGlobalNPC.holyBoss].target].Center.X; npc.direction = playerLocation < 0 ? 1 : -1; npc.spriteDirection = npc.direction; double deg = npc.ai[1]; double rad = deg * (Math.PI / 180); double dist = 400; npc.position.X = parent.Center.X - (int)(Math.Cos(rad) * dist) - npc.width / 2; npc.position.Y = parent.Center.Y - (int)(Math.Sin(rad) * dist) - npc.height / 2; npc.ai[1] += 1f; } public override bool PreDraw(SpriteBatch spriteBatch, Color lightColor) { SpriteEffects spriteEffects = SpriteEffects.None; if (npc.spriteDirection == 1) spriteEffects = SpriteEffects.FlipHorizontally; Texture2D texture2D15 = Main.npcTexture[npc.type]; Vector2 vector11 = new Vector2((float)(Main.npcTexture[npc.type].Width / 2), (float)(Main.npcTexture[npc.type].Height / Main.npcFrameCount[npc.type] / 2)); Color color36 = Color.White; float amount9 = 0.5f; int num153 = 5; if (npc.ai[0] == 2f) num153 = 10; if (CalamityConfig.Instance.Afterimages) { for (int num155 = 1; num155 < num153; num155 += 2) { Color color38 = lightColor; color38 = Color.Lerp(color38, color36, amount9); color38 = npc.GetAlpha(color38); color38 *= (float)(num153 - num155) / 15f; Vector2 vector41 = npc.oldPos[num155] + new Vector2((float)npc.width, (float)npc.height) / 2f - Main.screenPosition; vector41 -= new Vector2((float)texture2D15.Width, (float)(texture2D15.Height / Main.npcFrameCount[npc.type])) * npc.scale / 2f; vector41 += vector11 * npc.scale + new Vector2(0f, npc.gfxOffY); spriteBatch.Draw(texture2D15, vector41, npc.frame, color38, npc.rotation, vector11, npc.scale, spriteEffects, 0f); } } Vector2 vector43 = npc.Center - Main.screenPosition; vector43 -= new Vector2((float)texture2D15.Width, (float)(texture2D15.Height / Main.npcFrameCount[npc.type])) * npc.scale / 2f; vector43 += vector11 * npc.scale + new Vector2(0f, npc.gfxOffY); spriteBatch.Draw(texture2D15, vector43, npc.frame, npc.GetAlpha(lightColor), npc.rotation, vector11, npc.scale, spriteEffects, 0f); texture2D15 = ModContent.GetTexture("CalamityMod/NPCs/ProfanedGuardians/ProfanedGuardianBossGlow"); Color color37 = Color.Lerp(Color.White, Color.Yellow, 0.5f); if (CalamityConfig.Instance.Afterimages) { for (int num163 = 1; num163 < num153; num163++) { Color color41 = color37; color41 = Color.Lerp(color41, color36, amount9); color41 = npc.GetAlpha(color41); color41 *= (float)(num153 - num163) / 15f; Vector2 vector44 = npc.oldPos[num163] + new Vector2((float)npc.width, (float)npc.height) / 2f - Main.screenPosition; vector44 -= new Vector2((float)texture2D15.Width, (float)(texture2D15.Height / Main.npcFrameCount[npc.type])) * npc.scale / 2f; vector44 += vector11 * npc.scale + new Vector2(0f, npc.gfxOffY); spriteBatch.Draw(texture2D15, vector44, npc.frame, color41, npc.rotation, vector11, npc.scale, spriteEffects, 0f); } } spriteBatch.Draw(texture2D15, vector43, npc.frame, color37, npc.rotation, vector11, npc.scale, spriteEffects, 0f); return false; } public override void NPCLoot() { if (!CalamityWorld.malice && !CalamityWorld.revenge) { int heartAmt = Main.rand.Next(3) + 3; for (int i = 0; i < heartAmt; i++) Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, ItemID.Heart); } } public override bool CheckActive() => false; public override void HitEffect(int hitDirection, double damage) { for (int k = 0; k < 3; k++) Dust.NewDust(npc.position, npc.width, npc.height, (int)CalamityDusts.ProfanedFire, hitDirection, -1f, 0, default, 1f); if (npc.life <= 0) { Gore.NewGore(npc.position, npc.velocity, mod.GetGoreSlot("Gores/ProfanedGuardianBossGores/ProfanedGuardianBossA"), 1f); Gore.NewGore(npc.position, npc.velocity, mod.GetGoreSlot("Gores/ProfanedGuardianBossGores/ProfanedGuardianBossA2"), 1f); Gore.NewGore(npc.position, npc.velocity, mod.GetGoreSlot("Gores/ProfanedGuardianBossGores/ProfanedGuardianBossA3"), 1f); Gore.NewGore(npc.position, npc.velocity, mod.GetGoreSlot("Gores/ProfanedGuardianBossGores/ProfanedGuardianBossA4"), 1f); for (int k = 0; k < 30; k++) Dust.NewDust(npc.position, npc.width, npc.height, (int)CalamityDusts.ProfanedFire, hitDirection, -1f, 0, default, 1f); } } } }