Files
crystall-punk-14/Content.Server/StationEvents/Events/BureaucraticErrorRule.cs

60 lines
2.3 KiB
C#
Raw Normal View History

using System.Linq;
2023-04-25 20:23:14 -04:00
using Content.Server.GameTicking.Rules.Components;
using Content.Server.Station.Components;
StationSystem/jobs/partial spawning refactor (#7580) * Partial work on StationSystem refactor. * WIP station jobs API. * forgor to fire off grid events. * Partial implementation of StationSpawningSystem * whoops infinite loop. * Spawners should work now. * it compiles. * tfw * Vestigial code cleanup. * fix station deletion. * attempt to make tests go brr * add latejoin spawnpoints to test maps. * make sure the station still exists while destructing spawners. * forgot an exists check. * destruction order check. * hopefully fix final test. * fail-safe radstorm. * Deep-clean job code further. This is bugged!!!!! * Fix job bug. (init order moment) * whooo cleanup * New job selection algorithm that tries to distribute fairly across stations. * small nitpicks * Give the heads their weights to replace the head field. * make overflow assign take a station list. * moment * Fixes and test #1 of many. * please fix nullspace * AssignJobs should no longer even consider showing up on a trace. * add comment. * Introduce station configs, praying i didn't miss something. * in one small change stations are now fully serializable. * Further doc comments. * whoops. * Solve bug where assignjobs didn't account for roundstart. * Fix spawning, improve the API. Caught an oversight in stationsystem that should've broke everything but didn't, whoops. * Goodbye JobController. * minor fix.. * fix test fail, remove debug logs. * quick serialization fixes. * fixes.. * sus * partialing * Update Content.Server/Station/Systems/StationJobsSystem.Roundstart.cs Co-authored-by: Kara <lunarautomaton6@gmail.com> * Use dirtying to avoid rebuilding the list 2,100 times. * add a bajillion more lines of docs (mostly in AssignJobs so i don't ever forget how it works) * Update Content.IntegrationTests/Tests/Station/StationJobsTest.cs Co-authored-by: Kara <lunarautomaton6@gmail.com> * Add the Mysteriously Missing Captain Check. * Put maprender back the way it belongs. * I love addressing reviews. * Update Content.Server/Station/Systems/StationJobsSystem.cs Co-authored-by: Kara <lunarautomaton6@gmail.com> * doc cleanup. * Fix bureaucratic error, add job slot tests. * zero cost abstractions when * cri * saner error. * Fix spawning failing certain tests due to gameticker not handling falliability correctly. Can't fix this until I refactor the rest of spawning code. * submodule gaming * Packedenger. * Documentation consistency. Co-authored-by: Kara <lunarautomaton6@gmail.com>
2022-05-10 13:43:30 -05:00
using Content.Server.Station.Systems;
2023-04-25 20:23:14 -04:00
using Content.Server.StationEvents.Components;
using JetBrains.Annotations;
using Robust.Shared.Random;
namespace Content.Server.StationEvents.Events;
[UsedImplicitly]
2023-04-25 20:23:14 -04:00
public sealed class BureaucraticErrorRule : StationEventSystem<BureaucraticErrorRuleComponent>
{
[Dependency] private readonly StationJobsSystem _stationJobs = default!;
2023-04-25 20:23:14 -04:00
protected override void Started(EntityUid uid, BureaucraticErrorRuleComponent component, GameRuleComponent gameRule, GameRuleStartedEvent args)
{
2023-04-25 20:23:14 -04:00
base.Started(uid, component, gameRule, args);
if (!TryGetRandomStation(out var chosenStation, HasComp<StationJobsComponent>))
return;
var jobList = _stationJobs.GetJobs(chosenStation.Value).Keys.ToList();
if (jobList.Count == 0)
return;
var mod = GetSeverityModifier();
// Low chance to completely change up the late-join landscape by closing all positions except infinite slots.
// Lower chance than the /tg/ equivalent of this event.
if (RobustRandom.Prob(Math.Min(0.25f * MathF.Sqrt(mod), 1.0f)))
{
var chosenJob = RobustRandom.PickAndTake(jobList);
_stationJobs.MakeJobUnlimited(chosenStation.Value, chosenJob); // INFINITE chaos.
foreach (var job in jobList)
{
if (_stationJobs.IsJobUnlimited(chosenStation.Value, job))
continue;
_stationJobs.TrySetJobSlot(chosenStation.Value, job, 0);
}
}
else
{
var lower = (int) (jobList.Count * Math.Min(1.0f, 0.20 * mod));
var upper = (int) (jobList.Count * Math.Min(1.0f, 0.30 * mod));
// Changing every role is maybe a bit too chaotic so instead change 20-30% of them.
var num = RobustRandom.Next(lower, upper);
for (var i = 0; i < num; i++)
{
var chosenJob = RobustRandom.PickAndTake(jobList);
if (_stationJobs.IsJobUnlimited(chosenStation.Value, chosenJob))
continue;
_stationJobs.TryAdjustJobSlot(chosenStation.Value, chosenJob, RobustRandom.Next(-3, 6), clamp: true);
}
}
}
}