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/Projectiles/BaseProjectiles/BaseGunHoldoutProjectile.cs b/Projectiles/BaseProjectiles/BaseGunHoldoutProjectile.cs index ccb458a981..f4605f3739 100644 --- a/Projectiles/BaseProjectiles/BaseGunHoldoutProjectile.cs +++ b/Projectiles/BaseProjectiles/BaseGunHoldoutProjectile.cs @@ -141,7 +141,7 @@ namespace CalamityMod.Projectiles.BaseProjectiles public override void SetDefaults() { - Projectile.width = Projectile.height = ItemTexture is null ? 0 : ItemTexture.Width(); + Projectile.width = Projectile.height = ItemTexture is null ? 1 : ItemTexture.Width(); Projectile.tileCollide = false; Projectile.netImportant = true; } @@ -171,15 +171,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(); - } } /// @@ -225,6 +222,9 @@ namespace CalamityMod.Projectiles.BaseProjectiles if (OffsetLengthFromArm != MaxOffsetLengthFromArm) OffsetLengthFromArm = MathHelper.Lerp(OffsetLengthFromArm, MaxOffsetLengthFromArm, RecoilResolveSpeed); + + Projectile.netUpdate = true; + Projectile.netSpam = 0; } /// @@ -258,6 +258,7 @@ namespace CalamityMod.Projectiles.BaseProjectiles writer.Write(Projectile.rotation); writer.Write(KeepRefreshingLifetime); writer.Write(OffsetLengthFromArm); + writer.Write(Projectile.spriteDirection); SendExtraAIHoldout(writer); } @@ -266,6 +267,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/GenesisHoldout.cs b/Projectiles/Magic/GenesisHoldout.cs index 65385f8a61..28276d0701 100644 --- a/Projectiles/Magic/GenesisHoldout.cs +++ b/Projectiles/Magic/GenesisHoldout.cs @@ -34,10 +34,7 @@ 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() @@ -50,7 +47,6 @@ namespace CalamityMod.Projectiles.Magic { FireYBeam = true; Windup = 60f; - Projectile.netUpdate = true; } if (FireYBeam) @@ -61,11 +57,8 @@ namespace CalamityMod.Projectiles.Magic else Shoot(false); - if (Windup > 10f) - { - if (!FireYBeam) - Windup -= 12f; - } + if (Windup > 10f && !FireYBeam) + Windup -= 12f; else Windup = 10f; @@ -77,14 +70,13 @@ namespace CalamityMod.Projectiles.Magic { 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); @@ -129,8 +121,6 @@ namespace CalamityMod.Projectiles.Magic 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/ElementalEruptionHouldout.cs b/Projectiles/Ranged/ElementalEruptionHouldout.cs index 93a5cbf4bd..bb8f4c68f1 100644 --- a/Projectiles/Ranged/ElementalEruptionHouldout.cs +++ b/Projectiles/Ranged/ElementalEruptionHouldout.cs @@ -18,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]; - private int FireBlobs { get; set; } + 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() @@ -66,8 +63,6 @@ namespace CalamityMod.Projectiles.Ranged } else FireBlobs--; - - Projectile.netUpdate = true; } else ShotCooldown--; 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 f2800e0a61..a282f52ad9 100644 --- a/Projectiles/Ranged/TheHiveHoldout.cs +++ b/Projectiles/Ranged/TheHiveHoldout.cs @@ -28,16 +28,16 @@ namespace CalamityMod.Projectiles.Ranged public static Color EffectsColor { get; set; } public static Color StaticEffectsColor { get; set; } = Color.Lime; - private ref float ShootingTimer => ref Projectile.ai[0]; - private ref float PostFireCooldown => ref Projectile.ai[1]; - private bool HasLetGo + 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; } - private bool FireNuke => ShootingTimer > MaxCharge; - private SlotId HiveHum { get; set; } + public bool FireNuke => ShootingTimer > MaxCharge; + public SlotId HiveHum { get; set; } public override void KillHoldoutLogic() { @@ -57,7 +57,6 @@ namespace CalamityMod.Projectiles.Ranged if (HeldItem.type == ItemType()) ShootRocket(); HasLetGo = true; - NetUpdate(); } if (!HasLetGo) @@ -104,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); @@ -175,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) @@ -212,7 +209,7 @@ namespace CalamityMod.Projectiles.Ranged OffsetLengthFromArm -= FireNuke ? 16f : 6f; } - private void PostFiringCooldown() + public void PostFiringCooldown() { Owner.channel = true; if (PostFireCooldown > 0) @@ -229,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 cff7bfed63..dc4086d841 100644 --- a/Projectiles/Ranged/WildfireBloomHoldout.cs +++ b/Projectiles/Ranged/WildfireBloomHoldout.cs @@ -20,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 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() @@ -58,8 +55,6 @@ namespace CalamityMod.Projectiles.Ranged } else FireBlobs--; - - Projectile.netUpdate = true; } else ShotCooldown--;