mirror of
https://github.com/space-syndicate/space-station-14.git
synced 2026-10-09 18:31:17 +03:00
Fix Nuke Target Station Map (#43583)
flukies begone Co-authored-by: Princess Cheeseballs <66055347+Pronana@users.noreply.github.com>
This commit is contained in:
parent
ee0f4050ef
commit
a363a61007
2 changed files with 78 additions and 23 deletions
|
|
@ -309,7 +309,7 @@ public sealed partial class GameTicker
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets all the gamerule entities which are currently active.
|
||||
/// Gets all the gamerule entities that have been added.
|
||||
/// </summary>
|
||||
public IEnumerable<EntityUid> GetAddedGameRules()
|
||||
{
|
||||
|
|
@ -321,6 +321,20 @@ public sealed partial class GameTicker
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets all the gamerule entities with {T} component that have been added.
|
||||
/// </summary>
|
||||
public IEnumerable<Entity<T>> GetAddedGameRules<T>() where T : Component
|
||||
{
|
||||
var query = EntityQueryEnumerator<T, GameRuleComponent>();
|
||||
while (query.MoveNext(out var uid, out var comp, out var ruleData))
|
||||
{
|
||||
if (IsGameRuleAdded(uid, ruleData))
|
||||
yield return (uid, comp);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets all the gamerule entities which are currently active.
|
||||
/// </summary>
|
||||
|
|
@ -333,6 +347,18 @@ public sealed partial class GameTicker
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets all the gamerule entities with {T} component that are currently active.
|
||||
/// </summary>
|
||||
public IEnumerable<Entity<T>> GetActiveGameRules<T>() where T : Component
|
||||
{
|
||||
var query = EntityQueryEnumerator<T, ActiveGameRuleComponent, GameRuleComponent>();
|
||||
while (query.MoveNext(out var uid, out var comp, out _, out _))
|
||||
{
|
||||
yield return (uid, comp);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets all gamerule prototypes
|
||||
/// </summary>
|
||||
|
|
|
|||
|
|
@ -22,9 +22,11 @@ public sealed class StationMapSystem : EntitySystem
|
|||
SubscribeLocalEvent<StationMapComponent, MapInitEvent>(OnMapInit);
|
||||
SubscribeLocalEvent<StationMapUserComponent, EntParentChangedMessage>(OnUserParentChanged);
|
||||
|
||||
SubscribeLocalEvent<NukeopsStationMapComponent, NukeopsTargetStationSelectedEvent>(OnNukeopsStationSelected);
|
||||
SubscribeLocalEvent<NukeopsStationMapComponent, ChooseStationMapEvent>(OnNukeOpsStationMap);
|
||||
SubscribeLocalEvent<NukeopsTargetStationSelectedEvent>(OnNukeopsStationSelected);
|
||||
|
||||
Subs.BuiEvents<StationMapComponent>(StationMapUiKey.Key, subs =>
|
||||
Subs.BuiEvents<StationMapComponent>(StationMapUiKey.Key,
|
||||
subs =>
|
||||
{
|
||||
subs.Event<BoundUIOpenedEvent>(OnStationMapOpened);
|
||||
subs.Event<BoundUIClosedEvent>(OnStationMapClosed);
|
||||
|
|
@ -36,18 +38,13 @@ public sealed class StationMapSystem : EntitySystem
|
|||
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))
|
||||
var ev = new ChooseStationMapEvent();
|
||||
RaiseLocalEvent(ent, ref ev);
|
||||
if (ev.Handled)
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
ent.Comp.TargetGrid = ev.TargetGrid;
|
||||
Dirty(ent);
|
||||
return;
|
||||
}
|
||||
|
||||
var station = _station.GetStationInMap(_xform.GetMapId(ent.Owner));
|
||||
|
|
@ -80,18 +77,50 @@ public sealed class StationMapSystem : EntitySystem
|
|||
comp.Map = uid;
|
||||
}
|
||||
|
||||
private void OnNukeopsStationSelected(Entity<NukeopsStationMapComponent> ent, ref NukeopsTargetStationSelectedEvent args)
|
||||
private void OnNukeOpsStationMap(Entity<NukeopsStationMapComponent> entity, ref ChooseStationMapEvent args)
|
||||
{
|
||||
if (args.TargetStation == null)
|
||||
// If we have this component, we don't want a fallback map!
|
||||
args.Handle();
|
||||
|
||||
foreach (var rule in _gameTicker.GetActiveGameRules<NukeopsRuleComponent>())
|
||||
{
|
||||
if (rule.Comp.TargetStation == null)
|
||||
continue;
|
||||
|
||||
args.TargetGrid = _station.GetLargestGrid((rule.Comp.TargetStation.Value, null));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnNukeopsStationSelected(ref NukeopsTargetStationSelectedEvent args)
|
||||
{
|
||||
if (args.TargetStation == null || !TryComp<RuleGridsComponent>(args.RuleEntity, out var ruleGrids))
|
||||
return;
|
||||
|
||||
if (!TryComp<StationMapComponent>(ent, out var stationMap) || !TryComp<RuleGridsComponent>(args.RuleEntity, out var ruleGrids))
|
||||
return;
|
||||
var mapquery = EntityQueryEnumerator<NukeopsStationMapComponent, StationMapComponent>();
|
||||
while (mapquery.MoveNext(out var uid, out _, out var map))
|
||||
{
|
||||
if (Transform(uid).MapID != ruleGrids.Map)
|
||||
continue;
|
||||
|
||||
if (Transform(ent).MapID != ruleGrids.Map)
|
||||
return;
|
||||
|
||||
stationMap.TargetGrid = _station.GetLargestGrid((args.TargetStation.Value, null));
|
||||
Dirty(ent);
|
||||
map.TargetGrid = _station.GetLargestGrid((args.TargetStation.Value, null));
|
||||
Dirty(uid, map);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Selects an alternative target for our station map!
|
||||
/// If handled, this will not get the map of the current station.
|
||||
/// </summary>
|
||||
[ByRefEvent]
|
||||
public record struct ChooseStationMapEvent
|
||||
{
|
||||
public EntityUid? TargetGrid;
|
||||
public bool Handled { get; private set; }
|
||||
|
||||
public void Handle()
|
||||
{
|
||||
Handled = true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue