mirror of
https://github.com/space-wizards/space-station-14.git
synced 2026-02-15 03:31:30 +01:00
* Initial commit * Accidentally included the nukie map changes * Fix the gridcheck * Addressing review * Review change * Review comments
98 lines
3.5 KiB
C#
98 lines
3.5 KiB
C#
using Content.Server.GameTicking;
|
|
using Content.Server.GameTicking.Rules;
|
|
using Content.Server.GameTicking.Rules.Components;
|
|
using Content.Shared.PowerCell;
|
|
using Content.Shared.Pinpointer;
|
|
using Content.Shared.Station;
|
|
using Robust.Server.GameObjects;
|
|
|
|
namespace Content.Server.Pinpointer;
|
|
|
|
public sealed class StationMapSystem : EntitySystem
|
|
{
|
|
[Dependency] private readonly UserInterfaceSystem _ui = default!;
|
|
[Dependency] private readonly PowerCellSystem _cell = default!;
|
|
[Dependency] private readonly SharedStationSystem _station = default!;
|
|
[Dependency] private readonly SharedTransformSystem _xform = default!;
|
|
[Dependency] private readonly GameTicker _gameTicker = default!;
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
SubscribeLocalEvent<StationMapComponent, MapInitEvent>(OnMapInit);
|
|
SubscribeLocalEvent<StationMapUserComponent, EntParentChangedMessage>(OnUserParentChanged);
|
|
|
|
SubscribeLocalEvent<NukeopsStationMapComponent, NukeopsTargetStationSelectedEvent>(OnNukeopsStationSelected);
|
|
|
|
Subs.BuiEvents<StationMapComponent>(StationMapUiKey.Key, subs =>
|
|
{
|
|
subs.Event<BoundUIOpenedEvent>(OnStationMapOpened);
|
|
subs.Event<BoundUIClosedEvent>(OnStationMapClosed);
|
|
});
|
|
}
|
|
|
|
private void OnMapInit(Entity<StationMapComponent> ent, ref MapInitEvent args)
|
|
{
|
|
if (!ent.Comp.InitializeWithStation)
|
|
return;
|
|
|
|
// If we ever find a need to make more exceptions like this, just turn this into an event.
|
|
if (HasComp<NukeopsStationMapComponent>(ent))
|
|
{
|
|
foreach (var rule in _gameTicker.GetActiveGameRules())
|
|
{
|
|
if (TryComp<NukeopsRuleComponent>(rule, out var nukeopsRule) && nukeopsRule.TargetStation != null)
|
|
{
|
|
ent.Comp.TargetGrid = _station.GetLargestGrid((nukeopsRule.TargetStation.Value, null));
|
|
Dirty(ent);
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|
|
var station = _station.GetStationInMap(_xform.GetMapId(ent.Owner));
|
|
if (station != null)
|
|
{
|
|
ent.Comp.TargetGrid = _station.GetLargestGrid((station.Value, null));
|
|
Dirty(ent);
|
|
}
|
|
}
|
|
|
|
private void OnStationMapClosed(EntityUid uid, StationMapComponent component, BoundUIClosedEvent args)
|
|
{
|
|
if (!Equals(args.UiKey, StationMapUiKey.Key))
|
|
return;
|
|
|
|
RemCompDeferred<StationMapUserComponent>(args.Actor);
|
|
}
|
|
|
|
private void OnUserParentChanged(EntityUid uid, StationMapUserComponent component, ref EntParentChangedMessage args)
|
|
{
|
|
_ui.CloseUi(component.Map, StationMapUiKey.Key, uid);
|
|
}
|
|
|
|
private void OnStationMapOpened(EntityUid uid, StationMapComponent component, BoundUIOpenedEvent args)
|
|
{
|
|
if (!_cell.TryUseActivatableCharge(uid))
|
|
return;
|
|
|
|
var comp = EnsureComp<StationMapUserComponent>(args.Actor);
|
|
comp.Map = uid;
|
|
}
|
|
|
|
private void OnNukeopsStationSelected(Entity<NukeopsStationMapComponent> ent, ref NukeopsTargetStationSelectedEvent args)
|
|
{
|
|
if (args.TargetStation == null)
|
|
return;
|
|
|
|
if (!TryComp<StationMapComponent>(ent, out var stationMap) || !TryComp<RuleGridsComponent>(args.RuleEntity, out var ruleGrids))
|
|
return;
|
|
|
|
if (Transform(ent).MapID != ruleGrids.Map)
|
|
return;
|
|
|
|
stationMap.TargetGrid = _station.GetLargestGrid((args.TargetStation.Value, null));
|
|
Dirty(ent);
|
|
}
|
|
}
|