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

46 lines
1.6 KiB
C#
Raw Permalink Normal View History

using Content.Server.GameTicking.Rules.Components;
2023-12-27 22:09:05 -05:00
using Content.Server.StationEvents.Components;
using Content.Server.StationRecords;
using Content.Server.StationRecords.Systems;
using Content.Shared.StationRecords;
using Content.Shared.GameTicking.Components;
2023-12-27 22:09:05 -05:00
using Robust.Shared.Random;
namespace Content.Server.StationEvents.Events;
public sealed class ClericalErrorRule : StationEventSystem<ClericalErrorRuleComponent>
{
[Dependency] private readonly StationRecordsSystem _stationRecords = default!;
protected override void Started(EntityUid uid, ClericalErrorRuleComponent component, GameRuleComponent gameRule, GameRuleStartedEvent args)
{
base.Started(uid, component, gameRule, args);
if (!TryGetRandomStation(out var chosenStation))
return;
if (!TryComp<StationRecordsComponent>(chosenStation, out var stationRecords))
return;
var recordCount = stationRecords.Records.Keys.Count;
if (recordCount == 0)
return;
var min = (int) Math.Max(1, Math.Round(component.MinToRemove * recordCount));
var max = (int) Math.Max(min, Math.Round(component.MaxToRemove * recordCount));
var toRemove = RobustRandom.Next(min, max);
2024-02-04 23:29:35 +00:00
var keys = new List<uint>();
2023-12-27 22:09:05 -05:00
for (var i = 0; i < toRemove; i++)
{
keys.Add(RobustRandom.Pick(stationRecords.Records.Keys));
}
2024-02-04 23:29:35 +00:00
foreach (var id in keys)
2023-12-27 22:09:05 -05:00
{
2024-02-04 23:29:35 +00:00
var key = new StationRecordKey(id, chosenStation.Value);
_stationRecords.RemoveRecord(key, stationRecords);
2023-12-27 22:09:05 -05:00
}
}
}