From af1375160028b1d1e4ba4e0987dd48ff9b271014 Mon Sep 17 00:00:00 2001 From: Leon Friedrich <60421075+ElectroJr@users.noreply.github.com> Date: Mon, 31 Jan 2022 20:07:03 +1300 Subject: [PATCH] Fix item actions (#6383) --- .../Components/ItemActionsComponent.cs | 21 ------------ Content.Shared/Actions/SharedActionSystem.cs | 33 ++++++++++++++++--- 2 files changed, 29 insertions(+), 25 deletions(-) diff --git a/Content.Shared/Actions/Components/ItemActionsComponent.cs b/Content.Shared/Actions/Components/ItemActionsComponent.cs index 27c0c8710c..45c54b207a 100644 --- a/Content.Shared/Actions/Components/ItemActionsComponent.cs +++ b/Content.Shared/Actions/Components/ItemActionsComponent.cs @@ -178,27 +178,6 @@ namespace Content.Shared.Actions.Components { GrantOrUpdate(actionType, toggleOn: toggleOn); } - - public void EquippedHand(EntityUid user, Hand hand) - { - // this entity cannot be granted actions if no actions component - if (!IoCManager.Resolve().TryGetComponent(user, out var actionsComponent)) - return; - Holder = user; - HolderActionsComponent = actionsComponent; - IsEquipped = true; - InHand = hand; - GrantOrUpdateAllToHolder(); - } - - public void UnequippedHand() - { - RevokeAllFromHolder(); - Holder = null; - HolderActionsComponent = null; - IsEquipped = false; - InHand = null; - } } /// diff --git a/Content.Shared/Actions/SharedActionSystem.cs b/Content.Shared/Actions/SharedActionSystem.cs index 2ca4a42a2f..7f21be8e0b 100644 --- a/Content.Shared/Actions/SharedActionSystem.cs +++ b/Content.Shared/Actions/SharedActionSystem.cs @@ -1,5 +1,6 @@ using Content.Shared.Actions.Components; using Content.Shared.Hands; +using Content.Shared.Inventory.Events; using Robust.Shared.GameObjects; using System; @@ -18,18 +19,42 @@ namespace Content.Shared.Actions base.Initialize(); UpdatesOutsidePrediction = true; - SubscribeLocalEvent(OnHandUnequipped); + SubscribeLocalEvent(OnGotEquipped); SubscribeLocalEvent(OnHandEquipped); + SubscribeLocalEvent((uid, comp, _) => OnUnequipped(uid, comp)); + SubscribeLocalEvent((uid, comp, _) => OnUnequipped(uid, comp)); + } + + private void OnGotEquipped(EntityUid uid, ItemActionsComponent component, GotEquippedEvent args) + { + if (!TryComp(args.Equipee, out SharedActionsComponent? actionsComponent)) + return; + + component.Holder = args.Equipee; + component.HolderActionsComponent = actionsComponent; + component.IsEquipped = true; + component.GrantOrUpdateAllToHolder(); } private void OnHandEquipped(EntityUid uid, ItemActionsComponent component, EquippedHandEvent args) { - component.EquippedHand(args.User, args.Hand); + if (!TryComp(args.User, out SharedActionsComponent? actionsComponent)) + return; + + component.Holder = args.User; + component.HolderActionsComponent = actionsComponent; + component.IsEquipped = true; + component.InHand = args.Hand; + component.GrantOrUpdateAllToHolder(); } - private void OnHandUnequipped(EntityUid uid, ItemActionsComponent component, UnequippedHandEvent args) + private void OnUnequipped(EntityUid uid, ItemActionsComponent component) { - component.UnequippedHand(); + component.RevokeAllFromHolder(); + component.Holder = null; + component.HolderActionsComponent = null; + component.IsEquipped = false; + component.InHand = null; } public override void Update(float frameTime)