Add smart equip shortcuts (#873)
This commit is contained in:
@@ -151,6 +151,12 @@ namespace Content.Server.GameObjects
|
||||
return success;
|
||||
}
|
||||
|
||||
public void PutInHandOrDrop(ItemComponent item)
|
||||
{
|
||||
if (!PutInHand(item))
|
||||
item.Owner.Transform.GridPosition = Owner.Transform.GridPosition;
|
||||
}
|
||||
|
||||
public bool CanPutInHand(ItemComponent item)
|
||||
{
|
||||
foreach (var hand in ActivePriorityEnumerable())
|
||||
|
||||
@@ -45,6 +45,8 @@ namespace Content.Server.GameObjects
|
||||
private int StorageCapacityMax = 10000;
|
||||
public HashSet<IPlayerSession> SubscribedSessions = new HashSet<IPlayerSession>();
|
||||
|
||||
public IReadOnlyCollection<IEntity> StoredEntities => storage.ContainedEntities;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
@@ -140,7 +142,6 @@ namespace Content.Server.GameObjects
|
||||
/// <returns></returns>
|
||||
public bool AttackBy(AttackByEventArgs eventArgs)
|
||||
{
|
||||
_ensureInitialCalculated();
|
||||
Logger.DebugS("Storage", "Storage (UID {0}) attacked by user (UID {1}) with entity (UID {2}).", Owner.Uid, eventArgs.User.Uid, eventArgs.AttackWith.Uid);
|
||||
|
||||
if(Owner.TryGetComponent<PlaceableSurfaceComponent>(out var placeableSurfaceComponent))
|
||||
@@ -363,8 +364,10 @@ namespace Content.Server.GameObjects
|
||||
/// <summary>
|
||||
/// Inserts an entity into the storage component from the players active hand.
|
||||
/// </summary>
|
||||
private bool PlayerInsertEntity(IEntity player)
|
||||
public bool PlayerInsertEntity(IEntity player)
|
||||
{
|
||||
_ensureInitialCalculated();
|
||||
|
||||
if (!player.TryGetComponent(out IHandsComponent hands) || hands.GetActiveHand == null)
|
||||
return false;
|
||||
|
||||
|
||||
@@ -1,9 +1,14 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using Content.Server.GameObjects;
|
||||
using Content.Server.GameObjects.Components;
|
||||
using Content.Server.GameObjects.Components.Stack;
|
||||
using Content.Server.Interfaces;
|
||||
using Content.Server.Interfaces.GameObjects;
|
||||
using Content.Server.Throw;
|
||||
using Content.Shared.GameObjects.Components.Inventory;
|
||||
using Content.Shared.Input;
|
||||
using Content.Shared.Interfaces;
|
||||
using Content.Shared.Physics;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Server.GameObjects;
|
||||
@@ -19,6 +24,7 @@ using Robust.Shared.Interfaces.Map;
|
||||
using Robust.Shared.Interfaces.Physics;
|
||||
using Robust.Shared.Interfaces.Timing;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.Log;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Maths;
|
||||
@@ -33,6 +39,7 @@ namespace Content.Server.GameObjects.EntitySystems
|
||||
#pragma warning disable 649
|
||||
[Dependency] private readonly IMapManager _mapManager;
|
||||
[Dependency] private readonly IEntitySystemManager _entitySystemManager;
|
||||
[Dependency] private readonly IServerNotifyManager _notifyManager;
|
||||
#pragma warning restore 649
|
||||
|
||||
private const float ThrowForce = 1.5f; // Throwing force of mobs in Newtons
|
||||
@@ -50,6 +57,8 @@ namespace Content.Server.GameObjects.EntitySystems
|
||||
input.BindMap.BindFunction(ContentKeyFunctions.Drop, new PointerInputCmdHandler(HandleDrop));
|
||||
input.BindMap.BindFunction(ContentKeyFunctions.ActivateItemInHand, InputCmdHandler.FromDelegate(HandleActivateItem));
|
||||
input.BindMap.BindFunction(ContentKeyFunctions.ThrowItemInHand, new PointerInputCmdHandler(HandleThrowItem));
|
||||
input.BindMap.BindFunction(ContentKeyFunctions.SmartEquipBackpack, InputCmdHandler.FromDelegate(HandleSmartEquipBackpack));
|
||||
input.BindMap.BindFunction(ContentKeyFunctions.SmartEquipBelt, InputCmdHandler.FromDelegate(HandleSmartEquipBelt));
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@@ -190,5 +199,53 @@ namespace Content.Server.GameObjects.EntitySystems
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void HandleSmartEquipBackpack(ICommonSession session)
|
||||
{
|
||||
HandleSmartEquip(session, EquipmentSlotDefines.Slots.BACKPACK);
|
||||
}
|
||||
|
||||
private void HandleSmartEquipBelt(ICommonSession session)
|
||||
{
|
||||
HandleSmartEquip(session, EquipmentSlotDefines.Slots.BELT);
|
||||
}
|
||||
|
||||
private void HandleSmartEquip(ICommonSession session, EquipmentSlotDefines.Slots equipementSlot)
|
||||
{
|
||||
var plyEnt = ((IPlayerSession) session).AttachedEntity;
|
||||
|
||||
if (plyEnt == null || !plyEnt.IsValid())
|
||||
return;
|
||||
|
||||
if (!plyEnt.TryGetComponent(out HandsComponent handsComp) || !plyEnt.TryGetComponent(out InventoryComponent inventoryComp))
|
||||
return;
|
||||
|
||||
if (!inventoryComp.TryGetSlotItem(equipementSlot, out ItemComponent equipmentItem)
|
||||
|| !equipmentItem.Owner.TryGetComponent<ServerStorageComponent>(out var storageComponent))
|
||||
{
|
||||
_notifyManager.PopupMessage(plyEnt, plyEnt, Loc.GetString("You have no {0} to take something out of!", EquipmentSlotDefines.SlotNames[equipementSlot].ToLower()));
|
||||
return;
|
||||
}
|
||||
|
||||
var heldItem = handsComp.GetHand(handsComp.ActiveIndex)?.Owner;
|
||||
|
||||
if (heldItem != null)
|
||||
{
|
||||
storageComponent.PlayerInsertEntity(plyEnt);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (storageComponent.StoredEntities.Count == 0)
|
||||
{
|
||||
_notifyManager.PopupMessage(plyEnt, plyEnt, Loc.GetString("There's nothing in your {0} to take out!", EquipmentSlotDefines.SlotNames[equipementSlot].ToLower()));
|
||||
}
|
||||
else
|
||||
{
|
||||
var lastStoredEntity = Enumerable.Last(storageComponent.StoredEntities);
|
||||
if (storageComponent.Remove(lastStoredEntity))
|
||||
handsComp.PutInHandOrDrop(lastStoredEntity.GetComponent<ItemComponent>());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user