Predict inventory slot interactions. (#6033)

This commit is contained in:
Leon Friedrich
2022-01-30 13:50:10 +13:00
committed by GitHub
parent c465715273
commit 47e597ca47
9 changed files with 138 additions and 140 deletions

View File

@@ -1,22 +1,14 @@
using Content.Server.Atmos;
using Content.Server.Hands.Components;
using Content.Server.Interaction;
using Content.Server.Storage.Components;
using Content.Server.Temperature.Systems;
using Content.Shared.Inventory;
using Content.Shared.Inventory.Events;
using Robust.Shared.Containers;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Map;
using InventoryComponent = Content.Shared.Inventory.InventoryComponent;
namespace Content.Server.Inventory
{
class ServerInventorySystem : InventorySystem
{
[Dependency] private readonly InteractionSystem _interactionSystem = default!;
public override void Initialize()
{
base.Initialize();
@@ -25,27 +17,7 @@ namespace Content.Server.Inventory
SubscribeLocalEvent<InventoryComponent, LowPressureEvent>(RelayInventoryEvent);
SubscribeLocalEvent<InventoryComponent, ModifyChangedTemperatureEvent>(RelayInventoryEvent);
SubscribeNetworkEvent<TryEquipNetworkMessage>(OnNetworkEquip);
SubscribeNetworkEvent<TryUnequipNetworkMessage>(OnNetworkUnequip);
SubscribeNetworkEvent<OpenSlotStorageNetworkMessage>(OnOpenSlotStorage);
SubscribeNetworkEvent<UseSlotNetworkMessage>(OnUseSlot);
}
private void OnUseSlot(UseSlotNetworkMessage ev)
{
if (!TryComp<HandsComponent>(ev.Uid, out var hands) || !TryGetSlotEntity(ev.Uid, ev.Slot, out var itemUid))
return;
var activeHand = hands.GetActiveHandItem;
if (activeHand != null)
{
_interactionSystem.InteractUsing(ev.Uid, activeHand.Owner, itemUid.Value,
new EntityCoordinates());
}
else if (TryUnequip(ev.Uid, ev.Slot))
{
hands.PutInHand(itemUid.Value);
}
}
private void OnOpenSlotStorage(OpenSlotStorageNetworkMessage ev)
@@ -55,15 +27,5 @@ namespace Content.Server.Inventory
storageComponent.OpenStorageUI(ev.Uid);
}
}
private void OnNetworkUnequip(TryUnequipNetworkMessage ev)
{
TryUnequip(ev.Actor, ev.Target, ev.Slot, ev.Silent, ev.Force);
}
private void OnNetworkEquip(TryEquipNetworkMessage ev)
{
TryEquip(ev.Actor, ev.Target, ev.ItemUid, ev.Slot, ev.Silent, ev.Force);
}
}
}