From 28fe9d9f3350f469e1765f994f4a7cfab45367bf Mon Sep 17 00:00:00 2001 From: Vordenburg <114301317+Vordenburg@users.noreply.github.com> Date: Sat, 5 Aug 2023 17:27:12 -0400 Subject: [PATCH] Refactor PacificationSystem (#18715) --- .../Traits/Assorted/PacifistComponent.cs | 10 --- .../Traits/Assorted/PacifistSystem.cs | 17 ---- Content.Shared/Alert/AlertType.cs | 1 + .../Pacification/PacificationSystem.cs | 77 ++++++++++-------- .../Pacification/PacifiedComponent.cs | 18 ++-- Resources/Locale/en-US/alerts/alerts.ftl | 3 + Resources/Prototypes/Alerts/alerts.yml | 11 ++- Resources/Prototypes/Traits/disabilities.yml | 4 +- .../Interface/Alerts/pacified.rsi/icon.png | Bin 0 -> 311 bytes .../Interface/Alerts/pacified.rsi/meta.json | 14 ++++ 10 files changed, 80 insertions(+), 75 deletions(-) delete mode 100644 Content.Server/Traits/Assorted/PacifistComponent.cs delete mode 100644 Content.Server/Traits/Assorted/PacifistSystem.cs create mode 100644 Resources/Textures/Interface/Alerts/pacified.rsi/icon.png create mode 100644 Resources/Textures/Interface/Alerts/pacified.rsi/meta.json diff --git a/Content.Server/Traits/Assorted/PacifistComponent.cs b/Content.Server/Traits/Assorted/PacifistComponent.cs deleted file mode 100644 index 095dc651fc..0000000000 --- a/Content.Server/Traits/Assorted/PacifistComponent.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace Content.Server.Traits.Assorted; - -/// -/// This is used for enforcing pacifism. -/// -[RegisterComponent] -public sealed class PacifistComponent : Component -{ - -} diff --git a/Content.Server/Traits/Assorted/PacifistSystem.cs b/Content.Server/Traits/Assorted/PacifistSystem.cs deleted file mode 100644 index 5d8b1f44db..0000000000 --- a/Content.Server/Traits/Assorted/PacifistSystem.cs +++ /dev/null @@ -1,17 +0,0 @@ -using Content.Shared.CombatMode.Pacification; - -namespace Content.Server.Traits.Assorted; - -/// -/// This handles enforced pacifism. -/// -public sealed class PacifistSystem : EntitySystem -{ - public override void Update(float frameTime) - { - foreach (var comp in EntityQuery()) - { - EnsureComp(comp.Owner); // It's a status effect so just enforce it. - } - } -} diff --git a/Content.Shared/Alert/AlertType.cs b/Content.Shared/Alert/AlertType.cs index 75447e90d7..64fd5943eb 100644 --- a/Content.Shared/Alert/AlertType.cs +++ b/Content.Shared/Alert/AlertType.cs @@ -39,6 +39,7 @@ namespace Content.Shared.Alert Essence, Corporeal, Bleed, + Pacified, Debug1, Debug2, Debug3, diff --git a/Content.Shared/CombatMode/Pacification/PacificationSystem.cs b/Content.Shared/CombatMode/Pacification/PacificationSystem.cs index a223c61053..670d3976ea 100644 --- a/Content.Shared/CombatMode/Pacification/PacificationSystem.cs +++ b/Content.Shared/CombatMode/Pacification/PacificationSystem.cs @@ -1,52 +1,57 @@ using Content.Shared.Actions; +using Content.Shared.Alert; using Content.Shared.Interaction.Events; +using Content.Shared.Popups; -namespace Content.Shared.CombatMode.Pacification +namespace Content.Shared.CombatMode.Pacification; + +public sealed class PacificationSystem : EntitySystem { - public sealed class PacificationSystem : EntitySystem + [Dependency] private readonly AlertsSystem _alertsSystem = default!; + [Dependency] private readonly SharedActionsSystem _actionsSystem = default!; + [Dependency] private readonly SharedCombatModeSystem _combatSystem = default!; + [Dependency] private readonly SharedPopupSystem _popupSystem = default!; + + public override void Initialize() { - [Dependency] private readonly SharedActionsSystem _actionsSystem = default!; - [Dependency] private readonly SharedCombatModeSystem _combatSystem = default!; + base.Initialize(); + SubscribeLocalEvent(OnStartup); + SubscribeLocalEvent(OnShutdown); + SubscribeLocalEvent(OnAttackAttempt); + } - public override void Initialize() - { - base.Initialize(); - SubscribeLocalEvent(OnStartup); - SubscribeLocalEvent(OnShutdown); - SubscribeLocalEvent(OnAttackAttempt); - } + private void OnAttackAttempt(EntityUid uid, PacifiedComponent component, AttackAttemptEvent args) + { + args.Cancel(); + } - private void OnAttackAttempt(EntityUid uid, PacifiedComponent component, AttackAttemptEvent args) - { - args.Cancel(); - } + private void OnStartup(EntityUid uid, PacifiedComponent component, ComponentStartup args) + { + if (!TryComp(uid, out var combatMode)) + return; - private void OnStartup(EntityUid uid, PacifiedComponent component, ComponentStartup args) - { - if (!TryComp(uid, out var combatMode)) - return; + if (combatMode.CanDisarm != null) + _combatSystem.SetCanDisarm(uid, false, combatMode); - if (combatMode.CanDisarm != null) - _combatSystem.SetCanDisarm(uid, false, combatMode); + _combatSystem.SetInCombatMode(uid, false, combatMode); - _combatSystem.SetInCombatMode(uid, false, combatMode); + if (combatMode.CombatToggleAction != null) + _actionsSystem.SetEnabled(combatMode.CombatToggleAction, false); - if (combatMode.CombatToggleAction != null) - { - _actionsSystem.SetEnabled(combatMode.CombatToggleAction, false); - } - } + _alertsSystem.ShowAlert(uid, AlertType.Pacified); + } - private void OnShutdown(EntityUid uid, PacifiedComponent component, ComponentShutdown args) - { - if (!TryComp(uid, out var combatMode)) - return; + private void OnShutdown(EntityUid uid, PacifiedComponent component, ComponentShutdown args) + { + if (!TryComp(uid, out var combatMode)) + return; - if (combatMode.CanDisarm != null) - _combatSystem.SetCanDisarm(uid, true, combatMode); + if (combatMode.CanDisarm != null) + _combatSystem.SetCanDisarm(uid, true, combatMode); - if (combatMode.CombatToggleAction != null) - _actionsSystem.SetEnabled(combatMode.CombatToggleAction, true); - } + if (combatMode.CombatToggleAction != null) + _actionsSystem.SetEnabled(combatMode.CombatToggleAction, true); + + _alertsSystem.ClearAlert(uid, AlertType.Pacified); } } diff --git a/Content.Shared/CombatMode/Pacification/PacifiedComponent.cs b/Content.Shared/CombatMode/Pacification/PacifiedComponent.cs index aee298a9d5..ad50b4bf1f 100644 --- a/Content.Shared/CombatMode/Pacification/PacifiedComponent.cs +++ b/Content.Shared/CombatMode/Pacification/PacifiedComponent.cs @@ -1,13 +1,13 @@ using Robust.Shared.GameStates; -namespace Content.Shared.CombatMode.Pacification -{ - /// - /// Status effect that disables combat mode. - /// - [RegisterComponent, NetworkedComponent] - public sealed class PacifiedComponent : Component - { +namespace Content.Shared.CombatMode.Pacification; + +/// +/// Status effect that disables combat mode. +/// +[RegisterComponent, NetworkedComponent] +[Access(typeof(PacificationSystem))] +public sealed class PacifiedComponent : Component +{ - } } diff --git a/Resources/Locale/en-US/alerts/alerts.ftl b/Resources/Locale/en-US/alerts/alerts.ftl index 1469543c33..a0af1a7953 100644 --- a/Resources/Locale/en-US/alerts/alerts.ftl +++ b/Resources/Locale/en-US/alerts/alerts.ftl @@ -86,3 +86,6 @@ alerts-pulling-desc = You're pulling something. Click the alert to stop. alerts-bleed-name = [color=red]Bleed[/color] alerts-bleed-desc = You're [color=red]bleeding[/color]. + +alerts-pacified-name = [color=green]Pacified[/color] +alerts-pacified-desc = You're pacified; you won't be able to attack anyone directly. diff --git a/Resources/Prototypes/Alerts/alerts.yml b/Resources/Prototypes/Alerts/alerts.yml index 7c7c75b8f8..b1c39e3663 100644 --- a/Resources/Prototypes/Alerts/alerts.yml +++ b/Resources/Prototypes/Alerts/alerts.yml @@ -1,4 +1,4 @@ -- type: alertOrder +- type: alertOrder # Defines ordering in alert tab, higher up = higher in tab. # List below can contain alert type or category, if both are present the id will take precedence. # If item is not in list it will go at the bottom (ties broken by alert type enum value) @@ -22,6 +22,7 @@ - category: Hunger - category: Thirst - alertType: Magboots + - alertType: Pacified - type: alert id: LowOxygen @@ -323,6 +324,14 @@ minSeverity: 0 maxSeverity: 10 +- type: alert + id: Pacified + icons: + - sprite: /Textures/Interface/Alerts/pacified.rsi + state: icon + name: alerts-pacified-name + description: alerts-pacified-desc + - type: alert id: Debug1 icons: diff --git a/Resources/Prototypes/Traits/disabilities.yml b/Resources/Prototypes/Traits/disabilities.yml index d820f0ded0..fd845aa8d2 100644 --- a/Resources/Prototypes/Traits/disabilities.yml +++ b/Resources/Prototypes/Traits/disabilities.yml @@ -1,4 +1,4 @@ -- type: trait +- type: trait id: Blindness name: trait-blindness-name description: trait-blindness-desc @@ -22,7 +22,7 @@ id: Pacifist name: trait-pacifist-name components: - - type: Pacifist + - type: Pacified - type: trait id: Paracusia diff --git a/Resources/Textures/Interface/Alerts/pacified.rsi/icon.png b/Resources/Textures/Interface/Alerts/pacified.rsi/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..3fc61bdabe689b33cee76c3196a0b7c1f2eda24a GIT binary patch literal 311 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnE3?yBabR7dy#sNMdu0Wb0M~q>TCc_LhhB;b{ z+H6eryeu6GtZ{;@rLwGb@@xtW>}rhc7VPYkl{kzzI2<|lMm<~&)Wuj54f8L$@Yxxg1a6Zc3Qndi+dInEdKbLh* G2~7Y`-E+DC literal 0 HcmV?d00001 diff --git a/Resources/Textures/Interface/Alerts/pacified.rsi/meta.json b/Resources/Textures/Interface/Alerts/pacified.rsi/meta.json new file mode 100644 index 0000000000..cb848b0c03 --- /dev/null +++ b/Resources/Textures/Interface/Alerts/pacified.rsi/meta.json @@ -0,0 +1,14 @@ +{ + "version": 1, + "license": "CC-BY-SA-4.0", + "copyright": "@Vordenburg", + "size": { + "x": 32, + "y": 32 + }, + "states": [ + { + "name": "icon" + } + ] +}