Fix StrippableSystem blunders (#26166)

* Fixes target hand check when no hands were needed.

* Adds missing CanStripX checks.

* Whitespace.

* Fixed bad math causing instant strips.
This commit is contained in:
Krunklehorn
2024-03-15 23:50:53 -04:00
committed by GitHub
parent 23e6d537a4
commit 8ecb78ee5a
2 changed files with 13 additions and 7 deletions

View File

@@ -122,13 +122,12 @@ namespace Content.Server.Strip
private void OnStripButtonPressed(Entity<StrippableComponent> strippable, ref StrippingSlotButtonPressed args) private void OnStripButtonPressed(Entity<StrippableComponent> strippable, ref StrippingSlotButtonPressed args)
{ {
if (args.Session.AttachedEntity is not { Valid: true } user || if (args.Session.AttachedEntity is not { Valid: true } user ||
!TryComp<HandsComponent>(user, out var userHands) || !TryComp<HandsComponent>(user, out var userHands))
!TryComp<HandsComponent>(strippable.Owner, out var targetHands))
return; return;
if (args.IsHand) if (args.IsHand)
{ {
StripHand((user, userHands), (strippable.Owner, targetHands), args.Slot, strippable); StripHand((user, userHands), (strippable.Owner, null), args.Slot, strippable);
return; return;
} }
@@ -478,6 +477,9 @@ namespace Content.Server.Strip
!Resolve(target, ref target.Comp)) !Resolve(target, ref target.Comp))
return; return;
if (!CanStripInsertHand(user, target, held, handName))
return;
_handsSystem.TryDrop(user, checkActionBlocker: false, handsComp: user.Comp); _handsSystem.TryDrop(user, checkActionBlocker: false, handsComp: user.Comp);
_handsSystem.TryPickup(target, held, handName, checkActionBlocker: false, animateUser: stealth, animate: stealth, handsComp: target.Comp); _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"); _adminLogger.Add(LogType.Stripping, LogImpact.Medium, $"{ToPrettyString(user):actor} has placed the item {ToPrettyString(held):item} in {ToPrettyString(target):target}'s hands");
@@ -542,7 +544,7 @@ namespace Content.Server.Strip
var (time, stealth) = GetStripTimeModifiers(user, target, targetStrippable.HandStripDelay); var (time, stealth) = GetStripTimeModifiers(user, target, targetStrippable.HandStripDelay);
if (!stealth) if (!stealth)
_popupSystem.PopupEntity( Loc.GetString("strippable-component-alert-owner", ("user", Identity.Entity(user, EntityManager)), ("item", item)), target, target); _popupSystem.PopupEntity(Loc.GetString("strippable-component-alert-owner", ("user", Identity.Entity(user, EntityManager)), ("item", item)), target, target);
var prefix = stealth ? "stealthily " : ""; 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"); _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");
@@ -569,12 +571,16 @@ namespace Content.Server.Strip
Entity<HandsComponent?> user, Entity<HandsComponent?> user,
Entity<HandsComponent?> target, Entity<HandsComponent?> target,
EntityUid item, EntityUid item,
string handName,
bool stealth) bool stealth)
{ {
if (!Resolve(user, ref user.Comp) || if (!Resolve(user, ref user.Comp) ||
!Resolve(target, ref target.Comp)) !Resolve(target, ref target.Comp))
return; return;
if (!CanStripRemoveHand(user, target, item, handName))
return;
_handsSystem.TryDrop(target, item, checkActionBlocker: false, handsComp: target.Comp); _handsSystem.TryDrop(target, item, checkActionBlocker: false, handsComp: target.Comp);
_handsSystem.PickupOrDrop(user, item, animateUser: stealth, animate: stealth, handsComp: user.Comp); _handsSystem.PickupOrDrop(user, item, animateUser: stealth, animate: stealth, handsComp: user.Comp);
_adminLogger.Add(LogType.Stripping, LogImpact.Medium, $"{ToPrettyString(user):actor} has stripped the item {ToPrettyString(item):item} from {ToPrettyString(target):target}'s hands"); _adminLogger.Add(LogType.Stripping, LogImpact.Medium, $"{ToPrettyString(user):actor} has stripped the item {ToPrettyString(item):item} from {ToPrettyString(target):target}'s hands");
@@ -625,7 +631,7 @@ namespace Content.Server.Strip
{ {
if (ev.InsertOrRemove) if (ev.InsertOrRemove)
StripInsertHand((entity.Owner, entity.Comp), ev.Target.Value, ev.Used.Value, ev.SlotOrHandName, ev.Args.Hidden); StripInsertHand((entity.Owner, entity.Comp), ev.Target.Value, ev.Used.Value, ev.SlotOrHandName, ev.Args.Hidden);
else StripRemoveHand((entity.Owner, entity.Comp), ev.Target.Value, ev.Used.Value, ev.Args.Hidden); else StripRemoveHand((entity.Owner, entity.Comp), ev.Target.Value, ev.Used.Value, ev.SlotOrHandName, ev.Args.Hidden);
} }
} }
} }

View File

@@ -35,11 +35,11 @@ namespace Content.Shared.Strip.Components
public abstract class BaseBeforeStripEvent(TimeSpan initialTime, bool stealth = false) : EntityEventArgs, IInventoryRelayEvent public abstract class BaseBeforeStripEvent(TimeSpan initialTime, bool stealth = false) : EntityEventArgs, IInventoryRelayEvent
{ {
public readonly TimeSpan InitialTime = initialTime; public readonly TimeSpan InitialTime = initialTime;
public TimeSpan Multiplier = TimeSpan.FromSeconds(1f); public float Multiplier = 1f;
public TimeSpan Additive = TimeSpan.Zero; public TimeSpan Additive = TimeSpan.Zero;
public bool Stealth = stealth; public bool Stealth = stealth;
public TimeSpan Time => TimeSpan.FromSeconds(MathF.Max(InitialTime.Seconds * Multiplier.Seconds + Additive.Seconds, 0f)); public TimeSpan Time => TimeSpan.FromSeconds(MathF.Max(InitialTime.Seconds * Multiplier + Additive.Seconds, 0f));
public SlotFlags TargetSlots { get; } = SlotFlags.GLOVES; public SlotFlags TargetSlots { get; } = SlotFlags.GLOVES;
} }