]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Raise hand (un)equipped events on container insert/remove (#15664)
authorMenshin <Menshin@users.noreply.github.com>
Sun, 23 Apr 2023 19:38:52 +0000 (21:38 +0200)
committerGitHub <noreply@github.com>
Sun, 23 Apr 2023 19:38:52 +0000 (05:38 +1000)
Content.Client/Hands/Systems/HandsSystem.cs
Content.Server/Hands/Systems/HandsSystem.cs
Content.Shared/Actions/SharedActionsSystem.cs
Content.Shared/Hands/EntitySystems/SharedHandsSystem.Drop.cs
Content.Shared/Hands/EntitySystems/SharedHandsSystem.Pickup.cs
Content.Shared/Hands/EntitySystems/SharedHandsSystem.cs
Content.Shared/Inventory/InventorySystem.Equip.cs

index 062958193b262f15476c7f4311acfc86f09891a8..83465dea6f9f58616f58d3a88b5de98dd6d83deb 100644 (file)
@@ -43,9 +43,6 @@ namespace Content.Client.Hands.Systems
         {
             base.Initialize();
 
-            SubscribeLocalEvent<HandsComponent, EntRemovedFromContainerMessage>(HandleItemRemoved);
-            SubscribeLocalEvent<HandsComponent, EntInsertedIntoContainerMessage>(HandleItemAdded);
-
             SubscribeLocalEvent<HandsComponent, PlayerAttachedEvent>(HandlePlayerAttached);
             SubscribeLocalEvent<HandsComponent, PlayerDetachedEvent>(HandlePlayerDetached);
             SubscribeLocalEvent<HandsComponent, ComponentAdd>(HandleCompAdd);
@@ -253,9 +250,11 @@ namespace Content.Client.Hands.Systems
 
         #region visuals
 
-        private void HandleItemAdded(EntityUid uid, HandsComponent handComp, ContainerModifiedMessage args)
+        protected override void HandleEntityInserted(EntityUid uid, HandsComponent hands, EntInsertedIntoContainerMessage args)
         {
-            if (!handComp.Hands.TryGetValue(args.Container.ID, out var hand))
+            base.HandleEntityInserted(uid, hands, args);
+
+            if (!hands.Hands.TryGetValue(args.Container.ID, out var hand))
                 return;
             UpdateHandVisuals(uid, args.Entity, hand);
             _stripSys.UpdateUi(uid);
@@ -269,9 +268,11 @@ namespace Content.Client.Hands.Systems
                 OnPlayerHandBlocked?.Invoke(hand.Name);
         }
 
-        private void HandleItemRemoved(EntityUid uid, HandsComponent handComp, ContainerModifiedMessage args)
+        protected override void HandleEntityRemoved(EntityUid uid, HandsComponent hands, EntRemovedFromContainerMessage args)
         {
-            if (!handComp.Hands.TryGetValue(args.Container.ID, out var hand))
+            base.HandleEntityRemoved(uid, hands, args);
+
+            if (!hands.Hands.TryGetValue(args.Container.ID, out var hand))
                 return;
             UpdateHandVisuals(uid, args.Entity, hand);
             _stripSys.UpdateUi(uid);
index 92b91ab75fd448cbcd27c619130e791c404f9777..84605b8e7c28b965b19d982844c4ff0bc12a9f8c 100644 (file)
@@ -54,8 +54,6 @@ namespace Content.Server.Hands.Systems
             SubscribeLocalEvent<HandsComponent, PullStartedMessage>(HandlePullStarted);
             SubscribeLocalEvent<HandsComponent, PullStoppedMessage>(HandlePullStopped);
 
-            SubscribeLocalEvent<HandsComponent, EntRemovedFromContainerMessage>(HandleEntityRemoved);
-
             SubscribeLocalEvent<HandsComponent, BodyPartAddedEvent>(HandleBodyPartAdded);
             SubscribeLocalEvent<HandsComponent, BodyPartRemovedEvent>(HandleBodyPartRemoved);
 
@@ -109,8 +107,10 @@ namespace Content.Server.Hands.Systems
             RaiseNetworkEvent(new PickupAnimationEvent(item, initialPosition, finalPosition), filter);
         }
 
-        private void HandleEntityRemoved(EntityUid uid, HandsComponent component, EntRemovedFromContainerMessage args)
+        protected override void HandleEntityRemoved(EntityUid uid, HandsComponent hands, EntRemovedFromContainerMessage args)
         {
+            base.HandleEntityRemoved(uid, hands, args);
+
             if (!Deleted(args.Entity) && TryComp(args.Entity, out HandVirtualItemComponent? @virtual))
                 _virtualSystem.Delete(@virtual, uid);
         }
index 3a096336a78b49d55376b86a61a1defa2c06d093..c94d914b977793c200fccc1b8a514000c354a105 100644 (file)
@@ -361,7 +361,7 @@ public abstract class SharedActionsSystem : EntitySystem
 
         // for client-exclusive actions, the client shouldn't mark the comp as dirty. Otherwise that just leads to
         // unnecessary prediction resetting and state handling.
-        if (dirty)
+        if (dirty && !action.ClientExclusive)
             Dirty(comp);
     }
 
@@ -380,12 +380,15 @@ public abstract class SharedActionsSystem : EntitySystem
     {
         comp ??= EnsureComp<ActionsComponent>(uid);
 
+        bool allClientExclusive = true;
+
         foreach (var action in actions)
         {
             AddAction(uid, action, provider, comp, false);
+            allClientExclusive = allClientExclusive && action.ClientExclusive;
         }
 
-        if (dirty)
+        if (dirty && !allClientExclusive)
             Dirty(comp);
     }
 
index 4d4d8ef085c553bb7f54d3a768c7a73d1db128d4..a1ddd17c13739cdeadd90e347caa8d336c5b1ed8 100644 (file)
@@ -7,6 +7,25 @@ namespace Content.Shared.Hands.EntitySystems;
 
 public abstract partial class SharedHandsSystem : EntitySystem
 {
+    private void InitializeDrop()
+    {
+        SubscribeLocalEvent<HandsComponent, EntRemovedFromContainerMessage>(HandleEntityRemoved);
+    }
+
+    protected virtual void HandleEntityRemoved(EntityUid uid, HandsComponent hands, EntRemovedFromContainerMessage args)
+    {
+        if (!TryGetHand(uid, args.Container.ID, out var hand))
+        {
+            return;
+        }
+
+        var gotUnequipped = new GotUnequippedHandEvent(uid, args.Entity, hand);
+        RaiseLocalEvent(args.Entity, gotUnequipped, false);
+
+        var didUnequip = new DidUnequipHandEvent(uid, args.Entity, hand);
+        RaiseLocalEvent(uid, didUnequip, false);
+    }
+
     /// <summary>
     ///     Checks if the contents of a hand is able to be removed from its container.
     /// </summary>
@@ -154,12 +173,6 @@ public abstract partial class SharedHandsSystem : EntitySystem
         if (doDropInteraction)
             _interactionSystem.DroppedInteraction(uid, entity);
 
-        var gotUnequipped = new GotUnequippedHandEvent(uid, entity, hand);
-        RaiseLocalEvent(entity, gotUnequipped, false);
-
-        var didUnequip = new DidUnequipHandEvent(uid, entity, hand);
-        RaiseLocalEvent(uid, didUnequip, true);
-
         if (hand == handsComp.ActiveHand)
             RaiseLocalEvent(entity, new HandDeselectedEvent(uid), false);
     }
index 846d67849cbb88acebdf367e39c9f270fc0368da..a5d4833fc41e1100c3d5db2de00c32ea1b297385 100644 (file)
@@ -10,6 +10,25 @@ namespace Content.Shared.Hands.EntitySystems;
 
 public abstract partial class SharedHandsSystem : EntitySystem
 {
+    private void InitializePickup()
+    {
+        SubscribeLocalEvent<HandsComponent, EntInsertedIntoContainerMessage>(HandleEntityInserted);
+    }
+
+    protected virtual void HandleEntityInserted(EntityUid uid, HandsComponent hands, EntInsertedIntoContainerMessage args)
+    {
+        if (!TryGetHand(uid, args.Container.ID, out var hand))
+        {
+            return;
+        }
+
+        var didEquip = new DidEquipHandEvent(uid, args.Entity, hand);
+        RaiseLocalEvent(uid, didEquip, false);
+
+        var gotEquipped = new GotEquippedHandEvent(uid, args.Entity, hand);
+        RaiseLocalEvent(args.Entity, gotEquipped, false);
+    }
+
     /// <summary>
     ///     Maximum pickup distance for which the pickup animation plays.
     /// </summary>
@@ -208,17 +227,6 @@ public abstract partial class SharedHandsSystem : EntitySystem
 
         Dirty(hands);
 
-        var didEquip = new DidEquipHandEvent(uid, entity, hand);
-        RaiseLocalEvent(uid, didEquip, false);
-
-        var gotEquipped = new GotEquippedHandEvent(uid, entity, hand);
-        RaiseLocalEvent(entity, gotEquipped, true);
-
-        // TODO this should REALLY be a cancellable thing, not a handled event.
-        // If one of the interactions resulted in the item being dropped, return early.
-        if (gotEquipped.Handled)
-            return;
-
         if (hand == hands.ActiveHand)
             RaiseLocalEvent(entity, new HandSelectedEvent(uid), false);
     }
index 2af4cb456f332bbc0d23153b1e0794512d697569..1cb7617a49d60c5d8822ded97fbfa72209cfe066 100644 (file)
@@ -23,6 +23,8 @@ public abstract partial class SharedHandsSystem : EntitySystem
         base.Initialize();
 
         InitializeInteractions();
+        InitializeDrop();
+        InitializePickup();
     }
 
     public override void Shutdown()
index 0baa270cad02776fbf206f561fbdddf81a553b9e..25dcf56921dd58e0771c2da95e71c1bc42ad0c25 100644 (file)
@@ -146,10 +146,6 @@ public abstract partial class InventorySystem
         if (!_handsSystem.CanDropHeld(actor, hands.ActiveHand!, checkActionBlocker: false))
             return;
 
-        var gotUnequipped = new GotUnequippedHandEvent(actor, held.Value, hands.ActiveHand!);
-        var didUnequip = new DidUnequipHandEvent(actor, held.Value, hands.ActiveHand!);
-        RaiseLocalEvent(held.Value, gotUnequipped, false);
-        RaiseLocalEvent(actor, didUnequip, true);
         RaiseLocalEvent(held.Value, new HandDeselectedEvent(actor), false);
 
         TryEquip(actor, actor, held.Value, ev.Slot, predicted: true, inventory: inventory, force: true);