using Content.Shared.Armable; using Content.Shared.Item.ItemToggle.Components; using Content.Shared.LandMines; using Content.Shared.Popups; using Content.Shared.StepTrigger.Systems; using Content.Shared.Trigger.Systems; using Robust.Shared.Audio.Systems; namespace Content.Server.LandMines; public sealed class LandMineSystem : EntitySystem { [Dependency] private readonly SharedAudioSystem _audioSystem = default!; [Dependency] private readonly SharedPopupSystem _popupSystem = default!; [Dependency] private readonly TriggerSystem _trigger = default!; public override void Initialize() { base.Initialize(); SubscribeLocalEvent(HandleStepOnTriggered); SubscribeLocalEvent(HandleStepOffTriggered); SubscribeLocalEvent(HandleStepTriggerAttempt); } /// /// Warns the player when stepped on. /// private void HandleStepOnTriggered(EntityUid uid, LandMineComponent component, ref StepTriggeredOnEvent args) { if (!string.IsNullOrEmpty(component.TriggerText)) { _popupSystem.PopupCoordinates( Loc.GetString(component.TriggerText, ("mine", uid)), Transform(uid).Coordinates, args.Tripper, PopupType.LargeCaution); } _audioSystem.PlayPvs(component.Sound, uid); } /// /// Sends a trigger when stepped off. /// private void HandleStepOffTriggered(EntityUid uid, LandMineComponent component, ref StepTriggeredOffEvent args) { // TODO: Adjust to the new trigger system _trigger.Trigger(uid, args.Tripper, TriggerSystem.DefaultTriggerKey); } /// /// Presumes that the landmine isn't armable and should be treated as always armed. /// If Armable and ItemToggle is present the event will continue only if the mine is activated. /// private void HandleStepTriggerAttempt(EntityUid uid, LandMineComponent component, ref StepTriggerAttemptEvent args) { args.Continue = true; if (HasComp(uid) && TryComp(uid, out var itemToggle)) args.Continue = itemToggle.Activated; } }