]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Cleanup mimic event (#23705)
authormetalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
Mon, 8 Jan 2024 06:26:02 +0000 (17:26 +1100)
committerGitHub <noreply@github.com>
Mon, 8 Jan 2024 06:26:02 +0000 (23:26 -0700)
* Cleanup mimic event

Now it won't be forced on dev map or mapping mode.

* Minor cleanup

Content.Server/Antag/Mimic/MobReplacementRuleComponent.cs [new file with mode: 0644]
Content.Server/Antag/MobReplacementRuleSystem.cs [new file with mode: 0644]
Resources/Prototypes/Entities/Markers/Spawners/Random/vending.yml
Resources/Prototypes/Entities/Markers/Spawners/Random/vendingdrinks.yml
Resources/Prototypes/Entities/Markers/Spawners/Random/vendingsnacks.yml
Resources/Prototypes/GameRules/events.yml

diff --git a/Content.Server/Antag/Mimic/MobReplacementRuleComponent.cs b/Content.Server/Antag/Mimic/MobReplacementRuleComponent.cs
new file mode 100644 (file)
index 0000000..d89d616
--- /dev/null
@@ -0,0 +1,21 @@
+using Robust.Shared.Prototypes;
+
+namespace Content.Server.Antag.Mimic;
+
+/// <summary>
+/// Replaces the relevant entities with mobs when the game rule is started.
+/// </summary>
+[RegisterComponent]
+public sealed partial class MobReplacementRuleComponent : Component
+{
+    // If you want more components use generics, using a whitelist would probably kill the server iterating every single entity.
+
+    [DataField]
+    public EntProtoId Proto = "MobMimic";
+
+    /// <summary>
+    /// Chance per-entity.
+    /// </summary>
+    [DataField]
+    public float Chance = 0.001f;
+}
diff --git a/Content.Server/Antag/MobReplacementRuleSystem.cs b/Content.Server/Antag/MobReplacementRuleSystem.cs
new file mode 100644 (file)
index 0000000..2446b97
--- /dev/null
@@ -0,0 +1,37 @@
+using Content.Server.Antag.Mimic;
+using Content.Server.GameTicking.Rules;
+using Content.Server.GameTicking.Rules.Components;
+using Content.Shared.VendingMachines;
+using Robust.Shared.Map;
+using Robust.Shared.Random;
+
+namespace Content.Server.Antag;
+
+public sealed class MobReplacementRuleSystem : GameRuleSystem<MobReplacementRuleComponent>
+{
+    [Dependency] private readonly IRobustRandom _random = default!;
+
+    protected override void Started(EntityUid uid, MobReplacementRuleComponent component, GameRuleComponent gameRule, GameRuleStartedEvent args)
+    {
+        base.Started(uid, component, gameRule, args);
+
+        var query = AllEntityQuery<VendingMachineComponent, TransformComponent>();
+        var spawns = new List<(EntityUid Entity, EntityCoordinates Coordinates)>();
+
+        while (query.MoveNext(out var vendingUid, out _, out var xform))
+        {
+            if (!_random.Prob(component.Chance))
+                continue;
+
+            spawns.Add((vendingUid, xform.Coordinates));
+        }
+
+        foreach (var entity in spawns)
+        {
+            var coordinates = entity.Coordinates;
+            Del(entity.Entity);
+
+            Spawn(component.Proto, coordinates);
+        }
+    }
+}
index 4da7ee54e6c31307b2cacb18563410903b30bee2..d55a7916b46440ef064e76e4facc6972954fcf13 100644 (file)
@@ -32,6 +32,3 @@
       - VendingMachineStarkist
       - VendingMachineSpaceUp
     chance: 1
-    rarePrototypes:
-      - MobMimic
-    rareChance: 0.001
index 65d2fb08623b55d55bbe24c8bbfe266a119e73cf..a911b7ebfc03526fbc7b305e2ea1b6300145d805 100644 (file)
@@ -23,6 +23,3 @@
       - VendingMachineStarkist
       - VendingMachineSpaceUp
     chance: 1
-    rarePrototypes:
-      - MobMimic
-    rareChance: 0.001
index e9c7d71c3a8afd717f1fea00dc210460872ea371..b634d50cc6cec5167c30e921cf87fb6a2a713b8d 100644 (file)
@@ -20,6 +20,3 @@
       - VendingMachineChang
       - VendingMachineDonut
     chance: 1
-    rarePrototypes:
-      - MobMimic
-    rareChance: 0.001
index b197b643f3ab48a44215ea4e313957a48c2ee445..43155e28272baa2e39b6732856f8d0ed4cf760ff 100644 (file)
     reoccurrenceDelay: 60
     duration: 1
   - type: IonStormRule
+
+- type: entity
+  id: MimicVendorRule
+  parent: BaseGameRule
+  noSpawn: true
+  components:
+    - type: StationEvent
+      earliestStart: 0
+      minimumPlayers: 20
+      weight: 5
+    - type: MobReplacementRule