using Content.Shared.Actions; using Content.Shared.Inventory; using Content.Shared.Inventory.Events; using Content.Shared.Overlays; using Content.Shared.StatusEffectNew; namespace Content.Shared.NightVision; /// /// Shows/hides the based on whether the observed /// entity has a equipped. /// public abstract partial class SharedNightVisionSystem : EntitySystem { [Dependency] private SharedActionsSystem _actions = default!; [SubscribeLocalEvent] private void OnStartup(Entity ent, ref MapInitEvent args) { if (ent.Comp.RelayOverlay) return; RefreshOverlay(ent); _actions.AddAction(ent, ref ent.Comp.ActionEntity, ent.Comp.Action); } [SubscribeLocalEvent] private void OnRefreshStatusEffect(Entity ent, ref StatusEffectRelayedEvent args) { if (!ent.Comp.Enabled) return; args.Args.Entities.Add(ent); } [SubscribeLocalEvent] private void OnRemove(Entity ent, ref ComponentShutdown args) { if (ent.Comp.RelayOverlay) return; RefreshOverlay(ent); _actions.RemoveAction(ent.Owner, ent.Comp.ActionEntity); } [SubscribeLocalEvent] private void OnCompEquip(Entity ent, ref GotEquippedEvent args) { if (!ent.Comp.RelayOverlay) return; RefreshOverlay(args.EquipTarget); _actions.AddAction(args.EquipTarget, ref ent.Comp.ActionEntity, ent.Comp.Action, ent); } [SubscribeLocalEvent] private void OnCompUnequip(Entity ent, ref GotUnequippedEvent args) { if (!ent.Comp.RelayOverlay) return; RefreshOverlay(args.EquipTarget); } [SubscribeLocalEvent] protected virtual void OnRefreshEquipmentHud(Entity ent, ref InventoryRelayedEvent args) { OnRefreshComponentHud(ent, ref args.Args); } [SubscribeLocalEvent] protected virtual void OnRefreshComponentHud(Entity ent, ref RefreshNightVisionEvent args) { if (!ent.Comp.Enabled) return; args.Entities.Add(ent); } [SubscribeLocalEvent] private void OnToggleNightVisionEvent(ToggleNightVisionEvent args) { var ent = args.Action.Comp.Container; if (!TryComp(ent, out var nightVisionComp)) return; SetEnabled(ent.Value, !nightVisionComp.Enabled, args.Performer); args.Handled = true; } /// /// Enables or disables the component. /// /// The night vision to toggle. /// Whether to enable or disable. /// Viewer of the night vision, used to refresh their overlay. If null, assumes the night vision entity is the viewer. public void SetEnabled(Entity ent, bool enabled, EntityUid? viewer = null) { if (!Resolve(ent, ref ent.Comp, false)) return; if (ent.Comp.Enabled == enabled) return; ent.Comp.Enabled = enabled; Dirty(ent); RefreshOverlay(viewer ?? ent); } protected virtual void RefreshOverlay(EntityUid entity) { } } [ByRefEvent] public record struct RefreshNightVisionEvent() : IInventoryRelayEvent { public SlotFlags TargetSlots => SlotFlags.WITHOUT_POCKET; public List> Entities = new(); }