using System.IO; using CalamityMod.Buffs.DamageOverTime; using CalamityMod.Dusts; using CalamityMod.Events; using CalamityMod.Items.Placeables.Furniture.Trophies; using CalamityMod.Items.Weapons.Ranged; using CalamityMod.NPCs.CalamityAIs.CalamityBossAIs; using CalamityMod.World; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using ReLogic.Content; using Terraria; using Terraria.Audio; using Terraria.GameContent; using Terraria.GameContent.Bestiary; using Terraria.GameContent.ItemDropRules; using Terraria.ID; using Terraria.ModLoader; namespace CalamityMod.NPCs.CalClone { [AutoloadBossHead] public class Cataclysm : ModNPC { public static Asset GlowTexture; public static readonly SoundStyle HitSound = new("CalamityMod/Sounds/Custom/CalamitasClone/CataclysmHit", 3); public static readonly SoundStyle DeathSound = new("CalamityMod/Sounds/Custom/CalamitasClone/CataclysmDeath"); public static readonly SoundStyle FlamethrowerStart = new("CalamityMod/Sounds/Custom/CalamitasClone/BrimstoneFlamethrowerCast"); public static readonly SoundStyle FlamethrowerLoop = new("CalamityMod/Sounds/Custom/CalamitasClone/BrimstoneFlamethrowerLoop"); public override void SetStaticDefaults() { Main.npcFrameCount[NPC.type] = 6; NPCID.Sets.TrailingMode[NPC.type] = 1; NPCID.Sets.BossBestiaryPriority.Add(Type); NPCID.Sets.NPCBestiaryDrawModifiers value = new NPCID.Sets.NPCBestiaryDrawModifiers() { PortraitScale = 0.8f, Scale = 0.5f, PortraitPositionYOverride = 0 }; NPCID.Sets.NPCBestiaryDrawOffset[Type] = value; if (!Main.dedServ) { GlowTexture = ModContent.Request(Texture + "Glow", AssetRequestMode.AsyncLoad); } } public override void SetDefaults() { NPC.BossBar = Main.BigBossProgressBar.NeverValid; NPC.Calamity().canBreakPlayerDefense = true; NPC.GetNPCDamage(); NPC.npcSlots = 5f; NPC.width = 120; NPC.height = 120; if (CalamityWorld.death || BossRushEvent.BossRushActive) NPC.scale *= 1.2f; NPC.defense = (CalamityWorld.death || BossRushEvent.BossRushActive) ? 15 : 10; NPC.DR_NERD((CalamityWorld.death || BossRushEvent.BossRushActive) ? 0.225f : 0.15f); NPC.LifeMaxNERB(11000, 13200, 80000); NPC.aiStyle = -1; AIType = -1; NPC.knockBackResist = 0f; NPC.noGravity = true; NPC.noTileCollide = true; NPC.HitSound = HitSound; NPC.DeathSound = DeathSound; NPC.Calamity().VulnerableToHeat = false; NPC.Calamity().VulnerableToCold = true; NPC.Calamity().VulnerableToWater = true; } public override void SetBestiary(BestiaryDatabase database, BestiaryEntry bestiaryEntry) { int associatedNPCType = ModContent.NPCType(); bestiaryEntry.UIInfoProvider = new CommonEnemyUICollectionInfoProvider(ContentSamples.NpcBestiaryCreditIdsByNpcNetIds[associatedNPCType], quickUnlock: true); bestiaryEntry.Info.AddRange(new IBestiaryInfoElement[] { BestiaryDatabaseNPCsPopulator.CommonTags.SpawnConditions.Times.NightTime, BestiaryDatabaseNPCsPopulator.CommonTags.SpawnConditions.Biomes.Surface, new FlavorTextBestiaryInfoElement("Mods.CalamityMod.Bestiary.Cataclysm") }); } public override void SendExtraAI(BinaryWriter writer) { for (int i = 0; i < 4; i++) writer.Write(NPC.Calamity().newAI[i]); } public override void ReceiveExtraAI(BinaryReader reader) { for (int i = 0; i < 4; i++) NPC.Calamity().newAI[i] = reader.ReadSingle(); } 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() { CalamitasCloneAI.VanillaCataclysmAI(NPC, Mod); } 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 = 7; 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 afterimageDrawPos = NPC.oldPos[i] + new Vector2((float)NPC.width, (float)NPC.height) / 2f - screenPos; afterimageDrawPos -= new Vector2((float)texture2D15.Width, (float)(texture2D15.Height / Main.npcFrameCount[NPC.type])) * NPC.scale / 2f; afterimageDrawPos += halfSizeTexture * NPC.scale + new Vector2(0f, NPC.gfxOffY); spriteBatch.Draw(texture2D15, afterimageDrawPos, 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 = GlowTexture.Value; Color pinkLerp = Color.Lerp(Color.White, Color.Red, 0.5f); if (CalamityClientConfig.Instance.Afterimages) { for (int j = 1; j < afterimageAmt; j++) { Color extraAfterimageColor = pinkLerp; extraAfterimageColor = Color.Lerp(extraAfterimageColor, Color.White, 0.5f); extraAfterimageColor *= (float)(afterimageAmt - j) / 15f; Vector2 extraAfterimageDrawPos = NPC.oldPos[j] + new Vector2((float)NPC.width, (float)NPC.height) / 2f - screenPos; extraAfterimageDrawPos -= new Vector2((float)texture2D15.Width, (float)(texture2D15.Height / Main.npcFrameCount[NPC.type])) * NPC.scale / 2f; extraAfterimageDrawPos += halfSizeTexture * NPC.scale + new Vector2(0f, NPC.gfxOffY); spriteBatch.Draw(texture2D15, extraAfterimageDrawPos, NPC.frame, extraAfterimageColor, NPC.rotation, halfSizeTexture, NPC.scale, spriteEffects, 0f); } } spriteBatch.Draw(texture2D15, drawLocation, NPC.frame, pinkLerp, NPC.rotation, halfSizeTexture, NPC.scale, spriteEffects, 0f); return false; } public override void ApplyDifficultyAndPlayerScaling(int numPlayers, float balance, float bossAdjustment) { NPC.lifeMax = (int)(NPC.lifeMax * balance); } public override bool CheckActive() => 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 void ModifyNPCLoot(NPCLoot npcLoot) { IItemDropRuleCondition KilledLast = DropHelper.If(() => !NPC.AnyNPCs(ModContent.NPCType()), desc: DropHelper.CataclysmKilledLast); npcLoot.Add(ItemDropRule.ByCondition(KilledLast, ModContent.ItemType(), 5)); npcLoot.Add(ItemDropRule.ByCondition(KilledLast, ModContent.ItemType())); } public override void HitEffect(NPC.HitInfo hit) { for (int k = 0; k < 5; k++) { Dust.NewDust(NPC.position, NPC.width, NPC.height, (int)CalamityDusts.Brimstone, 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("Cataclysm").Type, NPC.scale); Gore.NewGore(NPC.GetSource_Death(), NPC.position, NPC.velocity, Mod.Find("Cataclysm2").Type, NPC.scale); Gore.NewGore(NPC.GetSource_Death(), NPC.position, NPC.velocity, Mod.Find("Cataclysm3").Type, NPC.scale); Gore.NewGore(NPC.GetSource_Death(), NPC.position, NPC.velocity, Mod.Find("Cataclysm4").Type, NPC.scale); Gore.NewGore(NPC.GetSource_Death(), NPC.position, NPC.velocity, Mod.Find("Cataclysm5").Type, NPC.scale); } NPC.position.X = NPC.position.X + (float)(NPC.width / 2); NPC.position.Y = NPC.position.Y + (float)(NPC.height / 2); NPC.width = 100; NPC.height = 100; NPC.position.X = NPC.position.X - (float)(NPC.width / 2); NPC.position.Y = NPC.position.Y - (float)(NPC.height / 2); for (int i = 0; i < 40; i++) { int brimDust = Dust.NewDust(NPC.position, NPC.width, NPC.height, (int)CalamityDusts.Brimstone, 0f, 0f, 100, default, 2f); Main.dust[brimDust].velocity *= 3f; if (Main.rand.NextBool()) { Main.dust[brimDust].scale = 0.5f; Main.dust[brimDust].fadeIn = 1f + (float)Main.rand.Next(10) * 0.1f; } } for (int j = 0; j < 70; j++) { int brimDust2 = Dust.NewDust(NPC.position, NPC.width, NPC.height, (int)CalamityDusts.Brimstone, 0f, 0f, 100, default, 3f); Main.dust[brimDust2].noGravity = true; Main.dust[brimDust2].velocity *= 5f; brimDust2 = Dust.NewDust(NPC.position, NPC.width, NPC.height, (int)CalamityDusts.Brimstone, 0f, 0f, 100, default, 2f); Main.dust[brimDust2].velocity *= 2f; } } } public override bool CanHitPlayer(Player target, ref int cooldownSlot) { cooldownSlot = ImmunityCooldownID.Bosses; return true; } public override void OnHitPlayer(Player target, Player.HurtInfo hurtInfo) { if (hurtInfo.Damage > 0) target.AddBuff(ModContent.BuffType(), 120, true); } } }