From 4997f92e189e1d21eadfdff46d9301db4545fc3d Mon Sep 17 00:00:00 2001 From: Aiden Date: Sat, 20 Jul 2024 00:53:57 -0500 Subject: [PATCH] MassHallucinationsRule Minor Refactor (#28748) * Update MassHallucinationsRule. * Update Content.Server/StationEvents/Events/MassHallucinationsRule.cs Co-authored-by: Ed <96445749+TheShuEd@users.noreply.github.com> * Update Content.Server/StationEvents/Events/MassHallucinationsRule.cs Co-authored-by: Ed <96445749+TheShuEd@users.noreply.github.com> * Update Content.Server/StationEvents/Events/MassHallucinationsRule.cs Co-authored-by: Ed <96445749+TheShuEd@users.noreply.github.com> * MGS Change * Update Content.Server/StationEvents/Events/MassHallucinationsRule.cs Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> * Update Content.Server/StationEvents/Events/MassHallucinationsRule.cs Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> * Move affectedentities to component, remove masshallucinationscomponent as its no longer needed to track entities. * Apply suggested changes. * No double checks --------- Co-authored-by: Ed <96445749+TheShuEd@users.noreply.github.com> Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> --- .../Components/MassHallucinationsComponent.cs | 11 ----------- .../MassHallucinationsRuleComponent.cs | 4 ++++ .../Events/MassHallucinationsRule.cs | 19 ++++++++++++------- 3 files changed, 16 insertions(+), 18 deletions(-) delete mode 100644 Content.Server/StationEvents/Components/MassHallucinationsComponent.cs diff --git a/Content.Server/StationEvents/Components/MassHallucinationsComponent.cs b/Content.Server/StationEvents/Components/MassHallucinationsComponent.cs deleted file mode 100644 index 99b893cad5..0000000000 --- a/Content.Server/StationEvents/Components/MassHallucinationsComponent.cs +++ /dev/null @@ -1,11 +0,0 @@ -using Content.Server.StationEvents.Events; - -namespace Content.Server.StationEvents.Components; - -/// -/// This is used to keep track of hallucinated entities to remove effects when event ends -/// -[RegisterComponent, Access(typeof(MassHallucinationsRule))] -public sealed partial class MassHallucinationsComponent : Component -{ -} diff --git a/Content.Server/StationEvents/Components/MassHallucinationsRuleComponent.cs b/Content.Server/StationEvents/Components/MassHallucinationsRuleComponent.cs index 63a1f87251..a5268f97a6 100644 --- a/Content.Server/StationEvents/Components/MassHallucinationsRuleComponent.cs +++ b/Content.Server/StationEvents/Components/MassHallucinationsRuleComponent.cs @@ -1,5 +1,6 @@ using Content.Server.StationEvents.Events; using Robust.Shared.Audio; +using Robust.Shared.Collections; namespace Content.Server.StationEvents.Components; @@ -23,4 +24,7 @@ public sealed partial class MassHallucinationsRuleComponent : Component [DataField("sounds", required: true)] public SoundSpecifier Sounds = default!; + + [DataField, ViewVariables(VVAccess.ReadOnly)] + public List AffectedEntities = new(); } diff --git a/Content.Server/StationEvents/Events/MassHallucinationsRule.cs b/Content.Server/StationEvents/Events/MassHallucinationsRule.cs index bfb7699e9d..b03231b5bc 100644 --- a/Content.Server/StationEvents/Events/MassHallucinationsRule.cs +++ b/Content.Server/StationEvents/Events/MassHallucinationsRule.cs @@ -2,9 +2,11 @@ using Content.Server.GameTicking.Rules.Components; using Content.Server.StationEvents.Components; using Content.Server.Traits.Assorted; using Content.Shared.GameTicking.Components; +using Content.Shared.Humanoid; using Content.Shared.Mind.Components; using Content.Shared.Traits.Assorted; + namespace Content.Server.StationEvents.Events; public sealed class MassHallucinationsRule : StationEventSystem @@ -14,16 +16,17 @@ public sealed class MassHallucinationsRule : StationEventSystem(); - while (query.MoveNext(out var ent, out _)) + + var query = EntityQueryEnumerator(); + while (query.MoveNext(out var ent, out _, out _)) { - if (!HasComp(ent)) + if (!EnsureComp(ent, out var paracusia)) { - EnsureComp(ent); - var paracusia = EnsureComp(ent); _paracusia.SetSounds(ent, component.Sounds, paracusia); _paracusia.SetTime(ent, component.MinTimeBetweenIncidents, component.MaxTimeBetweenIncidents, paracusia); _paracusia.SetDistance(ent, component.MaxSoundDistance); + + component.AffectedEntities.Add(ent); } } } @@ -31,10 +34,12 @@ public sealed class MassHallucinationsRule : StationEventSystem(); - while (query.MoveNext(out var ent, out _)) + + foreach (var ent in component.AffectedEntities) { RemComp(ent); } + + component.AffectedEntities.Clear(); } } -- 2.51.2