* Mega Antag Refactor * last minute delta save * more workshopping * more shit * ok tested this for once * okkkkk sure * generic delays for starting rules * well darn * nukies partially * ouagh * ballin' faded and smonkin wed * obliterated the diff * Spread my arms and soak up congratulations * I've got plenty of love, but nothing to show for it * but there’s too much sunlight Shining on my laptop monitor, so I Can’t see anything with any amount of clarity * ok this junk * OOK! * fubar * most of sloth's review * oh boy * eek * hell yea! * ASDFJASDJFvsakcvjkzjnhhhyh
46 lines
1.6 KiB
C#
46 lines
1.6 KiB
C#
using Content.Server.GameTicking.Components;
|
|
using Content.Server.GameTicking.Rules.Components;
|
|
using Content.Server.StationEvents.Components;
|
|
using Content.Server.StationRecords;
|
|
using Content.Server.StationRecords.Systems;
|
|
using Content.Shared.StationRecords;
|
|
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);
|
|
var keys = new List<uint>();
|
|
for (var i = 0; i < toRemove; i++)
|
|
{
|
|
keys.Add(RobustRandom.Pick(stationRecords.Records.Keys));
|
|
}
|
|
|
|
foreach (var id in keys)
|
|
{
|
|
var key = new StationRecordKey(id, chosenStation.Value);
|
|
_stationRecords.RemoveRecord(key, stationRecords);
|
|
}
|
|
}
|
|
}
|