2022-05-07 02:09:29 -03:00
|
|
|
using System.Linq;
|
2023-04-25 20:23:14 -04:00
|
|
|
using Content.Server.GameTicking.Rules.Components;
|
2023-05-19 15:45:09 -05:00
|
|
|
using Content.Server.Station.Components;
|
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;
|
2022-02-25 23:10:09 -06:00
|
|
|
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>
|
2022-02-25 23:10:09 -06:00
|
|
|
{
|
2022-07-10 18:48:41 -07:00
|
|
|
[Dependency] private readonly StationJobsSystem _stationJobs = default!;
|
2022-02-25 23:10:09 -06:00
|
|
|
|
2023-04-25 20:23:14 -04:00
|
|
|
protected override void Started(EntityUid uid, BureaucraticErrorRuleComponent component, GameRuleComponent gameRule, GameRuleStartedEvent args)
|
2022-02-25 23:10:09 -06:00
|
|
|
{
|
2023-04-25 20:23:14 -04:00
|
|
|
base.Started(uid, component, gameRule, args);
|
2022-07-10 18:48:41 -07:00
|
|
|
|
2023-05-19 15:45:09 -05:00
|
|
|
if (!TryGetRandomStation(out var chosenStation, HasComp<StationJobsComponent>))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
var jobList = _stationJobs.GetJobs(chosenStation.Value).Keys.ToList();
|
|
|
|
|
|
|
|
|
|
if (jobList.Count == 0)
|
|
|
|
|
return;
|
2022-02-25 23:10:09 -06:00
|
|
|
|
2022-10-18 19:51:47 -07:00
|
|
|
var mod = GetSeverityModifier();
|
|
|
|
|
|
2022-02-25 23:10:09 -06:00
|
|
|
// 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.
|
2022-10-18 19:51:47 -07:00
|
|
|
if (RobustRandom.Prob(Math.Min(0.25f * MathF.Sqrt(mod), 1.0f)))
|
2022-02-25 23:10:09 -06:00
|
|
|
{
|
2022-07-10 18:48:41 -07:00
|
|
|
var chosenJob = RobustRandom.PickAndTake(jobList);
|
2023-05-19 15:45:09 -05:00
|
|
|
_stationJobs.MakeJobUnlimited(chosenStation.Value, chosenJob); // INFINITE chaos.
|
2022-02-25 23:10:09 -06:00
|
|
|
foreach (var job in jobList)
|
|
|
|
|
{
|
2023-05-19 15:45:09 -05:00
|
|
|
if (_stationJobs.IsJobUnlimited(chosenStation.Value, job))
|
2022-02-25 23:10:09 -06:00
|
|
|
continue;
|
2023-05-19 15:45:09 -05:00
|
|
|
_stationJobs.TrySetJobSlot(chosenStation.Value, job, 0);
|
2022-02-25 23:10:09 -06:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2022-10-18 19:51:47 -07:00
|
|
|
var lower = (int) (jobList.Count * Math.Min(1.0f, 0.20 * mod));
|
|
|
|
|
var upper = (int) (jobList.Count * Math.Min(1.0f, 0.30 * mod));
|
2022-02-25 23:10:09 -06:00
|
|
|
// Changing every role is maybe a bit too chaotic so instead change 20-30% of them.
|
2023-03-28 06:58:13 -05:00
|
|
|
var num = RobustRandom.Next(lower, upper);
|
|
|
|
|
for (var i = 0; i < num; i++)
|
2022-02-25 23:10:09 -06:00
|
|
|
{
|
2022-07-10 18:48:41 -07:00
|
|
|
var chosenJob = RobustRandom.PickAndTake(jobList);
|
2023-05-19 15:45:09 -05:00
|
|
|
if (_stationJobs.IsJobUnlimited(chosenStation.Value, chosenJob))
|
2022-02-25 23:10:09 -06:00
|
|
|
continue;
|
|
|
|
|
|
2023-05-19 15:45:09 -05:00
|
|
|
_stationJobs.TryAdjustJobSlot(chosenStation.Value, chosenJob, RobustRandom.Next(-3, 6), clamp: true);
|
2022-02-25 23:10:09 -06:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|