From da3ca4e9709281d958c90cef8ecd563f7033755a Mon Sep 17 00:00:00 2001 From: Stephen Thiebaud Date: Wed, 7 Jan 2026 19:55:09 -0600 Subject: [PATCH] fix: acrobatics pack more proper syncing --- CalamityNetcode.cs | 2 + Items/Accessories/WulfrumAcrobaticsPack.cs | 108 ++++++++++++++++++++- Projectiles/Typeless/WulfrumHook.cs | 28 +++++- 3 files changed, 132 insertions(+), 6 deletions(-) diff --git a/CalamityNetcode.cs b/CalamityNetcode.cs index 33c5e2f016..1f087980dc 100644 --- a/CalamityNetcode.cs +++ b/CalamityNetcode.cs @@ -212,5 +212,7 @@ namespace CalamityMod SyncPlayerDrawParameter, DialogueDisplayStart, + + WulfrumAcrobaticsSync, } } diff --git a/Items/Accessories/WulfrumAcrobaticsPack.cs b/Items/Accessories/WulfrumAcrobaticsPack.cs index e8723b67b3..476bcab30c 100644 --- a/Items/Accessories/WulfrumAcrobaticsPack.cs +++ b/Items/Accessories/WulfrumAcrobaticsPack.cs @@ -1,9 +1,13 @@ using System; using System.Collections.Generic; +using System.IO; using System.Linq; +using System.Net.Sockets; using CalamityMod.DataStructures; using CalamityMod.Items.Materials; +using CalamityMod.Packets; using CalamityMod.Projectiles.Typeless; +using CalamityMod.World; using Microsoft.Xna.Framework; using Terraria; using Terraria.Audio; @@ -23,7 +27,6 @@ namespace CalamityMod.Items.Accessories public static readonly SoundStyle GrabSound = new("CalamityMod/Sounds/Custom/WulfrumHookGrapple") { Volume = 0.7f, MaxInstances = 1, SoundLimitBehavior = SoundLimitBehavior.ReplaceOldest }; public static readonly SoundStyle ReleaseSound = new("CalamityMod/Sounds/Custom/WulfrumHookDisengage") { Volume = 0.7f, MaxInstances = 1, SoundLimitBehavior = SoundLimitBehavior.ReplaceOldest }; - public override void SetDefaults() { Item.width = 20; @@ -73,6 +76,7 @@ namespace CalamityMod.Items.Accessories } //Prevent players with a wulfrum pack to spawn any non-wulfrum hooks. + /* public override void OnSpawn(Projectile projectile, IEntitySource source) { Player owner = Main.player[projectile.owner]; @@ -80,7 +84,7 @@ namespace CalamityMod.Items.Accessories { projectile.active = false; } - } + }*/ } public class WulfrumPackPlayer : ModPlayer @@ -226,6 +230,40 @@ namespace CalamityMod.Items.Accessories public bool PlayerOnGround => Collision.SolidCollision(Player.position + Vector2.UnitY * 2f * Player.gravDir, Player.width, Player.height, false); + public override void Load() + { + base.Load(); + + /* + On_Player.QuickGrapple += (orig, self) => + { + var player = self.GetModPlayer(); + if (!player.WulfrumPackEquipped) + { + orig(self); + return; + } + + if (player.hookCooldown > 0) + { + + } + }; + */ + + On_Player.QuickGrapple_GetItemToUse += QuickGrapple_GetItemToUse_PrioritizeAcrobaticsPack; + } + + private static Item QuickGrapple_GetItemToUse_PrioritizeAcrobaticsPack(On_Player.orig_QuickGrapple_GetItemToUse orig, Player self) + { + if (self.TryGetModPlayer(out var mPlayer) && mPlayer.WulfrumPackEquipped && mPlayer.PackItem is not null) + { + return mPlayer.PackItem; + } + + return orig(self); + } + public override void ResetEffects() { WulfrumPackEquipped = false; @@ -646,4 +684,70 @@ namespace CalamityMod.Items.Accessories } } } + + internal sealed class WulfrumAcrobaticsSync : CalamityPacket + { + public static WulfrumAcrobaticsSync Instance { get; private set; } + + public override byte MessageType => (byte)CalamityModMessageType.WulfrumAcrobaticsSync; + + public static void Send(Player player, WulfrumPackPlayer mPlayer, Projectile proj, int toClient = -1, int ignoreClient = -1) + { + Send( + (byte)player.whoAmI, + mPlayer.SwingLength, + mPlayer.OldPosition, + proj.Center, + (byte)proj.whoAmI + ); + } + + private static void Send( + byte playerWhoAmI, + float swingLength, + Vector2 playerOldPos, + Vector2 projCenter, + byte projWhoAmI, + int toClient = -1, + int ignoreClient = -1 + ) + { + var packet = Instance.CreateBasePacket(); + packet.Write(playerWhoAmI); + packet.Write(swingLength); + packet.WriteVector2(playerOldPos); + packet.WriteVector2(projCenter); + packet.Write(projWhoAmI); + packet.Send(toClient, ignoreClient); + } + + public override void HandlePacket(in BinaryReader packet, int sender) + { + var playerWhoAmI = packet.ReadByte(); + var swingLength = packet.ReadSingle(); + var playerOldPos = packet.ReadVector2(); + var projCenter = packet.ReadVector2(); + var projWhoAmI = packet.ReadByte(); + + if (Main.player[playerWhoAmI].TryGetModPlayer(out var mPlayer)) + { + mPlayer.SwingLength = swingLength; + mPlayer.OldPosition = playerOldPos; + mPlayer.SetSegments(projCenter); + mPlayer.Grapple = projWhoAmI; + } + + if (Main.netMode == NetmodeID.Server) + { + Send( + playerWhoAmI, + swingLength, + playerOldPos, + projCenter, + projWhoAmI, + ignoreClient: sender + ); + } + } + } } diff --git a/Projectiles/Typeless/WulfrumHook.cs b/Projectiles/Typeless/WulfrumHook.cs index 20d8259506..b9dfb9f9c2 100644 --- a/Projectiles/Typeless/WulfrumHook.cs +++ b/Projectiles/Typeless/WulfrumHook.cs @@ -54,6 +54,16 @@ namespace CalamityMod.Projectiles.Typeless Projectile.aiStyle = ProjAIStyleID.Hook; //The projectile uses entirely custom AI, but for some reason terraria's only way to distinguish what is and isnt a hook is its ai style. } + public override bool? CanUseGrapple(Player player) + { + if (player.TryGetModPlayer(out var mPlayer) && mPlayer.hookCooldown > 0) + { + return false; + } + + return base.CanUseGrapple(player); + } + public override bool? CanDamage() => false; public override bool PreAI() => false; @@ -156,8 +166,11 @@ namespace CalamityMod.Projectiles.Typeless if (!tile.HasUnactuatedTile || !tile.CanTileBeLatchedOnTo(EquippedHook == ItemID.SquirrelHook && Projectile.Distance(Owner.Center) > 96) || Owner.IsBlacklistedForGrappling(tilePos)) continue; + + /* if (Main.myPlayer != Owner.whoAmI) continue; + */ OnGrapple(worldPos, x, y); @@ -197,8 +210,12 @@ namespace CalamityMod.Projectiles.Typeless Owner.grappling[Owner.grapCount] = Projectile.whoAmI; Owner.grapCount++; } - if (EquippedHook == ItemID.QueenSlimeHook) + + if (EquippedHook == ItemID.QueenSlimeHook && Owner.whoAmI == Main.myPlayer) + { Owner.DoQueenSlimeHookTeleport(grapplePos + new Vector2(-(Owner.Center - Projectile.Center).Length() * 0.75f, 0).RotatedBy(Projectile.DirectionTo(Owner.Center).ToRotation())); + } + mp.SwingLength = (Owner.Center - Projectile.Center).Length(); mp.OldPosition = Owner.Center - Owner.velocity; mp.SetSegments(Projectile.Center); @@ -208,11 +225,14 @@ namespace CalamityMod.Projectiles.Typeless if (tileVisualHitbox.HasValue) Projectile.Center = tileVisualHitbox.Value.Center.ToVector2(); - Projectile.netUpdate = true; - NetMessage.SendData(MessageID.PlayerControls, -1, -1, null, Owner.whoAmI); + if (Owner.whoAmI == Main.myPlayer) + { + Projectile.netUpdate = true; + NetMessage.SendData(MessageID.PlayerControls, -1, -1, null, Owner.whoAmI); + WulfrumAcrobaticsSync.Send(Owner, mp, Projectile); + } } - public override void OnKill(int timeLeft) { if (Owner.grappling[0] == Projectile.whoAmI)