diff --git a/Content.Server/_DV/Xenoarchaeology/XenoArtifacts/Triggers/Systems/ArtifactMetapsionicTriggerSystem.cs b/Content.Server/_DV/Xenoarchaeology/XenoArtifacts/Triggers/Systems/ArtifactMetapsionicTriggerSystem.cs index 2459ae548e5..83a8bd74367 100644 --- a/Content.Server/_DV/Xenoarchaeology/XenoArtifacts/Triggers/Systems/ArtifactMetapsionicTriggerSystem.cs +++ b/Content.Server/_DV/Xenoarchaeology/XenoArtifacts/Triggers/Systems/ArtifactMetapsionicTriggerSystem.cs @@ -3,17 +3,22 @@ using Content.Server._DV.Xenoarchaeology.XenoArtifacts.Triggers.Components; using Content.Server.Xenoarchaeology.Artifact; using Content.Shared.Abilities.Psionics; using Content.Shared.Xenoarchaeology.Artifact.Components; +using Content.Shared.Xenoarchaeology.Artifact.XAT; namespace Content.Server.Xenoarchaeology.XenoArtifacts.Triggers.Systems; -public sealed class ArtifactMetapsionicTriggerSystem : EntitySystem +public sealed class ArtifactMetapsionicTriggerSystem : BaseXATSystem { [Dependency] private readonly XenoArtifactSystem _artifact = default!; + private EntityQuery _xenoArtifactQuery; + public override void Initialize() { base.Initialize(); + _xenoArtifactQuery = GetEntityQuery(); + SubscribeLocalEvent(OnPowerDetected); SubscribeLocalEvent(OnGlimmerEventEnded); @@ -21,37 +26,34 @@ public sealed class ArtifactMetapsionicTriggerSystem : EntitySystem private void OnPowerDetected(Entity ent, ref PsionicPowerDetectedEvent args) { - if (!TryComp(ent, out var artifactComp)) + if (!TryComp(ent, out var node)) return; - var artifactEntity = new Entity(ent, artifactComp); - var coords = Transform(ent).Coordinates; + if (node.Attached == null) + return; - _artifact.TryActivateXenoArtifact( - artifactEntity, - user: null, - target: null, - coordinates: coords - ); + var artifact = _xenoArtifactQuery.Get(GetEntity(node.Attached.Value)); + + if (!CanTrigger(artifact, (ent.Owner, node))) + return; + + Trigger(artifact, (ent.Owner, ent.Comp, node)); } private void OnGlimmerEventEnded(GlimmerEventEndedEvent args) { - var query = EntityQueryEnumerator(); - while (query.MoveNext(out var uid, out _)) + var query = EntityQueryEnumerator(); + while (query.MoveNext(out var uid, out var comp, out var node)) { - if (!TryComp(uid, out var artifactComp)) + if (node.Attached == null) continue; - var artifactEntity = new Entity(uid, artifactComp); - var coords = Transform(uid).Coordinates; + var artifact = _xenoArtifactQuery.Get(GetEntity(node.Attached.Value)); - _artifact.TryActivateXenoArtifact( - artifactEntity, - user: null, - target: null, - coordinates: coords - ); + if (!CanTrigger(artifact, (uid, node))) + continue; + + Trigger(artifact, (uid, comp, node)); } } }