using Content.Shared.Actions; using Content.Shared.CombatMode; using Content.Shared.Communications; using Content.Shared.Examine; using Content.Shared.Hands.Components; using Content.Shared.Interaction; using Content.Shared.Inventory.Events; using Content.Shared.Ninja.Components; using Content.Shared.Popups; using Content.Shared.Research.Components; using Content.Shared.Timing; using Content.Shared.Toggleable; using Robust.Shared.Timing; namespace Content.Shared.Ninja.Systems; /// /// Provides the toggle action and handles examining and unequipping. /// public abstract class SharedNinjaGlovesSystem : EntitySystem { [Dependency] private readonly IGameTiming _timing = default!; [Dependency] protected readonly SharedAppearanceSystem Appearance = default!; [Dependency] private readonly SharedCombatModeSystem _combatMode = default!; [Dependency] protected readonly SharedInteractionSystem Interaction = default!; [Dependency] protected readonly SharedPopupSystem Popup = default!; [Dependency] private readonly UseDelaySystem _useDelay = default!; [Dependency] private readonly ActionContainerSystem _actionContainer = default!; public override void Initialize() { base.Initialize(); SubscribeLocalEvent(OnGetItemActions); SubscribeLocalEvent(OnExamined); SubscribeLocalEvent(OnUnequipped); SubscribeLocalEvent(OnMapInit); } private void OnMapInit(EntityUid uid, NinjaGlovesComponent component, MapInitEvent args) { _actionContainer.EnsureAction(uid, ref component.ToggleActionEntity, component.ToggleAction); Dirty(uid, component); } /// /// Disable glove abilities and show the popup if they were enabled previously. /// public void DisableGloves(EntityUid uid, NinjaGlovesComponent? comp = null) { // already disabled? if (!Resolve(uid, ref comp) || comp.User == null) return; var user = comp.User.Value; comp.User = null; Dirty(uid, comp); Appearance.SetData(uid, ToggleVisuals.Toggled, false); Popup.PopupClient(Loc.GetString("ninja-gloves-off"), user, user); RemComp(user); RemComp(user); RemComp(user); RemComp(user); RemComp(user); } /// /// Adds the toggle action when equipped. /// private void OnGetItemActions(EntityUid uid, NinjaGlovesComponent comp, GetItemActionsEvent args) { if (HasComp(args.User)) args.AddAction(ref comp.ToggleActionEntity, comp.ToggleAction); } /// /// Show if the gloves are enabled when examining. /// private void OnExamined(EntityUid uid, NinjaGlovesComponent comp, ExaminedEvent args) { if (!args.IsInDetailsRange) return; args.PushText(Loc.GetString(comp.User != null ? "ninja-gloves-examine-on" : "ninja-gloves-examine-off")); } /// /// Disable gloves when unequipped and clean up ninja's gloves reference /// private void OnUnequipped(EntityUid uid, NinjaGlovesComponent comp, GotUnequippedEvent args) { if (comp.User != null) { var user = comp.User.Value; Popup.PopupClient(Loc.GetString("ninja-gloves-off"), user, user); DisableGloves(uid, comp); } } // TODO: generic event thing /// /// GloveCheck but for abilities stored on the player, skips some checks. /// Intended to be more generic, doesn't require the user to be a ninja or have any ninja equipment. /// public bool AbilityCheck(EntityUid uid, BeforeInteractHandEvent args, out EntityUid target) { target = args.Target; return _timing.IsFirstTimePredicted && !_combatMode.IsInCombatMode(uid) && !_useDelay.ActiveDelay(uid) && TryComp(uid, out var hands) && hands.ActiveHandEntity == null && Interaction.InRangeUnobstructed(uid, target); } }