From d1ff0e4b8974e0142ca82002b1275cf553908dcf Mon Sep 17 00:00:00 2001 From: Dreitone Date: Fri, 6 Feb 2026 00:49:07 -0600 Subject: [PATCH] fix starmada, starfleet and basegunholdout projectile syncing --- .../BaseGunHoldoutProjectile.cs | 56 +++++++++++++------ Projectiles/Ranged/FetidEmesisHoldout.cs | 3 + Projectiles/Ranged/StarfleetHoldout.cs | 2 +- Projectiles/Ranged/StarmadaHoldout.cs | 22 +++++++- 4 files changed, 61 insertions(+), 22 deletions(-) diff --git a/Projectiles/BaseProjectiles/BaseGunHoldoutProjectile.cs b/Projectiles/BaseProjectiles/BaseGunHoldoutProjectile.cs index 84fc068a5f..9f2d8a4941 100644 --- a/Projectiles/BaseProjectiles/BaseGunHoldoutProjectile.cs +++ b/Projectiles/BaseProjectiles/BaseGunHoldoutProjectile.cs @@ -197,27 +197,46 @@ namespace CalamityMod.Projectiles.BaseProjectiles // The center of the player, taking into account if they have a mount or not. Vector2 armPosition = Owner.RotatedRelativePoint(Owner.MountedCenter, true); - // 14NOV2024: Ozzatron: clamped mouse position unnecessary, only used for direction - // The vector between the player and the mouse, used for pointing the holdout. - Vector2 ownerToMouse = Owner.Calamity().mouseWorld - armPosition; - // The direction this holdout's pointing at. float holdoutDirection = Projectile.velocity.ToRotation(); - // A range from -1 to 1 for when the holdout is pointing downards of upwards, respectively. - // Used for the offsets. - float proximityLookingUpwards = Vector2.Dot(ownerToMouse.SafeNormalize(Vector2.Zero), -Vector2.UnitY * Owner.gravDir); + // Only the owner should compute aiming from mouse position. + // Non-owner clients use the synced rotation/direction to avoid jitter. + if (Projectile.owner == Main.myPlayer) + { + // 14NOV2024: Ozzatron: clamped mouse position unnecessary, only used for direction + // The vector between the player and the mouse, used for pointing the holdout. + Vector2 ownerToMouse = Owner.Calamity().mouseWorld - armPosition; - int direction = MathF.Sign(ownerToMouse.X); + // A range from -1 to 1 for when the holdout is pointing downards of upwards, respectively. + // Used for the offsets. + float proximityLookingUpwards = Vector2.Dot(ownerToMouse.SafeNormalize(Vector2.Zero), -Vector2.UnitY * Owner.gravDir); - Vector2 lengthOffset = Projectile.rotation.ToRotationVector2() * OffsetLengthFromArm; - Vector2 armOffset = new Vector2(Utils.Remap(MathF.Abs(proximityLookingUpwards), 0f, 1f, 0f, proximityLookingUpwards > 0f ? OffsetXUpwards : OffsetXDownwards) * direction, BaseOffsetY * Owner.gravDir + Utils.Remap(MathF.Abs(proximityLookingUpwards), 0f, 1f, 0f, proximityLookingUpwards > 0f ? OffsetYUpwards : OffsetYDownwards) * Owner.gravDir); - Projectile.Center = armPosition + lengthOffset + armOffset; - Projectile.velocity = holdoutDirection.AngleTowards(ownerToMouse.ToRotation(), WeaponTurnSpeed).ToRotationVector2(); - Projectile.rotation = holdoutDirection; + int direction = MathF.Sign(ownerToMouse.X); - Projectile.spriteDirection = direction; - Owner.ChangeDir(direction); + Vector2 lengthOffset = Projectile.rotation.ToRotationVector2() * OffsetLengthFromArm; + Vector2 armOffset = new Vector2(Utils.Remap(MathF.Abs(proximityLookingUpwards), 0f, 1f, 0f, proximityLookingUpwards > 0f ? OffsetXUpwards : OffsetXDownwards) * direction, BaseOffsetY * Owner.gravDir + Utils.Remap(MathF.Abs(proximityLookingUpwards), 0f, 1f, 0f, proximityLookingUpwards > 0f ? OffsetYUpwards : OffsetYDownwards) * Owner.gravDir); + Projectile.Center = armPosition + lengthOffset + armOffset; + Projectile.velocity = holdoutDirection.AngleTowards(ownerToMouse.ToRotation(), WeaponTurnSpeed).ToRotationVector2(); + Projectile.rotation = holdoutDirection; + + Projectile.spriteDirection = direction; + Owner.ChangeDir(direction); + } + else + { + Vector2 lengthOffset = Projectile.rotation.ToRotationVector2() * OffsetLengthFromArm; + float proximityLookingUpwards = Vector2.Dot(Projectile.velocity.SafeNormalize(Vector2.Zero), -Vector2.UnitY * Owner.gravDir); + int direction = Projectile.spriteDirection; + + Vector2 armOffset = new Vector2(Utils.Remap(MathF.Abs(proximityLookingUpwards), 0f, 1f, 0f, proximityLookingUpwards > 0f ? OffsetXUpwards : OffsetXDownwards) * direction, BaseOffsetY * Owner.gravDir + Utils.Remap(MathF.Abs(proximityLookingUpwards), 0f, 1f, 0f, proximityLookingUpwards > 0f ? OffsetYUpwards : OffsetYDownwards) * Owner.gravDir); + Projectile.Center = armPosition + lengthOffset + armOffset; + Projectile.velocity = Projectile.rotation.ToRotationVector2(); + + Owner.ChangeDir(direction); + } + + int currentDirection = Projectile.spriteDirection; Owner.heldProj = Projectile.whoAmI; if (SetUsage) @@ -226,8 +245,8 @@ namespace CalamityMod.Projectiles.BaseProjectiles // -Pi/2 because the arms rotation starts with arms pointing down. float armRotation = (Projectile.rotation - MathHelper.PiOver2) * Owner.gravDir + (Owner.gravDir == -1 ? MathHelper.Pi : 0f); - Owner.SetCompositeArmFront(true, FrontArmStretch, armRotation + ExtraFrontArmRotation * direction); - Owner.SetCompositeArmBack(true, BackArmStretch, armRotation + ExtraBackArmRotation * direction); + Owner.SetCompositeArmFront(true, FrontArmStretch, armRotation + ExtraFrontArmRotation * currentDirection); + Owner.SetCompositeArmBack(true, BackArmStretch, armRotation + ExtraBackArmRotation * currentDirection); if (KeepRefreshingLifetime) Projectile.timeLeft = 2; @@ -235,7 +254,8 @@ namespace CalamityMod.Projectiles.BaseProjectiles if (OffsetLengthFromArm != MaxOffsetLengthFromArm) OffsetLengthFromArm = MathHelper.Lerp(OffsetLengthFromArm, MaxOffsetLengthFromArm, RecoilResolveSpeed); - Projectile.ForceNetUpdate(); + if (Projectile.owner == Main.myPlayer) + Projectile.ForceNetUpdate(); } /// diff --git a/Projectiles/Ranged/FetidEmesisHoldout.cs b/Projectiles/Ranged/FetidEmesisHoldout.cs index 584635a71f..c712407bed 100644 --- a/Projectiles/Ranged/FetidEmesisHoldout.cs +++ b/Projectiles/Ranged/FetidEmesisHoldout.cs @@ -28,6 +28,7 @@ namespace CalamityMod.Projectiles.Ranged public int maxFrames = 420; public int initialFireTime = 45; public float shineScale = 0; + private bool secondShot = true; public override void KillHoldoutLogic() { @@ -69,6 +70,7 @@ namespace CalamityMod.Projectiles.Ranged OffsetLengthFromArm -= 5f; shineScale = 1; + secondShot = false; } if (shootingTimer >= 60 && revFrames < maxFrames) { @@ -81,6 +83,7 @@ namespace CalamityMod.Projectiles.Ranged Projectile.netUpdate = true; } shootingTimer = 0; + secondShot = true; } shootingTimer += revSpeed; diff --git a/Projectiles/Ranged/StarfleetHoldout.cs b/Projectiles/Ranged/StarfleetHoldout.cs index 19648f1d63..4c61eb2ea8 100644 --- a/Projectiles/Ranged/StarfleetHoldout.cs +++ b/Projectiles/Ranged/StarfleetHoldout.cs @@ -100,7 +100,7 @@ namespace CalamityMod.Projectiles.Ranged bool leftShootChecks = Owner.whoAmI == Main.myPlayer && (Main.mouseLeft && !Main.mapFullscreen && !Owner.mouseInterface && shootingCooldown == 0) && hasAmmo; bool rightShootChecks = Owner.whoAmI == Main.myPlayer && (Owner.Calamity().mouseRight && !Main.mapFullscreen && !Owner.mouseInterface && starburstCooldown == 0 && starburstTimer == 0); - if (Main.mouseLeft && !hasAmmo && OffsetLengthFromArm >= 24.5f) + if (Owner.whoAmI == Main.myPlayer && Main.mouseLeft && !hasAmmo && OffsetLengthFromArm >= 24.5f) { OffsetLengthFromArm -= 8; SoundStyle click = new("CalamityMod/Sounds/Item/DudFire"); diff --git a/Projectiles/Ranged/StarmadaHoldout.cs b/Projectiles/Ranged/StarmadaHoldout.cs index c37be6670a..1f7ce2f7c5 100644 --- a/Projectiles/Ranged/StarmadaHoldout.cs +++ b/Projectiles/Ranged/StarmadaHoldout.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.IO; using CalamityMod.Dusts; using CalamityMod.Items.Weapons.Ranged; using CalamityMod.Particles; @@ -57,6 +58,19 @@ namespace CalamityMod.Projectiles.Ranged public bool naildriver => ((starburstTimer <= starburstPerfectTime + perfectLeniancy) && (starburstTimer >= starburstPerfectTime - perfectLeniancy)); // if within perfect frame window public bool scattershot => !naildriver && ((starburstTimer <= starburstPerfectTime + goodLeniancy) && (starburstTimer >= starburstPerfectTime - goodLeniancy)); // If within early or late frame window public override void KillHoldoutLogic() { } + public override void SendExtraAIHoldout(BinaryWriter writer) + { + writer.Write(lastUseTime); + writer.Write(gunPower); + writer.Write(lastGunPower); + } + + public override void ReceiveExtraAIHoldout(BinaryReader reader) + { + lastUseTime = reader.ReadInt32(); + gunPower = reader.ReadInt32(); + lastGunPower = reader.ReadInt32(); + } public override void SetDefaults() { base.SetDefaults(); @@ -97,10 +111,10 @@ namespace CalamityMod.Projectiles.Ranged return; } bool hasAmmo = Owner.PickAmmo(HeldItem, out _, out _, out _, out _, out _, true); - bool leftShootChecks = (Main.mouseLeft && !Main.mapFullscreen && !Owner.mouseInterface && shootingCooldown == 0) && hasAmmo; - bool rightShootChecks = Owner.Calamity().mouseRight && !Main.mapFullscreen && !Owner.mouseInterface && starburstCooldown == 0 && starburstTimer == 0; + bool leftShootChecks = Owner.whoAmI == Main.myPlayer && (Main.mouseLeft && !Main.mapFullscreen && !Owner.mouseInterface && shootingCooldown == 0) && hasAmmo; + bool rightShootChecks = Owner.whoAmI == Main.myPlayer && Owner.Calamity().mouseRight && !Main.mapFullscreen && !Owner.mouseInterface && starburstCooldown == 0 && starburstTimer == 0; - if (Main.mouseLeft && !hasAmmo && shake < 0.1f) + if (Owner.whoAmI == Main.myPlayer && Main.mouseLeft && !hasAmmo && shake < 0.1f) { shake = 0.8f; SoundStyle click = new("CalamityMod/Sounds/Item/DudFire"); @@ -111,6 +125,7 @@ namespace CalamityMod.Projectiles.Ranged FireShotgun(); if (rightShootChecks) { + Projectile.ForceNetUpdate(); SoundStyle blast1 = new("CalamityMod/Sounds/Item/StarfleetStarburst"); AudSlot1 = SoundEngine.PlaySound(blast1 with { Volume = 0.7f + gunPower * 0.1f, Pitch = 0f, MaxInstances = 8 }, Projectile.Center); SoundStyle blast2 = new("CalamityMod/Sounds/Item/StarfleetStarburst"); @@ -192,6 +207,7 @@ namespace CalamityMod.Projectiles.Ranged } public void FireShotgun() { + Projectile.ForceNetUpdate(); // 50% chance to not consume ammo Owner.PickAmmo(HeldItem, out _, out _, out _, out _, out _, Main.rand.NextBool());