Fix cargo gifts (#18449)

Some of the IDs were invalid and no typeserializer.
This commit is contained in:
metalgearsloth
2023-07-31 04:53:54 +10:00
committed by GitHub
parent 9647d2cf59
commit b0b1597aad
5 changed files with 29 additions and 15 deletions

View File

@@ -9,6 +9,7 @@ using Content.Server.Station.Components;
using Content.Server.Station.Systems;
using Content.Server.StationEvents.Components;
using Content.Shared.Database;
using Robust.Shared.Collections;
using Robust.Shared.Map;
using Robust.Shared.Map.Components;
using Robust.Shared.Player;
@@ -135,20 +136,32 @@ public abstract class StationEventSystem<T> : GameRuleSystem<T> where T : Compon
protected bool TryGetRandomStation([NotNullWhen(true)] out EntityUid? station, Func<EntityUid, bool>? filter = null)
{
var stations = new ValueList<EntityUid>();
if (filter == null)
{
stations.EnsureCapacity(Count<StationEventEligibleComponent>());
}
filter ??= _ => true;
var query = AllEntityQuery<StationEventEligibleComponent>();
// augh. sorry sloth there's no better API and my goal today isn't adding 50 entitymanager methods :waa:
var stations = EntityManager.GetAllComponents(typeof(StationEventEligibleComponent)).Select(x => x.Uid).Where(filter).ToArray();
while (query.MoveNext(out var uid, out _))
{
if (!filter(uid))
continue;
if (stations.Length == 0)
stations.Add(uid);
}
if (stations.Count == 0)
{
station = null;
return false;
}
station = RobustRandom.Pick(stations);
// TODO: Engine PR.
station = stations[RobustRandom.Next(stations.Count)];
return true;
}