]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
clerical error station event (#23091)
authorNemanja <98561806+EmoGarbage404@users.noreply.github.com>
Thu, 28 Dec 2023 03:09:05 +0000 (22:09 -0500)
committerGitHub <noreply@github.com>
Thu, 28 Dec 2023 03:09:05 +0000 (20:09 -0700)
Content.Server/StationEvents/Components/ClericalErrorRuleComponent.cs [new file with mode: 0644]
Content.Server/StationEvents/Events/ClericalErrorRule.cs [new file with mode: 0644]
Resources/Locale/en-US/station-events/events/bureaucratic-error.ftl
Resources/Prototypes/GameRules/events.yml

diff --git a/Content.Server/StationEvents/Components/ClericalErrorRuleComponent.cs b/Content.Server/StationEvents/Components/ClericalErrorRuleComponent.cs
new file mode 100644 (file)
index 0000000..afbb992
--- /dev/null
@@ -0,0 +1,23 @@
+using Content.Server.StationEvents.Events;
+
+namespace Content.Server.StationEvents.Components;
+
+/// <summary>
+/// This is a station event that randomly removes some records from the station record database.
+/// </summary>
+[RegisterComponent]
+[Access(typeof(ClericalErrorRule))]
+public sealed partial class ClericalErrorRuleComponent : Component
+{
+    /// <summary>
+    /// The minimum percentage number of records to remove from the station.
+    /// </summary>
+    [DataField, ViewVariables(VVAccess.ReadWrite)]
+    public float MinToRemove = 0.0025f;
+
+    /// <summary>
+    /// The maximum percentage number of records to remove from the station.
+    /// </summary>
+    [DataField, ViewVariables(VVAccess.ReadWrite)]
+    public float MaxToRemove = 0.1f;
+}
diff --git a/Content.Server/StationEvents/Events/ClericalErrorRule.cs b/Content.Server/StationEvents/Events/ClericalErrorRule.cs
new file mode 100644 (file)
index 0000000..c1b4cd9
--- /dev/null
@@ -0,0 +1,43 @@
+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<StationRecordKey>();
+        for (var i = 0; i < toRemove; i++)
+        {
+            keys.Add(RobustRandom.Pick(stationRecords.Records.Keys));
+        }
+
+        foreach (var key in keys)
+        {
+            _stationRecords.RemoveRecord(chosenStation.Value, key, stationRecords);
+        }
+    }
+}
index 8042ac871e9212b13afdc1f4ab2539afc91861d7..9323c4cb8c5486be803f507ab2bca628cb82becf 100644 (file)
@@ -1 +1,2 @@
 station-event-bureaucratic-error-announcement = A recent bureaucratic error in the Organic Resources Department may result in personnel shortages in some departments and redundant staffing in others.
+station-event-clerical-error-announcement = A minor clerical error in the Organic Resources Department has resulted in the permanent destruction of some of the station records.
index 6534a686ea7cec9d518e1e04e1db91c9a8dea021..b197b643f3ab48a44215ea4e313957a48c2ee445 100644 (file)
     duration: 1
   - type: BureaucraticErrorRule
 
+- type: entity
+  id: ClericalError
+  parent: BaseGameRule
+  noSpawn: true
+  components:
+  - type: StationEvent
+    startAnnouncement: station-event-clerical-error-announcement
+    minimumPlayers: 15
+    weight: 5
+    duration: 1
+  - type: ClericalErrorRule
+
 - type: entity
   parent: BaseGameRule
   id: ClosetSkeleton