From f0d9782df418d4d4c3b1127a7adfafa5b3ace09c Mon Sep 17 00:00:00 2001
From: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
Date: Mon, 8 Jan 2024 17:26:02 +1100
Subject: [PATCH] Cleanup mimic event (#23705)
* Cleanup mimic event
Now it won't be forced on dev map or mapping mode.
* Minor cleanup
---
.../Mimic/MobReplacementRuleComponent.cs | 21 +++++++++++
.../Antag/MobReplacementRuleSystem.cs | 37 +++++++++++++++++++
.../Markers/Spawners/Random/vending.yml | 3 --
.../Markers/Spawners/Random/vendingdrinks.yml | 3 --
.../Markers/Spawners/Random/vendingsnacks.yml | 3 --
Resources/Prototypes/GameRules/events.yml | 11 ++++++
6 files changed, 69 insertions(+), 9 deletions(-)
create mode 100644 Content.Server/Antag/Mimic/MobReplacementRuleComponent.cs
create mode 100644 Content.Server/Antag/MobReplacementRuleSystem.cs
diff --git a/Content.Server/Antag/Mimic/MobReplacementRuleComponent.cs b/Content.Server/Antag/Mimic/MobReplacementRuleComponent.cs
new file mode 100644
index 0000000000..d89d61606d
--- /dev/null
+++ b/Content.Server/Antag/Mimic/MobReplacementRuleComponent.cs
@@ -0,0 +1,21 @@
+using Robust.Shared.Prototypes;
+
+namespace Content.Server.Antag.Mimic;
+
+///
+/// Replaces the relevant entities with mobs when the game rule is started.
+///
+[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";
+
+ ///
+ /// Chance per-entity.
+ ///
+ [DataField]
+ public float Chance = 0.001f;
+}
diff --git a/Content.Server/Antag/MobReplacementRuleSystem.cs b/Content.Server/Antag/MobReplacementRuleSystem.cs
new file mode 100644
index 0000000000..2446b976e1
--- /dev/null
+++ b/Content.Server/Antag/MobReplacementRuleSystem.cs
@@ -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
+{
+ [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();
+ 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);
+ }
+ }
+}
diff --git a/Resources/Prototypes/Entities/Markers/Spawners/Random/vending.yml b/Resources/Prototypes/Entities/Markers/Spawners/Random/vending.yml
index 4da7ee54e6..d55a7916b4 100644
--- a/Resources/Prototypes/Entities/Markers/Spawners/Random/vending.yml
+++ b/Resources/Prototypes/Entities/Markers/Spawners/Random/vending.yml
@@ -32,6 +32,3 @@
- VendingMachineStarkist
- VendingMachineSpaceUp
chance: 1
- rarePrototypes:
- - MobMimic
- rareChance: 0.001
diff --git a/Resources/Prototypes/Entities/Markers/Spawners/Random/vendingdrinks.yml b/Resources/Prototypes/Entities/Markers/Spawners/Random/vendingdrinks.yml
index 65d2fb0862..a911b7ebfc 100644
--- a/Resources/Prototypes/Entities/Markers/Spawners/Random/vendingdrinks.yml
+++ b/Resources/Prototypes/Entities/Markers/Spawners/Random/vendingdrinks.yml
@@ -23,6 +23,3 @@
- VendingMachineStarkist
- VendingMachineSpaceUp
chance: 1
- rarePrototypes:
- - MobMimic
- rareChance: 0.001
diff --git a/Resources/Prototypes/Entities/Markers/Spawners/Random/vendingsnacks.yml b/Resources/Prototypes/Entities/Markers/Spawners/Random/vendingsnacks.yml
index e9c7d71c3a..b634d50cc6 100644
--- a/Resources/Prototypes/Entities/Markers/Spawners/Random/vendingsnacks.yml
+++ b/Resources/Prototypes/Entities/Markers/Spawners/Random/vendingsnacks.yml
@@ -20,6 +20,3 @@
- VendingMachineChang
- VendingMachineDonut
chance: 1
- rarePrototypes:
- - MobMimic
- rareChance: 0.001
diff --git a/Resources/Prototypes/GameRules/events.yml b/Resources/Prototypes/GameRules/events.yml
index b197b643f3..43155e2827 100644
--- a/Resources/Prototypes/GameRules/events.yml
+++ b/Resources/Prototypes/GameRules/events.yml
@@ -441,3 +441,14 @@
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
--
2.51.2