BureaucraticErrorRule.cs 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. using System.Linq;
  2. using Content.Server.Station.Components;
  3. using Content.Server.Station.Systems;
  4. using Content.Server.StationEvents.Components;
  5. using Content.Shared.GameTicking.Components;
  6. using Content.Shared.Roles;
  7. using JetBrains.Annotations;
  8. using Robust.Shared.Random;
  9. namespace Content.Server.StationEvents.Events;
  10. [UsedImplicitly]
  11. public sealed class BureaucraticErrorRule : StationEventSystem<BureaucraticErrorRuleComponent>
  12. {
  13. [Dependency] private readonly StationJobsSystem _stationJobs = default!;
  14. protected override void Started(EntityUid uid, BureaucraticErrorRuleComponent component, GameRuleComponent gameRule, GameRuleStartedEvent args)
  15. {
  16. base.Started(uid, component, gameRule, args);
  17. if (!TryGetRandomStation(out var chosenStation, HasComp<StationJobsComponent>))
  18. return;
  19. var jobList = _stationJobs.GetJobs(chosenStation.Value).Keys.ToList();
  20. foreach(var job in component.IgnoredJobs)
  21. jobList.Remove(job);
  22. if (jobList.Count == 0)
  23. return;
  24. // Low chance to completely change up the late-join landscape by closing all positions except infinite slots.
  25. // Lower chance than the /tg/ equivalent of this event.
  26. if (RobustRandom.Prob(0.25f))
  27. {
  28. var chosenJob = RobustRandom.PickAndTake(jobList);
  29. _stationJobs.MakeJobUnlimited(chosenStation.Value, chosenJob); // INFINITE chaos.
  30. foreach (var job in jobList)
  31. {
  32. if (_stationJobs.IsJobUnlimited(chosenStation.Value, job))
  33. continue;
  34. _stationJobs.TrySetJobSlot(chosenStation.Value, job, 0);
  35. }
  36. }
  37. else
  38. {
  39. var lower = (int) (jobList.Count * 0.20);
  40. var upper = (int) (jobList.Count * 0.30);
  41. // Changing every role is maybe a bit too chaotic so instead change 20-30% of them.
  42. var num = RobustRandom.Next(lower, upper);
  43. for (var i = 0; i < num; i++)
  44. {
  45. var chosenJob = RobustRandom.PickAndTake(jobList);
  46. if (_stationJobs.IsJobUnlimited(chosenStation.Value, chosenJob))
  47. continue;
  48. _stationJobs.TryAdjustJobSlot(chosenStation.Value, chosenJob, RobustRandom.Next(-3, 6), clamp: true);
  49. }
  50. }
  51. }
  52. }