From: Leon Friedrich <60421075+ElectroJr@users.noreply.github.com> Date: Wed, 5 Apr 2023 00:19:28 +0000 (+1200) Subject: DoAfter & misc interaction fixes (#15144) X-Git-Url: https://git.smokeofanarchy.ru/gitweb.cgi?a=commitdiff_plain;h=b9b81801315c359fb3ce4c9a953329bc8af19494;p=space-station-14.git DoAfter & misc interaction fixes (#15144) --- diff --git a/Content.Server/Construction/ConstructionSystem.Interactions.cs b/Content.Server/Construction/ConstructionSystem.Interactions.cs index bfe8f7e04d..0a9d3c543b 100644 --- a/Content.Server/Construction/ConstructionSystem.Interactions.cs +++ b/Content.Server/Construction/ConstructionSystem.Interactions.cs @@ -7,6 +7,7 @@ using Content.Shared.Construction; using Content.Shared.Construction.Steps; using Content.Shared.DoAfter; using Content.Shared.Interaction; +using Content.Shared.Radio.EntitySystems; using Content.Shared.Tools.Components; using Robust.Shared.Containers; using Robust.Shared.Map; @@ -30,13 +31,20 @@ namespace Content.Server.Construction private void InitializeInteractions() { - SubscribeLocalEvent(EnqueueEvent); + SubscribeLocalEvent(OnDoAfterComplete); // Event handling. Add your subscriptions here! Just make sure they're all handled by EnqueueEvent. - SubscribeLocalEvent(EnqueueEvent, new []{typeof(AnchorableSystem)}); + SubscribeLocalEvent(EnqueueEvent, new []{typeof(AnchorableSystem), typeof(EncryptionKeySystem)}); SubscribeLocalEvent(EnqueueEvent); } + private void OnDoAfterComplete(EntityUid uid, ConstructionComponent component, ConstructionInteractDoAfterEvent args) + { + component.DoAfter = null; + if (!args.Cancelled) + EnqueueEvent(uid, component, args); + } + /// /// Takes in an entity with and an object event, and handles any /// possible construction interactions, depending on the construction's state. @@ -223,11 +231,8 @@ namespace Content.Server.Construction // The DoAfter events can only perform special logic when we're not validating events. if (ev is ConstructionInteractDoAfterEvent interactDoAfter) { - if (!validation) - construction.DoAfter = null; - - if (interactDoAfter.Cancelled) - return HandleResult.False; + // cancelled events should not reach this point. + DebugTools.Assert(!interactDoAfter.Cancelled); ev = new InteractUsingEvent( interactDoAfter.User, @@ -256,12 +261,6 @@ namespace Content.Server.Construction if (ev is not InteractUsingEvent interactUsing) break; - if (construction.DoAfter != null && !validation) - { - _doAfterSystem.Cancel(construction.DoAfter); - return HandleResult.False; - } - // TODO: Sanity checks. user = interactUsing.User; @@ -343,12 +342,6 @@ namespace Content.Server.Construction if (ev is not InteractUsingEvent interactUsing) break; - if (construction.DoAfter != null && !validation) - { - _doAfterSystem.Cancel(construction.DoAfter); - return HandleResult.False; - } - // TODO: Sanity checks. user = interactUsing.User; diff --git a/Content.Server/Wires/WiresSystem.cs b/Content.Server/Wires/WiresSystem.cs index 2199ee1643..304a63b049 100644 --- a/Content.Server/Wires/WiresSystem.cs +++ b/Content.Server/Wires/WiresSystem.cs @@ -463,12 +463,16 @@ public sealed class WiresSystem : SharedWiresSystem _toolSystem.HasQuality(args.Used, "Pulsing", tool))) { if (TryComp(args.User, out ActorComponent? actor)) + { _uiSystem.TryOpen(uid, WiresUiKey.Key, actor.PlayerSession); + args.Handled = true; + } } else if (_toolSystem.UseTool(args.Used, args.User, uid, ScrewTime, "Screwing", new WirePanelDoAfterEvent(), toolComponent: tool)) { _adminLogger.Add(LogType.Action, LogImpact.Low, $"{ToPrettyString(args.User):user} is screwing {ToPrettyString(uid):target}'s {(panel.Open ? "open" : "closed")} maintenance panel at {Transform(uid).Coordinates:targetlocation}"); + args.Handled = true; } } diff --git a/Content.Shared/Clothing/EntitySystems/ToggleableClothingSystem.cs b/Content.Shared/Clothing/EntitySystems/ToggleableClothingSystem.cs index 0f69dafbed..fa5c2f647c 100644 --- a/Content.Shared/Clothing/EntitySystems/ToggleableClothingSystem.cs +++ b/Content.Shared/Clothing/EntitySystems/ToggleableClothingSystem.cs @@ -245,14 +245,14 @@ public sealed class ToggleableClothingSystem : EntitySystem var parent = Transform(target).ParentUid; if (component.Container.ContainedEntity == null) - _inventorySystem.TryUnequip(parent, component.Slot); + _inventorySystem.TryUnequip(user, parent, component.Slot); else if (_inventorySystem.TryGetSlotEntity(parent, component.Slot, out var existing)) { _popupSystem.PopupEntity(Loc.GetString("toggleable-clothing-remove-first", ("entity", existing)), user, user); } else - _inventorySystem.TryEquip(parent, component.ClothingUid.Value, component.Slot); + _inventorySystem.TryEquip(user, parent, component.ClothingUid.Value, component.Slot); } private void OnGetActions(EntityUid uid, ToggleableClothingComponent component, GetItemActionsEvent args) diff --git a/Content.Shared/Radio/EntitySystems/EncryptionKeySystem.cs b/Content.Shared/Radio/EntitySystems/EncryptionKeySystem.cs index a69438c354..16d6960d99 100644 --- a/Content.Shared/Radio/EntitySystems/EncryptionKeySystem.cs +++ b/Content.Shared/Radio/EntitySystems/EncryptionKeySystem.cs @@ -92,27 +92,27 @@ public sealed class EncryptionKeySystem : EntitySystem if ( args.Handled || !TryComp(uid, out var storage)) return; - args.Handled = true; - - if (!component.KeysUnlocked) - { - if (_net.IsClient && _timing.IsFirstTimePredicted) - _popup.PopupEntity(Loc.GetString("encryption-keys-are-locked"), uid, args.User); - return; - } - - if (TryComp(args.Used, out var key)) + if (HasComp(args.Used)) { + args.Handled = true; TryInsertKey(uid, component, args); } - else + else if (TryComp(args.Used, out var tool) && tool.Qualities.Contains(component.KeysExtractionMethod)) { - TryRemoveKey(uid, component, args); + args.Handled = true; + TryRemoveKey(uid, component, args, tool); } } private void TryInsertKey(EntityUid uid, EncryptionKeyHolderComponent component, InteractUsingEvent args) { + if (!component.KeysUnlocked) + { + if (_net.IsClient && _timing.IsFirstTimePredicted) + _popup.PopupEntity(Loc.GetString("encryption-keys-are-locked"), uid, args.User); + return; + } + if (TryComp(uid, out var panel) && !panel.Open) { if (_net.IsClient && _timing.IsFirstTimePredicted) @@ -137,10 +137,15 @@ public sealed class EncryptionKeySystem : EntitySystem } } - private void TryRemoveKey(EntityUid uid, EncryptionKeyHolderComponent component, InteractUsingEvent args) + private void TryRemoveKey(EntityUid uid, EncryptionKeyHolderComponent component, InteractUsingEvent args, + ToolComponent? tool) { - if (!TryComp(args.Used, out var tool) || !tool.Qualities.Contains(component.KeysExtractionMethod)) + if (!component.KeysUnlocked) + { + if (_net.IsClient && _timing.IsFirstTimePredicted) + _popup.PopupEntity(Loc.GetString("encryption-keys-are-locked"), uid, args.User); return; + } if (TryComp(uid, out var panel) && !panel.Open) {