Refactor stations to properly use entity prototypes. (stationsv3) (#16570)
* Update StationSpawningSystem.cs Web-edit to allow feeding in an existing entity. * Update StationSpawningSystem.cs value type moment * Update StationSpawningSystem.cs * Oh goddamnit this is a refactor now. * awawawa * aaaaaaaaaaa * ee * forgot records. * no records? no records. * What's in a name? * Sloth forcing me to do the refactor properly smh. * e * optional evac in test. * tests pls work * awa --------- Co-authored-by: moonheart08 <moonheart08@users.noreply.github.com>
This commit is contained in:
@@ -24,9 +24,9 @@ public sealed class AnomalySpawnRule : StationEventSystem<AnomalySpawnRuleCompon
|
||||
{
|
||||
base.Started(uid, component, gameRule, args);
|
||||
|
||||
if (StationSystem.Stations.Count == 0)
|
||||
return; // No stations
|
||||
var chosenStation = RobustRandom.Pick(StationSystem.Stations.ToList());
|
||||
if (!TryGetRandomStation(out var chosenStation))
|
||||
return;
|
||||
|
||||
if (!TryComp<StationDataComponent>(chosenStation, out var stationData))
|
||||
return;
|
||||
|
||||
|
||||
@@ -26,9 +26,8 @@ public sealed class BreakerFlipRule : StationEventSystem<BreakerFlipRuleComponen
|
||||
{
|
||||
base.Started(uid, component, gameRule, args);
|
||||
|
||||
if (StationSystem.Stations.Count == 0)
|
||||
if (!TryGetRandomStation(out var chosenStation))
|
||||
return;
|
||||
var chosenStation = RobustRandom.Pick(StationSystem.Stations.ToList());
|
||||
|
||||
var stationApcs = new List<ApcComponent>();
|
||||
foreach (var (apc, transform) in EntityQuery<ApcComponent, TransformComponent>())
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System.Linq;
|
||||
using Content.Server.GameTicking.Rules.Components;
|
||||
using Content.Server.Station.Components;
|
||||
using Content.Server.Station.Systems;
|
||||
using Content.Server.StationEvents.Components;
|
||||
using JetBrains.Annotations;
|
||||
@@ -16,10 +17,13 @@ public sealed class BureaucraticErrorRule : StationEventSystem<BureaucraticError
|
||||
{
|
||||
base.Started(uid, component, gameRule, args);
|
||||
|
||||
if (StationSystem.Stations.Count == 0)
|
||||
return; // No stations
|
||||
var chosenStation = RobustRandom.Pick(StationSystem.Stations.ToList());
|
||||
var jobList = _stationJobs.GetJobs(chosenStation).Keys.ToList();
|
||||
if (!TryGetRandomStation(out var chosenStation, HasComp<StationJobsComponent>))
|
||||
return;
|
||||
|
||||
var jobList = _stationJobs.GetJobs(chosenStation.Value).Keys.ToList();
|
||||
|
||||
if (jobList.Count == 0)
|
||||
return;
|
||||
|
||||
var mod = GetSeverityModifier();
|
||||
|
||||
@@ -28,12 +32,12 @@ public sealed class BureaucraticErrorRule : StationEventSystem<BureaucraticError
|
||||
if (RobustRandom.Prob(Math.Min(0.25f * MathF.Sqrt(mod), 1.0f)))
|
||||
{
|
||||
var chosenJob = RobustRandom.PickAndTake(jobList);
|
||||
_stationJobs.MakeJobUnlimited(chosenStation, chosenJob); // INFINITE chaos.
|
||||
_stationJobs.MakeJobUnlimited(chosenStation.Value, chosenJob); // INFINITE chaos.
|
||||
foreach (var job in jobList)
|
||||
{
|
||||
if (_stationJobs.IsJobUnlimited(chosenStation, job))
|
||||
if (_stationJobs.IsJobUnlimited(chosenStation.Value, job))
|
||||
continue;
|
||||
_stationJobs.TrySetJobSlot(chosenStation, job, 0);
|
||||
_stationJobs.TrySetJobSlot(chosenStation.Value, job, 0);
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -45,10 +49,10 @@ public sealed class BureaucraticErrorRule : StationEventSystem<BureaucraticError
|
||||
for (var i = 0; i < num; i++)
|
||||
{
|
||||
var chosenJob = RobustRandom.PickAndTake(jobList);
|
||||
if (_stationJobs.IsJobUnlimited(chosenStation, chosenJob))
|
||||
if (_stationJobs.IsJobUnlimited(chosenStation.Value, chosenJob))
|
||||
continue;
|
||||
|
||||
_stationJobs.TryAdjustJobSlot(chosenStation, chosenJob, RobustRandom.Next(-3, 6), clamp: true);
|
||||
_stationJobs.TryAdjustJobSlot(chosenStation.Value, chosenJob, RobustRandom.Next(-3, 6), clamp: true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,8 +22,9 @@ namespace Content.Server.StationEvents.Events
|
||||
var mod = MathF.Sqrt(GetSeverityModifier());
|
||||
|
||||
// Essentially we'll pick out a target amount of gas to leak, then a rate to leak it at, then work out the duration from there.
|
||||
if (TryFindRandomTile(out component.TargetTile, out component.TargetStation, out component.TargetGrid, out component.TargetCoords))
|
||||
if (TryFindRandomTile(out component.TargetTile, out var target, out component.TargetGrid, out component.TargetCoords))
|
||||
{
|
||||
component.TargetStation = target.Value;
|
||||
component.FoundTile = true;
|
||||
|
||||
component.LeakGas = RobustRandom.Pick(component.LeakableGases);
|
||||
|
||||
@@ -23,9 +23,8 @@ namespace Content.Server.StationEvents.Events
|
||||
{
|
||||
base.Started(uid, component, gameRule, args);
|
||||
|
||||
if (StationSystem.Stations.Count == 0)
|
||||
if (!TryGetRandomStation(out var chosenStation))
|
||||
return;
|
||||
var chosenStation = RobustRandom.Pick(StationSystem.Stations.ToList());
|
||||
|
||||
foreach (var (apc, transform) in EntityQuery<ApcComponent, TransformComponent>(true))
|
||||
{
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using Content.Server.Administration.Logs;
|
||||
using Content.Server.Atmos.EntitySystems;
|
||||
using Content.Server.Chat.Systems;
|
||||
@@ -131,19 +133,37 @@ public abstract class StationEventSystem<T> : GameRuleSystem<T> where T : Compon
|
||||
GameTicker.EndGameRule(uid, component);
|
||||
}
|
||||
|
||||
protected bool TryFindRandomTile(out Vector2i tile, out EntityUid targetStation, out EntityUid targetGrid, out EntityCoordinates targetCoords)
|
||||
protected bool TryGetRandomStation([NotNullWhen(true)] out EntityUid? station, Func<EntityUid, bool>? filter = null)
|
||||
{
|
||||
filter ??= _ => true;
|
||||
|
||||
// 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.Owner).Where(filter).ToArray();
|
||||
|
||||
if (stations.Length == 0)
|
||||
{
|
||||
station = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
station = RobustRandom.Pick(stations);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
protected bool TryFindRandomTile(out Vector2i tile, [NotNullWhen(true)] out EntityUid? targetStation, out EntityUid targetGrid, out EntityCoordinates targetCoords)
|
||||
{
|
||||
tile = default;
|
||||
|
||||
targetCoords = EntityCoordinates.Invalid;
|
||||
if (StationSystem.Stations.Count == 0)
|
||||
if (!TryGetRandomStation(out targetStation))
|
||||
{
|
||||
targetStation = EntityUid.Invalid;
|
||||
targetGrid = EntityUid.Invalid;
|
||||
return false;
|
||||
}
|
||||
targetStation = RobustRandom.Pick(StationSystem.Stations);
|
||||
var possibleTargets = Comp<StationDataComponent>(targetStation).Grids;
|
||||
var possibleTargets = Comp<StationDataComponent>(targetStation.Value).Grids;
|
||||
if (possibleTargets.Count == 0)
|
||||
{
|
||||
targetGrid = EntityUid.Invalid;
|
||||
|
||||
@@ -22,9 +22,8 @@ public sealed class VentClogRule : StationEventSystem<VentClogRuleComponent>
|
||||
{
|
||||
base.Started(uid, component, gameRule, args);
|
||||
|
||||
if (StationSystem.Stations.Count == 0)
|
||||
if (!TryGetRandomStation(out var chosenStation))
|
||||
return;
|
||||
var chosenStation = RobustRandom.Pick(StationSystem.Stations.ToList());
|
||||
|
||||
// TODO: "safe random" for chems. Right now this includes admin chemicals.
|
||||
var allReagents = PrototypeManager.EnumeratePrototypes<ReagentPrototype>()
|
||||
|
||||
Reference in New Issue
Block a user