Fix stripping not marking interactions as handled (#28292)

This commit is contained in:
Leon Friedrich
2024-05-26 15:18:27 +12:00
committed by GitHub
parent b8020776cc
commit a38e6475cb
2 changed files with 26 additions and 34 deletions

View File

@@ -1,7 +1,6 @@
using System.Linq;
using Content.Server.Administration.Logs;
using Content.Server.Ensnaring;
using Content.Shared.CombatMode;
using Content.Shared.Cuffs;
using Content.Shared.Cuffs.Components;
using Content.Shared.Database;
@@ -10,7 +9,6 @@ using Content.Shared.Ensnaring.Components;
using Content.Shared.Hands.Components;
using Content.Shared.Hands.EntitySystems;
using Content.Shared.IdentityManagement;
using Content.Shared.Interaction;
using Content.Shared.Interaction.Events;
using Content.Shared.Inventory;
using Content.Shared.Inventory.VirtualItem;
@@ -18,7 +16,6 @@ using Content.Shared.Popups;
using Content.Shared.Strip;
using Content.Shared.Strip.Components;
using Content.Shared.Verbs;
using Robust.Server.GameObjects;
using Robust.Shared.Player;
using Robust.Shared.Utility;
@@ -28,7 +25,6 @@ namespace Content.Server.Strip
{
[Dependency] private readonly InventorySystem _inventorySystem = default!;
[Dependency] private readonly EnsnareableSystem _ensnaringSystem = default!;
[Dependency] private readonly UserInterfaceSystem _userInterfaceSystem = default!;
[Dependency] private readonly SharedCuffableSystem _cuffableSystem = default!;
[Dependency] private readonly SharedDoAfterSystem _doAfterSystem = default!;
@@ -45,7 +41,6 @@ namespace Content.Server.Strip
SubscribeLocalEvent<StrippableComponent, GetVerbsEvent<Verb>>(AddStripVerb);
SubscribeLocalEvent<StrippableComponent, GetVerbsEvent<ExamineVerb>>(AddStripExamineVerb);
SubscribeLocalEvent<StrippableComponent, ActivateInWorldEvent>(OnActivateInWorld);
// BUI
SubscribeLocalEvent<StrippableComponent, StrippingSlotButtonPressed>(OnStripButtonPressed);
@@ -68,7 +63,7 @@ namespace Content.Server.Strip
{
Text = Loc.GetString("strip-verb-get-data-text"),
Icon = new SpriteSpecifier.Texture(new("/Textures/Interface/VerbIcons/outfit.svg.192dpi.png")),
Act = () => StartOpeningStripper(args.User, (uid, component), true),
Act = () => TryOpenStrippingUi(args.User, (uid, component), true),
};
args.Verbs.Add(verb);
@@ -86,37 +81,13 @@ namespace Content.Server.Strip
{
Text = Loc.GetString("strip-verb-get-data-text"),
Icon = new SpriteSpecifier.Texture(new("/Textures/Interface/VerbIcons/outfit.svg.192dpi.png")),
Act = () => StartOpeningStripper(args.User, (uid, component), true),
Act = () => TryOpenStrippingUi(args.User, (uid, component), true),
Category = VerbCategory.Examine,
};
args.Verbs.Add(verb);
}
private void OnActivateInWorld(EntityUid uid, StrippableComponent component, ActivateInWorldEvent args)
{
if (args.Target == args.User)
return;
if (!HasComp<ActorComponent>(args.User))
return;
StartOpeningStripper(args.User, (uid, component));
}
public override void StartOpeningStripper(EntityUid user, Entity<StrippableComponent> strippable, bool openInCombat = false)
{
base.StartOpeningStripper(user, strippable, openInCombat);
if (TryComp<CombatModeComponent>(user, out var mode) && mode.IsInCombatMode && !openInCombat)
return;
if (HasComp<StrippingComponent>(user))
{
_userInterfaceSystem.OpenUi(strippable.Owner, StrippingUiKey.Key, user);
}
}
private void OnStripButtonPressed(Entity<StrippableComponent> strippable, ref StrippingSlotButtonPressed args)
{
if (args.Actor is not { Valid: true } user ||

View File

@@ -1,17 +1,31 @@
using Content.Shared.CombatMode;
using Content.Shared.DragDrop;
using Content.Shared.Hands.Components;
using Content.Shared.Interaction;
using Content.Shared.Strip.Components;
namespace Content.Shared.Strip;
public abstract class SharedStrippableSystem : EntitySystem
{
[Dependency] private readonly SharedUserInterfaceSystem _ui = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<StrippingComponent, CanDropTargetEvent>(OnCanDropOn);
SubscribeLocalEvent<StrippableComponent, CanDropDraggedEvent>(OnCanDrop);
SubscribeLocalEvent<StrippableComponent, DragDropDraggedEvent>(OnDragDrop);
SubscribeLocalEvent<StrippableComponent, ActivateInWorldEvent>(OnActivateInWorld);
}
private void OnActivateInWorld(EntityUid uid, StrippableComponent component, ActivateInWorldEvent args)
{
if (args.Handled || args.Target == args.User)
return;
if (TryOpenStrippingUi(args.User, (uid, component)))
args.Handled = true;
}
public (TimeSpan Time, bool Stealth) GetStripTimeModifiers(EntityUid user, EntityUid target, TimeSpan initialTime)
@@ -29,13 +43,20 @@ public abstract class SharedStrippableSystem : EntitySystem
if (args.Handled || args.Target != args.User)
return;
StartOpeningStripper(args.User, (uid, component));
args.Handled = true;
if (TryOpenStrippingUi(args.User, (uid, component)))
args.Handled = true;
}
public virtual void StartOpeningStripper(EntityUid user, Entity<StrippableComponent> component, bool openInCombat = false)
public bool TryOpenStrippingUi(EntityUid user, Entity<StrippableComponent> target, bool openInCombat = false)
{
if (!openInCombat && TryComp<CombatModeComponent>(user, out var mode) && mode.IsInCombatMode)
return false;
if (!HasComp<StrippingComponent>(user))
return false;
_ui.OpenUi(target.Owner, StrippingUiKey.Key, user);
return true;
}
private void OnCanDropOn(EntityUid uid, StrippingComponent component, ref CanDropTargetEvent args)