diff --git a/Projectiles/Magic/VisceraBeam.cs b/Projectiles/Magic/VisceraBeam.cs index b68e52be1a..05fa325ad1 100644 --- a/Projectiles/Magic/VisceraBeam.cs +++ b/Projectiles/Magic/VisceraBeam.cs @@ -15,6 +15,7 @@ namespace CalamityMod.Projectiles.Magic public new string LocalizationCategory => "Projectiles.Magic"; public override string Texture => "CalamityMod/Projectiles/InvisibleProj"; + private int storedPenetrate; public override void SetStaticDefaults() { ProjectileID.Sets.TrailCacheLength[Type] = 20; @@ -28,7 +29,7 @@ namespace CalamityMod.Projectiles.Magic Projectile.friendly = true; Projectile.DamageType = DamageClass.Magic; Projectile.ignoreWater = true; - Projectile.penetrate = 7; + storedPenetrate = Projectile.penetrate = 7; Projectile.MaxUpdates = 100; Projectile.timeLeft = 900; Projectile.usesLocalNPCImmunity = true; @@ -62,22 +63,27 @@ namespace CalamityMod.Projectiles.Magic if (Projectile.ai[1] > 0) { - SoundStyle hitSound = new("CalamityMod/Sounds/NPCKilled/PerfLargeDeath"); - SoundEngine.PlaySound(hitSound with { Volume = 0.5f }, Projectile.Center); - for (int i = 0; i <= 14; i++) - { - BloodParticle blood = new BloodParticle(Projectile.Center, new Vector2(15, 15).RotatedByRandom(100) * Main.rand.NextFloat(0.1f, 0.9f) + new Vector2(0, -7), 60, Main.rand.NextFloat(0.4f, 0.65f), Color.Red); - GeneralParticleHandler.SpawnParticle(blood); - } - Projectile.NewProjectile(Projectile.GetSource_FromThis(), Projectile.Center, Vector2.Zero, ModContent.ProjectileType(), (int)(Projectile.damage * 0.75f), Projectile.knockBack * 4, Projectile.owner, 0f, Projectile.ai[1]); - - Particle bloodsplosion = new CustomPulse(Projectile.Center, Vector2.Zero, Color.DarkRed, "CalamityMod/Particles/DetailedExplosion", Vector2.One, Main.rand.NextFloat(-15f, 15f), 0.16f, 0.87f, (int)(Viscera.BoomLifetime * 0.38f), false); - GeneralParticleHandler.SpawnParticle(bloodsplosion); - Particle bloodsplosion2 = new CustomPulse(Projectile.Center, Vector2.Zero, new Color(255, 32, 32), "CalamityMod/Particles/DustyCircleHardEdge", Vector2.One, Main.rand.NextFloat(-15f, 15f), 0.03f, 0.155f, Viscera.BoomLifetime); - GeneralParticleHandler.SpawnParticle(bloodsplosion2); } - else + + if (Projectile.ai[2] < 1) + { + for (int i = 0; i < 2; i++) + Projectile.NewProjectile(Projectile.GetSource_OnHit(target), Projectile.Center, -Projectile.velocity.SafeNormalize(Vector2.Zero).RotatedByRandom(0.5f) * Main.rand.NextFloat(3, 5), ModContent.ProjectileType(), 5, 0f, Projectile.owner); + Projectile.ai[2]++; + } + } + + public override void AI() + { + Player Owner = Main.player[Projectile.owner]; + float targetDist = Vector2.Distance(Owner.Center, Projectile.Center); + + if (Projectile.ai[1] > 0) + Projectile.penetrate = 1; + + // On-hit effects of piercing beams + if (Projectile.ai[1] == 0f && Projectile.penetrate != storedPenetrate) { SoundStyle hitSound = new("CalamityMod/Sounds/NPCHit/PerfLargeHit", 3); SoundEngine.PlaySound(hitSound with { Volume = 0.7f }, Projectile.Center); @@ -89,23 +95,8 @@ namespace CalamityMod.Projectiles.Magic dust.velocity = Projectile.velocity.RotatedByRandom(0.5) * Main.rand.NextFloat(0.8f, 1.9f); dust.noGravity = true; } + storedPenetrate = Projectile.penetrate; } - if (Projectile.ai[2] < 1){ - for (int i = 0; i < 2; i++) { - Projectile.NewProjectile(Projectile.GetSource_OnHit(target), Projectile.Center, -Projectile.velocity.SafeNormalize(Vector2.Zero).RotatedByRandom(0.5f) * Main.rand.NextFloat(3, 5), ModContent.ProjectileType(), 5, 0f, Projectile.owner); - } - Projectile.ai[2]++; - } - - } - - public override void AI() - { - Player Owner = Main.player[Projectile.owner]; - float targetDist = Vector2.Distance(Owner.Center, Projectile.Center); - - if (Projectile.ai[1] > 0) - Projectile.penetrate = 1; Projectile.localAI[0] += 1f; if (Projectile.localAI[0] == 16f) diff --git a/Projectiles/Magic/VisceraBoom.cs b/Projectiles/Magic/VisceraBoom.cs index 4bfebc2c25..f457177a03 100644 --- a/Projectiles/Magic/VisceraBoom.cs +++ b/Projectiles/Magic/VisceraBoom.cs @@ -1,9 +1,11 @@ using CalamityMod.Buffs.DamageOverTime; using CalamityMod.Items.Weapons.Magic; +using CalamityMod.Particles; using Microsoft.Xna.Framework; using Terraria; -using Terraria.ModLoader; +using Terraria.Audio; using Terraria.ID; +using Terraria.ModLoader; namespace CalamityMod.Projectiles.Magic { @@ -24,6 +26,24 @@ namespace CalamityMod.Projectiles.Magic } public override void AI() { + // Visual effects + if (Projectile.ai[0] == 0f) + { + SoundStyle hitSound = new("CalamityMod/Sounds/NPCKilled/PerfLargeDeath"); + SoundEngine.PlaySound(hitSound with { Volume = 0.5f }, Projectile.Center); + for (int i = 0; i <= 14; i++) + { + BloodParticle blood = new BloodParticle(Projectile.Center, new Vector2(15, 15).RotatedByRandom(100) * Main.rand.NextFloat(0.1f, 0.9f) + new Vector2(0, -7), 60, Main.rand.NextFloat(0.4f, 0.65f), Color.Red); + GeneralParticleHandler.SpawnParticle(blood); + } + Particle bloodsplosion = new CustomPulse(Projectile.Center, Vector2.Zero, Color.DarkRed, "CalamityMod/Particles/DetailedExplosion", Vector2.One, Main.rand.NextFloat(-15f, 15f), 0.16f, 0.87f, (int)(Viscera.BoomLifetime * 0.38f), false); + GeneralParticleHandler.SpawnParticle(bloodsplosion); + Particle bloodsplosion2 = new CustomPulse(Projectile.Center, Vector2.Zero, new Color(255, 32, 32), "CalamityMod/Particles/DustyCircleHardEdge", Vector2.One, Main.rand.NextFloat(-15f, 15f), 0.03f, 0.155f, Viscera.BoomLifetime); + GeneralParticleHandler.SpawnParticle(bloodsplosion2); + + Projectile.ai[0] = 1f; + } + for (int i = 0; i <= 2; i++) { float speed = Projectile.ai[1] > 0 ? 25 : 15; diff --git a/Projectiles/Melee/Yoyos/LaceratorYoyo.cs b/Projectiles/Melee/Yoyos/LaceratorYoyo.cs index fb0fb6b52a..96c173fec5 100644 --- a/Projectiles/Melee/Yoyos/LaceratorYoyo.cs +++ b/Projectiles/Melee/Yoyos/LaceratorYoyo.cs @@ -48,18 +48,17 @@ namespace CalamityMod.Projectiles.Melee.Yoyos Projectile.MaxUpdates = MaxUpdates; Projectile.usesLocalNPCImmunity = true; Projectile.localNPCHitCooldown = 6 * MaxUpdates; - } public override void SendExtraAI(BinaryWriter writer) { writer.Write(chargeProgress); } - public override void ReceiveExtraAI(BinaryReader reader) { - chargeProgress = reader.ReadInt32(); + chargeProgress = reader.ReadSingle(); } + public override void AI() { if (sawDir == 0) diff --git a/Projectiles/Ranged/BlissfulBombardierHoldout.cs b/Projectiles/Ranged/BlissfulBombardierHoldout.cs index be1fd02fbb..5fcbb6ddc3 100644 --- a/Projectiles/Ranged/BlissfulBombardierHoldout.cs +++ b/Projectiles/Ranged/BlissfulBombardierHoldout.cs @@ -1,4 +1,5 @@ using System; +using System.IO; using CalamityMod.Dusts; using CalamityMod.Items.Potions.Alcohol; using CalamityMod.Items.Weapons.Ranged; @@ -33,10 +34,21 @@ namespace CalamityMod.Projectiles.Ranged public ref float shootingTimer => ref Projectile.ai[0]; public ref float PostFireCooldown => ref Projectile.ai[1]; public bool hasFired = false; + + public override void SendExtraAIHoldout(BinaryWriter writer) + { + writer.Write(shootingTimer); + } + public override void ReceiveExtraAIHoldout(BinaryReader reader) + { + shootingTimer = reader.ReadSingle(); + } + public override void KillHoldoutLogic() { } + public override void ManageHoldout() { // The center of the player, taking into account if they have a mount or not. diff --git a/Projectiles/Ranged/BlissfulBombardierSplitProjectile.cs b/Projectiles/Ranged/BlissfulBombardierSplitProjectile.cs index 14adc0efa3..88a9e7ac4b 100644 --- a/Projectiles/Ranged/BlissfulBombardierSplitProjectile.cs +++ b/Projectiles/Ranged/BlissfulBombardierSplitProjectile.cs @@ -61,8 +61,8 @@ namespace CalamityMod.Projectiles.Ranged public override void OnKill(int timeLeft) { - // Only do rocket effects for the owner client side - if (Projectile.owner != Main.myPlayer) + // Don't do rocket effects on the server + if (Main.dedServ) return; var info = new CalamityUtils.RocketBehaviorInfo((int)RocketID) diff --git a/Projectiles/Ranged/FlashRoundProj.cs b/Projectiles/Ranged/FlashRoundProj.cs index 51615c3a6a..f5e18e683d 100644 --- a/Projectiles/Ranged/FlashRoundProj.cs +++ b/Projectiles/Ranged/FlashRoundProj.cs @@ -18,6 +18,7 @@ namespace CalamityMod.Projectiles.Ranged public float shineRot = 0; public bool onSpawn = true; public ref float time => ref Projectile.ai[2]; + private const int MaxTime = 600; public override void SetStaticDefaults() { ProjectileID.Sets.TrailCacheLength[Type] = 15; @@ -31,7 +32,7 @@ namespace CalamityMod.Projectiles.Ranged Projectile.friendly = true; Projectile.DamageType = DamageClass.Ranged; Projectile.penetrate = 2; - Projectile.timeLeft = 600; + Projectile.timeLeft = MaxTime; Projectile.extraUpdates = 3; Projectile.usesLocalNPCImmunity = true; Projectile.localNPCHitCooldown = -1; @@ -62,6 +63,11 @@ namespace CalamityMod.Projectiles.Ranged shineRot = Main.rand.NextFloat(-5, 5); onSpawn = false; } + // Handles spawning flash effect when bouncing off enemies/tiles + if (time == 0 && Projectile.timeLeft < MaxTime) + { + MakeFlash(false); + } shineRot += Math.Sign(shineRot) * 0.05f; Player Owner = Main.player[Projectile.owner]; @@ -81,6 +87,53 @@ namespace CalamityMod.Projectiles.Ranged time++; } + public override void ModifyHitNPC(NPC target, ref NPC.HitModifiers modifiers) + { + float damageMult = Projectile.numHits == 0 ? 1 : 0.3f; + modifiers.SourceDamage *= damageMult; + } + public override void OnHitNPC(NPC target, NPC.HitInfo hit, int damageDone) + { + time = 0; + Projectile.velocity = Vector2.Lerp(Utils.DirectionFrom(Projectile.Center, target.Center) * 12, Vector2.UnitY * -7, 0.75f).RotatedByRandom(0.25f); + Projectile.netUpdate = true; + } + public override bool OnTileCollide(Vector2 oldVelocity) + { + time = 0; + if (Projectile.velocity.X != oldVelocity.X) + { + Projectile.velocity.X = -oldVelocity.X; + } + if (Projectile.velocity.Y != oldVelocity.Y) + { + Projectile.velocity.Y = -oldVelocity.Y; + } + if (Projectile.velocity.X < 2 && Projectile.velocity.X > 0) + Projectile.velocity.X = 2; + if (Projectile.velocity.X > -2 && Projectile.velocity.X < 0) + Projectile.velocity.X = -2; + if (Projectile.velocity.Y < 2 && Projectile.velocity.Y > 0) + Projectile.velocity.Y = 2; + if (Projectile.velocity.Y > -2 && Projectile.velocity.Y < 0) + Projectile.velocity.Y = -2; + + Projectile.velocity *= 0.97f; + + int expectedDamage = Math.Max((int)(Projectile.damage * 1.13f), Projectile.damage + 2); + Projectile.damage = expectedDamage; + + if (bounces <= 0) + { + Projectile.Kill(); + return false; + } + for (int i = 0; i < Main.maxNPCs; i++) + Projectile.localNPCImmunity[i] = 0; + bounces--; + return false; + } + public override bool PreDraw(ref Color lightColor) { float sine = (float)Math.Sin(Projectile.timeLeft * 0.175f / MathHelper.Pi); @@ -92,13 +145,8 @@ namespace CalamityMod.Projectiles.Ranged Main.EntitySpriteDraw(shine.Value, Projectile.Center - Main.screenPosition, null, Color.White with { A = 0 } * 0.6f, Projectile.rotation + shineRot, shine.Size() / 2f, new Vector2(1 + 0.9f * -trueSine, 1 + 0.9f * trueSine) * Projectile.scale * 0.13f, SpriteEffects.None, 0); return false; } - public override void OnHitNPC(NPC target, NPC.HitInfo hit, int damageDone) - { - time = 0; - Projectile.velocity = Vector2.Lerp(Utils.DirectionFrom(Projectile.Center, target.Center) * 12, Vector2.UnitY * -7, 0.75f).RotatedByRandom(0.25f); - makeDust(false); - } - public void makeDust(bool onlyFlash) // This is basically the tile/hit effects + + public void MakeFlash(bool onlyFlash) // This is basically the tile/hit effects { if (!onlyFlash) { @@ -127,51 +175,8 @@ namespace CalamityMod.Projectiles.Ranged dust.noLightEmittence = true; } // Doesn't actually do damage, just an aoe for knockback - Projectile.NewProjectile(Projectile.GetSource_FromThis(), Projectile.Center, Vector2.Zero, ModContent.ProjectileType(), 5, 0f, Projectile.owner); - } - public override bool OnTileCollide(Vector2 oldVelocity) - { - time = 0; - if (Projectile.velocity.X != oldVelocity.X) - { - Projectile.velocity.X = -oldVelocity.X; - } - if (Projectile.velocity.Y != oldVelocity.Y) - { - Projectile.velocity.Y = -oldVelocity.Y; - } - if (Projectile.velocity.X < 2 && Projectile.velocity.X > 0) - Projectile.velocity.X = 2; - if (Projectile.velocity.X > -2 && Projectile.velocity.X < 0) - Projectile.velocity.X = -2; - if (Projectile.velocity.Y < 2 && Projectile.velocity.Y > 0) - Projectile.velocity.Y = 2; - if (Projectile.velocity.Y > -2 && Projectile.velocity.Y < 0) - Projectile.velocity.Y = -2; - - Projectile.velocity *= 0.97f; - - int expectedDamage = Math.Max((int)(Projectile.damage * 1.13f), Projectile.damage + 2); - Projectile.damage = expectedDamage; - - makeDust(false); - if (bounces <= 0) - { - Projectile.Kill(); - return false; - } - for (int i = 0; i < Main.maxNPCs; i++) - Projectile.localNPCImmunity[i] = 0; - bounces--; - return false; - } - public override void ModifyHitNPC(NPC target, ref NPC.HitModifiers modifiers) - { - float damageMult = (Projectile.numHits == 0 ? 1 : 0.3f); - modifiers.SourceDamage *= damageMult; - } - public override void OnKill(int timeLeft) - { + if (Main.myPlayer == Projectile.owner) + Projectile.NewProjectile(Projectile.GetSource_FromThis(), Projectile.Center, Vector2.Zero, ModContent.ProjectileType(), 5, 0f, Projectile.owner); } } } diff --git a/Projectiles/Ranged/NukeOfBliss.cs b/Projectiles/Ranged/NukeOfBliss.cs index 5543e63a47..c58d7eb599 100644 --- a/Projectiles/Ranged/NukeOfBliss.cs +++ b/Projectiles/Ranged/NukeOfBliss.cs @@ -139,8 +139,8 @@ namespace CalamityMod.Projectiles.Ranged public override void OnKill(int timeLeft) { - // Only do rocket effects for the owner client side - if (Projectile.owner != Main.myPlayer) + // Don't do rocket effects on the server + if (Main.dedServ) return; var info = new CalamityUtils.RocketBehaviorInfo((int)RocketID) diff --git a/Projectiles/Ranged/ScorchedEarthRocket.cs b/Projectiles/Ranged/ScorchedEarthRocket.cs index 4313ba0061..7fc2aff143 100644 --- a/Projectiles/Ranged/ScorchedEarthRocket.cs +++ b/Projectiles/Ranged/ScorchedEarthRocket.cs @@ -1,4 +1,5 @@ -using CalamityMod.Particles; +using System.IO; +using CalamityMod.Particles; using CalamityMod.Projectiles.Typeless; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; @@ -33,6 +34,14 @@ namespace CalamityMod.Projectiles.Ranged Projectile.timeLeft = 300; Projectile.DamageType = DamageClass.Ranged; } + public override void SendExtraAI(BinaryWriter writer) + { + writer.Write(HasHit); + } + public override void ReceiveExtraAI(BinaryReader reader) + { + HasHit = reader.ReadBoolean(); + } public override void AI() { @@ -96,7 +105,6 @@ namespace CalamityMod.Projectiles.Ranged } if (RocketID == ItemID.RocketII || RocketID == ItemID.RocketIV || RocketID == ItemID.MiniNukeII) { - var info = new CalamityUtils.RocketBehaviorInfo((int)RocketID); int blastRadius = (int)(Projectile.RocketBehavior(info) * 3f); if (time % 5 == 0) @@ -150,13 +158,11 @@ namespace CalamityMod.Projectiles.Ranged HasHit = true; Projectile.netUpdate = true; } - public override void OnHitPlayer(Player target, Player.HurtInfo info) { HasHit = true; Projectile.netUpdate = true; } - public override bool OnTileCollide(Vector2 oldVelocity) { HasHit = true; @@ -166,39 +172,11 @@ namespace CalamityMod.Projectiles.Ranged public override void OnKill(int timeLeft) { - if (HasHit == true && !BonusEffectMode && Projectile.ai[2] == 0) + if (HasHit && !BonusEffectMode && Projectile.ai[2] == 0) { - if (Projectile.owner == Main.myPlayer) - { - bool isClusterRocket = (RocketID == ItemID.ClusterRocketI || RocketID == ItemID.ClusterRocketII); - //If using a rocket with extra effects, spawn an invisible copy that handes the tile breaking/liquid spawning logic - if (RocketID == ItemID.RocketII || RocketID == ItemID.RocketIV || RocketID == ItemID.MiniNukeII || RocketID == ItemID.DryRocket || RocketID == ItemID.WetRocket || RocketID == ItemID.LavaRocket || RocketID == ItemID.HoneyRocket) - Projectile.NewProjectile(Projectile.GetSource_FromThis(), Projectile.Center, Vector2.Zero, ModContent.ProjectileType(), 0, 0f, Projectile.owner, RocketID, 0f, 2f); - // Create Blast - float blastSize = 300; - float minMultiplier = 0.25f; - int hitsToMinMult = 4; - int debuff1 = BuffID.Daybreak; - int debuff2 = BuffID.Oiled; - int debuffTime = 360; - //The explosion has a different damage scaling depending on which rocket type you have. Left is Cluster Rocket, right is Non-Cluster. - Projectile blast = Projectile.NewProjectileDirect(Projectile.GetSource_FromThis(), Projectile.Center, Vector2.Zero, ModContent.ProjectileType(), (int)(Projectile.damage * (isClusterRocket ? 0.75f : 1)), Projectile.knockBack, Projectile.owner, blastSize, minMultiplier, hitsToMinMult); - blast.localAI[0] = debuff1; - blast.localAI[2] = debuff2; - blast.localAI[1] = debuffTime; - blast.timeLeft = 15; - blast.DamageType = DamageClass.Ranged; - for (int j = 0; j < (isClusterRocket ? 9 : 5); j++) - { - Vector2 velocity = Main.rand.NextVector2Unit() * Main.rand.NextFloat(8f, 10f); - Projectile.NewProjectile(Projectile.GetSource_FromThis(), Projectile.Center, velocity, ModContent.ProjectileType(), (int)(Projectile.damage * 0.25), Projectile.knockBack * 0.25f, Projectile.owner); - } - } - - // Handle FX for all clients + // Visual effects SoundEngine.PlaySound(SoundID.Item14, Projectile.Center); SoundEngine.PlaySound(RocketExplosion with { MaxInstances = 2 }, Projectile.Center); - for (int i = 0; i < 15; i++) { Vector2 randVel = new Vector2(12, 12).RotatedByRandom(100) * Main.rand.NextFloat(0.8f, 1.6f); @@ -220,6 +198,34 @@ namespace CalamityMod.Projectiles.Ranged Particle blastRing5 = new CustomPulse(Projectile.Center, Vector2.Zero, Color.OrangeRed, "CalamityMod/Particles/FlameExplosion", Vector2.One, Main.rand.NextFloat(-10, 10), 0f, 0.13f, 20, true, 1f); GeneralParticleHandler.SpawnParticle(blastRing5); } + + // Below is projectile spawning logic, so it should only run on one instance + if (Main.myPlayer != Projectile.owner) + return; + + bool isClusterRocket = RocketID == ItemID.ClusterRocketI || RocketID == ItemID.ClusterRocketII; + // If using a rocket with extra effects, spawn an invisible copy that handes the tile breaking/liquid spawning logic + if (RocketID == ItemID.RocketII || RocketID == ItemID.RocketIV || RocketID == ItemID.MiniNukeII || RocketID == ItemID.DryRocket || RocketID == ItemID.WetRocket || RocketID == ItemID.LavaRocket || RocketID == ItemID.HoneyRocket) + Projectile.NewProjectile(Projectile.GetSource_FromThis(), Projectile.Center, Vector2.Zero, ModContent.ProjectileType(), 0, 0f, Projectile.owner, RocketID, 0f, 2f); + // Create blast + float blastSize = 300; + float minMultiplier = 0.25f; + int hitsToMinMult = 4; + int debuff1 = BuffID.Daybreak; + int debuff2 = BuffID.Oiled; + int debuffTime = 360; + // The explosion has a different damage scaling depending on which rocket type you have. Left is Cluster Rocket, right is Non-Cluster. + Projectile blast = Projectile.NewProjectileDirect(Projectile.GetSource_FromThis(), Projectile.Center, Vector2.Zero, ModContent.ProjectileType(), (int)(Projectile.damage * (isClusterRocket ? 0.75f : 1)), Projectile.knockBack, Projectile.owner, blastSize, minMultiplier, hitsToMinMult); + blast.localAI[0] = debuff1; + blast.localAI[2] = debuff2; + blast.localAI[1] = debuffTime; + blast.timeLeft = 15; + blast.DamageType = DamageClass.Ranged; + for (int j = 0; j < (isClusterRocket ? 9 : 5); j++) + { + Vector2 velocity = Main.rand.NextVector2Unit() * Main.rand.NextFloat(8f, 10f); + Projectile.NewProjectile(Projectile.GetSource_FromThis(), Projectile.Center, velocity, ModContent.ProjectileType(), (int)(Projectile.damage * 0.25), Projectile.knockBack * 0.25f, Projectile.owner); + } } } public override bool PreDraw(ref Color lightColor) diff --git a/Projectiles/Summon/DazzlingStabber.cs b/Projectiles/Summon/DazzlingStabber.cs index 4322dbb52a..ac5051de40 100644 --- a/Projectiles/Summon/DazzlingStabber.cs +++ b/Projectiles/Summon/DazzlingStabber.cs @@ -1,4 +1,5 @@ using System; +using System.IO; using CalamityMod.Buffs.DamageOverTime; using CalamityMod.Buffs.Summon; using CalamityMod.Dusts; @@ -19,9 +20,10 @@ namespace CalamityMod.Projectiles.Summon public ref float AttackDelay => ref Projectile.ai[0]; public ref float RestOffsetAngle => ref Projectile.ai[1]; public ref float KnifeType => ref Projectile.ai[2]; // 1 - Crystal, 2 - Stone, 3 - Fire - public Color color1 = Color.White; + public Color bladeColor = Color.White; public int attackCooldown = 0; public int attacksDone = 0; + private bool justHit = false; public NPC potentialTarget; public float moveSmoothing = 50; public float damageMult = 1; @@ -49,23 +51,36 @@ namespace CalamityMod.Projectiles.Summon Projectile.DamageType = DamageClass.Summon; } + public override void SendExtraAI(BinaryWriter writer) + { + writer.Write(attackCooldown); + writer.Write(attacksDone); + writer.Write(justHit); + } + public override void ReceiveExtraAI(BinaryReader reader) + { + attackCooldown = reader.ReadInt32(); + attacksDone = reader.ReadInt32(); + justHit = reader.ReadBoolean(); + } + public override void AI() { switch (KnifeType) { case 1: // Crystal - color1 = Color.Orchid; + bladeColor = Color.Orchid; Projectile.extraUpdates = 1; damageMult = 0.5f; Projectile.ArmorPenetration = 40; break; case 2: // Rock - color1 = Color.OrangeRed; + bladeColor = Color.OrangeRed; Projectile.extraUpdates = 2; damageMult = 3; break; default: // Flame - color1 = Color.Orange; + bladeColor = Color.Orange; damageMult = 1; Projectile.ArmorPenetration = 20; break; @@ -82,11 +97,46 @@ namespace CalamityMod.Projectiles.Summon storedPos = potentialTarget.Center; } + // On-hit visuals + if (justHit) + { + if (KnifeType == 1) + { + SoundEngine.PlaySound(SoundID.DD2_WitherBeastCrystalImpact with { Volume = 0.7f, Pitch = attacksDone * 0.05f }, Projectile.Center); + if (attacksDone >= 6) + { + for (int i = 0; i < 9; i++) + { + Dust dust = Dust.NewDustPerfect(Projectile.Center, ModContent.DustType(), Projectile.velocity.SafeNormalize(Vector2.UnitX).RotatedByRandom(0.5f) * Main.rand.NextFloat(10f, 20f)); + dust.noGravity = true; + dust.scale = Main.rand.NextFloat(1.25f, 1.75f); + dust.color = Color.Orchid; + dust.noLightEmittence = true; + } + for (int i = 0; i < 4; i++) + { + Particle spark = new CustomSpark(Projectile.Center, (Projectile.velocity.SafeNormalize(Vector2.UnitX)).RotatedByRandom(0.6f) * Main.rand.NextFloat(15f, 20f), "CalamityMod/Particles/ProvidenceMarkParticle", false, 25, Main.rand.NextFloat(1.35f, 1.6f), Color.Orchid, new Vector2(1.3f, 0.5f), true, false, 0, false, false, Main.rand.NextFloat(0.25f, 0.35f)); + GeneralParticleHandler.SpawnParticle(spark); + } + } + } + if (KnifeType == 2) + { + SoundStyle slam = new("CalamityMod/Sounds/NPCHit/RavagerRockPillarHit", 2); + SoundEngine.PlaySound(slam with { Volume = 0.4f, Pitch = Main.rand.NextFloat(-0.25f, -0.15f), MaxInstances = -1 }, Projectile.Center); + for (int i = 0; i < 7; i++) + { + Particle spark = new CustomSpark(Projectile.Center, Vector2.One.RotatedByRandom(100) * Main.rand.NextFloat(1f, 5f), "CalamityMod/Projectiles/Typeless/ArtifactOfResilienceShard6", false, Main.rand.Next(15, 25 + 1), Main.rand.NextFloat(0.75f, 1.2f), Color.White, new Vector2(1.3f, 0.5f), false, false, Main.rand.NextFloat(-5, 5), false, false); + GeneralParticleHandler.SpawnParticle(spark); + } + } + } + if (potentialTarget != null) { if (KnifeType == 1 && attacksDone > 0 && Utils.Distance(Projectile.Center, storedPos) < 150 && attackCooldown == 0) { - Particle spark = new GlowSparkParticle(Projectile.Center, -Projectile.velocity * 0.1f, false, 20, 0.03f, color1 * 0.55f, new Vector2(0.8f, 2.3f), true, false, 0.45f); + Particle spark = new GlowSparkParticle(Projectile.Center, -Projectile.velocity * 0.1f, false, 20, 0.03f, bladeColor * 0.55f, new Vector2(0.8f, 2.3f), true, false, 0.45f); GeneralParticleHandler.SpawnParticle(spark); } if (KnifeType == 2 && attackCooldown == 0) @@ -102,7 +152,7 @@ namespace CalamityMod.Projectiles.Summon Dust dust = Dust.NewDustPerfect(Projectile.Center, memesHatesLists ? 278 : ModContent.DustType(), -Projectile.velocity.SafeNormalize(Vector2.UnitX).RotatedByRandom(0.4f) * Main.rand.NextFloat(1f, 4f)); dust.noGravity = !memesHatesLists; dust.scale = Main.rand.NextFloat(0.55f, 1.1f); - dust.color = color1; + dust.color = bladeColor; } } if (KnifeType == 3) @@ -255,38 +305,16 @@ namespace CalamityMod.Projectiles.Summon } public override void OnHitNPC(NPC target, NPC.HitInfo hit, int damageDone) { + justHit = true; if (KnifeType == 1) { AttackDelay = 15; attacksDone++; - SoundEngine.PlaySound(SoundID.DD2_WitherBeastCrystalImpact with { Volume = 0.7f, Pitch = attacksDone * 0.05f }, Projectile.Center); if (attacksDone >= 6) - { - for (int i = 0; i < 9; i++) - { - Dust dust = Dust.NewDustPerfect(Projectile.Center, ModContent.DustType(), Projectile.velocity.SafeNormalize(Vector2.UnitX).RotatedByRandom(0.5f) * Main.rand.NextFloat(10f, 20f)); - dust.noGravity = true; - dust.scale = Main.rand.NextFloat(1.25f, 1.75f); - dust.color = Color.Orchid; - dust.noLightEmittence = true; - } - for (int i = 0; i < 4; i++) - { - Particle spark = new CustomSpark(Projectile.Center, (Projectile.velocity.SafeNormalize(Vector2.UnitX)).RotatedByRandom(0.6f) * Main.rand.NextFloat(15f, 20f), "CalamityMod/Particles/ProvidenceMarkParticle", false, 25, Main.rand.NextFloat(1.35f, 1.6f), Color.Orchid, new Vector2(1.3f, 0.5f), true, false, 0, false, false, Main.rand.NextFloat(0.25f, 0.35f)); - GeneralParticleHandler.SpawnParticle(spark); - } attackCooldown = Main.rand.Next(80, 95 + 1); - } } if (KnifeType == 2) { - SoundStyle slam = new("CalamityMod/Sounds/NPCHit/RavagerRockPillarHit", 2); - SoundEngine.PlaySound(slam with { Volume = 0.4f, Pitch = Main.rand.NextFloat(-0.25f, -0.15f), MaxInstances = -1 }, Projectile.Center); - for (int i = 0; i < 7; i++) - { - Particle spark = new CustomSpark(Projectile.Center, Vector2.One.RotatedByRandom(100) * Main.rand.NextFloat(1f, 5f), "CalamityMod/Projectiles/Typeless/ArtifactOfResilienceShard6", false, Main.rand.Next(15, 25 + 1), Main.rand.NextFloat(0.75f, 1.2f), Color.White, new Vector2(1.3f, 0.5f), false, false, Main.rand.NextFloat(-5, 5), false, false); - GeneralParticleHandler.SpawnParticle(spark); - } Projectile.velocity = (-Projectile.velocity.SafeNormalize(Vector2.UnitX) * 15).RotatedByRandom(0.7f); attackCooldown = Main.rand.Next(45, 60 + 1); } @@ -296,11 +324,9 @@ namespace CalamityMod.Projectiles.Summon attackCooldown = 5; target.AddBuff(ModContent.BuffType(), 180); } + Projectile.netUpdate = true; } - public override void ModifyHitNPC(NPC target, ref NPC.HitModifiers modifiers) - { - modifiers.SourceDamage *= damageMult; - } + public override void ModifyHitNPC(NPC target, ref NPC.HitModifiers modifiers) => modifiers.SourceDamage *= damageMult; public override void OnHitPlayer(Player target, Player.HurtInfo info) => target.AddBuff(ModContent.BuffType(), 180); @@ -316,7 +342,7 @@ namespace CalamityMod.Projectiles.Summon if (KnifeType == 3) tex = ModContent.Request("CalamityMod/Projectiles/Summon/DazzlingStabber3").Value; - Projectile.DrawProjectileWithBackglow(color1 with { A = 0 }, lightColor, 3.5f, tex); + Projectile.DrawProjectileWithBackglow(bladeColor with { A = 0 }, lightColor, 3.5f, tex); return false; } diff --git a/Projectiles/Typeless/ClaretCannonProj.cs b/Projectiles/Typeless/ClaretCannonProj.cs index 0a67da9052..a78dbd9c39 100644 --- a/Projectiles/Typeless/ClaretCannonProj.cs +++ b/Projectiles/Typeless/ClaretCannonProj.cs @@ -37,6 +37,7 @@ namespace CalamityMod.Projectiles.Typeless { Collision.HitTiles(Projectile.position, Projectile.velocity, Projectile.width, Projectile.height); SoundEngine.PlaySound(SoundID.Dig, Projectile.position); + Projectile.netUpdate = true; return true; } @@ -46,33 +47,35 @@ namespace CalamityMod.Projectiles.Typeless return; SoundEngine.PlaySound(new SoundStyle("CalamityMod/Sounds/NPCKilled/PerfLargeDeath") { Volume = 0.5f }, Projectile.Center); SoundEngine.PlaySound(new SoundStyle("CalamityMod/Sounds/Custom/BloodPactCrit") { Volume = 0.5f }, Projectile.Center); + float particleScale = 8f; + Particle bloodsplosion = new CustomPulse(Projectile.Center, Vector2.Zero, Color.DarkRed, "CalamityMod/Particles/DetailedExplosion", Vector2.One, Main.rand.NextFloat(-15f, 15f), 0.16f * particleScale / 5f, 0.87f * particleScale / 5f, (int)(40 * 0.38f), false); + GeneralParticleHandler.SpawnParticle(bloodsplosion); + Particle bloodsplosion2 = new CustomPulse(Projectile.Center, Vector2.Zero, new Color(255, 32, 32), "CalamityMod/Particles/DustyCircleHardEdge", Vector2.One, Main.rand.NextFloat(-15f, 15f), 0.03f * particleScale / 5f, 0.155f * particleScale / 5f, 40); + GeneralParticleHandler.SpawnParticle(bloodsplosion2); + Projectile.netUpdate = true; } - public override void OnHitNPC(NPC target, NPC.HitInfo hit, int damageDone) + public override void OnHitNPC(NPC target, NPC.HitInfo hit, int damageDone) { target.AddBuff(ModContent.BuffType(), ClaretCannon.ClaretCooldownMax / 2); target.AddBuff(BuffID.BetsysCurse, ClaretCannon.ClaretCooldownMax); if (Projectile.penetrate == -1) return; var player = Main.player[Projectile.owner]; - float orbCount = 20; - for (var i = 0; i < orbCount; i++) + for (var i = 0; i < 20; i++) { Projectile.NewProjectile(Projectile.GetSource_OnHit(target), Projectile.Center, -Projectile.velocity.SafeNormalize(Vector2.Zero).RotatedByRandom(1) * Main.rand.NextFloat(2.75f, 5.25f), ModContent.ProjectileType(), 20, 0f, player.whoAmI); } - Projectile.position = Projectile.Center; - Projectile.Size = new Vector2(352); - Projectile.Center = Projectile.position; - Projectile.penetrate = -1; - Projectile.extraUpdates = 0; - Projectile.timeLeft = 2; - Projectile.velocity *= 0; - Projectile.damage /= 2; - float particleScale = 8f; - Particle bloodsplosion = new CustomPulse(Projectile.Center, Vector2.Zero, Color.DarkRed, "CalamityMod/Particles/DetailedExplosion", Vector2.One, Main.rand.NextFloat(-15f, 15f), 0.16f*particleScale/5f, 0.87f * particleScale / 5f, (int)(40 * 0.38f), false); - GeneralParticleHandler.SpawnParticle(bloodsplosion); - Particle bloodsplosion2 = new CustomPulse(Projectile.Center, Vector2.Zero, new Color(255, 32, 32), "CalamityMod/Particles/DustyCircleHardEdge", Vector2.One, Main.rand.NextFloat(-15f, 15f), 0.03f * particleScale / 5f, 0.155f * particleScale / 5f, 40); - GeneralParticleHandler.SpawnParticle(bloodsplosion2); + Projectile.position = Projectile.Center; + Projectile.Size = new Vector2(352); + Projectile.Center = Projectile.position; + Projectile.penetrate = -1; + Projectile.extraUpdates = 0; + Projectile.timeLeft = 2; + Projectile.velocity *= 0; + Projectile.damage /= 2; + Projectile.netUpdate = true; + } } -} \ No newline at end of file +}