]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Predicted multihanded component (#36712)
authormetalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
Sat, 19 Apr 2025 08:05:20 +0000 (18:05 +1000)
committerGitHub <noreply@github.com>
Sat, 19 Apr 2025 08:05:20 +0000 (18:05 +1000)
* Predicted multihanded component

* Refview

* reh

Content.Client/Items/Systems/MultiHandedItemSystem.cs [deleted file]
Content.Server/Item/MultiHandedItemSystem.cs [deleted file]
Content.Shared/Item/MultiHandedItemComponent.cs
Content.Shared/Item/MultiHandedItemSystem.cs [new file with mode: 0644]
Content.Shared/Item/SharedMultiHandedItemSystem.cs [deleted file]

diff --git a/Content.Client/Items/Systems/MultiHandedItemSystem.cs b/Content.Client/Items/Systems/MultiHandedItemSystem.cs
deleted file mode 100644 (file)
index 716a4ad..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
-using Content.Shared.Hands;
-using Content.Shared.Item;
-
-namespace Content.Client.Items.Systems;
-
-public sealed class MultiHandedItemSystem : SharedMultiHandedItemSystem
-{
-    protected override void OnEquipped(EntityUid uid, MultiHandedItemComponent component, GotEquippedHandEvent args)
-    {
-    }
-
-    protected override void OnUnequipped(EntityUid uid, MultiHandedItemComponent component, GotUnequippedHandEvent args)
-    {
-    }
-}
diff --git a/Content.Server/Item/MultiHandedItemSystem.cs b/Content.Server/Item/MultiHandedItemSystem.cs
deleted file mode 100644 (file)
index 9146c7c..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
-using Content.Server.Hands.Systems;
-using Content.Server.Inventory;
-using Content.Shared.Hands;
-using Content.Shared.Item;
-
-namespace Content.Server.Item;
-
-public sealed class MultiHandedItemSystem : SharedMultiHandedItemSystem
-{
-    [Dependency] private readonly VirtualItemSystem _virtualItem = default!;
-
-    protected override void OnEquipped(EntityUid uid, MultiHandedItemComponent component, GotEquippedHandEvent args)
-    {
-        for (var i = 0; i < component.HandsNeeded - 1; i++)
-        {
-            _virtualItem.TrySpawnVirtualItemInHand(uid, args.User);
-        }
-    }
-
-    protected override void OnUnequipped(EntityUid uid, MultiHandedItemComponent component, GotUnequippedHandEvent args)
-    {
-        _virtualItem.DeleteInHandsMatching(args.User, uid);
-    }
-}
index 9a90d063ba792d9740bffe8ff5fc5c379551cc4b..3a0ac23bcd38f4e8a70bde3af5deb497e2558fc4 100644 (file)
@@ -9,6 +9,6 @@ namespace Content.Shared.Item;
 [RegisterComponent, NetworkedComponent]
 public sealed partial class MultiHandedItemComponent : Component
 {
-    [DataField("handsNeeded"), ViewVariables(VVAccess.ReadWrite)]
+    [DataField]
     public int HandsNeeded = 2;
 }
diff --git a/Content.Shared/Item/MultiHandedItemSystem.cs b/Content.Shared/Item/MultiHandedItemSystem.cs
new file mode 100644 (file)
index 0000000..da9d895
--- /dev/null
@@ -0,0 +1,56 @@
+using Content.Shared.Hands;
+using Content.Shared.Hands.Components;
+using Content.Shared.Hands.EntitySystems;
+using Content.Shared.Inventory.VirtualItem;
+using Content.Shared.Popups;
+using Robust.Shared.Timing;
+
+namespace Content.Shared.Item;
+
+public sealed class MultiHandedItemSystem : EntitySystem
+{
+    [Dependency] private readonly IGameTiming _timing = default!;
+    [Dependency] private readonly SharedHandsSystem _hands = default!;
+    [Dependency] private readonly SharedPopupSystem _popup = default!;
+    [Dependency] private readonly SharedVirtualItemSystem _virtualItem = default!;
+
+    /// <inheritdoc/>
+    public override void Initialize()
+    {
+        SubscribeLocalEvent<MultiHandedItemComponent, GettingPickedUpAttemptEvent>(OnAttemptPickup);
+        SubscribeLocalEvent<MultiHandedItemComponent, VirtualItemDeletedEvent>(OnVirtualItemDeleted);
+        SubscribeLocalEvent<MultiHandedItemComponent, GotEquippedHandEvent>(OnEquipped);
+        SubscribeLocalEvent<MultiHandedItemComponent, GotUnequippedHandEvent>(OnUnequipped);
+    }
+
+    private void OnEquipped(Entity<MultiHandedItemComponent> ent, ref GotEquippedHandEvent args)
+    {
+        for (var i = 0; i < ent.Comp.HandsNeeded - 1; i++)
+        {
+            _virtualItem.TrySpawnVirtualItemInHand(ent.Owner, args.User);
+        }
+    }
+
+    private void OnUnequipped(Entity<MultiHandedItemComponent> ent, ref GotUnequippedHandEvent args)
+    {
+        _virtualItem.DeleteInHandsMatching(args.User, ent.Owner);
+    }
+
+    private void OnAttemptPickup(Entity<MultiHandedItemComponent> ent, ref GettingPickedUpAttemptEvent args)
+    {
+        if (TryComp<HandsComponent>(args.User, out var hands) && hands.CountFreeHands() >= ent.Comp.HandsNeeded)
+            return;
+
+        args.Cancel();
+        _popup.PopupPredictedCursor(Loc.GetString("multi-handed-item-pick-up-fail",
+            ("number", ent.Comp.HandsNeeded - 1), ("item", ent.Owner)), args.User);
+    }
+
+    private void OnVirtualItemDeleted(Entity<MultiHandedItemComponent> ent, ref VirtualItemDeletedEvent args)
+    {
+        if (args.BlockingEntity != ent.Owner || _timing.ApplyingState)
+            return;
+
+        _hands.TryDrop(args.User, ent.Owner);
+    }
+}
diff --git a/Content.Shared/Item/SharedMultiHandedItemSystem.cs b/Content.Shared/Item/SharedMultiHandedItemSystem.cs
deleted file mode 100644 (file)
index 0259b36..0000000
+++ /dev/null
@@ -1,47 +0,0 @@
-using Content.Shared.Hands;
-using Content.Shared.Hands.Components;
-using Content.Shared.Hands.EntitySystems;
-using Content.Shared.Popups;
-using Robust.Shared.Timing;
-
-namespace Content.Shared.Item;
-
-public abstract class SharedMultiHandedItemSystem : EntitySystem
-{
-    [Dependency] private readonly IGameTiming _timing = default!;
-    [Dependency] private readonly SharedHandsSystem _hands = default!;
-    [Dependency] private readonly SharedPopupSystem _popup = default!;
-
-    /// <inheritdoc/>
-    public override void Initialize()
-    {
-        SubscribeLocalEvent<MultiHandedItemComponent, GettingPickedUpAttemptEvent>(OnAttemptPickup);
-        SubscribeLocalEvent<MultiHandedItemComponent, VirtualItemDeletedEvent>(OnVirtualItemDeleted);
-        SubscribeLocalEvent<MultiHandedItemComponent, GotEquippedHandEvent>(OnEquipped);
-        SubscribeLocalEvent<MultiHandedItemComponent, GotUnequippedHandEvent>(OnUnequipped);
-    }
-
-    protected abstract void OnEquipped(EntityUid uid, MultiHandedItemComponent component, GotEquippedHandEvent args);
-    protected abstract void OnUnequipped(EntityUid uid, MultiHandedItemComponent component, GotUnequippedHandEvent args);
-
-    private void OnAttemptPickup(EntityUid uid, MultiHandedItemComponent component, GettingPickedUpAttemptEvent args)
-    {
-        if (TryComp<HandsComponent>(args.User, out var hands) && hands.CountFreeHands() >= component.HandsNeeded)
-            return;
-
-        args.Cancel();
-        if (_timing.IsFirstTimePredicted)
-        {
-            _popup.PopupCursor(Loc.GetString("multi-handed-item-pick-up-fail",
-                ("number", component.HandsNeeded - 1), ("item", uid)), args.User);
-        }
-    }
-
-    private void OnVirtualItemDeleted(EntityUid uid, MultiHandedItemComponent component, VirtualItemDeletedEvent args)
-    {
-        if (args.BlockingEntity != uid)
-            return;
-
-        _hands.TryDrop(args.User, uid);
-    }
-}