using Content.Server.Power.Components; using Content.Server.Power.Events; using Content.Server.Xenoarchaeology.XenoArtifacts.Triggers.Components; using Content.Shared.Interaction; using Content.Shared.Tools.Components; using Content.Shared.Tools.Systems; namespace Content.Server.Xenoarchaeology.XenoArtifacts.Triggers.Systems; public sealed class ArtifactElectricityTriggerSystem : EntitySystem { [Dependency] private readonly ArtifactSystem _artifactSystem = default!; [Dependency] private readonly SharedToolSystem _toolSystem = default!; public override void Initialize() { base.Initialize(); SubscribeLocalEvent(OnInteractUsing); SubscribeLocalEvent(OnPowerPulse); } public override void Update(float frameTime) { base.Update(frameTime); List> toUpdate = new(); var query = EntityQueryEnumerator(); while (query.MoveNext(out var uid, out var trigger, out var power, out var artifact)) { if (power.ReceivedPower <= trigger.MinPower) continue; toUpdate.Add((uid, artifact)); } foreach (var a in toUpdate) { _artifactSystem.TryActivateArtifact(a, null, a); } } private void OnInteractUsing(EntityUid uid, ArtifactElectricityTriggerComponent component, InteractUsingEvent args) { if (args.Handled) return; if (!_toolSystem.HasQuality(args.Used, SharedToolSystem.PulseQuality)) return; args.Handled = _artifactSystem.TryActivateArtifact(uid, args.User); } private void OnPowerPulse(EntityUid uid, ArtifactElectricityTriggerComponent component, PowerPulseEvent args) { _artifactSystem.TryActivateArtifact(uid, args.User); } }