HandsSystem Refactor (#38438)
* checkpoint * pt 2 * pt... i forgot * pt 4 * patch * More test fixes * optimization!!! * the REAL hand system * fix RetractableItemActionSystem.cs oversight * the review * test * remove test usage of body prototype * Update Content.IntegrationTests/Tests/Interaction/InteractionTest.cs Co-authored-by: Tayrtahn <tayrtahn@gmail.com> * hellcode * hellcode 2 * Minor cleanup * test * Chasing the last of the bugs * changes --------- Co-authored-by: Tayrtahn <tayrtahn@gmail.com>
This commit is contained in:
@@ -104,8 +104,8 @@ public abstract class SharedStrippableSystem : EntitySystem
|
||||
|
||||
var hasEnt = _inventorySystem.TryGetSlotEntity(strippable, args.Slot, out var held, inventory);
|
||||
|
||||
if (userHands.ActiveHandEntity != null && !hasEnt)
|
||||
StartStripInsertInventory((user, userHands), strippable.Owner, userHands.ActiveHandEntity.Value, args.Slot);
|
||||
if (_handsSystem.GetActiveItem((user, userHands)) is { } activeItem && !hasEnt)
|
||||
StartStripInsertInventory((user, userHands), strippable.Owner, activeItem, args.Slot);
|
||||
else if (hasEnt)
|
||||
StartStripRemoveInventory(user, strippable.Owner, held!.Value, args.Slot);
|
||||
}
|
||||
@@ -124,11 +124,10 @@ public abstract class SharedStrippableSystem : EntitySystem
|
||||
if (!target.Comp.CanBeStripped)
|
||||
return;
|
||||
|
||||
if (!_handsSystem.TryGetHand(target.Owner, handId, out var handSlot))
|
||||
return;
|
||||
var heldEntity = _handsSystem.GetHeldItem(target.Owner, handId);
|
||||
|
||||
// Is the target a handcuff?
|
||||
if (TryComp<VirtualItemComponent>(handSlot.HeldEntity, out var virtualItem) &&
|
||||
if (TryComp<VirtualItemComponent>(heldEntity, out var virtualItem) &&
|
||||
TryComp<CuffableComponent>(target.Owner, out var cuffable) &&
|
||||
_cuffableSystem.GetAllCuffs(cuffable).Contains(virtualItem.BlockingEntity))
|
||||
{
|
||||
@@ -136,10 +135,10 @@ public abstract class SharedStrippableSystem : EntitySystem
|
||||
return;
|
||||
}
|
||||
|
||||
if (user.Comp.ActiveHandEntity != null && handSlot.HeldEntity == null)
|
||||
StartStripInsertHand(user, target, user.Comp.ActiveHandEntity.Value, handId, targetStrippable);
|
||||
else if (handSlot.HeldEntity != null)
|
||||
StartStripRemoveHand(user, target, handSlot.HeldEntity.Value, handId, targetStrippable);
|
||||
if (_handsSystem.GetActiveItem(user.AsNullable()) is { } activeItem && heldEntity == null)
|
||||
StartStripInsertHand(user, target, activeItem, handId, targetStrippable);
|
||||
else if (heldEntity != null)
|
||||
StartStripRemoveHand(user, target, heldEntity.Value, handId, targetStrippable);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -154,16 +153,10 @@ public abstract class SharedStrippableSystem : EntitySystem
|
||||
if (!Resolve(user, ref user.Comp))
|
||||
return false;
|
||||
|
||||
if (user.Comp.ActiveHand == null)
|
||||
if (!_handsSystem.TryGetActiveItem(user, out var activeItem) || activeItem != held)
|
||||
return false;
|
||||
|
||||
if (user.Comp.ActiveHandEntity == null)
|
||||
return false;
|
||||
|
||||
if (user.Comp.ActiveHandEntity != held)
|
||||
return false;
|
||||
|
||||
if (!_handsSystem.CanDropHeld(user, user.Comp.ActiveHand))
|
||||
if (!_handsSystem.CanDropHeld(user, user.Comp.ActiveHandId!))
|
||||
{
|
||||
_popupSystem.PopupCursor(Loc.GetString("strippable-component-cannot-drop"));
|
||||
return false;
|
||||
@@ -210,10 +203,14 @@ public abstract class SharedStrippableSystem : EntitySystem
|
||||
var (time, stealth) = GetStripTimeModifiers(user, target, held, slotDef.StripTime);
|
||||
|
||||
if (!stealth)
|
||||
{
|
||||
_popupSystem.PopupEntity(Loc.GetString("strippable-component-alert-owner-insert",
|
||||
("user", Identity.Entity(user, EntityManager)),
|
||||
("item", user.Comp.ActiveHandEntity!.Value)),
|
||||
target, target, PopupType.Large);
|
||||
("item", _handsSystem.GetActiveItem((user, user.Comp))!.Value)),
|
||||
target,
|
||||
target,
|
||||
PopupType.Large);
|
||||
}
|
||||
|
||||
var prefix = stealth ? "stealthily " : "";
|
||||
_adminLogger.Add(LogType.Stripping, LogImpact.Low, $"{ToPrettyString(user):actor} is trying to {prefix}place the item {ToPrettyString(held):item} in {ToPrettyString(target):target}'s {slot} slot");
|
||||
@@ -246,7 +243,7 @@ public abstract class SharedStrippableSystem : EntitySystem
|
||||
if (!CanStripInsertInventory(user, target, held, slot))
|
||||
return;
|
||||
|
||||
if (!_handsSystem.TryDrop(user, handsComp: user.Comp))
|
||||
if (!_handsSystem.TryDrop(user))
|
||||
return;
|
||||
|
||||
_inventorySystem.TryEquip(user, target, held, slot, triggerHandContact: true);
|
||||
@@ -305,10 +302,15 @@ public abstract class SharedStrippableSystem : EntitySystem
|
||||
if (IsStripHidden(slotDef, user))
|
||||
_popupSystem.PopupEntity(Loc.GetString("strippable-component-alert-owner-hidden", ("slot", slot)), target, target, PopupType.Large);
|
||||
else
|
||||
{
|
||||
_popupSystem.PopupEntity(Loc.GetString("strippable-component-alert-owner",
|
||||
("user", Identity.Entity(user, EntityManager)),
|
||||
("item", item)),
|
||||
target, target, PopupType.Large);
|
||||
target,
|
||||
target,
|
||||
PopupType.Large);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
var prefix = stealth ? "stealthily " : "";
|
||||
@@ -368,23 +370,16 @@ public abstract class SharedStrippableSystem : EntitySystem
|
||||
if (!target.Comp.CanBeStripped)
|
||||
return false;
|
||||
|
||||
if (user.Comp.ActiveHand == null)
|
||||
if (!_handsSystem.TryGetActiveItem(user, out var activeItem) || activeItem != held)
|
||||
return false;
|
||||
|
||||
if (user.Comp.ActiveHandEntity == null)
|
||||
return false;
|
||||
|
||||
if (user.Comp.ActiveHandEntity != held)
|
||||
return false;
|
||||
|
||||
if (!_handsSystem.CanDropHeld(user, user.Comp.ActiveHand))
|
||||
if (!_handsSystem.CanDropHeld(user, user.Comp.ActiveHandId!))
|
||||
{
|
||||
_popupSystem.PopupCursor(Loc.GetString("strippable-component-cannot-drop"));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!_handsSystem.TryGetHand(target, handName, out var handSlot, target.Comp) ||
|
||||
!_handsSystem.CanPickupToHand(target, user.Comp.ActiveHandEntity.Value, handSlot, checkActionBlocker: false, target.Comp))
|
||||
if (!_handsSystem.CanPickupToHand(target, activeItem.Value, handName, checkActionBlocker: false, target.Comp))
|
||||
{
|
||||
_popupSystem.PopupCursor(Loc.GetString("strippable-component-cannot-put-message", ("owner", Identity.Entity(target, EntityManager))));
|
||||
return false;
|
||||
@@ -414,10 +409,15 @@ public abstract class SharedStrippableSystem : EntitySystem
|
||||
var (time, stealth) = GetStripTimeModifiers(user, target, null, targetStrippable.HandStripDelay);
|
||||
|
||||
if (!stealth)
|
||||
{
|
||||
_popupSystem.PopupEntity(Loc.GetString("strippable-component-alert-owner-insert-hand",
|
||||
("user", Identity.Entity(user, EntityManager)),
|
||||
("item", user.Comp.ActiveHandEntity!.Value)),
|
||||
target, target, PopupType.Large);
|
||||
("item", _handsSystem.GetActiveItem(user)!.Value)),
|
||||
target,
|
||||
target,
|
||||
PopupType.Large);
|
||||
|
||||
}
|
||||
|
||||
var prefix = stealth ? "stealthily " : "";
|
||||
_adminLogger.Add(LogType.Stripping, LogImpact.Low, $"{ToPrettyString(user):actor} is trying to {prefix}place the item {ToPrettyString(held):item} in {ToPrettyString(target):target}'s hands");
|
||||
@@ -452,7 +452,7 @@ public abstract class SharedStrippableSystem : EntitySystem
|
||||
if (!CanStripInsertHand(user, target, held, handName))
|
||||
return;
|
||||
|
||||
_handsSystem.TryDrop(user, checkActionBlocker: false, handsComp: user.Comp);
|
||||
_handsSystem.TryDrop(user, checkActionBlocker: false);
|
||||
_handsSystem.TryPickup(target, held, handName, checkActionBlocker: false, animateUser: stealth, animate: !stealth, handsComp: target.Comp);
|
||||
_adminLogger.Add(LogType.Stripping, LogImpact.Medium, $"{ToPrettyString(user):actor} has placed the item {ToPrettyString(held):item} in {ToPrettyString(target):target}'s hands");
|
||||
|
||||
@@ -474,22 +474,22 @@ public abstract class SharedStrippableSystem : EntitySystem
|
||||
if (!target.Comp.CanBeStripped)
|
||||
return false;
|
||||
|
||||
if (!_handsSystem.TryGetHand(target, handName, out var handSlot, target.Comp))
|
||||
if (!_handsSystem.TryGetHand(target, handName, out _))
|
||||
{
|
||||
_popupSystem.PopupCursor(Loc.GetString("strippable-component-item-slot-free-message", ("owner", Identity.Entity(target, EntityManager))));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (HasComp<VirtualItemComponent>(handSlot.HeldEntity))
|
||||
if (!_handsSystem.TryGetHeldItem(target, handName, out var heldEntity))
|
||||
return false;
|
||||
|
||||
if (handSlot.HeldEntity == null)
|
||||
if (HasComp<VirtualItemComponent>(heldEntity))
|
||||
return false;
|
||||
|
||||
if (handSlot.HeldEntity != item)
|
||||
if (heldEntity != item)
|
||||
return false;
|
||||
|
||||
if (!_handsSystem.CanDropHeld(target, handSlot, false))
|
||||
if (!_handsSystem.CanDropHeld(target, handName, false))
|
||||
{
|
||||
_popupSystem.PopupCursor(Loc.GetString("strippable-component-cannot-drop-message", ("owner", Identity.Entity(target, EntityManager))));
|
||||
return false;
|
||||
@@ -519,10 +519,13 @@ public abstract class SharedStrippableSystem : EntitySystem
|
||||
var (time, stealth) = GetStripTimeModifiers(user, target, null, targetStrippable.HandStripDelay);
|
||||
|
||||
if (!stealth)
|
||||
{
|
||||
_popupSystem.PopupEntity(Loc.GetString("strippable-component-alert-owner",
|
||||
("user", Identity.Entity(user, EntityManager)),
|
||||
("item", item)),
|
||||
target, target);
|
||||
target,
|
||||
target);
|
||||
}
|
||||
|
||||
var prefix = stealth ? "stealthily " : "";
|
||||
_adminLogger.Add(LogType.Stripping, LogImpact.Low, $"{ToPrettyString(user):actor} is trying to {prefix}strip the item {ToPrettyString(item):item} from {ToPrettyString(target):target}'s hands");
|
||||
@@ -560,7 +563,7 @@ public abstract class SharedStrippableSystem : EntitySystem
|
||||
if (!CanStripRemoveHand(user, target, item, handName))
|
||||
return;
|
||||
|
||||
_handsSystem.TryDrop(target, item, checkActionBlocker: false, handsComp: target.Comp);
|
||||
_handsSystem.TryDrop(target, item, checkActionBlocker: false);
|
||||
_handsSystem.PickupOrDrop(user, item, animateUser: stealth, animate: !stealth, handsComp: user.Comp);
|
||||
_adminLogger.Add(LogType.Stripping, LogImpact.High, $"{ToPrettyString(user):actor} has stripped the item {ToPrettyString(item):item} from {ToPrettyString(target):target}'s hands");
|
||||
|
||||
@@ -580,13 +583,17 @@ public abstract class SharedStrippableSystem : EntitySystem
|
||||
{
|
||||
if ( ev.Event.InsertOrRemove && !CanStripInsertInventory((entity.Owner, entity.Comp), args.Target.Value, args.Used.Value, ev.Event.SlotOrHandName) ||
|
||||
!ev.Event.InsertOrRemove && !CanStripRemoveInventory(entity.Owner, args.Target.Value, args.Used.Value, ev.Event.SlotOrHandName))
|
||||
ev.Cancel();
|
||||
{
|
||||
ev.Cancel();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( ev.Event.InsertOrRemove && !CanStripInsertHand((entity.Owner, entity.Comp), args.Target.Value, args.Used.Value, ev.Event.SlotOrHandName) ||
|
||||
!ev.Event.InsertOrRemove && !CanStripRemoveHand(entity.Owner, args.Target.Value, args.Used.Value, ev.Event.SlotOrHandName))
|
||||
ev.Cancel();
|
||||
{
|
||||
ev.Cancel();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user