diff --git a/ExtraTextures/ThanatosVentParticle.png b/ExtraTextures/ThanatosVentParticle.png new file mode 100644 index 0000000000..a66a5aa743 Binary files /dev/null and b/ExtraTextures/ThanatosVentParticle.png differ diff --git a/Gores/Thanatos/ThanatosVentParticle1.cs b/Gores/Thanatos/ThanatosVentParticle1.cs deleted file mode 100644 index 6d83177eaa..0000000000 --- a/Gores/Thanatos/ThanatosVentParticle1.cs +++ /dev/null @@ -1,35 +0,0 @@ -using Terraria; -using Terraria.ID; -using Terraria.ModLoader; - -namespace CalamityMod.Gores -{ - public class ThanatosVentParticle1 : ModGore - { - public override void OnSpawn(Gore gore) - { - gore.sticky = false; - } - - public override bool Update(Gore gore) - { - if (Main.netMode == NetmodeID.Server || !gore.active) - return false; - - gore.velocity *= 0.98f; - gore.scale -= 0.007f; - if (gore.scale < 0.1f) - { - gore.scale = 0.1f; - gore.alpha = 255; - } - - gore.position += gore.velocity; - - if (gore.alpha >= 255) - gore.active = false; - - return false; - } - } -} diff --git a/Gores/Thanatos/ThanatosVentParticle1.png b/Gores/Thanatos/ThanatosVentParticle1.png deleted file mode 100644 index ec84d9232c..0000000000 Binary files a/Gores/Thanatos/ThanatosVentParticle1.png and /dev/null differ diff --git a/Gores/Thanatos/ThanatosVentParticle2.cs b/Gores/Thanatos/ThanatosVentParticle2.cs deleted file mode 100644 index d82e66d768..0000000000 --- a/Gores/Thanatos/ThanatosVentParticle2.cs +++ /dev/null @@ -1,35 +0,0 @@ -using Terraria; -using Terraria.ID; -using Terraria.ModLoader; - -namespace CalamityMod.Gores -{ - public class ThanatosVentParticle2 : ModGore - { - public override void OnSpawn(Gore gore) - { - gore.sticky = false; - } - - public override bool Update(Gore gore) - { - if (Main.netMode == NetmodeID.Server || !gore.active) - return false; - - gore.velocity *= 0.98f; - gore.scale -= 0.007f; - if (gore.scale < 0.1f) - { - gore.scale = 0.1f; - gore.alpha = 255; - } - - gore.position += gore.velocity; - - if (gore.alpha >= 255) - gore.active = false; - - return false; - } - } -} diff --git a/Gores/Thanatos/ThanatosVentParticle2.png b/Gores/Thanatos/ThanatosVentParticle2.png deleted file mode 100644 index 50a693e93e..0000000000 Binary files a/Gores/Thanatos/ThanatosVentParticle2.png and /dev/null differ diff --git a/Gores/Thanatos/ThanatosVentParticle3.cs b/Gores/Thanatos/ThanatosVentParticle3.cs deleted file mode 100644 index 1eee878087..0000000000 --- a/Gores/Thanatos/ThanatosVentParticle3.cs +++ /dev/null @@ -1,35 +0,0 @@ -using Terraria; -using Terraria.ID; -using Terraria.ModLoader; - -namespace CalamityMod.Gores -{ - public class ThanatosVentParticle3 : ModGore - { - public override void OnSpawn(Gore gore) - { - gore.sticky = false; - } - - public override bool Update(Gore gore) - { - if (Main.netMode == NetmodeID.Server || !gore.active) - return false; - - gore.velocity *= 0.98f; - gore.scale -= 0.007f; - if (gore.scale < 0.1f) - { - gore.scale = 0.1f; - gore.alpha = 255; - } - - gore.position += gore.velocity; - - if (gore.alpha >= 255) - gore.active = false; - - return false; - } - } -} \ No newline at end of file diff --git a/Gores/Thanatos/ThanatosVentParticle3.png b/Gores/Thanatos/ThanatosVentParticle3.png deleted file mode 100644 index 221e95e948..0000000000 Binary files a/Gores/Thanatos/ThanatosVentParticle3.png and /dev/null differ diff --git a/NPCs/ExoMechs/Thanatos/ThanatosBody1.cs b/NPCs/ExoMechs/Thanatos/ThanatosBody1.cs index 86e7cd7fb3..14694e9bc7 100644 --- a/NPCs/ExoMechs/Thanatos/ThanatosBody1.cs +++ b/NPCs/ExoMechs/Thanatos/ThanatosBody1.cs @@ -1,6 +1,7 @@ using CalamityMod.Buffs.DamageOverTime; using CalamityMod.Buffs.StatDebuffs; using CalamityMod.Events; +using CalamityMod.Particles; using CalamityMod.Projectiles.Boss; using CalamityMod.World; using Microsoft.Xna.Framework; @@ -17,6 +18,7 @@ namespace CalamityMod.NPCs.ExoMechs.Thanatos { // Whether the body is venting heat or not, it is vulnerable to damage during venting private bool vulnerable = false; + public ThanatosSmokeParticleSet SmokeDrawer = new ThanatosSmokeParticleSet(-1, 4, 0f, 16f, 1.5f); public override void SetStaticDefaults() { @@ -323,6 +325,7 @@ namespace CalamityMod.NPCs.ExoMechs.Thanatos npc.Calamity().unbreakableDR = !vulnerable; // Vent noise and steam + SmokeDrawer.ParticleSpawnRate = 9999999; if (vulnerable) { // Noise @@ -331,17 +334,18 @@ namespace CalamityMod.NPCs.ExoMechs.Thanatos // Steam float maxSteamTime = 180f; - int maxGores = 4; npc.localAI[0] += 1f; - if (npc.localAI[0] < maxSteamTime && npc.localAI[0] % 18f == 0f) + if (npc.localAI[0] < maxSteamTime) { - int goreAmt = maxGores - (int)Math.Round(npc.localAI[0] / 60f); - CalamityUtils.ExplosionGores(npc.Center, goreAmt, true, npc.velocity); + SmokeDrawer.BaseMoveRotation = npc.rotation - MathHelper.PiOver2; + SmokeDrawer.ParticleSpawnRate = 3; } } else npc.localAI[0] = 0f; + SmokeDrawer.Update(); + Vector2 vector18 = new Vector2(npc.position.X + npc.width * 0.5f, npc.position.Y + npc.height * 0.5f); float num191 = Main.player[npc.target].position.X + (Main.player[npc.target].width / 2); float num192 = Main.player[npc.target].position.Y + (Main.player[npc.target].height / 2); @@ -461,11 +465,12 @@ namespace CalamityMod.NPCs.ExoMechs.Thanatos Vector2 center = npc.Center - Main.screenPosition; center -= new Vector2(texture.Width, texture.Height / Main.npcFrameCount[npc.type]) * npc.scale / 2f; - center += vector * npc.scale + new Vector2(0f, 4f + npc.gfxOffY); + center += vector * npc.scale + new Vector2(0f, npc.gfxOffY); spriteBatch.Draw(texture, center, npc.frame, npc.GetAlpha(drawColor), npc.rotation, vector, npc.scale, spriteEffects, 0f); texture = ModContent.GetTexture("CalamityMod/NPCs/ExoMechs/Thanatos/ThanatosBody1Glow"); spriteBatch.Draw(texture, center, npc.frame, Color.White * npc.Opacity, npc.rotation, vector, npc.scale, spriteEffects, 0f); + SmokeDrawer.DrawSet(npc.Center); } public override bool CheckActive() => false; diff --git a/NPCs/ExoMechs/Thanatos/ThanatosBody2.cs b/NPCs/ExoMechs/Thanatos/ThanatosBody2.cs index a56561eb56..5c6f60fbc2 100644 --- a/NPCs/ExoMechs/Thanatos/ThanatosBody2.cs +++ b/NPCs/ExoMechs/Thanatos/ThanatosBody2.cs @@ -1,6 +1,7 @@ using CalamityMod.Buffs.DamageOverTime; using CalamityMod.Buffs.StatDebuffs; using CalamityMod.Events; +using CalamityMod.Particles; using CalamityMod.Projectiles.Boss; using CalamityMod.World; using Microsoft.Xna.Framework; @@ -17,6 +18,7 @@ namespace CalamityMod.NPCs.ExoMechs.Thanatos { // Whether the body is venting heat or not, it is vulnerable to damage during venting private bool vulnerable = false; + public ThanatosSmokeParticleSet SmokeDrawer = new ThanatosSmokeParticleSet(-1, 4, 0f, 16f, 1.5f); public override void SetStaticDefaults() { @@ -323,6 +325,7 @@ namespace CalamityMod.NPCs.ExoMechs.Thanatos npc.Calamity().unbreakableDR = !vulnerable; // Vent noise and steam + SmokeDrawer.ParticleSpawnRate = 9999999; if (vulnerable) { // Noise @@ -331,17 +334,18 @@ namespace CalamityMod.NPCs.ExoMechs.Thanatos // Steam float maxSteamTime = 180f; - int maxGores = 4; npc.localAI[0] += 1f; - if (npc.localAI[0] < maxSteamTime && npc.localAI[0] % 18f == 0f) + if (npc.localAI[0] < maxSteamTime) { - int goreAmt = maxGores - (int)Math.Round(npc.localAI[0] / 60f); - CalamityUtils.ExplosionGores(npc.Center, goreAmt, true, npc.velocity); + SmokeDrawer.BaseMoveRotation = npc.rotation - MathHelper.PiOver2; + SmokeDrawer.ParticleSpawnRate = 3; } } else npc.localAI[0] = 0f; + SmokeDrawer.Update(); + Vector2 vector18 = new Vector2(npc.position.X + npc.width * 0.5f, npc.position.Y + npc.height * 0.5f); float num191 = Main.player[npc.target].position.X + (Main.player[npc.target].width / 2); float num192 = Main.player[npc.target].position.Y + (Main.player[npc.target].height / 2); @@ -461,11 +465,12 @@ namespace CalamityMod.NPCs.ExoMechs.Thanatos Vector2 center = npc.Center - Main.screenPosition; center -= new Vector2(texture.Width, texture.Height / Main.npcFrameCount[npc.type]) * npc.scale / 2f; - center += vector * npc.scale + new Vector2(0f, 4f + npc.gfxOffY); + center += vector * npc.scale + new Vector2(0f, npc.gfxOffY); spriteBatch.Draw(texture, center, npc.frame, npc.GetAlpha(drawColor), npc.rotation, vector, npc.scale, spriteEffects, 0f); texture = ModContent.GetTexture("CalamityMod/NPCs/ExoMechs/Thanatos/ThanatosBody2Glow"); spriteBatch.Draw(texture, center, npc.frame, Color.White * npc.Opacity, npc.rotation, vector, npc.scale, spriteEffects, 0f); + SmokeDrawer.DrawSet(npc.Center); } public override bool CheckActive() => false; diff --git a/NPCs/ExoMechs/Thanatos/ThanatosHead.cs b/NPCs/ExoMechs/Thanatos/ThanatosHead.cs index e1b3d158dd..fc7a8922be 100644 --- a/NPCs/ExoMechs/Thanatos/ThanatosHead.cs +++ b/NPCs/ExoMechs/Thanatos/ThanatosHead.cs @@ -772,7 +772,7 @@ namespace CalamityMod.NPCs.ExoMechs.Thanatos Vector2 center = npc.Center - Main.screenPosition; center -= new Vector2(texture.Width, texture.Height / Main.npcFrameCount[npc.type]) * npc.scale / 2f; - center += vector * npc.scale + new Vector2(0f, 4f + npc.gfxOffY); + center += vector * npc.scale + new Vector2(0f, npc.gfxOffY); spriteBatch.Draw(texture, center, npc.frame, npc.GetAlpha(drawColor), npc.rotation, vector, npc.scale, spriteEffects, 0f); texture = ModContent.GetTexture("CalamityMod/NPCs/ExoMechs/Thanatos/ThanatosHeadGlow"); diff --git a/NPCs/ExoMechs/Thanatos/ThanatosTail.cs b/NPCs/ExoMechs/Thanatos/ThanatosTail.cs index a863e5c35c..e19759e911 100644 --- a/NPCs/ExoMechs/Thanatos/ThanatosTail.cs +++ b/NPCs/ExoMechs/Thanatos/ThanatosTail.cs @@ -461,7 +461,7 @@ namespace CalamityMod.NPCs.ExoMechs.Thanatos Vector2 center = npc.Center - Main.screenPosition; center -= new Vector2(texture.Width, texture.Height / Main.npcFrameCount[npc.type]) * npc.scale / 2f; - center += vector * npc.scale + new Vector2(0f, 4f + npc.gfxOffY); + center += vector * npc.scale + new Vector2(0f, npc.gfxOffY); spriteBatch.Draw(texture, center, npc.frame, npc.GetAlpha(drawColor), npc.rotation, vector, npc.scale, spriteEffects, 0f); texture = ModContent.GetTexture("CalamityMod/NPCs/ExoMechs/Thanatos/ThanatosTailGlow"); diff --git a/Particles/BaseParticleSet.cs b/Particles/BaseParticleSet.cs new file mode 100644 index 0000000000..8490181b26 --- /dev/null +++ b/Particles/BaseParticleSet.cs @@ -0,0 +1,77 @@ +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using System; +using System.Collections.Generic; +using System.Linq; +using Terraria; +using Terraria.ID; + +namespace CalamityMod.Particles +{ + public abstract class BaseParticleSet + { + public int LocalTimer { get; internal set; } + public int SetLifetime { get; internal set; } + public int ParticleSpawnRate; + public List Particles = new List(); + public abstract int ParticleLifetime { get; } + public abstract void UpdateBehavior(Particle particle); + public abstract Particle SpawnParticle(); + public abstract Color DetermineParticleColor(float lifetimeCompletion); + public abstract Texture2D ParticleTexture { get; } + public virtual int ParticleFrameVariants => 1; + public virtual Func OrderFunction { get; } = null; + + public BaseParticleSet(int setLifetime, int particleSpawnRate) + { + SetLifetime = setLifetime; + ParticleSpawnRate = particleSpawnRate; + } + + public virtual void Update() + { + // Don't perform any operations on the server. Doing so would be a waste of space as these sets are entirely based on drawcode. + if (Main.netMode == NetmodeID.Server) + return; + + bool closeToDeath = LocalTimer >= SetLifetime - ParticleLifetime && SetLifetime > 0; + if (LocalTimer % ParticleSpawnRate == 0 && !closeToDeath) + { + Particle particle = SpawnParticle(); + particle.Lifetime = ParticleLifetime; + particle.Variant = Main.rand.Next(ParticleFrameVariants); + Particles.Add(particle); + } + + // Update and increment the time of all particles. + for (int i = 0; i < Particles.Count; i++) + { + Particles[i].Time++; + UpdateBehavior(Particles[i]); + } + + // Clear all expired particles. + Particles.RemoveAll(particle => particle.Time >= particle.Lifetime); + LocalTimer++; + } + + public virtual void DrawSet(Vector2 basePosition) + { + if (Main.netMode == NetmodeID.Server) + return; + + IEnumerable orderedParticles = Particles; + if (OrderFunction != null) + orderedParticles = orderedParticles.OrderBy(OrderFunction); + + foreach (Particle particle in Particles.OrderBy(p => p.Time)) + { + Vector2 drawPosition = basePosition - Main.screenPosition + particle.RelativeOffset; + Color particleColor = DetermineParticleColor(particle.Time / (float)particle.Lifetime); + Rectangle frame = ParticleTexture.Frame(1, ParticleFrameVariants, 0, particle.Variant); + + Main.spriteBatch.Draw(ParticleTexture, drawPosition, frame, particleColor, 0f, frame.Size() * 0.5f, particle.Scale, SpriteEffects.None, 0f); + } + } + } +} \ No newline at end of file diff --git a/Particles/Particle.cs b/Particles/Particle.cs new file mode 100644 index 0000000000..cf3bac931f --- /dev/null +++ b/Particles/Particle.cs @@ -0,0 +1,21 @@ +using Microsoft.Xna.Framework; + +namespace CalamityMod.Particles +{ + public class Particle + { + public int Time; + public int Lifetime; + public int Variant; + public float Scale; + public Vector2 RelativeOffset; + public Particle(int lifetime, Vector2 relativeOffset, float scale, int variant = 0) + { + Time = 0; + Lifetime = lifetime; + Variant = variant; + Scale = scale; + RelativeOffset = relativeOffset; + } + } +} \ No newline at end of file diff --git a/Particles/ThanatosSmokeParticleSet.cs b/Particles/ThanatosSmokeParticleSet.cs new file mode 100644 index 0000000000..dba17d45f6 --- /dev/null +++ b/Particles/ThanatosSmokeParticleSet.cs @@ -0,0 +1,36 @@ +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using Terraria; +using Terraria.ModLoader; + +namespace CalamityMod.Particles +{ + public class ThanatosSmokeParticleSet : BaseParticleSet + { + public float SpawnAreaCompactness; + public float RelativePower; + public float BaseMoveRotation; + public float MoveRotationOffset; + public override int ParticleLifetime => 50; + public override int ParticleFrameVariants => 3; + public override Texture2D ParticleTexture => ModContent.GetTexture("CalamityMod/ExtraTextures/ThanatosVentParticle"); + public ThanatosSmokeParticleSet(int setLifetime, int particleSpawnRate, float baseMoveRotation, float spawnAreaCompactness, float relativePower) : + base(setLifetime, particleSpawnRate) + { + MoveRotationOffset = Main.rand.NextFloat(-0.36f, 0.36f); + BaseMoveRotation = baseMoveRotation; + SpawnAreaCompactness = spawnAreaCompactness; + RelativePower = relativePower; + } + + public override void UpdateBehavior(Particle particle) + { + particle.Scale += RelativePower * 0.02f; + particle.RelativeOffset -= (BaseMoveRotation + Main.rand.NextFloat(-0.38f, 0.38f)).ToRotationVector2() * RelativePower * 4.5f; + } + + public override Color DetermineParticleColor(float lifetimeCompletion) => Color.White * Utils.InverseLerp(1f, 0.85f, lifetimeCompletion, true); + + public override Particle SpawnParticle() => new Particle(ParticleLifetime, Main.rand.NextVector2Circular(1f, 1f) * SpawnAreaCompactness, 0.06f, Main.rand.Next(3)); + } +} \ No newline at end of file