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>
This commit is contained in:
@@ -1,11 +0,0 @@
|
||||
using Content.Server.StationEvents.Events;
|
||||
|
||||
namespace Content.Server.StationEvents.Components;
|
||||
|
||||
/// <summary>
|
||||
/// This is used to keep track of hallucinated entities to remove effects when event ends
|
||||
/// </summary>
|
||||
[RegisterComponent, Access(typeof(MassHallucinationsRule))]
|
||||
public sealed partial class MassHallucinationsComponent : Component
|
||||
{
|
||||
}
|
||||
@@ -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<EntityUid> AffectedEntities = new();
|
||||
}
|
||||
|
||||
@@ -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<MassHallucinationsRuleComponent>
|
||||
@@ -14,16 +16,17 @@ public sealed class MassHallucinationsRule : StationEventSystem<MassHallucinatio
|
||||
protected override void Started(EntityUid uid, MassHallucinationsRuleComponent component, GameRuleComponent gameRule, GameRuleStartedEvent args)
|
||||
{
|
||||
base.Started(uid, component, gameRule, args);
|
||||
var query = EntityQueryEnumerator<MindContainerComponent>();
|
||||
while (query.MoveNext(out var ent, out _))
|
||||
|
||||
var query = EntityQueryEnumerator<MindContainerComponent, HumanoidAppearanceComponent>();
|
||||
while (query.MoveNext(out var ent, out _, out _))
|
||||
{
|
||||
if (!HasComp<ParacusiaComponent>(ent))
|
||||
if (!EnsureComp<ParacusiaComponent>(ent, out var paracusia))
|
||||
{
|
||||
EnsureComp<MassHallucinationsComponent>(ent);
|
||||
var paracusia = EnsureComp<ParacusiaComponent>(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<MassHallucinatio
|
||||
protected override void Ended(EntityUid uid, MassHallucinationsRuleComponent component, GameRuleComponent gameRule, GameRuleEndedEvent args)
|
||||
{
|
||||
base.Ended(uid, component, gameRule, args);
|
||||
var query = EntityQueryEnumerator<MassHallucinationsComponent>();
|
||||
while (query.MoveNext(out var ent, out _))
|
||||
|
||||
foreach (var ent in component.AffectedEntities)
|
||||
{
|
||||
RemComp<ParacusiaComponent>(ent);
|
||||
}
|
||||
|
||||
component.AffectedEntities.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user