diff --git a/Items/CalamityGlobalItemTweaks.cs b/Items/CalamityGlobalItemTweaks.cs index 4b73cceaba..84cac6a50a 100644 --- a/Items/CalamityGlobalItemTweaks.cs +++ b/Items/CalamityGlobalItemTweaks.cs @@ -217,7 +217,7 @@ namespace CalamityMod.Items { ItemID.ShadowFlameBow, Do(PointBlank, DamageExact(55)) }, { ItemID.ShadowFlameHexDoll, Do(DamageExact(40), ShootSpeedExact(30)) }, { ItemID.ShadowFlameKnife, Do(DamageExact(70)) }, - { ItemID.SharpTears, Do(DamageExact(49)) }, + { ItemID.SharpTears, Do(DamageExact(49)) }, // Blood Thorn { ItemID.Shotgun, Do(PointBlank, DamageExact(36), AutoReuse) }, { ItemID.Shroomerang, Do(ShootSpeedExact(11)) }, { ItemID.SilverBullet, Do(DamageExact(8)) }, diff --git a/Items/Weapons/Magic/Genesis.cs b/Items/Weapons/Magic/Genesis.cs index 3574304c4f..9e3d003e4a 100644 --- a/Items/Weapons/Magic/Genesis.cs +++ b/Items/Weapons/Magic/Genesis.cs @@ -15,6 +15,7 @@ namespace CalamityMod.Items.Weapons.Magic public static float StarterWindup = 60f; public new string LocalizationCategory => "Items.Weapons.Magic"; + public override void SetDefaults() { Item.width = 108; @@ -44,7 +45,8 @@ namespace CalamityMod.Items.Weapons.Magic public override bool Shoot(Player player, EntitySource_ItemUse_WithAmmo source, Vector2 position, Vector2 velocity, int type, int damage, float knockback) { - Projectile.NewProjectileDirect(source, player.MountedCenter, Vector2.Zero, ModContent.ProjectileType(), damage, knockback, player.whoAmI, 0, 1); + Projectile holdout = Projectile.NewProjectileDirect(source, player.MountedCenter, Vector2.Zero, ModContent.ProjectileType(), damage, knockback, player.whoAmI, 0, 1); + holdout.velocity = player.Calamity().mouseWorld - player.RotatedRelativePoint(player.MountedCenter); return false; } diff --git a/Items/Weapons/Magic/Omicron.cs b/Items/Weapons/Magic/Omicron.cs index 5028c9f3a0..010a7b2f7e 100644 --- a/Items/Weapons/Magic/Omicron.cs +++ b/Items/Weapons/Magic/Omicron.cs @@ -12,6 +12,9 @@ namespace CalamityMod.Items.Weapons.Magic { public class Omicron : ModItem, ILocalizedModType { + public static float FireRate = 15f; + public static float StarterWinup = 60f; + public new string LocalizationCategory => "Items.Weapons.Magic"; public override void SetDefaults() diff --git a/Items/Weapons/Ranged/TheHive.cs b/Items/Weapons/Ranged/TheHive.cs index 2092626a5c..89e585472d 100644 --- a/Items/Weapons/Ranged/TheHive.cs +++ b/Items/Weapons/Ranged/TheHive.cs @@ -14,6 +14,7 @@ namespace CalamityMod.Items.Weapons.Ranged { public new string LocalizationCategory => "Items.Weapons.Ranged"; + public static float MaxCharge = 90f; public static int OriginalUseTime = 34; public override void SetDefaults() diff --git a/Projectiles/BaseProjectiles/BaseGunHoldoutProjectile.cs b/Projectiles/BaseProjectiles/BaseGunHoldoutProjectile.cs index ca12e9cbd7..81c50e3baa 100644 --- a/Projectiles/BaseProjectiles/BaseGunHoldoutProjectile.cs +++ b/Projectiles/BaseProjectiles/BaseGunHoldoutProjectile.cs @@ -2,6 +2,7 @@ using System.IO; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; +using ReLogic.Content; using Terraria; using Terraria.DataStructures; using Terraria.GameContent; @@ -126,6 +127,8 @@ namespace CalamityMod.Projectiles.BaseProjectiles private Type AssociatedItemType => ItemLoader.GetItem(AssociatedItemID).GetType(); + private Asset ItemTexture => TextureAssets.Item[AssociatedItemID]; + #endregion #region Overridden Members @@ -138,18 +141,12 @@ namespace CalamityMod.Projectiles.BaseProjectiles public override void SetDefaults() { - Projectile.width = Projectile.height = TextureAssets.Item[AssociatedItemID].Width(); + Projectile.width = Projectile.height = ItemTexture is null ? 1 : ItemTexture.Width(); Projectile.tileCollide = false; Projectile.netImportant = true; } - public override void OnSpawn(IEntitySource source) - { - Owner = Main.player[Projectile.owner]; - OffsetLengthFromArm = MaxOffsetLengthFromArm; - HeldItem = Owner.ActiveItem(); - Projectile.velocity = Owner.Calamity().mouseWorld - Owner.RotatedRelativePoint(Owner.MountedCenter); - } + public override void OnSpawn(IEntitySource source) => OffsetLengthFromArm = MaxOffsetLengthFromArm; public override bool ShouldUpdatePosition() => false; @@ -161,6 +158,10 @@ namespace CalamityMod.Projectiles.BaseProjectiles public override void AI() { + // Multiplayer null-checking. + Owner ??= Main.player[Projectile.owner]; + HeldItem ??= Owner.ActiveItem(); + KillHoldoutLogic(); ManageHoldout(); HoldoutAI(); @@ -168,15 +169,12 @@ namespace CalamityMod.Projectiles.BaseProjectiles /// /// Here goes the code for when the holdout needs to despawn.
- /// Defaults to despawning when the owner isn't holding or isn't using the correspondent weapon. + /// Defaults to despawning when the owner isn't using the correspondent weapon. ///
public virtual void KillHoldoutLogic() { if (Owner.CantUseHoldout()) - { - Projectile.netUpdate = true; Projectile.Kill(); - } } /// @@ -222,6 +220,9 @@ namespace CalamityMod.Projectiles.BaseProjectiles if (OffsetLengthFromArm != MaxOffsetLengthFromArm) OffsetLengthFromArm = MathHelper.Lerp(OffsetLengthFromArm, MaxOffsetLengthFromArm, RecoilResolveSpeed); + + Projectile.netUpdate = true; + Projectile.netSpam = 0; } /// @@ -255,6 +256,7 @@ namespace CalamityMod.Projectiles.BaseProjectiles writer.Write(Projectile.rotation); writer.Write(KeepRefreshingLifetime); writer.Write(OffsetLengthFromArm); + writer.Write(Projectile.spriteDirection); SendExtraAIHoldout(writer); } @@ -263,6 +265,7 @@ namespace CalamityMod.Projectiles.BaseProjectiles Projectile.rotation = reader.ReadSingle(); KeepRefreshingLifetime = reader.ReadBoolean(); OffsetLengthFromArm = reader.ReadSingle(); + Projectile.spriteDirection = reader.ReadInt32(); ReceiveExtraAIHoldout(reader); } diff --git a/Projectiles/Magic/GenesisBeam.cs b/Projectiles/Magic/GenesisBeam.cs index 9a2a2167fd..1a6f1196e0 100644 --- a/Projectiles/Magic/GenesisBeam.cs +++ b/Projectiles/Magic/GenesisBeam.cs @@ -2,7 +2,6 @@ using Microsoft.Xna.Framework; using Terraria; using Terraria.Audio; -using Terraria.ID; using Terraria.ModLoader; namespace CalamityMod.Projectiles.Magic @@ -11,11 +10,17 @@ namespace CalamityMod.Projectiles.Magic { public new string LocalizationCategory => "Projectiles.Magic"; public override string Texture => "CalamityMod/Projectiles/InvisibleProj"; - public ref float time => ref Projectile.ai[0]; - public ref float isSplit => ref Projectile.ai[1]; - public bool splitShot = false; - public Color mainColor = Color.MediumSlateBlue; + public ref float Time => ref Projectile.ai[0]; + public ref float IsSplit => ref Projectile.ai[1]; + public bool SplitShot + { + get => Projectile.ai[2] == 1f; + set => Projectile.ai[2] = value == true ? 1f : 0f; + } + + public Color MainColor { get; set; } = Color.MediumSlateBlue; + public override void SetDefaults() { Projectile.width = 12; @@ -29,47 +34,50 @@ namespace CalamityMod.Projectiles.Magic Projectile.extraUpdates = 75; Projectile.timeLeft = 20; } + public override void AI() { - if (isSplit == 0) + if (IsSplit == 0) + SplitShot = true; + + if (Time == 0) { - Projectile.netUpdate = true; - splitShot = true; - } - if (time == 0) - { - if (splitShot) + if (SplitShot) Projectile.penetrate = 1; else Projectile.timeLeft = 50; } - if (Projectile.timeLeft % 2 == 0 && (!splitShot && time > 2 || (splitShot && time > 3 && Projectile.timeLeft > 2))) + if (Projectile.timeLeft % 2 == 0 && (!SplitShot && Time > 2 || (SplitShot && Time > 3 && Projectile.timeLeft > 2))) { - Particle spark = new GlowSparkParticle(Projectile.Center, -Projectile.velocity * 0.05f, false, 17, 0.06f, mainColor, new Vector2(0.5f, 1.3f)); + Particle spark = new GlowSparkParticle(Projectile.Center, -Projectile.velocity * 0.05f, false, 17, 0.06f, MainColor, new Vector2(0.5f, 1.3f)); GeneralParticleHandler.SpawnParticle(spark); } Vector2 dustVel = new Vector2(2, 2).RotatedByRandom(100) * Main.rand.NextFloat(0.1f, 0.8f); Dust dust = Dust.NewDustPerfect(Projectile.Center + dustVel, Main.rand.NextBool(4) ? 264 : 66, dustVel, 0, default, Main.rand.NextFloat(0.9f, 1.2f)); dust.noGravity = true; - dust.color = Main.rand.NextBool() ? Color.Lerp(mainColor, Color.White, 0.5f) : mainColor; + dust.color = Main.rand.NextBool() ? Color.Lerp(MainColor, Color.White, 0.5f) : MainColor; - time++; + Time++; } + public override void OnKill(int timeLeft) { int numProj = 2; float rotation = MathHelper.ToRadians(12); - if (splitShot) + if (SplitShot) { for (int i = 0; i < numProj; i++) { Vector2 perturbedSpeed = Projectile.velocity.RotatedBy(MathHelper.Lerp(-rotation, rotation, i / (numProj - 1))); - Projectile.NewProjectile(Projectile.GetSource_FromThis(), Projectile.Center, perturbedSpeed, ModContent.ProjectileType(), Projectile.damage, Projectile.knockBack, Projectile.owner, 0f, 1f); + + if (Main.myPlayer == Projectile.owner) + Projectile.NewProjectile(Projectile.GetSource_FromThis(), Projectile.Center, perturbedSpeed, ModContent.ProjectileType(), Projectile.damage, Projectile.knockBack, Projectile.owner, 0f, 1f); + for (int k = 0; k < 3; k++) { - Particle blastRing = new CustomPulse(Projectile.Center, Vector2.Zero, mainColor, "CalamityMod/Particles/BloomCircle", Vector2.One, Main.rand.NextFloat(-10, 10), 0.5f, 0.4f, 35); + Particle blastRing = new CustomPulse(Projectile.Center, Vector2.Zero, MainColor, "CalamityMod/Particles/BloomCircle", Vector2.One, Main.rand.NextFloat(-10, 10), 0.5f, 0.4f, 35); GeneralParticleHandler.SpawnParticle(blastRing); Particle blastRing2 = new CustomPulse(Projectile.Center, Vector2.Zero, Color.White, "CalamityMod/Particles/BloomCircle", Vector2.One, Main.rand.NextFloat(-10, 10), 0.4f, 0.3f, 35); GeneralParticleHandler.SpawnParticle(blastRing2); @@ -81,7 +89,7 @@ namespace CalamityMod.Projectiles.Magic Vector2 dustVel = new Vector2(13, 13).RotatedByRandom(100) * Main.rand.NextFloat(0.1f, 0.8f); Dust dust = Dust.NewDustPerfect(Projectile.Center + dustVel, Main.rand.NextBool(4) ? 264 : 66, dustVel, 0, default, Main.rand.NextFloat(0.9f, 1.2f)); dust.noGravity = true; - dust.color = Main.rand.NextBool() ? Color.Lerp(mainColor, Color.White, 0.5f) : mainColor; + dust.color = Main.rand.NextBool() ? Color.Lerp(MainColor, Color.White, 0.5f) : MainColor; } } else @@ -91,13 +99,17 @@ namespace CalamityMod.Projectiles.Magic Vector2 dustVel = Projectile.velocity * Main.rand.NextFloat(0.1f, 1.5f); Dust dust = Dust.NewDustPerfect(Projectile.Center + dustVel + Main.rand.NextVector2Circular(6, 6), Main.rand.NextBool(4) ? 264 : 66, dustVel, 0, default, Main.rand.NextFloat(0.9f, 1.2f)); dust.noGravity = true; - dust.color = Main.rand.NextBool() ? Color.Lerp(mainColor, Color.White, 0.5f) : mainColor; + dust.color = Main.rand.NextBool() ? Color.Lerp(MainColor, Color.White, 0.5f) : MainColor; } } + + Projectile.netSpam = 0; + Projectile.netUpdate = true; } + public override void ModifyHitNPC(NPC target, ref NPC.HitModifiers modifiers) { - if (splitShot) // This is the sweet spot + if (SplitShot) // This is the sweet spot { modifiers.SourceDamage *= 1.5f; @@ -108,7 +120,7 @@ namespace CalamityMod.Projectiles.Magic for (int k = 0; k < points; k++) { Vector2 velocity = spinningPoint.RotatedBy(radians * k).RotatedBy(-0.45f * rotRando); - Particle subTrail = new GlowSparkParticle(Projectile.Center + velocity * 10.5f, velocity * 5, false, 10, 0.045f, mainColor, new Vector2(2, 0.4f), true); + Particle subTrail = new GlowSparkParticle(Projectile.Center + velocity * 10.5f, velocity * 5, false, 10, 0.045f, MainColor, new Vector2(2, 0.4f), true); GeneralParticleHandler.SpawnParticle(subTrail); } diff --git a/Projectiles/Magic/GenesisHoldout.cs b/Projectiles/Magic/GenesisHoldout.cs index 65385f8a61..d0d83c08e1 100644 --- a/Projectiles/Magic/GenesisHoldout.cs +++ b/Projectiles/Magic/GenesisHoldout.cs @@ -34,23 +34,21 @@ namespace CalamityMod.Projectiles.Magic public override void KillHoldoutLogic() { if (HeldItem.type != Owner.ActiveItem().type || Owner.CantUseHoldout()) - { Projectile.Kill(); - Projectile.netUpdate = true; - } } public override void HoldoutAI() { if (ShootingTimer >= FireRate) { - if (Owner.CheckMana(Owner.ActiveItem(), -1, true, false)) + if (Owner.CheckMana(HeldItem, -1, true, false)) { + MaxFirerateShots++; + if (MaxFirerateShots == 6f) { FireYBeam = true; Windup = 60f; - Projectile.netUpdate = true; } if (FireYBeam) @@ -61,6 +59,8 @@ namespace CalamityMod.Projectiles.Magic else Shoot(false); + ShootingTimer = 0f; + if (Windup > 10f) { if (!FireYBeam) @@ -69,22 +69,19 @@ namespace CalamityMod.Projectiles.Magic else Windup = 10f; - MaxFirerateShots++; - ShootingTimer = 0f; FireYBeam = false; } else { SoundEngine.PlaySound(SoundID.MaxMana with { Pitch = -0.5f }, Projectile.Center); Projectile.Kill(); - Projectile.netUpdate = true; } } ShootingTimer++; } - private void Shoot(bool yBeam) + public void Shoot(bool yBeam) { Vector2 shootDirection = Projectile.velocity.SafeNormalize(Vector2.Zero); @@ -99,7 +96,8 @@ namespace CalamityMod.Projectiles.Magic SoundStyle fire = new("CalamityMod/Sounds/Item/LanceofDestinyStrong"); SoundEngine.PlaySound(fire with { Volume = 0.35f, Pitch = 1f, PitchVariance = 0.15f }, Projectile.Center); - Projectile.NewProjectileDirect(Projectile.GetSource_FromThis(), GunTipPosition, firingVelocity3, ModContent.ProjectileType(), Projectile.damage * 9, Projectile.knockBack, Projectile.owner, 0, 0); + if (Main.myPlayer == Projectile.owner) + Projectile.NewProjectileDirect(Projectile.GetSource_FromThis(), GunTipPosition, firingVelocity3, ModContent.ProjectileType(), Projectile.damage * 9, Projectile.knockBack, Projectile.owner, 0, 0); Particle pulse3 = new GlowSparkParticle(GunTipPosition, shootDirection * 18, false, 6, 0.057f, EffectsColor, new Vector2(1.7f, 0.8f), true); GeneralParticleHandler.SpawnParticle(pulse3); @@ -117,20 +115,22 @@ namespace CalamityMod.Projectiles.Magic for (int i = 0; i < 4; i++) { firingVelocity3 = (shootDirection * 10).RotatedBy((0.05f * (i + 1)) * Utils.GetLerpValue(0, 55, Windup, true)); - Projectile.NewProjectileDirect(Projectile.GetSource_FromThis(), GunTipPosition, firingVelocity3 * (1 - i * 0.1f), ModContent.ProjectileType(), Projectile.damage, Projectile.knockBack, Projectile.owner, 0, 1); + + if (Main.myPlayer == Projectile.owner) + Projectile.NewProjectileDirect(Projectile.GetSource_FromThis(), GunTipPosition, firingVelocity3 * (1 - i * 0.1f), ModContent.ProjectileType(), Projectile.damage, Projectile.knockBack, Projectile.owner, 0, 1); } for (int i = 0; i < 4; i++) { firingVelocity3 = (shootDirection * 10).RotatedBy((-0.05f * (i + 1)) * Utils.GetLerpValue(0, 55, Windup, true)); - Projectile.NewProjectileDirect(Projectile.GetSource_FromThis(), GunTipPosition, firingVelocity3 * (1 - i * 0.1f), ModContent.ProjectileType(), Projectile.damage, Projectile.knockBack, Projectile.owner, 0, 1); + + if (Main.myPlayer == Projectile.owner) + Projectile.NewProjectileDirect(Projectile.GetSource_FromThis(), GunTipPosition, firingVelocity3 * (1 - i * 0.1f), ModContent.ProjectileType(), Projectile.damage, Projectile.knockBack, Projectile.owner, 0, 1); } Particle pulse3 = new GlowSparkParticle(GunTipPosition, shootDirection * 18, false, 6, 0.057f, EffectsColor, new Vector2(1.7f, 0.8f), true); GeneralParticleHandler.SpawnParticle(pulse3); } - Projectile.netUpdate = true; - // Inside here go all the things that dedicated servers shouldn't spend resources on. // Like visuals and sounds. if (Main.dedServ) diff --git a/Projectiles/Magic/OmicronHoldout.cs b/Projectiles/Magic/OmicronHoldout.cs index 49c022c8a6..9a73374df0 100644 --- a/Projectiles/Magic/OmicronHoldout.cs +++ b/Projectiles/Magic/OmicronHoldout.cs @@ -6,6 +6,7 @@ using Terraria; using Terraria.Audio; using Terraria.ID; using Terraria.ModLoader; +using static CalamityMod.Items.Weapons.Magic.Omicron; namespace CalamityMod.Projectiles.Magic { @@ -18,50 +19,30 @@ namespace CalamityMod.Projectiles.Magic public override float BaseOffsetY => -5f; public override float OffsetYDownwards => 5f; - public Color StaticEffectsColor = Color.MediumVioletRed; + public ref float ShootingTimer => ref Projectile.ai[0]; + public ref float PostFireCooldown => ref Projectile.ai[1]; + public ref float MaxFireRateShots => ref Projectile.ai[2]; - public float FiringTime = 15; - public float Windup = 60; - public bool WindingUp = false; - public int time = 0; - public int PostFireCooldown = 0; - public bool fireYBeam = false; - public int maxFirerateShots = 0; - - private ref float ShootingTimer => ref Projectile.ai[0]; + public float Windup { get; set; } = StarterWinup; + public Color EffectsColor { get; set; } = Color.MediumVioletRed; public override void KillHoldoutLogic() { - if (Owner is null || !Owner.active || Owner.CCed || Owner.dead || Owner.noItems) - { - if (PostFireCooldown <= 0) - Projectile.Kill(); - Projectile.netUpdate = true; - } + if (Owner.CantUseHoldout() && PostFireCooldown <= 0) + Projectile.Kill(); } public override void HoldoutAI() { - Item heldItem = Owner.ActiveItem(); - - // Fire if the owner stops channeling or otherwise cannot use the weapon. - if (Owner.CantUseHoldout()) - { - if (PostFireCooldown <= 0) - Projectile.Kill(); - } - if (PostFireCooldown > 0) - { PostFiringCooldown(); - } if (Owner.Calamity().mouseRight && PostFireCooldown <= 0) { - if (Owner.CheckMana(Owner.ActiveItem(), (int)(heldItem.mana * Owner.manaCost) * 16, true, false)) + if (Owner.CheckMana(Owner.ActiveItem(), (int)(HeldItem.mana * Owner.manaCost) * 16, true, false)) { PostFireCooldown = 100; - Shoot(heldItem, true); + Shoot(true); ShootingTimer = 0; } else @@ -74,31 +55,26 @@ namespace CalamityMod.Projectiles.Magic } } } - else if (ShootingTimer >= FiringTime) + else if (ShootingTimer >= FireRate) { if (Owner.CheckMana(Owner.ActiveItem(), -1, true, false) && PostFireCooldown <= 0) { - maxFirerateShots++; + MaxFireRateShots++; - if (maxFirerateShots == 5) + if (MaxFireRateShots == 5) { Windup = 60; - maxFirerateShots = 1; + MaxFireRateShots = 1; } - Shoot(heldItem, false); + Shoot(false); ShootingTimer = 0; - if (Windup > 10) - { - if (maxFirerateShots > 0) - Windup -= 12; - } + if (Windup > 10 && MaxFireRateShots > 0) + Windup -= 12; else - { Windup = 10; - } } else if (PostFireCooldown <= 0) { @@ -107,9 +83,11 @@ namespace CalamityMod.Projectiles.Magic } } + ShootingTimer++; } - private void Shoot(Item item, bool yBeam) + + public void Shoot(bool yBeam) { Vector2 shootDirection = Projectile.velocity.SafeNormalize(Vector2.Zero); @@ -126,7 +104,7 @@ namespace CalamityMod.Projectiles.Magic for (int k = 0; k < 6; k++) { - Particle pulse2 = new GlowSparkParticle(GunTipPosition, shootDirection * 28, false, 8, 0.087f, StaticEffectsColor, new Vector2(2.3f, 0.9f), true); + Particle pulse2 = new GlowSparkParticle(GunTipPosition, shootDirection * 28, false, 8, 0.087f, EffectsColor, new Vector2(2.3f, 0.9f), true); GeneralParticleHandler.SpawnParticle(pulse2); } @@ -135,7 +113,7 @@ namespace CalamityMod.Projectiles.Magic for (int i = 0; i < 8; i++) { - SparkParticle spark2 = new SparkParticle(GunTipPosition + Main.rand.NextVector2Circular(10, 10), firingVelocity3 * Main.rand.NextFloat(0.7f, 1.3f), false, Main.rand.Next(20, 30), Main.rand.NextFloat(0.4f, 0.55f), StaticEffectsColor); + SparkParticle spark2 = new SparkParticle(GunTipPosition + Main.rand.NextVector2Circular(10, 10), firingVelocity3 * Main.rand.NextFloat(0.7f, 1.3f), false, Main.rand.Next(20, 30), Main.rand.NextFloat(0.4f, 0.55f), EffectsColor); GeneralParticleHandler.SpawnParticle(spark2); } } @@ -155,7 +133,7 @@ namespace CalamityMod.Projectiles.Magic Projectile.NewProjectileDirect(Projectile.GetSource_FromThis(), GunTipPosition, firingVelocity3 * (1 - i * 0.1f), ModContent.ProjectileType(), Projectile.damage, Projectile.knockBack, Projectile.owner, 0, 2); } - Particle pulse3 = new GlowSparkParticle(GunTipPosition, shootDirection * 18, false, 6, 0.057f, StaticEffectsColor, new Vector2(1.7f, 0.8f), true); + Particle pulse3 = new GlowSparkParticle(GunTipPosition, shootDirection * 18, false, 6, 0.057f, EffectsColor, new Vector2(1.7f, 0.8f), true); GeneralParticleHandler.SpawnParticle(pulse3); } @@ -171,7 +149,7 @@ namespace CalamityMod.Projectiles.Magic Dust dust2 = Dust.NewDustPerfect(GunTipPosition, Main.rand.NextBool(4) ? 267 : 66, shootVel); dust2.scale = Main.rand.NextFloat(1.15f, 1.45f); dust2.noGravity = true; - dust2.color = Main.rand.NextBool() ? Color.Lerp(StaticEffectsColor, Color.White, 0.5f) : StaticEffectsColor; + dust2.color = Main.rand.NextBool() ? Color.Lerp(EffectsColor, Color.White, 0.5f) : EffectsColor; } // By decreasing the offset length of the gun from the arms, we give an effect of recoil. @@ -180,18 +158,19 @@ namespace CalamityMod.Projectiles.Magic else OffsetLengthFromArm -= 6f; } - private void PostFiringCooldown() + + public void PostFiringCooldown() { Owner.channel = true; if (PostFireCooldown > 0 && Main.rand.NextBool()) { Vector2 smokeVel = new Vector2(0, -8) * Main.rand.NextFloat(0.1f, 1.1f); - Particle smoke = new HeavySmokeParticle(GunTipPosition, smokeVel, StaticEffectsColor, Main.rand.Next(30, 50 + 1), Main.rand.NextFloat(0.1f, 0.4f), 0.5f, Main.rand.NextFloat(-0.2f, 0.2f), Main.rand.NextBool(), required: true); + Particle smoke = new HeavySmokeParticle(GunTipPosition, smokeVel, EffectsColor, Main.rand.Next(30, 50 + 1), Main.rand.NextFloat(0.1f, 0.4f), 0.5f, Main.rand.NextFloat(-0.2f, 0.2f), Main.rand.NextBool(), required: true); GeneralParticleHandler.SpawnParticle(smoke); Dust dust = Dust.NewDustPerfect(GunTipPosition, 303, smokeVel.RotatedByRandom(0.1f), 80, default, Main.rand.NextFloat(0.2f, 0.8f)); dust.noGravity = false; - dust.color = StaticEffectsColor; + dust.color = EffectsColor; } ShootingTimer = 0; PostFireCooldown--; diff --git a/Projectiles/Ranged/ArcNovaDiffuserHoldout.cs b/Projectiles/Ranged/ArcNovaDiffuserHoldout.cs index bc886a28f8..e042721fbb 100644 --- a/Projectiles/Ranged/ArcNovaDiffuserHoldout.cs +++ b/Projectiles/Ranged/ArcNovaDiffuserHoldout.cs @@ -24,19 +24,16 @@ namespace CalamityMod.Projectiles.Ranged public static float BulletSpeed = 12f; public SlotId NovaChargeSlot; - private ref float CurrentChargingFrames => ref Projectile.ai[0]; - private ref float ShotsLoaded => ref Projectile.ai[1]; - private ref float ShootRecoilTimer => ref Projectile.ai[2]; // Dual functions for rapid fire shooting cooldown and recoil - private bool ChargeLV1 => CurrentChargingFrames >= ArcNovaDiffuser.Charge1Frames; - private bool ChargeLV2 => CurrentChargingFrames >= ArcNovaDiffuser.Charge2Frames; + public ref float CurrentChargingFrames => ref Projectile.ai[0]; + public ref float ShotsLoaded => ref Projectile.ai[1]; + public ref float ShootRecoilTimer => ref Projectile.ai[2]; // Dual functions for rapid fire shooting cooldown and recoil + public bool ChargeLV1 => CurrentChargingFrames >= ArcNovaDiffuser.Charge1Frames; + public bool ChargeLV2 => CurrentChargingFrames >= ArcNovaDiffuser.Charge2Frames; public override void KillHoldoutLogic() { if (HeldItem.type != Owner.ActiveItem().type || Owner is null || !Owner.active || Owner.CCed || Owner.dead || Owner.noItems) - { Projectile.Kill(); - Projectile.netUpdate = true; - } } public override void HoldoutAI() @@ -74,8 +71,6 @@ namespace CalamityMod.Projectiles.Ranged ShotsLoaded = 0; ShootRecoilTimer = 24f; OffsetLengthFromArm -= 25f; - Projectile.netSpam = 0; - Projectile.netUpdate = true; } // Retracting recoil else if (ShootRecoilTimer > 0) @@ -107,8 +102,6 @@ namespace CalamityMod.Projectiles.Ranged ShotsLoaded--; ShootRecoilTimer = 16f; OffsetLengthFromArm -= 5f; - Projectile.netSpam = 0; - Projectile.netUpdate = true; } } // Retracting any remaining recoil diff --git a/Projectiles/Ranged/BloodfireArrowProj.cs b/Projectiles/Ranged/BloodfireArrowProj.cs index 822774e748..92725f50c7 100644 --- a/Projectiles/Ranged/BloodfireArrowProj.cs +++ b/Projectiles/Ranged/BloodfireArrowProj.cs @@ -100,7 +100,7 @@ namespace CalamityMod.Projectiles.Ranged if (player.moonLeech) return; - if (Main.player[Main.myPlayer].lifeSteal <= 0f || target.lifeMax <= 5) + if (target.lifeMax <= 5) return; float lifeRatio = (float)player.statLife / player.statLifeMax2; diff --git a/Projectiles/Ranged/ElementalEruptionHouldout.cs b/Projectiles/Ranged/ElementalEruptionHouldout.cs index e3c445aa01..bb8f4c68f1 100644 --- a/Projectiles/Ranged/ElementalEruptionHouldout.cs +++ b/Projectiles/Ranged/ElementalEruptionHouldout.cs @@ -1,4 +1,5 @@ -using CalamityMod.Items.Weapons.Ranged; +using System.IO; +using CalamityMod.Items.Weapons.Ranged; using CalamityMod.Projectiles.BaseProjectiles; using Microsoft.Xna.Framework; using Terraria; @@ -17,19 +18,16 @@ namespace CalamityMod.Projectiles.Ranged public override float BaseOffsetY => -5f; public override float OffsetYDownwards => 10f; - private ref float ShotCooldown => ref Projectile.ai[0]; - private ref float ShotsFired => ref Projectile.ai[1]; - private ref float ShootTimer => ref Projectile.ai[2]; - public int FireBlobs = 0; + public ref float ShotCooldown => ref Projectile.ai[0]; + public ref float ShotsFired => ref Projectile.ai[1]; + public ref float ShootTimer => ref Projectile.ai[2]; + public int FireBlobs { get; set; } public override void KillHoldoutLogic() { base.KillHoldoutLogic(); if (ShotsFired >= 24) - { Projectile.Kill(); - Projectile.netUpdate = true; - } } public override void HoldoutAI() @@ -91,5 +89,9 @@ namespace CalamityMod.Projectiles.Ranged base.OnSpawn(source); SoundEngine.PlaySound(SoundID.Item73 with { Volume = 0.7f }, Projectile.Center); } + + public override void SendExtraAIHoldout(BinaryWriter writer) => writer.Write(FireBlobs); + + public override void ReceiveExtraAIHoldout(BinaryReader reader) => FireBlobs = reader.ReadInt32(); } } diff --git a/Projectiles/Ranged/FlakKrakenHoldout.cs b/Projectiles/Ranged/FlakKrakenHoldout.cs index 2eaeff6f2a..362c7e66a2 100644 --- a/Projectiles/Ranged/FlakKrakenHoldout.cs +++ b/Projectiles/Ranged/FlakKrakenHoldout.cs @@ -134,8 +134,6 @@ namespace CalamityMod.Projectiles.Ranged SoundEngine.PlaySound(new SoundStyle("CalamityMod/Sounds/Item/FlakKrakenShoot") { Volume = 0.6f }, GunTipPosition); } - - NetUpdate(); } // When it has shot all the projectiles in the burst, reset all the variables and back to shooting. @@ -143,7 +141,6 @@ namespace CalamityMod.Projectiles.Ranged { ShootingTimer = 0f; TimerBetweenBursts = 0f; - NetUpdate(); } } @@ -155,12 +152,5 @@ namespace CalamityMod.Projectiles.Ranged base.OnSpawn(source); FrontArmStretch = Player.CompositeArmStretchAmount.ThreeQuarters; } - - public void NetUpdate() - { - Projectile.netUpdate = true; - if (Projectile.netSpam >= 10) - Projectile.netSpam = 9; - } } } diff --git a/Projectiles/Ranged/FlakToxicannonHoldout.cs b/Projectiles/Ranged/FlakToxicannonHoldout.cs index 05b47dfeeb..1bf6ce82a7 100644 --- a/Projectiles/Ranged/FlakToxicannonHoldout.cs +++ b/Projectiles/Ranged/FlakToxicannonHoldout.cs @@ -135,7 +135,7 @@ namespace CalamityMod.Projectiles.Ranged } ShootingTimer = 0f; - Projectile.netUpdate = true; + } ShootingTimer++; diff --git a/Projectiles/Ranged/ScorpioHoldout.cs b/Projectiles/Ranged/ScorpioHoldout.cs index c18f942a5d..36669dd5f8 100644 --- a/Projectiles/Ranged/ScorpioHoldout.cs +++ b/Projectiles/Ranged/ScorpioHoldout.cs @@ -29,7 +29,7 @@ namespace CalamityMod.Projectiles.Ranged // It'll carry over to the projectiles that it shoots. public static int DustEffectsID { get; set; } public static Color EffectsColor { get; set; } - public static Color StaticEffectsColor = Color.Turquoise; + public static Color StaticEffectsColor { get; set; } = Color.Turquoise; public override void HoldoutAI() { @@ -58,7 +58,6 @@ namespace CalamityMod.Projectiles.Ranged { ShootingTimer = 0f; TimerBetweenBursts = 0f; - NetUpdate(); } } @@ -155,8 +154,6 @@ namespace CalamityMod.Projectiles.Ranged rocketType, projSpeed); - NetUpdate(); - // Inside here go all the things that dedicated servers shouldn't spend resources on. // Like visuals and sounds. if (Main.dedServ) @@ -195,13 +192,6 @@ namespace CalamityMod.Projectiles.Ranged GeneralParticleHandler.SpawnParticle(shootPulse); } - public void NetUpdate() - { - Projectile.netUpdate = true; - if (Projectile.netSpam >= 10) - Projectile.netSpam = 9; - } - public override bool PreDraw(ref Color lightColor) { Texture2D texture = Terraria.GameContent.TextureAssets.Projectile[Projectile.type].Value; diff --git a/Projectiles/Ranged/TheHiveHoldout.cs b/Projectiles/Ranged/TheHiveHoldout.cs index f29cb26b3e..a282f52ad9 100644 --- a/Projectiles/Ranged/TheHiveHoldout.cs +++ b/Projectiles/Ranged/TheHiveHoldout.cs @@ -8,6 +8,7 @@ using Terraria; using Terraria.Audio; using Terraria.DataStructures; using Terraria.ID; +using static CalamityMod.Items.Weapons.Ranged.TheHive; using static Terraria.ModLoader.ModContent; namespace CalamityMod.Projectiles.Ranged @@ -25,14 +26,18 @@ namespace CalamityMod.Projectiles.Ranged // It'll carry over to the projectiles that it shoots. public static int DustEffectsID { get; set; } public static Color EffectsColor { get; set; } - public static Color StaticEffectsColor = Color.Lime; + public static Color StaticEffectsColor { get; set; } = Color.Lime; - private ref float ShootingTimer => ref Projectile.ai[0]; - private bool FireNuke; - private float PostFireCooldown = 0; - private bool HasLetGo = false; - private SlotId HiveHum; - private const float MaxCharge = 90f; + public ref float ShootingTimer => ref Projectile.ai[0]; + public ref float PostFireCooldown => ref Projectile.ai[1]; + public bool HasLetGo + { + get => Projectile.ai[2] == 1f; + set => Projectile.ai[2] = value == true ? 1f : 0f; + } + + public bool FireNuke => ShootingTimer > MaxCharge; + public SlotId HiveHum { get; set; } public override void KillHoldoutLogic() { @@ -42,9 +47,6 @@ namespace CalamityMod.Projectiles.Ranged public override void HoldoutAI() { - - FireNuke = ShootingTimer > MaxCharge; - // If there's no player, or the player is the server, or the owner's stunned, there'll be no holdout. if (Owner.CantUseHoldout() && !HasLetGo) { @@ -54,7 +56,6 @@ namespace CalamityMod.Projectiles.Ranged } if (HeldItem.type == ItemType()) ShootRocket(); - NetUpdate(); HasLetGo = true; } @@ -102,7 +103,7 @@ namespace CalamityMod.Projectiles.Ranged } } - private void ShootRocket() + public void ShootRocket() { // We use the velocity of this projectile as its direction vector. Vector2 shootDirection = Projectile.velocity.SafeNormalize(Vector2.Zero); @@ -173,8 +174,6 @@ namespace CalamityMod.Projectiles.Ranged PostFireCooldown = 30; } - NetUpdate(); - // Inside here go all the things that dedicated servers shouldn't spend resources on. // Like visuals and sounds. if (Main.dedServ) @@ -210,7 +209,7 @@ namespace CalamityMod.Projectiles.Ranged OffsetLengthFromArm -= FireNuke ? 16f : 6f; } - private void PostFiringCooldown() + public void PostFiringCooldown() { Owner.channel = true; if (PostFireCooldown > 0) @@ -227,21 +226,11 @@ namespace CalamityMod.Projectiles.Ranged else { if (SoundEngine.TryGetActiveSound(HiveHum, out var hum) && hum.IsPlaying) - { hum?.Stop(); - } Projectile.Kill(); - NetUpdate(); } } - private void NetUpdate() - { - Projectile.netUpdate = true; - if (Projectile.netSpam >= 10) - Projectile.netSpam = 9; - } - public override void OnSpawn(IEntitySource source) { base.OnSpawn(source); diff --git a/Projectiles/Ranged/WildfireBloomHoldout.cs b/Projectiles/Ranged/WildfireBloomHoldout.cs index 6144e97939..dc4086d841 100644 --- a/Projectiles/Ranged/WildfireBloomHoldout.cs +++ b/Projectiles/Ranged/WildfireBloomHoldout.cs @@ -1,12 +1,10 @@ -using CalamityMod.Items.Weapons.Ranged; +using System.IO; +using CalamityMod.Items.Weapons.Ranged; using CalamityMod.Projectiles.BaseProjectiles; using Microsoft.Xna.Framework; -using Microsoft.Xna.Framework.Graphics; -using ReLogic.Content; using Terraria; using Terraria.Audio; using Terraria.DataStructures; -using Terraria.GameContent; using Terraria.ID; using Terraria.ModLoader; @@ -22,19 +20,16 @@ namespace CalamityMod.Projectiles.Ranged public override float BaseOffsetY => -5f; public override float OffsetYDownwards => 5f; - private ref float ShotCooldown => ref Projectile.ai[0]; - private ref float ShotsFired => ref Projectile.ai[1]; - private ref float ShootTimer => ref Projectile.ai[2]; - public int FireBlobs = 0; + public ref float ShotCooldown => ref Projectile.ai[0]; + public ref float ShotsFired => ref Projectile.ai[1]; + public ref float ShootTimer => ref Projectile.ai[2]; + public int FireBlobs { get; set; } public override void KillHoldoutLogic() { base.KillHoldoutLogic(); if (ShotsFired >= 16) - { Projectile.Kill(); - Projectile.netUpdate = true; - } } public override void HoldoutAI() @@ -83,5 +78,9 @@ namespace CalamityMod.Projectiles.Ranged base.OnSpawn(source); SoundEngine.PlaySound(SoundID.Item73 with { Volume = 0.7f }, Projectile.Center); } + + public override void SendExtraAIHoldout(BinaryWriter writer) => writer.Write(FireBlobs); + + public override void ReceiveExtraAIHoldout(BinaryReader reader) => FireBlobs = reader.ReadInt32(); } }