Files
tbd-station-14/Content.Server/StationEvents/Events/BureaucraticErrorRule.cs
SlamBamActionman 5740a88208 Fix Station AI being affected by Bureaucratic Event (#32021)
* init commit

* I forgot components exist

* delta told me to make it a list
2024-09-11 13:24:24 +02:00

62 lines
2.3 KiB
C#
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using System.Linq;
using Content.Server.Station.Components;
using Content.Server.Station.Systems;
using Content.Server.StationEvents.Components;
using Content.Shared.GameTicking.Components;
using Content.Shared.Roles;
using JetBrains.Annotations;
using Robust.Shared.Random;
namespace Content.Server.StationEvents.Events;
[UsedImplicitly]
public sealed class BureaucraticErrorRule : StationEventSystem<BureaucraticErrorRuleComponent>
{
[Dependency] private readonly StationJobsSystem _stationJobs = default!;
protected override void Started(EntityUid uid, BureaucraticErrorRuleComponent component, GameRuleComponent gameRule, GameRuleStartedEvent args)
{
base.Started(uid, component, gameRule, args);
if (!TryGetRandomStation(out var chosenStation, HasComp<StationJobsComponent>))
return;
var jobList = _stationJobs.GetJobs(chosenStation.Value).Keys.ToList();
foreach(var job in component.IgnoredJobs)
jobList.Remove(job);
if (jobList.Count == 0)
return;
// 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(0.25f))
{
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 * 0.20);
var upper = (int) (jobList.Count * 0.30);
// 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);
}
}
}
}