From 64a12861cef626fa27a65c3a18f562eaf312bd6e Mon Sep 17 00:00:00 2001 From: Spatison <137375981+Spatison@users.noreply.github.com> Date: Thu, 29 Aug 2024 20:10:05 +0300 Subject: [PATCH] fix: sound --- Content.Server/Hands/Systems/HandsSystem.cs | 15 ++++------- .../SharedHandsSystem.Interactions.cs | 27 +++++++++++++++++++ .../Item/ItemToggle/SharedItemToggleSystem.cs | 3 --- Content.Shared/Wieldable/WieldableSystem.cs | 9 +++++++ 4 files changed, 41 insertions(+), 13 deletions(-) diff --git a/Content.Server/Hands/Systems/HandsSystem.cs b/Content.Server/Hands/Systems/HandsSystem.cs index bd24ddab5d..559c832a9c 100644 --- a/Content.Server/Hands/Systems/HandsSystem.cs +++ b/Content.Server/Hands/Systems/HandsSystem.cs @@ -51,9 +51,7 @@ public override void Initialize() SubscribeLocalEvent(OnExploded); - CommandBinds.Builder - .Bind(ContentKeyFunctions.ThrowItemInHand, new PointerInputCmdHandler(HandleThrowItem)) - .Register(); + SubscribeLocalEvent(OnHandleThrowItem); // WD EDIT } public override void Shutdown() @@ -163,21 +161,18 @@ private void HandlePullStopped(EntityUid uid, HandsComponent component, PullStop #region interactions - private bool HandleThrowItem(ICommonSession? playerSession, EntityCoordinates coordinates, EntityUid entity) + private void OnHandleThrowItem(EntityUid uid, HandsComponent component, HandleThrowItemEvent args) // WD EDIT { - if (playerSession?.AttachedEntity is not {Valid: true} player || !Exists(player)) - return false; - - return ThrowHeldItem(player, coordinates); + ThrowHeldItem(uid, args.Coordinates, hands:component); // WD EDIT } /// /// Throw the player's currently held item. /// - public bool ThrowHeldItem(EntityUid player, EntityCoordinates coordinates, float minDistance = 0.1f) + public bool ThrowHeldItem(EntityUid player, EntityCoordinates coordinates, float minDistance = 0.1f, HandsComponent? hands = null) // WD EDIT { if (ContainerSystem.IsEntityInContainer(player) || - !TryComp(player, out HandsComponent? hands) || + !Resolve(player, ref hands) || // WD EDIT hands.ActiveHandEntity is not { } throwEnt || !_actionBlockerSystem.CanThrow(player, throwEnt)) return false; diff --git a/Content.Shared/Hands/EntitySystems/SharedHandsSystem.Interactions.cs b/Content.Shared/Hands/EntitySystems/SharedHandsSystem.Interactions.cs index 32339eb03a..63557dddc7 100644 --- a/Content.Shared/Hands/EntitySystems/SharedHandsSystem.Interactions.cs +++ b/Content.Shared/Hands/EntitySystems/SharedHandsSystem.Interactions.cs @@ -29,6 +29,7 @@ private void InitializeInteractions() .Bind(ContentKeyFunctions.AltUseItemInHand, InputCmdHandler.FromDelegate(HandleAltUseInHand, handle: false, outsidePrediction: false)) .Bind(ContentKeyFunctions.SwapHands, InputCmdHandler.FromDelegate(SwapHandsPressed, handle: false, outsidePrediction: false)) .Bind(ContentKeyFunctions.Drop, new PointerInputCmdHandler(DropPressed)) + .Bind(ContentKeyFunctions.ThrowItemInHand, new PointerInputCmdHandler(HandleThrowItem)) // WD EDIT .Register(); } @@ -100,6 +101,19 @@ private bool DropPressed(ICommonSession? session, EntityCoordinates coords, Enti // always send to server. return false; } + + // WD EDIT START + private bool HandleThrowItem(ICommonSession? session, EntityCoordinates coords, EntityUid netEntity) + { + if (session?.AttachedEntity != null && TryComp(session.AttachedEntity.Value, out var hands) && hands.ActiveHandEntity != null) + { + RaiseLocalEvent(session.AttachedEntity.Value, new HandleThrowItemEvent(coords)); + RaiseLocalEvent(hands.ActiveHandEntity.Value, new ThrowItemEvent(session.AttachedEntity.Value, coords)); + } + + return false; + } + // WD EDIT END #endregion public bool TryActivateItemInHand(EntityUid uid, HandsComponent? handsComp = null, string? handName = null) @@ -205,3 +219,16 @@ private void HandleExamined(EntityUid uid, HandsComponent handsComp, ExaminedEve } } } + +// WD EDIT START +public struct HandleThrowItemEvent(EntityCoordinates coordinates) +{ + public EntityCoordinates Coordinates = coordinates; +} + +public struct ThrowItemEvent(EntityUid user, EntityCoordinates coordinates) +{ + public EntityUid User = user; + public EntityCoordinates Coordinates = coordinates; +} +// WD EDIT END diff --git a/Content.Shared/Item/ItemToggle/SharedItemToggleSystem.cs b/Content.Shared/Item/ItemToggle/SharedItemToggleSystem.cs index 39f38ba90c..523f67bac3 100644 --- a/Content.Shared/Item/ItemToggle/SharedItemToggleSystem.cs +++ b/Content.Shared/Item/ItemToggle/SharedItemToggleSystem.cs @@ -240,9 +240,6 @@ private void OnIsHotEvent(EntityUid uid, ItemToggleHotComponent itemToggleHot, I /// private void UpdateActiveSound(EntityUid uid, ItemToggleActiveSoundComponent activeSound, ref ItemToggledEvent args) { - if (_netManager.IsClient) // WD EDIT - return; - if (args.Activated) { if (activeSound.ActiveSound != null && activeSound.PlayingStream == null) diff --git a/Content.Shared/Wieldable/WieldableSystem.cs b/Content.Shared/Wieldable/WieldableSystem.cs index 6bd406c1ca..476f6bf424 100644 --- a/Content.Shared/Wieldable/WieldableSystem.cs +++ b/Content.Shared/Wieldable/WieldableSystem.cs @@ -37,6 +37,7 @@ public override void Initialize() SubscribeLocalEvent(OnUseInHand, before: [typeof(SharedGunSystem)]); SubscribeLocalEvent(OnItemUnwielded); SubscribeLocalEvent(OnItemLeaveHand); + SubscribeLocalEvent(OnThrowItem); SubscribeLocalEvent(OnVirtualItemDeleted); SubscribeLocalEvent>(AddToggleWieldVerb); @@ -261,6 +262,14 @@ private void OnItemLeaveHand(EntityUid uid, WieldableComponent component, GotUne RaiseLocalEvent(uid, new ItemUnwieldedEvent(args.User, force: true), true); } + private void OnThrowItem(EntityUid uid, WieldableComponent component, ThrowItemEvent args) + { + if (!component.Wielded) + return; + + RaiseLocalEvent(uid, new ItemUnwieldedEvent(args.User, force: true), true); + } + private void OnVirtualItemDeleted(EntityUid uid, WieldableComponent component, VirtualItemDeletedEvent args) { if (args.BlockingEntity == uid && component.Wielded)