using Content.Shared.Actions; using Content.Shared.Actions.Components; using Content.Shared.Implants; using Content.Shared.Mindshield.Components; using Content.Shared.Popups; using Content.Shared.Tag; using Robust.Shared.Prototypes; namespace Content.Shared.Mindshield.FakeMindShield; /// /// This system is responsible for handling the fake mindshield implant. /// public sealed partial class FakeMindShieldSystem : EntitySystem { [Dependency] private SharedActionsSystem _actions = default!; [Dependency] private SharedPopupSystem _popup = default!; [Dependency] private TagSystem _tag = default!; /// /// This tag should be placed on the fake mindshield action for identification. /// private static readonly ProtoId FakeMindShieldImplantTag = "FakeMindShieldImplant"; /// /// Displays a popup to inform the player of activation or deactivation. /// /// /// An associated tuple. The state in will be used /// to display the appropriate popup. /// private void ShowTogglePopup(Entity ent) { var message = ent.Comp.IsEnabled ? Loc.GetString("fake-mindshield-enabled") : Loc.GetString("fake-mindshield-disabled"); _popup.PopupEntity(message, ent, ent); } /// /// Run when is raised. Toggles the component and the action indication. /// /// An associated tuple. The state in will be toggled. /// The event arguments. Will be marked as handled. [SubscribeLocalEvent] private void OnToggleMindshield(Entity ent, ref FakeMindShieldToggleEvent args) { ent.Comp.IsEnabled = !ent.Comp.IsEnabled; args.Toggle = true; args.Handled = true; ShowTogglePopup(ent); Dirty(ent); } /// /// Handles implant interactions with chameleon outfits. /// (De)Activates the mindshield if the chameleon outfit requires it. Displays a popup if state changes. /// /// An associated tuple. The state in will be set if changed. /// The event arguments. [SubscribeLocalEvent] private void OnChameleonControllerOutfitSelected(Entity ent, ref ChameleonControllerOutfitSelectedEvent args) { if (ent.Comp.IsEnabled == args.ChameleonOutfit.HasMindShield) return; // This assumes there is only one fake mindshield action per entity (This is currently enforced) if (!TryComp(ent, out var actionsComp)) return; ent.Comp.IsEnabled = args.ChameleonOutfit.HasMindShield; foreach (var action in actionsComp.Actions) { if (!_tag.HasTag(action, FakeMindShieldImplantTag)) continue; if (!TryComp(action, out var actionComp)) continue; _actions.SetToggled(action, args.ChameleonOutfit.HasMindShield); ShowTogglePopup(ent); if (actionComp.UseDelay != null) _actions.SetCooldown(action, actionComp.UseDelay.Value); break; } Dirty(ent); } } /// /// Generic . /// public sealed partial class FakeMindShieldToggleEvent : InstantActionEvent;