Add smart equip shortcuts (#873)
This commit is contained in:
@@ -28,6 +28,8 @@ namespace Content.Client.Input
|
|||||||
human.AddFunction(ContentKeyFunctions.OpenContextMenu);
|
human.AddFunction(ContentKeyFunctions.OpenContextMenu);
|
||||||
human.AddFunction(ContentKeyFunctions.OpenCraftingMenu);
|
human.AddFunction(ContentKeyFunctions.OpenCraftingMenu);
|
||||||
human.AddFunction(ContentKeyFunctions.OpenInventoryMenu);
|
human.AddFunction(ContentKeyFunctions.OpenInventoryMenu);
|
||||||
|
human.AddFunction(ContentKeyFunctions.SmartEquipBackpack);
|
||||||
|
human.AddFunction(ContentKeyFunctions.SmartEquipBelt);
|
||||||
human.AddFunction(ContentKeyFunctions.MouseMiddle);
|
human.AddFunction(ContentKeyFunctions.MouseMiddle);
|
||||||
human.AddFunction(ContentKeyFunctions.ToggleCombatMode);
|
human.AddFunction(ContentKeyFunctions.ToggleCombatMode);
|
||||||
human.AddFunction(ContentKeyFunctions.WideAttack);
|
human.AddFunction(ContentKeyFunctions.WideAttack);
|
||||||
|
|||||||
@@ -69,6 +69,8 @@ namespace Content.Client.UserInterface
|
|||||||
Switch hands: [color=#a4885c]{4}[/color]
|
Switch hands: [color=#a4885c]{4}[/color]
|
||||||
Use held item: [color=#a4885c]{5}[/color]
|
Use held item: [color=#a4885c]{5}[/color]
|
||||||
Drop held item: [color=#a4885c]{6}[/color]
|
Drop held item: [color=#a4885c]{6}[/color]
|
||||||
|
Smart equip from backpack: [color=#a4885c]{24}[/color]
|
||||||
|
Smart equip from belt: [color=#a4885c]{25}[/color]
|
||||||
Open inventory: [color=#a4885c]{7}[/color]
|
Open inventory: [color=#a4885c]{7}[/color]
|
||||||
Open character window: [color=#a4885c]{8}[/color]
|
Open character window: [color=#a4885c]{8}[/color]
|
||||||
Open crafting window: [color=#a4885c]{9}[/color]
|
Open crafting window: [color=#a4885c]{9}[/color]
|
||||||
@@ -106,7 +108,9 @@ Toggle sandbox window: [color=#a4885c]{21}[/color]",
|
|||||||
Key(OpenTileSpawnWindow),
|
Key(OpenTileSpawnWindow),
|
||||||
Key(OpenSandboxWindow),
|
Key(OpenSandboxWindow),
|
||||||
Key(Use),
|
Key(Use),
|
||||||
Key(WideAttack)));
|
Key(WideAttack),
|
||||||
|
Key(SmartEquipBackpack),
|
||||||
|
Key(SmartEquipBelt)));
|
||||||
|
|
||||||
//Gameplay
|
//Gameplay
|
||||||
VBox.AddChild(new Label { FontOverride = headerFont, Text = "\nGameplay" });
|
VBox.AddChild(new Label { FontOverride = headerFont, Text = "\nGameplay" });
|
||||||
|
|||||||
@@ -151,6 +151,12 @@ namespace Content.Server.GameObjects
|
|||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void PutInHandOrDrop(ItemComponent item)
|
||||||
|
{
|
||||||
|
if (!PutInHand(item))
|
||||||
|
item.Owner.Transform.GridPosition = Owner.Transform.GridPosition;
|
||||||
|
}
|
||||||
|
|
||||||
public bool CanPutInHand(ItemComponent item)
|
public bool CanPutInHand(ItemComponent item)
|
||||||
{
|
{
|
||||||
foreach (var hand in ActivePriorityEnumerable())
|
foreach (var hand in ActivePriorityEnumerable())
|
||||||
|
|||||||
@@ -45,6 +45,8 @@ namespace Content.Server.GameObjects
|
|||||||
private int StorageCapacityMax = 10000;
|
private int StorageCapacityMax = 10000;
|
||||||
public HashSet<IPlayerSession> SubscribedSessions = new HashSet<IPlayerSession>();
|
public HashSet<IPlayerSession> SubscribedSessions = new HashSet<IPlayerSession>();
|
||||||
|
|
||||||
|
public IReadOnlyCollection<IEntity> StoredEntities => storage.ContainedEntities;
|
||||||
|
|
||||||
public override void Initialize()
|
public override void Initialize()
|
||||||
{
|
{
|
||||||
base.Initialize();
|
base.Initialize();
|
||||||
@@ -140,7 +142,6 @@ namespace Content.Server.GameObjects
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public bool AttackBy(AttackByEventArgs eventArgs)
|
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);
|
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))
|
if(Owner.TryGetComponent<PlaceableSurfaceComponent>(out var placeableSurfaceComponent))
|
||||||
@@ -363,8 +364,10 @@ namespace Content.Server.GameObjects
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Inserts an entity into the storage component from the players active hand.
|
/// Inserts an entity into the storage component from the players active hand.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private bool PlayerInsertEntity(IEntity player)
|
public bool PlayerInsertEntity(IEntity player)
|
||||||
{
|
{
|
||||||
|
_ensureInitialCalculated();
|
||||||
|
|
||||||
if (!player.TryGetComponent(out IHandsComponent hands) || hands.GetActiveHand == null)
|
if (!player.TryGetComponent(out IHandsComponent hands) || hands.GetActiveHand == null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,14 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Linq;
|
||||||
|
using Content.Server.GameObjects;
|
||||||
using Content.Server.GameObjects.Components;
|
using Content.Server.GameObjects.Components;
|
||||||
using Content.Server.GameObjects.Components.Stack;
|
using Content.Server.GameObjects.Components.Stack;
|
||||||
|
using Content.Server.Interfaces;
|
||||||
using Content.Server.Interfaces.GameObjects;
|
using Content.Server.Interfaces.GameObjects;
|
||||||
using Content.Server.Throw;
|
using Content.Server.Throw;
|
||||||
|
using Content.Shared.GameObjects.Components.Inventory;
|
||||||
using Content.Shared.Input;
|
using Content.Shared.Input;
|
||||||
|
using Content.Shared.Interfaces;
|
||||||
using Content.Shared.Physics;
|
using Content.Shared.Physics;
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
using Robust.Server.GameObjects;
|
using Robust.Server.GameObjects;
|
||||||
@@ -19,6 +24,7 @@ using Robust.Shared.Interfaces.Map;
|
|||||||
using Robust.Shared.Interfaces.Physics;
|
using Robust.Shared.Interfaces.Physics;
|
||||||
using Robust.Shared.Interfaces.Timing;
|
using Robust.Shared.Interfaces.Timing;
|
||||||
using Robust.Shared.IoC;
|
using Robust.Shared.IoC;
|
||||||
|
using Robust.Shared.Localization;
|
||||||
using Robust.Shared.Log;
|
using Robust.Shared.Log;
|
||||||
using Robust.Shared.Map;
|
using Robust.Shared.Map;
|
||||||
using Robust.Shared.Maths;
|
using Robust.Shared.Maths;
|
||||||
@@ -33,6 +39,7 @@ namespace Content.Server.GameObjects.EntitySystems
|
|||||||
#pragma warning disable 649
|
#pragma warning disable 649
|
||||||
[Dependency] private readonly IMapManager _mapManager;
|
[Dependency] private readonly IMapManager _mapManager;
|
||||||
[Dependency] private readonly IEntitySystemManager _entitySystemManager;
|
[Dependency] private readonly IEntitySystemManager _entitySystemManager;
|
||||||
|
[Dependency] private readonly IServerNotifyManager _notifyManager;
|
||||||
#pragma warning restore 649
|
#pragma warning restore 649
|
||||||
|
|
||||||
private const float ThrowForce = 1.5f; // Throwing force of mobs in Newtons
|
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.Drop, new PointerInputCmdHandler(HandleDrop));
|
||||||
input.BindMap.BindFunction(ContentKeyFunctions.ActivateItemInHand, InputCmdHandler.FromDelegate(HandleActivateItem));
|
input.BindMap.BindFunction(ContentKeyFunctions.ActivateItemInHand, InputCmdHandler.FromDelegate(HandleActivateItem));
|
||||||
input.BindMap.BindFunction(ContentKeyFunctions.ThrowItemInHand, new PointerInputCmdHandler(HandleThrowItem));
|
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 />
|
/// <inheritdoc />
|
||||||
@@ -190,5 +199,53 @@ namespace Content.Server.GameObjects.EntitySystems
|
|||||||
|
|
||||||
return true;
|
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>());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,8 @@ namespace Content.Shared.Input
|
|||||||
public static readonly BoundKeyFunction OpenContextMenu = "OpenContextMenu";
|
public static readonly BoundKeyFunction OpenContextMenu = "OpenContextMenu";
|
||||||
public static readonly BoundKeyFunction OpenCraftingMenu = "OpenCraftingMenu";
|
public static readonly BoundKeyFunction OpenCraftingMenu = "OpenCraftingMenu";
|
||||||
public static readonly BoundKeyFunction OpenInventoryMenu = "OpenInventoryMenu";
|
public static readonly BoundKeyFunction OpenInventoryMenu = "OpenInventoryMenu";
|
||||||
|
public static readonly BoundKeyFunction SmartEquipBackpack = "SmartEquipBackpack";
|
||||||
|
public static readonly BoundKeyFunction SmartEquipBelt = "SmartEquipBelt";
|
||||||
public static readonly BoundKeyFunction OpenTutorial = "OpenTutorial";
|
public static readonly BoundKeyFunction OpenTutorial = "OpenTutorial";
|
||||||
public static readonly BoundKeyFunction SwapHands = "SwapHands";
|
public static readonly BoundKeyFunction SwapHands = "SwapHands";
|
||||||
public static readonly BoundKeyFunction ThrowItemInHand = "ThrowItemInHand";
|
public static readonly BoundKeyFunction ThrowItemInHand = "ThrowItemInHand";
|
||||||
|
|||||||
@@ -21,6 +21,7 @@
|
|||||||
state: utilitybelt
|
state: utilitybelt
|
||||||
- type: Clothing
|
- type: Clothing
|
||||||
Size: 50
|
Size: 50
|
||||||
|
QuickEquip: false
|
||||||
sprite: Clothing/belt_utility.rsi
|
sprite: Clothing/belt_utility.rsi
|
||||||
- type: Storage
|
- type: Storage
|
||||||
Capacity: 40 # Full tool loadout is 35, plus an extra
|
Capacity: 40 # Full tool loadout is 35, plus an extra
|
||||||
|
|||||||
@@ -105,6 +105,14 @@ binds:
|
|||||||
- function: OpenInventoryMenu
|
- function: OpenInventoryMenu
|
||||||
type: state
|
type: state
|
||||||
key: I
|
key: I
|
||||||
|
- function: SmartEquipBackpack
|
||||||
|
type: State
|
||||||
|
key: B
|
||||||
|
mod1: Shift
|
||||||
|
- function: SmartEquipBelt
|
||||||
|
type: State
|
||||||
|
key: E
|
||||||
|
mod1: Shift
|
||||||
- function: ShowDebugConsole
|
- function: ShowDebugConsole
|
||||||
type: state
|
type: state
|
||||||
key: Tilde
|
key: Tilde
|
||||||
|
|||||||
Reference in New Issue
Block a user