* Functioning ECS verbs Currently only ID card console works. * Changed verb types and allow ID card insertions * Verb GUI sorting and verb networking * More networking, and shared components * Clientside verbs work now. * Verb enums changed to bitmask flags * Verb Categories redo * Fix range check * GasTank Verb * Remove unnecessary bodypart verb * Buckle Verb * buckle & unbuckle verbs * Updated range checks * Item cabinet verbs * Add range user override * construction verb * Chemistry machine verbs * Climb Verb * Generalise pulled entity verbs * ViewVariables Verb * rejuvenate, delete, sentient, control verbs * Outfit verb * inrangeunoccluded and tubedirection verbs * attach-to verbs * remove unused verbs and move VV * Rename DebugVerbSystem * Ghost role and pointing verbs * Remove global verbs * Allow verbs to raise events * Changing categories and simplifying debug verbs * Add rotate and flip verbs * fix rejuvenate test * redo context menu * new Add Gas debug verb * Add Set Temperature debug verb * Uncuff verb * Disposal unit verbs * Add pickup verb * lock/unlock verb * Remove verb type, add specific verb events * rename verb messages -> events * Context menu displays verbs by interaction type * Updated context menu HandleMove previously, checked if entities moved 1 tile from click location. Now checks if entities moved out of view. Now you can actually right-click interact with yourself while walking! * Misc Verb menu GUI changes * Fix non-human/ghost verbs * Update types and categories * Allow non-ghost/human to open context menu * configuration verb * tagger verb * Morgue Verbs * Medical Scanner Verbs * Fix solution refactor merge issues * Fix context menu in-view check * Remove prepare GUI * Redo verb restrictions * Fix context menu UI * Disposal Verbs * Spill verb * Light verb * Hand Held light verb * power cell verbs * storage verbs and adding names to insert/eject * Pulling verb * Close context menu on verb execution * Strip verb * AmmoBox verb * fix pull verb * gun barrel verbs revolver verb energy weapon verbs Bolt action verb * Magazine gun barrel verbs * Add charger verbs * PDA verbs * Transfer amount verb * Add reagent verb * make alt-click use ECS verbs * Delete old verb files * Magboot verb * finalising tweaks * context menu visibility changes * code cleanup * Update AdminAddReagentUI.cs * Remove HasFlag * Consistent verb keys * Remove Linq, add comment * Fix in-inventory check * Update GUI text alignment and padding * Added close-menu option * Changed some "interaction" verbs to "activation" * Remove verb keys, use sorted sets * fix master merge * update some verb text * Undo Changes Remove some new verbs that can be added later undid some .ftl bugfixes, can and should be done separately * fix merge * Undo file rename * fix merge * Misc Cleanup * remove contraction * Fix keybinding issue * fix comment * merge fix * fix merge * fix merge * fix merge * fix merge * fix open-close verbs * adjust uncuff verb * fix merge and undo the renaming of SharedPullableComponent to PullableComponent. I'm tired of all of those merge conflicts
448 lines
15 KiB
C#
448 lines
15 KiB
C#
using System.Collections.Generic;
|
|
using System.Threading;
|
|
using Content.Server.Cuffs.Components;
|
|
using Content.Server.DoAfter;
|
|
using Content.Server.Hands.Components;
|
|
using Content.Server.Inventory.Components;
|
|
using Content.Server.Items;
|
|
using Content.Server.UserInterface;
|
|
using Content.Shared.ActionBlocker;
|
|
using Content.Shared.DragDrop;
|
|
using Content.Shared.Hands.Components;
|
|
using Content.Shared.Popups;
|
|
using Content.Shared.Strip.Components;
|
|
using Robust.Server.GameObjects;
|
|
using Robust.Server.Player;
|
|
using Robust.Shared.GameObjects;
|
|
using Robust.Shared.Localization;
|
|
using Robust.Shared.ViewVariables;
|
|
using static Content.Shared.Inventory.EquipmentSlotDefines;
|
|
|
|
namespace Content.Server.Strip
|
|
{
|
|
[RegisterComponent]
|
|
[ComponentReference(typeof(SharedStrippableComponent))]
|
|
public sealed class StrippableComponent : SharedStrippableComponent
|
|
{
|
|
public const float StripDelay = 2f;
|
|
|
|
// TODO: This component needs localization.
|
|
|
|
[ViewVariables]
|
|
private BoundUserInterface? UserInterface => Owner.GetUIOrNull(StrippingUiKey.Key);
|
|
|
|
protected override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
|
|
if (UserInterface != null)
|
|
{
|
|
UserInterface.OnReceiveMessage += HandleUserInterfaceMessage;
|
|
}
|
|
|
|
Owner.EnsureComponentWarn<InventoryComponent>();
|
|
Owner.EnsureComponentWarn<HandsComponent>();
|
|
Owner.EnsureComponentWarn<CuffableComponent>();
|
|
|
|
if (Owner.TryGetComponent(out CuffableComponent? cuffed))
|
|
{
|
|
cuffed.OnCuffedStateChanged += UpdateSubscribed;
|
|
}
|
|
|
|
if (Owner.TryGetComponent(out InventoryComponent? inventory))
|
|
{
|
|
inventory.OnItemChanged += UpdateSubscribed;
|
|
}
|
|
|
|
if (Owner.TryGetComponent(out HandsComponent? hands))
|
|
{
|
|
hands.OnItemChanged += UpdateSubscribed;
|
|
}
|
|
|
|
// Initial update.
|
|
UpdateSubscribed();
|
|
}
|
|
|
|
private void UpdateSubscribed()
|
|
{
|
|
if (UserInterface == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
var inventory = GetInventorySlots();
|
|
var hands = GetHandSlots();
|
|
var cuffs = GetHandcuffs();
|
|
|
|
UserInterface.SetState(new StrippingBoundUserInterfaceState(inventory, hands, cuffs));
|
|
}
|
|
|
|
public override bool Drop(DragDropEvent args)
|
|
{
|
|
if (!args.User.TryGetComponent(out ActorComponent? actor)) return false;
|
|
|
|
OpenUserInterface(actor.PlayerSession);
|
|
return true;
|
|
}
|
|
|
|
private Dictionary<EntityUid, string> GetHandcuffs()
|
|
{
|
|
var dictionary = new Dictionary<EntityUid, string>();
|
|
|
|
if (!Owner.TryGetComponent(out CuffableComponent? cuffed))
|
|
{
|
|
return dictionary;
|
|
}
|
|
|
|
foreach (IEntity entity in cuffed.StoredEntities)
|
|
{
|
|
dictionary.Add(entity.Uid, entity.Name);
|
|
}
|
|
|
|
return dictionary;
|
|
}
|
|
|
|
private Dictionary<Slots, string> GetInventorySlots()
|
|
{
|
|
var dictionary = new Dictionary<Slots, string>();
|
|
|
|
if (!Owner.TryGetComponent(out InventoryComponent? inventory))
|
|
{
|
|
return dictionary;
|
|
}
|
|
|
|
foreach (var slot in inventory.Slots)
|
|
{
|
|
dictionary[slot] = inventory.GetSlotItem(slot)?.Owner.Name ?? "None";
|
|
}
|
|
|
|
return dictionary;
|
|
}
|
|
|
|
private Dictionary<string, string> GetHandSlots()
|
|
{
|
|
var dictionary = new Dictionary<string, string>();
|
|
|
|
if (!Owner.TryGetComponent(out HandsComponent? hands))
|
|
{
|
|
return dictionary;
|
|
}
|
|
|
|
foreach (var hand in hands.HandNames)
|
|
{
|
|
var owner = hands.GetItem(hand)?.Owner;
|
|
|
|
if (owner?.HasComponent<HandVirtualItemComponent>() ?? true)
|
|
{
|
|
dictionary[hand] = "None";
|
|
continue;
|
|
}
|
|
|
|
dictionary[hand] = owner.Name;
|
|
}
|
|
|
|
return dictionary;
|
|
}
|
|
|
|
public void OpenUserInterface(IPlayerSession session)
|
|
{
|
|
UserInterface?.Open(session);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Places item in user's active hand to an inventory slot.
|
|
/// </summary>
|
|
private async void PlaceActiveHandItemInInventory(IEntity user, Slots slot)
|
|
{
|
|
var inventory = Owner.GetComponent<InventoryComponent>();
|
|
var userHands = user.GetComponent<HandsComponent>();
|
|
var item = userHands.GetActiveHand;
|
|
|
|
bool Check()
|
|
{
|
|
if (!EntitySystem.Get<ActionBlockerSystem>().CanInteract(user))
|
|
return false;
|
|
|
|
if (item == null)
|
|
{
|
|
user.PopupMessageCursor(Loc.GetString("strippable-component-not-holding-anything"));
|
|
return false;
|
|
}
|
|
|
|
if (!userHands.CanDrop(userHands.ActiveHand!))
|
|
{
|
|
user.PopupMessageCursor(Loc.GetString("strippable-component-cannot-drop"));
|
|
return false;
|
|
}
|
|
|
|
if (!inventory.HasSlot(slot))
|
|
return false;
|
|
|
|
if (inventory.TryGetSlotItem(slot, out ItemComponent _))
|
|
{
|
|
user.PopupMessageCursor(Loc.GetString("strippable-component-item-slot-occupied",("owner", Owner)));
|
|
return false;
|
|
}
|
|
|
|
if (!inventory.CanEquip(slot, item, false))
|
|
{
|
|
user.PopupMessageCursor(Loc.GetString("strippable-component-cannot-equip-message",("owner", Owner)));
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
var doAfterSystem = EntitySystem.Get<DoAfterSystem>();
|
|
|
|
var doAfterArgs = new DoAfterEventArgs(user, StripDelay, CancellationToken.None, Owner)
|
|
{
|
|
ExtraCheck = Check,
|
|
BreakOnStun = true,
|
|
BreakOnDamage = true,
|
|
BreakOnTargetMove = true,
|
|
BreakOnUserMove = true,
|
|
NeedHand = true,
|
|
};
|
|
|
|
var result = await doAfterSystem.WaitDoAfter(doAfterArgs);
|
|
if (result != DoAfterStatus.Finished) return;
|
|
|
|
userHands.Drop(item!.Owner, false);
|
|
inventory.Equip(slot, item!.Owner, false);
|
|
|
|
UpdateSubscribed();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Places item in user's active hand in one of the entity's hands.
|
|
/// </summary>
|
|
private async void PlaceActiveHandItemInHands(IEntity user, string hand)
|
|
{
|
|
var hands = Owner.GetComponent<HandsComponent>();
|
|
var userHands = user.GetComponent<HandsComponent>();
|
|
var item = userHands.GetActiveHand;
|
|
|
|
bool Check()
|
|
{
|
|
if (!EntitySystem.Get<ActionBlockerSystem>().CanInteract(user))
|
|
return false;
|
|
|
|
if (item == null)
|
|
{
|
|
user.PopupMessageCursor(Loc.GetString("strippable-component-not-holding-anything"));
|
|
return false;
|
|
}
|
|
|
|
if (!userHands.CanDrop(userHands.ActiveHand!))
|
|
{
|
|
user.PopupMessageCursor(Loc.GetString("strippable-component-cannot-drop"));
|
|
return false;
|
|
}
|
|
|
|
if (!hands.HasHand(hand))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
if (hands.TryGetItem(hand, out var _))
|
|
{
|
|
user.PopupMessageCursor(Loc.GetString("strippable-component-item-slot-occupied-message", ("owner", Owner)));
|
|
return false;
|
|
}
|
|
|
|
if (!hands.CanPickupEntity(hand, item.Owner, checkActionBlocker: false))
|
|
{
|
|
user.PopupMessageCursor(Loc.GetString("strippable-component-cannot-put-message",("owner", Owner)));
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
var doAfterSystem = EntitySystem.Get<DoAfterSystem>();
|
|
|
|
var doAfterArgs = new DoAfterEventArgs(user, StripDelay, CancellationToken.None, Owner)
|
|
{
|
|
ExtraCheck = Check,
|
|
BreakOnStun = true,
|
|
BreakOnDamage = true,
|
|
BreakOnTargetMove = true,
|
|
BreakOnUserMove = true,
|
|
NeedHand = true,
|
|
};
|
|
|
|
var result = await doAfterSystem.WaitDoAfter(doAfterArgs);
|
|
if (result != DoAfterStatus.Finished) return;
|
|
|
|
userHands.Drop(hand);
|
|
hands.TryPickupEntity(hand, item!.Owner, checkActionBlocker: false);
|
|
UpdateSubscribed();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Takes an item from the inventory and places it in the user's active hand.
|
|
/// </summary>
|
|
private async void TakeItemFromInventory(IEntity user, Slots slot)
|
|
{
|
|
var inventory = Owner.GetComponent<InventoryComponent>();
|
|
var userHands = user.GetComponent<HandsComponent>();
|
|
|
|
bool Check()
|
|
{
|
|
if (!EntitySystem.Get<ActionBlockerSystem>().CanInteract(user))
|
|
return false;
|
|
|
|
if (!inventory.HasSlot(slot))
|
|
return false;
|
|
|
|
if (!inventory.TryGetSlotItem(slot, out ItemComponent? itemToTake))
|
|
{
|
|
user.PopupMessageCursor(Loc.GetString("strippable-component-item-slot-free-message",("owner", Owner)));
|
|
return false;
|
|
}
|
|
|
|
if (!inventory.CanUnequip(slot, false))
|
|
{
|
|
user.PopupMessageCursor(Loc.GetString("strippable-component-cannot-unequip-message",("owner", Owner)));
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
var doAfterSystem = EntitySystem.Get<DoAfterSystem>();
|
|
|
|
var doAfterArgs = new DoAfterEventArgs(user, StripDelay, CancellationToken.None, Owner)
|
|
{
|
|
ExtraCheck = Check,
|
|
BreakOnStun = true,
|
|
BreakOnDamage = true,
|
|
BreakOnTargetMove = true,
|
|
BreakOnUserMove = true,
|
|
};
|
|
|
|
var result = await doAfterSystem.WaitDoAfter(doAfterArgs);
|
|
if (result != DoAfterStatus.Finished) return;
|
|
|
|
var item = inventory.GetSlotItem(slot);
|
|
inventory.Unequip(slot, false);
|
|
|
|
if (item != null)
|
|
{
|
|
userHands.PutInHandOrDrop(item);
|
|
}
|
|
|
|
UpdateSubscribed();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Takes an item from a hand and places it in the user's active hand.
|
|
/// </summary>
|
|
private async void TakeItemFromHands(IEntity user, string hand)
|
|
{
|
|
var hands = Owner.GetComponent<HandsComponent>();
|
|
var userHands = user.GetComponent<HandsComponent>();
|
|
|
|
bool Check()
|
|
{
|
|
if (!EntitySystem.Get<ActionBlockerSystem>().CanInteract(user))
|
|
return false;
|
|
|
|
if (!hands.HasHand(hand))
|
|
return false;
|
|
|
|
if (!hands.TryGetItem(hand, out var heldItem))
|
|
{
|
|
user.PopupMessageCursor(Loc.GetString("strippable-component-item-slot-free-message",("owner", Owner)));
|
|
return false;
|
|
}
|
|
|
|
if (heldItem.Owner.HasComponent<HandVirtualItemComponent>())
|
|
return false;
|
|
|
|
if (!hands.CanDrop(hand, false))
|
|
{
|
|
user.PopupMessageCursor(Loc.GetString("strippable-component-cannot-drop-message",("owner", Owner)));
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
var doAfterSystem = EntitySystem.Get<DoAfterSystem>();
|
|
|
|
var doAfterArgs = new DoAfterEventArgs(user, StripDelay, CancellationToken.None, Owner)
|
|
{
|
|
ExtraCheck = Check,
|
|
BreakOnStun = true,
|
|
BreakOnDamage = true,
|
|
BreakOnTargetMove = true,
|
|
BreakOnUserMove = true,
|
|
};
|
|
|
|
var result = await doAfterSystem.WaitDoAfter(doAfterArgs);
|
|
if (result != DoAfterStatus.Finished) return;
|
|
|
|
var item = hands.GetItem(hand);
|
|
hands.Drop(hand, false);
|
|
userHands.PutInHandOrDrop(item!);
|
|
UpdateSubscribed();
|
|
}
|
|
|
|
private void HandleUserInterfaceMessage(ServerBoundUserInterfaceMessage obj)
|
|
{
|
|
var user = obj.Session.AttachedEntity;
|
|
if (user == null || !(user.TryGetComponent(out HandsComponent? userHands))) return;
|
|
|
|
var placingItem = userHands.GetActiveHand != null;
|
|
|
|
switch (obj.Message)
|
|
{
|
|
case StrippingInventoryButtonPressed inventoryMessage:
|
|
|
|
if (Owner.TryGetComponent<InventoryComponent>(out var inventory))
|
|
{
|
|
if (inventory.TryGetSlotItem(inventoryMessage.Slot, out ItemComponent _))
|
|
placingItem = false;
|
|
|
|
if (placingItem)
|
|
PlaceActiveHandItemInInventory(user, inventoryMessage.Slot);
|
|
else
|
|
TakeItemFromInventory(user, inventoryMessage.Slot);
|
|
}
|
|
break;
|
|
|
|
case StrippingHandButtonPressed handMessage:
|
|
|
|
if (Owner.TryGetComponent<HandsComponent>(out var hands))
|
|
{
|
|
if (hands.TryGetItem(handMessage.Hand, out _))
|
|
placingItem = false;
|
|
|
|
if (placingItem)
|
|
PlaceActiveHandItemInHands(user, handMessage.Hand);
|
|
else
|
|
TakeItemFromHands(user, handMessage.Hand);
|
|
}
|
|
break;
|
|
|
|
case StrippingHandcuffButtonPressed handcuffMessage:
|
|
|
|
if (Owner.TryGetComponent<CuffableComponent>(out var cuffed))
|
|
{
|
|
foreach (var entity in cuffed.StoredEntities)
|
|
{
|
|
if (entity.Uid == handcuffMessage.Handcuff)
|
|
{
|
|
cuffed.TryUncuff(user, entity);
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|