* Create BuckleableComponent.cs * Add strap component and keybind to buckle targeted entity * Remove buckle keybind, turn it into a verb * Add moving and attaching the buckled entity to the strap * Fix reality collapsing when clicking on a buckled entity * Add strap position to buckle a mob in the standing or down position * Add new default strap position that makes no change to the mob's standing state * Add Strap component to office chairs and stools * Add Strap component to the pilot chair * Add buckled status effect icon * Add status effect click behaviour * Add buckling and unbuckling sounds * Change Buckle verb to only appear when an entity can be currently buckled * Rotate buckled entity in the direction of the seat * Disable entity rotation when buckled * Fix buckle rotation on beds * Buckling now finds the closest strap to the buckleable entity * Fix rotation when unbuckling an entity * Move buckle verb to StrapComponent * Added buckled entity unbuckle verb, range and interaction checks * Add checks for currently occupied straps * Add unbuckling entity if its respective strap component is removed * Add Clickable, InteractionOutline and Collidable components to bed * Add rotation property to strap component * Rename Buckleable to Buckle * Add Buckle and Strap sizes to buckle multiple entities in the same strap * Remove out of range popup message from strap verb GetData * Move BuckledTo setter logic to its methods * Fix Strap BuckledEntities being public * Fix not updating status when Buckle component is removed * Change BuckleComponent.BuckledTo to be of type StrapComponent * Fix NRE when unbuckling * Add buckle perspective messages * Fix not equals comparison in strap verb * Add added check to Strap TryAdd * Change buckle.ogg and unbuckle.ogg from stereo to mono * Remove -2f volume on buckle and unbuckle sounds * Add summary to Strap TryAdd and Remove methods * Make buckled entities unable to fall * Fix default strap position not rotating the buckled entity * Add downing after unbuckling an entity if it is knocked down * Prevent an entity from buckling onto itself Fixes stack overflow error * Disable recursive buckling * Add buckling onto straps by clicking them with an empty hand * Add recursive buckle check to the trybuckle method as well * Fix being able to click on a different strap to unbuckle from the current one * Merge TryUnbuckle and ForceUnbuckle with a force argument * Remove explicit unimplemented status effect clicking cases * Add documentation to EffectBlockerSystem and ActionBlockerSystem
224 lines
8.6 KiB
C#
224 lines
8.6 KiB
C#
using System.Linq;
|
|
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 JetBrains.Annotations;
|
|
using Robust.Server.GameObjects.EntitySystemMessages;
|
|
using Robust.Server.Interfaces.Player;
|
|
using Robust.Shared.GameObjects;
|
|
using Robust.Shared.GameObjects.Systems;
|
|
using Robust.Shared.Input;
|
|
using Robust.Shared.Input.Binding;
|
|
using Robust.Shared.Interfaces.Map;
|
|
using Robust.Shared.IoC;
|
|
using Robust.Shared.Localization;
|
|
using Robust.Shared.Map;
|
|
using Robust.Shared.Players;
|
|
using System;
|
|
using Content.Shared.GameObjects.EntitySystems;
|
|
|
|
namespace Content.Server.GameObjects.EntitySystems
|
|
{
|
|
[UsedImplicitly]
|
|
internal sealed class HandsSystem : EntitySystem
|
|
{
|
|
#pragma warning disable 649
|
|
[Dependency] private readonly IMapManager _mapManager;
|
|
[Dependency] private readonly IServerNotifyManager _notifyManager;
|
|
#pragma warning restore 649
|
|
|
|
private const float ThrowForce = 1.5f; // Throwing force of mobs in Newtons
|
|
|
|
/// <inheritdoc />
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
|
|
SubscribeLocalEvent<EntRemovedFromContainerMessage>(HandleContainerModified);
|
|
SubscribeLocalEvent<EntInsertedIntoContainerMessage>(HandleContainerModified);
|
|
|
|
CommandBinds.Builder
|
|
.Bind(ContentKeyFunctions.SwapHands, InputCmdHandler.FromDelegate(HandleSwapHands))
|
|
.Bind(ContentKeyFunctions.Drop, new PointerInputCmdHandler(HandleDrop))
|
|
.Bind(ContentKeyFunctions.ActivateItemInHand, InputCmdHandler.FromDelegate(HandleActivateItem))
|
|
.Bind(ContentKeyFunctions.ThrowItemInHand, new PointerInputCmdHandler(HandleThrowItem))
|
|
.Bind(ContentKeyFunctions.SmartEquipBackpack, InputCmdHandler.FromDelegate(HandleSmartEquipBackpack))
|
|
.Bind(ContentKeyFunctions.SmartEquipBelt, InputCmdHandler.FromDelegate(HandleSmartEquipBelt))
|
|
.Register<HandsSystem>();
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public override void Shutdown()
|
|
{
|
|
CommandBinds.Unregister<HandsSystem>();
|
|
base.Shutdown();
|
|
}
|
|
|
|
private static void HandleContainerModified(ContainerModifiedMessage args)
|
|
{
|
|
if (args.Container.Owner.TryGetComponent(out IHandsComponent handsComponent))
|
|
{
|
|
handsComponent.HandleSlotModifiedMaybe(args);
|
|
}
|
|
}
|
|
|
|
private static bool TryGetAttachedComponent<T>(IPlayerSession session, out T component)
|
|
where T : Component
|
|
{
|
|
component = default;
|
|
|
|
var ent = session.AttachedEntity;
|
|
|
|
if (ent == null || !ent.IsValid())
|
|
return false;
|
|
|
|
if (!ent.TryGetComponent(out T comp))
|
|
return false;
|
|
|
|
component = comp;
|
|
return true;
|
|
}
|
|
|
|
private static void HandleSwapHands(ICommonSession session)
|
|
{
|
|
if (!TryGetAttachedComponent(session as IPlayerSession, out HandsComponent handsComp))
|
|
return;
|
|
|
|
var interactionSystem = EntitySystem.Get<InteractionSystem>();
|
|
|
|
var oldItem = handsComp.GetActiveHand;
|
|
|
|
handsComp.SwapHands();
|
|
|
|
var newItem = handsComp.GetActiveHand;
|
|
|
|
if(oldItem != null)
|
|
interactionSystem.HandDeselectedInteraction(handsComp.Owner, oldItem.Owner);
|
|
|
|
if(newItem != null)
|
|
interactionSystem.HandSelectedInteraction(handsComp.Owner, newItem.Owner);
|
|
}
|
|
|
|
private bool HandleDrop(ICommonSession session, GridCoordinates coords, EntityUid uid)
|
|
{
|
|
var ent = ((IPlayerSession) session).AttachedEntity;
|
|
|
|
if (ent == null || !ent.IsValid())
|
|
return false;
|
|
|
|
if (!ent.TryGetComponent(out HandsComponent handsComp))
|
|
return false;
|
|
|
|
if (handsComp.GetActiveHand == null)
|
|
return false;
|
|
|
|
var entCoords = ent.Transform.GridPosition.Position;
|
|
var entToDesiredDropCoords = coords.Position - entCoords;
|
|
var targetLength = Math.Min(entToDesiredDropCoords.Length, InteractionSystem.InteractionRange - 0.001f); // InteractionRange is reduced due to InRange not dealing with floating point error
|
|
var newCoords = new GridCoordinates((entToDesiredDropCoords.Normalized * targetLength) + entCoords, coords.GridID);
|
|
var rayLength = EntitySystem.Get<SharedInteractionSystem>().UnobstructedRayLength(ent.Transform.MapPosition, newCoords.ToMap(_mapManager), ignoredEnt: ent);
|
|
|
|
handsComp.Drop(handsComp.ActiveIndex, new GridCoordinates(entCoords + (entToDesiredDropCoords.Normalized * rayLength), coords.GridID));
|
|
|
|
return true;
|
|
}
|
|
|
|
private static void HandleActivateItem(ICommonSession session)
|
|
{
|
|
if (!TryGetAttachedComponent(session as IPlayerSession, out HandsComponent handsComp))
|
|
return;
|
|
|
|
handsComp.ActivateItem();
|
|
}
|
|
|
|
private bool HandleThrowItem(ICommonSession session, GridCoordinates coords, EntityUid uid)
|
|
{
|
|
var plyEnt = ((IPlayerSession)session).AttachedEntity;
|
|
|
|
if (plyEnt == null || !plyEnt.IsValid())
|
|
return false;
|
|
|
|
if (!plyEnt.TryGetComponent(out HandsComponent handsComp))
|
|
return false;
|
|
|
|
if (!handsComp.CanDrop(handsComp.ActiveIndex))
|
|
return false;
|
|
|
|
var throwEnt = handsComp.GetHand(handsComp.ActiveIndex).Owner;
|
|
|
|
if (!handsComp.ThrowItem())
|
|
return false;
|
|
|
|
// throw the item, split off from a stack if it's meant to be thrown individually
|
|
if (!throwEnt.TryGetComponent(out StackComponent stackComp) || stackComp.Count < 2 || !stackComp.ThrowIndividually)
|
|
{
|
|
handsComp.Drop(handsComp.ActiveIndex);
|
|
}
|
|
else
|
|
{
|
|
stackComp.Use(1);
|
|
throwEnt = throwEnt.EntityManager.SpawnEntity(throwEnt.Prototype.ID, plyEnt.Transform.GridPosition);
|
|
|
|
// can only throw one item at a time, regardless of what the prototype stack size is.
|
|
if (throwEnt.TryGetComponent<StackComponent>(out var newStackComp))
|
|
newStackComp.Count = 1;
|
|
}
|
|
|
|
ThrowHelper.ThrowTo(throwEnt, ThrowForce, coords, plyEnt.Transform.GridPosition, false, plyEnt);
|
|
|
|
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>());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|