Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
MetalSage committed Feb 12, 2024
1 parent cc8a8e6 commit 152a35b
Showing 1 changed file with 26 additions and 27 deletions.
53 changes: 26 additions & 27 deletions Content.Server/Stories/Shuttles/Systems/RepeatedArrivalsSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ public sealed class RepeatedArrivalsSystem : EntitySystem
[Dependency] private readonly StationSpawningSystem _stationSpawning = default!;
[Dependency] private readonly StationSystem _station = default!;

private EntityQuery<PendingClockInComponent> _pendingQuery;
private EntityQuery<ArrivalsBlacklistComponent> _blacklistQuery;
private EntityQuery<MobStateComponent> _mobQuery;

/// <summary>
/// If enabled then spawns players on an alternate map so they can take a shuttle to the station.
/// </summary>
Expand All @@ -47,6 +51,10 @@ public override void Initialize()

SubscribeLocalEvent<RoundStartingEvent>(OnRoundStarting);

_pendingQuery = GetEntityQuery<PendingClockInComponent>();
_blacklistQuery = GetEntityQuery<ArrivalsBlacklistComponent>();
_mobQuery = GetEntityQuery<MobStateComponent>();

// Don't invoke immediately as it will get set in the natural course of things.
Enabled = _cfgManager.GetCVar(CCVars.ArrivalsShuttles);
_cfgManager.OnValueChanged(CCVars.ArrivalsShuttles, SetArrivals);
Expand All @@ -58,31 +66,36 @@ public override void Shutdown()
_cfgManager.UnsubValueChanged(CCVars.ArrivalsShuttles, SetArrivals);
}

private void DumpChildren(EntityUid uid,
ref FTLStartedEvent args,
EntityQuery<PendingClockInComponent> pendingEntQuery,
EntityQuery<ArrivalsBlacklistComponent> arrivalsBlacklistQuery,
EntityQuery<MobStateComponent> mobQuery,
EntityQuery<TransformComponent> xformQuery)
private void DumpChildren(EntityUid uid, ref FTLStartedEvent args)
{
if (pendingEntQuery.HasComponent(uid))
var toDump = new List<Entity<TransformComponent>>();
DumpChildren(uid, ref args, toDump);
foreach (var (ent, xform) in toDump)
{
var rotation = xform.LocalRotation;
_transform.SetCoordinates(ent, new EntityCoordinates(args.FromMapUid!.Value, args.FTLFrom.Transform(xform.LocalPosition)));
_transform.SetWorldRotation(ent, args.FromRotation + rotation);
}
}

private void DumpChildren(EntityUid uid, ref FTLStartedEvent args, List<Entity<TransformComponent>> toDump)
{
if (_pendingQuery.HasComponent(uid))
return;

var xform = xformQuery.GetComponent(uid);
var xform = Transform(uid);

if (mobQuery.HasComponent(uid) || arrivalsBlacklistQuery.HasComponent(uid))
if (_mobQuery.HasComponent(uid) || _blacklistQuery.HasComponent(uid))
{
var rotation = xform.LocalRotation;
_transform.SetCoordinates(uid, new EntityCoordinates(args.FromMapUid!.Value, args.FTLFrom.Transform(xform.LocalPosition)));
_transform.SetWorldRotation(uid, args.FromRotation + rotation);
toDump.Add((uid, xform));
return;
}

var children = xform.ChildEnumerator;

while (children.MoveNext(out var child))
{
DumpChildren(child.Value, ref args, pendingEntQuery, arrivalsBlacklistQuery, mobQuery, xformQuery);
DumpChildren(child, ref args, toDump);
}
}

Expand Down Expand Up @@ -149,20 +162,6 @@ private void OnRoundStarting(RoundStartingEvent ev)

private void SetupArrivalsStation()
{
var mapId = _mapManager.CreateMap();

if (!_loader.TryLoad(mapId, _cfgManager.GetCVar(CCVars.ArrivalsMap), out var uids))
{
return;
}

foreach (var id in uids)
{
EnsureComp<ArrivalsSourceComponent>(id);
EnsureComp<ProtectedGridComponent>(id);
EnsureComp<PreventPilotComponent>(id);
}

// Handle roundstart stations.
var query = AllEntityQuery<StationArrivalsComponent>();

Expand Down

0 comments on commit 152a35b

Please sign in to comment.