using System; using CalamityMod.Dusts; using CalamityMod.Events; using CalamityMod.NPCs.ProfanedGuardians; using CalamityMod.World; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Terraria; using Terraria.GameContent; using Terraria.ID; using Terraria.ModLoader; namespace CalamityMod.NPCs.Providence { [AutoloadBossHead] public class ProvSpawnOffense : ModNPC { private bool start = true; public override string Texture => "CalamityMod/NPCs/ProfanedGuardians/ProfanedGuardianCommander"; public override void SetStaticDefaults() { this.HideFromBestiary(); Main.npcFrameCount[NPC.type] = 10; NPCID.Sets.NeedsExpertScaling[NPC.type] = true; NPCID.Sets.TrailingMode[NPC.type] = 1; } public override void SetDefaults() { NPC.BossBar = Main.BigBossProgressBar.NeverValid; NPC.Calamity().canBreakPlayerDefense = true; NPC.npcSlots = 1f; NPC.aiStyle = -1; NPC.damage = 0; NPC.width = 228; NPC.height = 186; NPC.defense = 40; NPC.DR_NERD(0.3f); NPC.lifeMax = 31875; if (BossRushEvent.BossRushActive) { NPC.lifeMax = 40000; } 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; // Scale stats in Expert and Master CalamityGlobalNPC.AdjustExpertModeStatScaling(NPC); CalamityGlobalNPC.AdjustMasterModeStatScaling(NPC); } public override void FindFrame(int frameHeight) { if (CalamityGlobalNPC.holyBoss < 0 || !Main.npc[CalamityGlobalNPC.holyBoss].active) NPC.frameCounter += 0.2f; else NPC.frameCounter += 0.12f + Main.npc[CalamityGlobalNPC.holyBoss].velocity.Length() / 120f; NPC.frameCounter %= Main.npcFrameCount[NPC.type]; int frame = (int)NPC.frameCounter; NPC.frame.Y = frame * frameHeight; } public override void AI() { CalamityGlobalNPC.holyBossAttacker = NPC.whoAmI; if (CalamityGlobalNPC.holyBoss < 0 || !Main.npc[CalamityGlobalNPC.holyBoss].active) { NPC.life = 0; NPC.HitEffect(); NPC.active = false; NPC.netUpdate = true; return; } // Rotation NPC.rotation = Main.npc[CalamityGlobalNPC.holyBoss].velocity.X * 0.005f; 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 = 450; 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, Vector2 screenPos, Color drawColor) { SpriteEffects spriteEffects = SpriteEffects.None; if (NPC.spriteDirection == 1) spriteEffects = SpriteEffects.FlipHorizontally; Texture2D texture2D15 = TextureAssets.Npc[NPC.type].Value; Vector2 halfSizeTexture = new Vector2((float)(TextureAssets.Npc[NPC.type].Value.Width / 2), (float)(TextureAssets.Npc[NPC.type].Value.Height / Main.npcFrameCount[NPC.type] / 2)); int afterimageAmt = 5; if (NPC.ai[0] == 2f) afterimageAmt = 10; if (CalamityClientConfig.Instance.Afterimages) { for (int i = 1; i < afterimageAmt; i += 2) { Color afterimageColor = drawColor; afterimageColor = Color.Lerp(afterimageColor, Color.White, 0.5f); afterimageColor = NPC.GetAlpha(afterimageColor); afterimageColor *= (float)(afterimageAmt - i) / 15f; Vector2 afterimagePos = NPC.oldPos[i] + new Vector2((float)NPC.width, (float)NPC.height) / 2f - screenPos; afterimagePos -= new Vector2((float)texture2D15.Width, (float)(texture2D15.Height / Main.npcFrameCount[NPC.type])) * NPC.scale / 2f; afterimagePos += halfSizeTexture * NPC.scale + new Vector2(0f, NPC.gfxOffY); spriteBatch.Draw(texture2D15, afterimagePos, NPC.frame, afterimageColor, NPC.rotation, halfSizeTexture, NPC.scale, spriteEffects, 0f); } } Vector2 drawLocation = NPC.Center - screenPos; drawLocation -= new Vector2((float)texture2D15.Width, (float)(texture2D15.Height / Main.npcFrameCount[NPC.type])) * NPC.scale / 2f; drawLocation += halfSizeTexture * NPC.scale + new Vector2(0f, NPC.gfxOffY); spriteBatch.Draw(texture2D15, drawLocation, NPC.frame, NPC.GetAlpha(drawColor), NPC.rotation, halfSizeTexture, NPC.scale, spriteEffects, 0f); texture2D15 = ProfanedGuardianCommander.Texture_Glow.Value; Color yellowLerpColor = Color.Lerp(Color.White, Color.Yellow, 0.5f); if (CalamityClientConfig.Instance.Afterimages) { for (int j = 1; j < afterimageAmt; j++) { Color yellowAfterimageColor = yellowLerpColor; yellowAfterimageColor = Color.Lerp(yellowAfterimageColor, Color.White, 0.5f); yellowAfterimageColor = NPC.GetAlpha(yellowAfterimageColor); yellowAfterimageColor *= (float)(afterimageAmt - j) / 15f; Vector2 yellowAfterimagePos = NPC.oldPos[j] + new Vector2((float)NPC.width, (float)NPC.height) / 2f - screenPos; yellowAfterimagePos -= new Vector2((float)texture2D15.Width, (float)(texture2D15.Height / Main.npcFrameCount[NPC.type])) * NPC.scale / 2f; yellowAfterimagePos += halfSizeTexture * NPC.scale + new Vector2(0f, NPC.gfxOffY); spriteBatch.Draw(texture2D15, yellowAfterimagePos, NPC.frame, yellowAfterimageColor, NPC.rotation, halfSizeTexture, NPC.scale, spriteEffects, 0f); } } NPC.DrawBackglow(ProvUtils.GetDayNightColor(0, true), 4f, spriteEffects, NPC.frame, Main.screenPosition, texture2D15); spriteBatch.Draw(texture2D15, drawLocation, NPC.frame, ProvUtils.GetDayNightColor(0), NPC.rotation, halfSizeTexture, NPC.scale, spriteEffects, 0f); return false; } public override void OnKill() { int heartAmt = Main.rand.Next(3) + 3; for (int i = 0; i < heartAmt; i++) Item.NewItem(NPC.GetSource_Loot(), (int)NPC.position.X, (int)NPC.position.Y, NPC.width, NPC.height, ItemID.Heart); } public override bool CheckActive() => false; public override void HitEffect(NPC.HitInfo hit) { for (int k = 0; k < 3; k++) Dust.NewDust(NPC.position, NPC.width, NPC.height, (int)CalamityDusts.ProfanedFire, hit.HitDirection, -1f, 0, default, 1f); if (NPC.life <= 0) { if (Main.netMode != NetmodeID.Server) { Gore.NewGore(NPC.GetSource_Death(), NPC.position, NPC.velocity, Mod.Find("ProfanedGuardianBossA").Type, 1f); Gore.NewGore(NPC.GetSource_Death(), NPC.position, NPC.velocity, Mod.Find("ProfanedGuardianBossA2").Type, 1f); Gore.NewGore(NPC.GetSource_Death(), NPC.position, NPC.velocity, Mod.Find("ProfanedGuardianBossA3").Type, 1f); Gore.NewGore(NPC.GetSource_Death(), NPC.position, NPC.velocity, Mod.Find("ProfanedGuardianBossA4").Type, 1f); } for (int k = 0; k < 30; k++) Dust.NewDust(NPC.position, NPC.width, NPC.height, (int)CalamityDusts.ProfanedFire, hit.HitDirection, -1f, 0, default, 1f); } } } }