From ce97225c2db44c4f772bdf985f2f2e81f42e34c6 Mon Sep 17 00:00:00 2001 From: Nemanja <98561806+EmoGarbage404@users.noreply.github.com> Date: Wed, 7 Aug 2024 01:15:35 -0400 Subject: [PATCH] Replace IClickAlert with events (#30728) * Replace IAlertClick with events * whoop * eek! --- Content.Client/Alerts/ClientAlertsSystem.cs | 2 +- .../Abilities/Mime/MimePowersSystem.cs | 20 +++++++++++++ Content.Server/Alert/Click/BreakVow.cs | 22 -------------- Content.Server/Alert/Click/RemoveCuffs.cs | 21 -------------- Content.Server/Alert/Click/RemoveEnsnare.cs | 28 ------------------ Content.Server/Alert/Click/ResistFire.cs | 25 ---------------- Content.Server/Alert/Click/RetakeVow.cs | 22 -------------- Content.Server/Alert/Click/StopBeingPulled.cs | 29 ------------------- Content.Server/Alert/Click/StopPiloting.cs | 26 ----------------- Content.Server/Alert/Click/StopPulling.cs | 27 ----------------- Content.Server/Alert/Click/ToggleInternals.cs | 19 ------------ Content.Server/Alert/Click/Unbuckle.cs | 19 ------------ .../Atmos/EntitySystems/FlammableSystem.cs | 10 +++++++ .../Body/Components/InternalsComponent.cs | 1 + .../Body/Systems/InternalsSystem.cs | 9 ++++++ .../Ensnaring/EnsnareableSystem.Ensnaring.cs | 19 ++++++++++++ .../Shuttles/Systems/ShuttleConsoleSystem.cs | 9 ++++++ Content.Shared/Abilities/Mime/MimePowers.cs | 7 +++++ Content.Shared/Alert/AlertPrototype.cs | 22 +++++++++++--- Content.Shared/Alert/AlertsSystem.cs | 17 +++++++++-- Content.Shared/Alert/IAlertClick.cs | 14 --------- .../ExtinguishOnInteractComponent.cs | 3 ++ .../Buckle/Components/BuckleComponent.cs | 2 ++ .../Buckle/SharedBuckleSystem.Buckle.cs | 8 +++++ .../Cuffs/Components/CuffableComponent.cs | 2 ++ Content.Shared/Cuffs/SharedCuffableSystem.cs | 9 ++++++ .../Components/EnsnareableComponent.cs | 2 ++ .../Internals/InternalsDoAfterEvent.cs | 5 +++- .../Pulling/Components/PullableComponent.cs | 2 ++ .../Pulling/Components/PullerComponent.cs | 2 ++ .../Movement/Pulling/Systems/PullingSystem.cs | 22 ++++++++++++++ .../Shuttles/Components/PilotComponent.cs | 2 ++ Resources/Prototypes/Alerts/alerts.yml | 20 ++++++------- 33 files changed, 177 insertions(+), 270 deletions(-) delete mode 100644 Content.Server/Alert/Click/BreakVow.cs delete mode 100644 Content.Server/Alert/Click/RemoveCuffs.cs delete mode 100644 Content.Server/Alert/Click/RemoveEnsnare.cs delete mode 100644 Content.Server/Alert/Click/ResistFire.cs delete mode 100644 Content.Server/Alert/Click/RetakeVow.cs delete mode 100644 Content.Server/Alert/Click/StopBeingPulled.cs delete mode 100644 Content.Server/Alert/Click/StopPiloting.cs delete mode 100644 Content.Server/Alert/Click/StopPulling.cs delete mode 100644 Content.Server/Alert/Click/ToggleInternals.cs delete mode 100644 Content.Server/Alert/Click/Unbuckle.cs create mode 100644 Content.Shared/Abilities/Mime/MimePowers.cs delete mode 100644 Content.Shared/Alert/IAlertClick.cs diff --git a/Content.Client/Alerts/ClientAlertsSystem.cs b/Content.Client/Alerts/ClientAlertsSystem.cs index 359c8957f9d7..525ef1f018fc 100644 --- a/Content.Client/Alerts/ClientAlertsSystem.cs +++ b/Content.Client/Alerts/ClientAlertsSystem.cs @@ -93,6 +93,6 @@ private void OnPlayerDetached(EntityUid uid, AlertsComponent component, LocalPla public void AlertClicked(ProtoId alertType) { - RaiseNetworkEvent(new ClickAlertEvent(alertType)); + RaisePredictiveEvent(new ClickAlertEvent(alertType)); } } diff --git a/Content.Server/Abilities/Mime/MimePowersSystem.cs b/Content.Server/Abilities/Mime/MimePowersSystem.cs index f3bf6e703f52..85230faab0f6 100644 --- a/Content.Server/Abilities/Mime/MimePowersSystem.cs +++ b/Content.Server/Abilities/Mime/MimePowersSystem.cs @@ -1,4 +1,5 @@ using Content.Server.Popups; +using Content.Shared.Abilities.Mime; using Content.Shared.Actions; using Content.Shared.Actions.Events; using Content.Shared.Alert; @@ -29,6 +30,9 @@ public override void Initialize() base.Initialize(); SubscribeLocalEvent(OnComponentInit); SubscribeLocalEvent(OnInvisibleWall); + + SubscribeLocalEvent(OnBreakVowAlert); + SubscribeLocalEvent(OnRetakeVowAlert); } public override void Update(float frameTime) @@ -99,6 +103,22 @@ private void OnInvisibleWall(EntityUid uid, MimePowersComponent component, Invis args.Handled = true; } + private void OnBreakVowAlert(Entity ent, ref BreakVowAlertEvent args) + { + if (args.Handled) + return; + BreakVow(ent, ent); + args.Handled = true; + } + + private void OnRetakeVowAlert(Entity ent, ref RetakeVowAlertEvent args) + { + if (args.Handled) + return; + RetakeVow(ent, ent); + args.Handled = true; + } + /// /// Break this mime's vow to not speak. /// diff --git a/Content.Server/Alert/Click/BreakVow.cs b/Content.Server/Alert/Click/BreakVow.cs deleted file mode 100644 index 400dabbb01d2..000000000000 --- a/Content.Server/Alert/Click/BreakVow.cs +++ /dev/null @@ -1,22 +0,0 @@ -using Content.Shared.Alert; -using Content.Server.Abilities.Mime; - -namespace Content.Server.Alert.Click -{ - /// - /// Break your mime vows - /// - [DataDefinition] - public sealed partial class BreakVow : IAlertClick - { - public void AlertClicked(EntityUid player) - { - var entManager = IoCManager.Resolve(); - - if (entManager.TryGetComponent(player, out MimePowersComponent? mimePowers)) - { - entManager.System().BreakVow(player, mimePowers); - } - } - } -} diff --git a/Content.Server/Alert/Click/RemoveCuffs.cs b/Content.Server/Alert/Click/RemoveCuffs.cs deleted file mode 100644 index b55484283a56..000000000000 --- a/Content.Server/Alert/Click/RemoveCuffs.cs +++ /dev/null @@ -1,21 +0,0 @@ -using Content.Server.Cuffs; -using Content.Shared.Alert; -using JetBrains.Annotations; - -namespace Content.Server.Alert.Click -{ - /// - /// Try to remove handcuffs from yourself - /// - [UsedImplicitly] - [DataDefinition] - public sealed partial class RemoveCuffs : IAlertClick - { - public void AlertClicked(EntityUid player) - { - var entityManager = IoCManager.Resolve(); - var cuffableSys = entityManager.System(); - cuffableSys.TryUncuff(player, player); - } - } -} diff --git a/Content.Server/Alert/Click/RemoveEnsnare.cs b/Content.Server/Alert/Click/RemoveEnsnare.cs deleted file mode 100644 index c33f4ae3417a..000000000000 --- a/Content.Server/Alert/Click/RemoveEnsnare.cs +++ /dev/null @@ -1,28 +0,0 @@ -using Content.Server.Ensnaring; -using Content.Shared.Alert; -using Content.Shared.Ensnaring.Components; -using JetBrains.Annotations; - -namespace Content.Server.Alert.Click; -[UsedImplicitly] -[DataDefinition] -public sealed partial class RemoveEnsnare : IAlertClick -{ - public void AlertClicked(EntityUid player) - { - var entManager = IoCManager.Resolve(); - if (entManager.TryGetComponent(player, out EnsnareableComponent? ensnareableComponent)) - { - foreach (var ensnare in ensnareableComponent.Container.ContainedEntities) - { - if (!entManager.TryGetComponent(ensnare, out EnsnaringComponent? ensnaringComponent)) - return; - - entManager.EntitySysManager.GetEntitySystem().TryFree(player, player, ensnare, ensnaringComponent); - - // Only one snare at a time. - break; - } - } - } -} diff --git a/Content.Server/Alert/Click/ResistFire.cs b/Content.Server/Alert/Click/ResistFire.cs deleted file mode 100644 index 9ae49c3f456c..000000000000 --- a/Content.Server/Alert/Click/ResistFire.cs +++ /dev/null @@ -1,25 +0,0 @@ -using Content.Server.Atmos.Components; -using Content.Server.Atmos.EntitySystems; -using Content.Shared.Alert; -using JetBrains.Annotations; - -namespace Content.Server.Alert.Click -{ - /// - /// Resist fire - /// - [UsedImplicitly] - [DataDefinition] - public sealed partial class ResistFire : IAlertClick - { - public void AlertClicked(EntityUid player) - { - var entManager = IoCManager.Resolve(); - - if (entManager.TryGetComponent(player, out FlammableComponent? flammable)) - { - entManager.System().Resist(player, flammable); - } - } - } -} diff --git a/Content.Server/Alert/Click/RetakeVow.cs b/Content.Server/Alert/Click/RetakeVow.cs deleted file mode 100644 index 1b7a15ea7473..000000000000 --- a/Content.Server/Alert/Click/RetakeVow.cs +++ /dev/null @@ -1,22 +0,0 @@ -using Content.Shared.Alert; -using Content.Server.Abilities.Mime; - -namespace Content.Server.Alert.Click -{ - /// - /// Retake your mime vows - /// - [DataDefinition] - public sealed partial class RetakeVow : IAlertClick - { - public void AlertClicked(EntityUid player) - { - var entManager = IoCManager.Resolve(); - - if (entManager.TryGetComponent(player, out MimePowersComponent? mimePowers)) - { - entManager.System().RetakeVow(player, mimePowers); - } - } - } -} diff --git a/Content.Server/Alert/Click/StopBeingPulled.cs b/Content.Server/Alert/Click/StopBeingPulled.cs deleted file mode 100644 index b02da38ecfa7..000000000000 --- a/Content.Server/Alert/Click/StopBeingPulled.cs +++ /dev/null @@ -1,29 +0,0 @@ -using Content.Shared.ActionBlocker; -using Content.Shared.Alert; -using Content.Shared.Movement.Pulling.Components; -using Content.Shared.Movement.Pulling.Systems; -using JetBrains.Annotations; - -namespace Content.Server.Alert.Click -{ - /// - /// Stop pulling something - /// - [UsedImplicitly] - [DataDefinition] - public sealed partial class StopBeingPulled : IAlertClick - { - public void AlertClicked(EntityUid player) - { - var entityManager = IoCManager.Resolve(); - - if (!entityManager.System().CanInteract(player, null)) - return; - - if (entityManager.TryGetComponent(player, out PullableComponent? playerPullable)) - { - entityManager.System().TryStopPull(player, playerPullable, user: player); - } - } - } -} diff --git a/Content.Server/Alert/Click/StopPiloting.cs b/Content.Server/Alert/Click/StopPiloting.cs deleted file mode 100644 index cd4e333c0a8c..000000000000 --- a/Content.Server/Alert/Click/StopPiloting.cs +++ /dev/null @@ -1,26 +0,0 @@ -using Content.Server.Shuttles.Systems; -using Content.Shared.Alert; -using Content.Shared.Shuttles.Components; -using JetBrains.Annotations; - -namespace Content.Server.Alert.Click -{ - /// - /// Stop piloting shuttle - /// - [UsedImplicitly] - [DataDefinition] - public sealed partial class StopPiloting : IAlertClick - { - public void AlertClicked(EntityUid player) - { - var entManager = IoCManager.Resolve(); - - if (entManager.TryGetComponent(player, out PilotComponent? pilotComponent) - && pilotComponent.Console != null) - { - entManager.System().RemovePilot(player, pilotComponent); - } - } - } -} diff --git a/Content.Server/Alert/Click/StopPulling.cs b/Content.Server/Alert/Click/StopPulling.cs deleted file mode 100644 index 76f9569429f9..000000000000 --- a/Content.Server/Alert/Click/StopPulling.cs +++ /dev/null @@ -1,27 +0,0 @@ -using Content.Shared.Alert; -using Content.Shared.Movement.Pulling.Components; -using Content.Shared.Movement.Pulling.Systems; -using JetBrains.Annotations; - -namespace Content.Server.Alert.Click -{ - /// - /// Stop pulling something - /// - [UsedImplicitly] - [DataDefinition] - public sealed partial class StopPulling : IAlertClick - { - public void AlertClicked(EntityUid player) - { - var entManager = IoCManager.Resolve(); - var ps = entManager.System(); - - if (entManager.TryGetComponent(player, out PullerComponent? puller) && - entManager.TryGetComponent(puller.Pulling, out PullableComponent? pullableComp)) - { - ps.TryStopPull(puller.Pulling.Value, pullableComp, user: player); - } - } - } -} diff --git a/Content.Server/Alert/Click/ToggleInternals.cs b/Content.Server/Alert/Click/ToggleInternals.cs deleted file mode 100644 index 523db04df30e..000000000000 --- a/Content.Server/Alert/Click/ToggleInternals.cs +++ /dev/null @@ -1,19 +0,0 @@ -using Content.Server.Body.Systems; -using Content.Shared.Alert; -using JetBrains.Annotations; - -namespace Content.Server.Alert.Click; - -/// -/// Attempts to toggle the internals for a particular entity -/// -[UsedImplicitly] -[DataDefinition] -public sealed partial class ToggleInternals : IAlertClick -{ - public void AlertClicked(EntityUid player) - { - var internalsSystem = IoCManager.Resolve().GetEntitySystem(); - internalsSystem.ToggleInternals(player, player, false); - } -} diff --git a/Content.Server/Alert/Click/Unbuckle.cs b/Content.Server/Alert/Click/Unbuckle.cs deleted file mode 100644 index 3e53955d8c5e..000000000000 --- a/Content.Server/Alert/Click/Unbuckle.cs +++ /dev/null @@ -1,19 +0,0 @@ -using Content.Shared.Alert; -using Content.Shared.Buckle; -using JetBrains.Annotations; - -namespace Content.Server.Alert.Click -{ - /// - /// Unbuckles if player is currently buckled. - /// - [UsedImplicitly] - [DataDefinition] - public sealed partial class Unbuckle : IAlertClick - { - public void AlertClicked(EntityUid player) - { - IoCManager.Resolve().System().TryUnbuckle(player, player); - } - } -} diff --git a/Content.Server/Atmos/EntitySystems/FlammableSystem.cs b/Content.Server/Atmos/EntitySystems/FlammableSystem.cs index dd0ac25d703b..cc816a3f10ef 100644 --- a/Content.Server/Atmos/EntitySystems/FlammableSystem.cs +++ b/Content.Server/Atmos/EntitySystems/FlammableSystem.cs @@ -72,6 +72,7 @@ public override void Initialize() SubscribeLocalEvent(OnIsHot); SubscribeLocalEvent(OnTileFire); SubscribeLocalEvent(OnRejuvenate); + SubscribeLocalEvent(OnResistFireAlert); SubscribeLocalEvent(IgniteOnCollide); SubscribeLocalEvent(OnIgniteLand); @@ -250,6 +251,15 @@ private void OnRejuvenate(EntityUid uid, FlammableComponent component, Rejuvenat Extinguish(uid, component); } + private void OnResistFireAlert(Entity ent, ref ResistFireAlertEvent args) + { + if (args.Handled) + return; + + Resist(ent, ent); + args.Handled = true; + } + public void UpdateAppearance(EntityUid uid, FlammableComponent? flammable = null, AppearanceComponent? appearance = null) { if (!Resolve(uid, ref flammable, ref appearance)) diff --git a/Content.Server/Body/Components/InternalsComponent.cs b/Content.Server/Body/Components/InternalsComponent.cs index ef908f96553c..a7edab4a6b08 100644 --- a/Content.Server/Body/Components/InternalsComponent.cs +++ b/Content.Server/Body/Components/InternalsComponent.cs @@ -25,4 +25,5 @@ public sealed partial class InternalsComponent : Component [DataField] public ProtoId InternalsAlert = "Internals"; } + } diff --git a/Content.Server/Body/Systems/InternalsSystem.cs b/Content.Server/Body/Systems/InternalsSystem.cs index e352b0a58a17..7e86cb6f07ea 100644 --- a/Content.Server/Body/Systems/InternalsSystem.cs +++ b/Content.Server/Body/Systems/InternalsSystem.cs @@ -38,6 +38,7 @@ public override void Initialize() SubscribeLocalEvent(OnInternalsShutdown); SubscribeLocalEvent>(OnGetInteractionVerbs); SubscribeLocalEvent(OnDoAfter); + SubscribeLocalEvent(OnToggleInternalsAlert); SubscribeLocalEvent(OnStartingGear); } @@ -161,6 +162,14 @@ private void OnDoAfter(Entity ent, ref InternalsDoAfterEvent args.Handled = true; } + private void OnToggleInternalsAlert(Entity ent, ref ToggleInternalsAlertEvent args) + { + if (args.Handled) + return; + ToggleInternals(ent, ent, false, internals: ent.Comp); + args.Handled = true; + } + private void OnInternalsStartup(Entity ent, ref ComponentStartup args) { _alerts.ShowAlert(ent, ent.Comp.InternalsAlert, GetSeverity(ent)); diff --git a/Content.Server/Ensnaring/EnsnareableSystem.Ensnaring.cs b/Content.Server/Ensnaring/EnsnareableSystem.Ensnaring.cs index 51d3242ce4f2..c9dec3782ff2 100644 --- a/Content.Server/Ensnaring/EnsnareableSystem.Ensnaring.cs +++ b/Content.Server/Ensnaring/EnsnareableSystem.Ensnaring.cs @@ -28,6 +28,7 @@ public void InitializeEnsnaring() SubscribeLocalEvent(OnStepTrigger); SubscribeLocalEvent(OnThrowHit); SubscribeLocalEvent(OnAttemptPacifiedThrow); + SubscribeLocalEvent(OnRemoveEnsnareAlert); } private void OnAttemptPacifiedThrow(Entity ent, ref AttemptPacifiedThrowEvent args) @@ -35,6 +36,24 @@ private void OnAttemptPacifiedThrow(Entity ent, ref AttemptP args.Cancel("pacified-cannot-throw-snare"); } + private void OnRemoveEnsnareAlert(Entity ent, ref RemoveEnsnareAlertEvent args) + { + if (args.Handled) + return; + + foreach (var ensnare in ent.Comp.Container.ContainedEntities) + { + if (!TryComp(ensnare, out var ensnaringComponent)) + return; + + TryFree(ent, ent, ensnare, ensnaringComponent); + + args.Handled = true; + // Only one snare at a time. + break; + } + } + private void OnComponentRemove(EntityUid uid, EnsnaringComponent component, ComponentRemove args) { if (!TryComp(component.Ensnared, out var ensnared)) diff --git a/Content.Server/Shuttles/Systems/ShuttleConsoleSystem.cs b/Content.Server/Shuttles/Systems/ShuttleConsoleSystem.cs index 7a19fd13b2e9..00a913aad867 100644 --- a/Content.Server/Shuttles/Systems/ShuttleConsoleSystem.cs +++ b/Content.Server/Shuttles/Systems/ShuttleConsoleSystem.cs @@ -71,6 +71,7 @@ public override void Initialize() SubscribeLocalEvent(OnUndock); SubscribeLocalEvent(OnGetState); + SubscribeLocalEvent(OnStopPilotingAlert); SubscribeLocalEvent(OnFtlDestStartup); SubscribeLocalEvent(OnFtlDestShutdown); @@ -196,6 +197,14 @@ private void OnGetState(EntityUid uid, PilotComponent component, ref ComponentGe args.State = new PilotComponentState(GetNetEntity(component.Console)); } + private void OnStopPilotingAlert(Entity ent, ref StopPilotingAlertEvent args) + { + if (ent.Comp.Console != null) + { + RemovePilot(ent, ent); + } + } + /// /// Returns the position and angle of all dockingcomponents. /// diff --git a/Content.Shared/Abilities/Mime/MimePowers.cs b/Content.Shared/Abilities/Mime/MimePowers.cs new file mode 100644 index 000000000000..969d7a139506 --- /dev/null +++ b/Content.Shared/Abilities/Mime/MimePowers.cs @@ -0,0 +1,7 @@ +using Content.Shared.Alert; + +namespace Content.Shared.Abilities.Mime; + +public sealed partial class BreakVowAlertEvent : BaseAlertEvent; + +public sealed partial class RetakeVowAlertEvent : BaseAlertEvent; diff --git a/Content.Shared/Alert/AlertPrototype.cs b/Content.Shared/Alert/AlertPrototype.cs index f53da27c0dea..a82cbd3daf6b 100644 --- a/Content.Shared/Alert/AlertPrototype.cs +++ b/Content.Shared/Alert/AlertPrototype.cs @@ -76,11 +76,11 @@ public sealed partial class AlertPrototype : IPrototype public bool SupportsSeverity => MaxSeverity != -1; /// - /// Defines what to do when the alert is clicked. - /// This will always be null on clientside. + /// Event raised on the user when they click on this alert. + /// Can be null. /// - [DataField(serverOnly: true)] - public IAlertClick? OnClick { get; private set; } + [DataField] + public BaseAlertEvent? ClickEvent; /// severity level, if supported by this alert /// the icon path to the texture for the provided severity level @@ -114,3 +114,17 @@ public SpriteSpecifier GetIcon(short? severity = null) return Icons[severity.Value - _minSeverity]; } } + +[ImplicitDataDefinitionForInheritors] +public abstract partial class BaseAlertEvent : HandledEntityEventArgs +{ + public EntityUid User; + + public ProtoId AlertId; + + protected BaseAlertEvent(EntityUid user, ProtoId alertId) + { + User = user; + AlertId = alertId; + } +} diff --git a/Content.Shared/Alert/AlertsSystem.cs b/Content.Shared/Alert/AlertsSystem.cs index 83c6fcd0dd74..c8f2a8e6bcac 100644 --- a/Content.Shared/Alert/AlertsSystem.cs +++ b/Content.Shared/Alert/AlertsSystem.cs @@ -195,7 +195,7 @@ public override void Initialize() SubscribeLocalEvent(OnAutoRemoveUnPaused); - SubscribeNetworkEvent(HandleClickAlert); + SubscribeAllEvent(HandleClickAlert); SubscribeLocalEvent(HandlePrototypesReloaded); LoadPrototypes(); } @@ -328,7 +328,20 @@ private void HandleClickAlert(ClickAlertEvent msg, EntitySessionEventArgs args) return; } - alert.OnClick?.AlertClicked(player.Value); + ActivateAlert(player.Value, alert); + } + + public bool ActivateAlert(EntityUid user, AlertPrototype alert) + { + if (alert.ClickEvent is not { } clickEvent) + return false; + + clickEvent.Handled = false; + clickEvent.User = user; + clickEvent.AlertId = alert.ID; + + RaiseLocalEvent(user, (object) clickEvent, true); + return clickEvent.Handled; } private void OnPlayerAttached(EntityUid uid, AlertsComponent component, PlayerAttachedEvent args) diff --git a/Content.Shared/Alert/IAlertClick.cs b/Content.Shared/Alert/IAlertClick.cs deleted file mode 100644 index c11fc10c0d7b..000000000000 --- a/Content.Shared/Alert/IAlertClick.cs +++ /dev/null @@ -1,14 +0,0 @@ -namespace Content.Shared.Alert -{ - /// - /// Defines what should happen when an alert is clicked. - /// - public interface IAlertClick - { - /// - /// Invoked on server side when user clicks an alert. - /// - /// - void AlertClicked(EntityUid player); - } -} diff --git a/Content.Shared/Atmos/Components/ExtinguishOnInteractComponent.cs b/Content.Shared/Atmos/Components/ExtinguishOnInteractComponent.cs index 02c1e3eb2642..cd3ecdd1c49b 100644 --- a/Content.Shared/Atmos/Components/ExtinguishOnInteractComponent.cs +++ b/Content.Shared/Atmos/Components/ExtinguishOnInteractComponent.cs @@ -1,3 +1,4 @@ +using Content.Shared.Alert; using Robust.Shared.Audio; namespace Content.Shared.Atmos.Components; @@ -27,3 +28,5 @@ public sealed partial class ExtinguishOnInteractComponent : Component [DataField] public LocId ExtinguishFailed = "candle-extinguish-failed"; } + +public sealed partial class ResistFireAlertEvent : BaseAlertEvent; diff --git a/Content.Shared/Buckle/Components/BuckleComponent.cs b/Content.Shared/Buckle/Components/BuckleComponent.cs index ee86e6d4de0f..c4810e8af085 100644 --- a/Content.Shared/Buckle/Components/BuckleComponent.cs +++ b/Content.Shared/Buckle/Components/BuckleComponent.cs @@ -1,4 +1,5 @@ using System.Diagnostics.CodeAnalysis; +using Content.Shared.Alert; using Content.Shared.Interaction; using Robust.Shared.GameStates; using Robust.Shared.Serialization; @@ -79,6 +80,7 @@ public sealed class BuckleState(NetEntity? buckledTo, bool dontCollide, TimeSpan public readonly TimeSpan? BuckleTime = buckleTime; } +public sealed partial class UnbuckleAlertEvent : BaseAlertEvent; /// /// Event raised directed at a strap entity before some entity gets buckled to it. diff --git a/Content.Shared/Buckle/SharedBuckleSystem.Buckle.cs b/Content.Shared/Buckle/SharedBuckleSystem.Buckle.cs index 0fbfd51d6985..4f91a29ebea1 100644 --- a/Content.Shared/Buckle/SharedBuckleSystem.Buckle.cs +++ b/Content.Shared/Buckle/SharedBuckleSystem.Buckle.cs @@ -41,6 +41,7 @@ private void InitializeBuckle() SubscribeLocalEvent(OnPullAttempt); SubscribeLocalEvent(OnBeingPulledAttempt); SubscribeLocalEvent(OnPullStarted); + SubscribeLocalEvent(OnUnbuckleAlert); SubscribeLocalEvent(OnBuckleInsertIntoEntityStorageAttempt); @@ -86,6 +87,13 @@ private void OnPullStarted(Entity ent, ref PullStartedMessage a Unbuckle(ent!, args.PullerUid); } + private void OnUnbuckleAlert(Entity ent, ref UnbuckleAlertEvent args) + { + if (args.Handled) + return; + args.Handled = TryUnbuckle(ent, ent, ent); + } + #endregion #region Transform diff --git a/Content.Shared/Cuffs/Components/CuffableComponent.cs b/Content.Shared/Cuffs/Components/CuffableComponent.cs index 4ddfe1b53ee1..a7eba34d8ce9 100644 --- a/Content.Shared/Cuffs/Components/CuffableComponent.cs +++ b/Content.Shared/Cuffs/Components/CuffableComponent.cs @@ -46,6 +46,8 @@ public sealed partial class CuffableComponent : Component public ProtoId CuffedAlert = "Handcuffed"; } +public sealed partial class RemoveCuffsAlertEvent : BaseAlertEvent; + [Serializable, NetSerializable] public sealed class CuffableComponentState : ComponentState { diff --git a/Content.Shared/Cuffs/SharedCuffableSystem.cs b/Content.Shared/Cuffs/SharedCuffableSystem.cs index 8889e0c9710a..d4cadcdbb84e 100644 --- a/Content.Shared/Cuffs/SharedCuffableSystem.cs +++ b/Content.Shared/Cuffs/SharedCuffableSystem.cs @@ -66,6 +66,7 @@ public override void Initialize() SubscribeLocalEvent(OnRejuvenate); SubscribeLocalEvent(OnStartup); SubscribeLocalEvent(HandleStopPull); + SubscribeLocalEvent(OnRemoveCuffsAlert); SubscribeLocalEvent(HandleMoveAttempt); SubscribeLocalEvent(OnEquipAttempt); SubscribeLocalEvent(OnUnequipAttempt); @@ -248,6 +249,14 @@ private void HandleStopPull(EntityUid uid, CuffableComponent component, AttemptS args.Cancelled = true; } + private void OnRemoveCuffsAlert(Entity ent, ref RemoveCuffsAlertEvent args) + { + if (args.Handled) + return; + TryUncuff(ent, ent, cuffable: ent.Comp); + args.Handled = true; + } + private void AddUncuffVerb(EntityUid uid, CuffableComponent component, GetVerbsEvent args) { // Can the user access the cuffs, and is there even anything to uncuff? diff --git a/Content.Shared/Ensnaring/Components/EnsnareableComponent.cs b/Content.Shared/Ensnaring/Components/EnsnareableComponent.cs index 2536fac4edcc..cd7824bb960b 100644 --- a/Content.Shared/Ensnaring/Components/EnsnareableComponent.cs +++ b/Content.Shared/Ensnaring/Components/EnsnareableComponent.cs @@ -47,6 +47,8 @@ public sealed partial class EnsnareableComponent : Component public ProtoId EnsnaredAlert = "Ensnared"; } +public sealed partial class RemoveEnsnareAlertEvent : BaseAlertEvent; + [Serializable, NetSerializable] public sealed class EnsnareableComponentState : ComponentState { diff --git a/Content.Shared/Internals/InternalsDoAfterEvent.cs b/Content.Shared/Internals/InternalsDoAfterEvent.cs index 13b6087ec0ee..9c0174b4fd20 100644 --- a/Content.Shared/Internals/InternalsDoAfterEvent.cs +++ b/Content.Shared/Internals/InternalsDoAfterEvent.cs @@ -1,4 +1,5 @@ -using Content.Shared.DoAfter; +using Content.Shared.Alert; +using Content.Shared.DoAfter; using Robust.Shared.Serialization; namespace Content.Shared.Internals; @@ -7,3 +8,5 @@ namespace Content.Shared.Internals; public sealed partial class InternalsDoAfterEvent : SimpleDoAfterEvent { } + +public sealed partial class ToggleInternalsAlertEvent : BaseAlertEvent; diff --git a/Content.Shared/Movement/Pulling/Components/PullableComponent.cs b/Content.Shared/Movement/Pulling/Components/PullableComponent.cs index 100cd9d6d3e6..aa44669fd14d 100644 --- a/Content.Shared/Movement/Pulling/Components/PullableComponent.cs +++ b/Content.Shared/Movement/Pulling/Components/PullableComponent.cs @@ -42,3 +42,5 @@ public sealed partial class PullableComponent : Component [DataField] public ProtoId PulledAlert = "Pulled"; } + +public sealed partial class StopBeingPulledAlertEvent : BaseAlertEvent; diff --git a/Content.Shared/Movement/Pulling/Components/PullerComponent.cs b/Content.Shared/Movement/Pulling/Components/PullerComponent.cs index 32e4d9b1f316..197d7cfd7c89 100644 --- a/Content.Shared/Movement/Pulling/Components/PullerComponent.cs +++ b/Content.Shared/Movement/Pulling/Components/PullerComponent.cs @@ -44,3 +44,5 @@ public sealed partial class PullerComponent : Component [DataField] public ProtoId PullingAlert = "Pulling"; } + +public sealed partial class StopPullingAlertEvent : BaseAlertEvent; diff --git a/Content.Shared/Movement/Pulling/Systems/PullingSystem.cs b/Content.Shared/Movement/Pulling/Systems/PullingSystem.cs index 557c316e26de..b5fc6948334a 100644 --- a/Content.Shared/Movement/Pulling/Systems/PullingSystem.cs +++ b/Content.Shared/Movement/Pulling/Systems/PullingSystem.cs @@ -58,6 +58,7 @@ public override void Initialize() SubscribeLocalEvent>(AddPullVerbs); SubscribeLocalEvent(OnPullableContainerInsert); SubscribeLocalEvent(OnModifyUncuffDuration); + SubscribeLocalEvent(OnStopBeingPulledAlert); SubscribeLocalEvent(OnAfterState); SubscribeLocalEvent(OnPullerContainerInsert); @@ -65,6 +66,7 @@ public override void Initialize() SubscribeLocalEvent(OnVirtualItemDeleted); SubscribeLocalEvent(OnRefreshMovespeed); SubscribeLocalEvent(OnDropHandItems); + SubscribeLocalEvent(OnStopPullingAlert); SubscribeLocalEvent(OnBuckled); SubscribeLocalEvent(OnGotBuckled); @@ -105,6 +107,15 @@ private void OnDropHandItems(EntityUid uid, PullerComponent pullerComp, DropHand TryStopPull(pullerComp.Pulling.Value, pullableComp, uid); } + private void OnStopPullingAlert(Entity ent, ref StopPullingAlertEvent args) + { + if (args.Handled) + return; + if (!TryComp(ent.Comp.Pulling, out var pullable)) + return; + args.Handled = TryStopPull(ent.Comp.Pulling.Value, pullable, ent); + } + private void OnPullerContainerInsert(Entity ent, ref EntGotInsertedIntoContainerMessage args) { if (ent.Comp.Pulling == null) @@ -133,6 +144,14 @@ private void OnModifyUncuffDuration(Entity ent, ref ModifyUnc args.Duration *= 2; } + private void OnStopBeingPulledAlert(Entity ent, ref StopBeingPulledAlertEvent args) + { + if (args.Handled) + return; + + args.Handled = TryStopPull(ent, ent, ent); + } + public override void Shutdown() { base.Shutdown(); @@ -491,6 +510,9 @@ public bool TryStopPull(EntityUid pullableUid, PullableComponent pullable, Entit if (pullerUidNull == null) return true; + if (user != null && !_blocker.CanInteract(user.Value, pullableUid)) + return false; + var msg = new AttemptStopPullingEvent(user); RaiseLocalEvent(pullableUid, msg, true); diff --git a/Content.Shared/Shuttles/Components/PilotComponent.cs b/Content.Shared/Shuttles/Components/PilotComponent.cs index cb42db4436fc..8823d309c3f5 100644 --- a/Content.Shared/Shuttles/Components/PilotComponent.cs +++ b/Content.Shared/Shuttles/Components/PilotComponent.cs @@ -39,4 +39,6 @@ public sealed partial class PilotComponent : Component public override bool SendOnlyToOwner => true; } + + public sealed partial class StopPilotingAlertEvent : BaseAlertEvent; } diff --git a/Resources/Prototypes/Alerts/alerts.yml b/Resources/Prototypes/Alerts/alerts.yml index c08453460f4f..ff66f2586b07 100644 --- a/Resources/Prototypes/Alerts/alerts.yml +++ b/Resources/Prototypes/Alerts/alerts.yml @@ -87,7 +87,7 @@ - type: alert id: Fire icons: [ /Textures/Interface/Alerts/Fire/fire.png ] - onClick: !type:ResistFire { } + clickEvent: !type:ResistFireAlertEvent name: alerts-on-fire-name description: alerts-on-fire-desc @@ -136,14 +136,14 @@ - type: alert id: Handcuffed - onClick: !type:RemoveCuffs { } + clickEvent: !type:RemoveCuffsAlertEvent icons: [ /Textures/Interface/Alerts/Handcuffed/Handcuffed.png ] name: alerts-handcuffed-name description: alerts-handcuffed-desc - type: alert id: Ensnared - onClick: !type:RemoveEnsnare { } + clickEvent: !type:RemoveEnsnareAlertEvent icons: - sprite: /Textures/Interface/Alerts/ensnared.rsi state: ensnared @@ -153,7 +153,7 @@ - type: alert id: Buckled category: Buckled - onClick: !type:Unbuckle { } + clickEvent: !type:UnbuckleAlertEvent icons: [ /Textures/Interface/Alerts/Buckle/buckled.png ] name: alerts-buckled-name description: alerts-buckled-desc @@ -275,7 +275,7 @@ - type: alert id: Internals category: Internals - onClick: !type:ToggleInternals {} + clickEvent: !type:ToggleInternalsAlertEvent icons: - sprite: /Textures/Interface/Alerts/internals.rsi state: internal0 @@ -291,7 +291,7 @@ - type: alert id: PilotingShuttle category: Piloting - onClick: !type:StopPiloting { } + clickEvent: !type:StopPilotingAlertEvent icons: [ /Textures/Interface/Alerts/piloting.png ] name: alerts-piloting-name description: alerts-piloting-desc @@ -365,27 +365,27 @@ id: VowOfSilence icons: [ /Textures/Interface/Alerts/Abilities/silenced.png ] name: alerts-vow-silence-name - onClick: !type:BreakVow { } + clickEvent: !type:BreakVowAlertEvent description: alerts-vow-silence-desc - type: alert id: VowBroken icons: [ /Textures/Interface/Actions/scream.png ] name: alerts-vow-broken-name - onClick: !type:RetakeVow { } + clickEvent: !type:RetakeVowAlertEvent description: alerts-vow-broken-desc - type: alert id: Pulled icons: [ /Textures/Interface/Alerts/Pull/pulled.png ] - onClick: !type:StopBeingPulled { } + clickEvent: !type:StopBeingPulledAlertEvent name: alerts-pulled-name description: alerts-pulled-desc - type: alert id: Pulling icons: [ /Textures/Interface/Alerts/Pull/pulling.png ] - onClick: !type:StopPulling { } + clickEvent: !type:StopPullingAlertEvent name: alerts-pulling-name description: alerts-pulling-desc