using Content.Server.PowerCell; using Content.Shared.Pinpointer; using Robust.Server.GameObjects; using Robust.Shared.Player; namespace Content.Server.Pinpointer; public sealed class StationMapSystem : EntitySystem { [Dependency] private readonly UserInterfaceSystem _ui = default!; [Dependency] private readonly PowerCellSystem _cell = default!; public override void Initialize() { base.Initialize(); SubscribeLocalEvent(OnUserParentChanged); SubscribeLocalEvent(OnStationMapOpened); SubscribeLocalEvent(OnStationMapClosed); } private void OnStationMapClosed(EntityUid uid, StationMapComponent component, BoundUIClosedEvent args) { if (!Equals(args.UiKey, StationMapUiKey.Key) || args.Session.AttachedEntity == null) return; RemCompDeferred(args.Session.AttachedEntity.Value); } private void OnUserParentChanged(EntityUid uid, StationMapUserComponent component, ref EntParentChangedMessage args) { if (TryComp(uid, out var actor)) { _ui.TryClose(component.Map, StationMapUiKey.Key, actor.PlayerSession); } } private void OnStationMapOpened(EntityUid uid, StationMapComponent component, BoundUIOpenedEvent args) { if (args.Session.AttachedEntity == null) return; if (!_cell.TryUseActivatableCharge(uid)) return; var comp = EnsureComp(args.Session.AttachedEntity.Value); comp.Map = uid; } }