From 839720b538648cd4e9c2b974f3161490dc657065 Mon Sep 17 00:00:00 2001 From: Slava0135 <40753025+Slava0135@users.noreply.github.com> Date: Sun, 9 Jul 2023 22:25:05 +0300 Subject: [PATCH] Fix vent critters spawn (#17833) * VentCrittersRule scaling chance + spawn on station * merge mouse migration and vent critters * fix prototypes * check if there is no valid locations --- .../Components/MouseMigrationRuleComponent.cs | 16 ------ .../Components/VentCrittersRuleComponent.cs | 6 +++ .../Events/MouseMigrationRule.cs | 33 ------------ .../StationEvents/Events/VentCrittersRule.cs | 54 +++++++++++++------ Resources/Prototypes/GameRules/events.yml | 48 +++++++++-------- 5 files changed, 69 insertions(+), 88 deletions(-) delete mode 100644 Content.Server/StationEvents/Components/MouseMigrationRuleComponent.cs delete mode 100644 Content.Server/StationEvents/Events/MouseMigrationRule.cs diff --git a/Content.Server/StationEvents/Components/MouseMigrationRuleComponent.cs b/Content.Server/StationEvents/Components/MouseMigrationRuleComponent.cs deleted file mode 100644 index cb6274624c..0000000000 --- a/Content.Server/StationEvents/Components/MouseMigrationRuleComponent.cs +++ /dev/null @@ -1,16 +0,0 @@ -using Content.Server.StationEvents.Events; - -namespace Content.Server.StationEvents.Components; - -[RegisterComponent, Access(typeof(MouseMigrationRule))] -public sealed class MouseMigrationRuleComponent : Component -{ - [DataField("spawnedPrototypeChoices")] - public List SpawnedPrototypeChoices = new() //we double up for that ez fake probability - { - "MobMouse", - "MobMouse1", - "MobMouse2", - "MobRatServant" - }; -} diff --git a/Content.Server/StationEvents/Components/VentCrittersRuleComponent.cs b/Content.Server/StationEvents/Components/VentCrittersRuleComponent.cs index 0cb4fc44f5..2e5c33973c 100644 --- a/Content.Server/StationEvents/Components/VentCrittersRuleComponent.cs +++ b/Content.Server/StationEvents/Components/VentCrittersRuleComponent.cs @@ -8,4 +8,10 @@ public sealed class VentCrittersRuleComponent : Component { [DataField("entries")] public List Entries = new(); + + /// + /// At least one special entry is guaranteed to spawn + /// + [DataField("specialEntries")] + public List SpecialEntries = new(); } diff --git a/Content.Server/StationEvents/Events/MouseMigrationRule.cs b/Content.Server/StationEvents/Events/MouseMigrationRule.cs deleted file mode 100644 index b0c54a7d0e..0000000000 --- a/Content.Server/StationEvents/Events/MouseMigrationRule.cs +++ /dev/null @@ -1,33 +0,0 @@ -using System.Linq; -using Content.Server.GameTicking.Rules.Components; -using Content.Server.StationEvents.Components; -using Robust.Shared.Random; - -namespace Content.Server.StationEvents.Events; - -public sealed class MouseMigrationRule : StationEventSystem -{ - protected override void Started(EntityUid uid, MouseMigrationRuleComponent component, GameRuleComponent gameRule, GameRuleStartedEvent args) - { - base.Started(uid, component, gameRule, args); - - var modifier = GetSeverityModifier(); - - var spawnLocations = EntityManager.EntityQuery().ToList(); - RobustRandom.Shuffle(spawnLocations); - - // sqrt so we dont get insane values for ramping events - var spawnAmount = (int) (RobustRandom.Next(7, 15) * Math.Sqrt(modifier)); // A small colony of critters. - - for (var i = 0; i < spawnAmount && i < spawnLocations.Count - 1; i++) - { - var spawnChoice = RobustRandom.Pick(component.SpawnedPrototypeChoices); - if (RobustRandom.Prob(Math.Min(0.01f * modifier, 1.0f)) || i == 0) //small chance for multiple, but always at least 1 - spawnChoice = "SpawnPointGhostRatKing"; - - var coords = spawnLocations[i].Item2.Coordinates; - Sawmill.Info($"Spawning mouse {spawnChoice} at {coords}"); - EntityManager.SpawnEntity(spawnChoice, coords); - } - } -} diff --git a/Content.Server/StationEvents/Events/VentCrittersRule.cs b/Content.Server/StationEvents/Events/VentCrittersRule.cs index 78188e642b..cdcf2bf6ff 100644 --- a/Content.Server/StationEvents/Events/VentCrittersRule.cs +++ b/Content.Server/StationEvents/Events/VentCrittersRule.cs @@ -1,7 +1,9 @@ using Content.Server.StationEvents.Components; -using Robust.Shared.Random; -using System.Linq; using Content.Server.GameTicking.Rules.Components; +using Content.Server.Station.Components; +using Content.Shared.Storage; +using Robust.Shared.Map; +using Robust.Shared.Random; namespace Content.Server.StationEvents.Events; @@ -16,23 +18,41 @@ public sealed class VentCrittersRule : StationEventSystem().ToList(); - RobustRandom.Shuffle(spawnLocations); - - // A small colony of critters. - var spawnAmount = RobustRandom.Next(spawnChoice.Amount, spawnChoice.MaxAmount); - Sawmill.Info($"Spawning {spawnAmount} of {spawnChoice}"); - foreach (var location in spawnLocations) + if (!TryGetRandomStation(out var station)) { - if (spawnAmount-- == 0) - break; + return; + } - var coords = Transform(location.Owner); - Spawn(spawnChoice.PrototypeId, coords.Coordinates); + var locations = EntityQueryEnumerator(); + var validLocations = new List(); + while (locations.MoveNext(out _, out _, out var transform)) + { + if (CompOrNull(transform.GridUid)?.Station == station) + { + validLocations.Add(transform.Coordinates); + foreach (var spawn in EntitySpawnCollection.GetSpawns(component.Entries, RobustRandom)) + { + Spawn(spawn, transform.Coordinates); + } + } + } + + if (component.SpecialEntries.Count == 0 || validLocations.Count == 0) + { + return; + } + + // guaranteed spawn + var specialEntry = RobustRandom.Pick(component.SpecialEntries); + var specialSpawn = RobustRandom.Pick(validLocations); + Spawn(specialEntry.PrototypeId, specialSpawn); + + foreach (var location in validLocations) + { + foreach (var spawn in EntitySpawnCollection.GetSpawns(component.SpecialEntries, RobustRandom)) + { + Spawn(spawn, location); + } } } } diff --git a/Resources/Prototypes/GameRules/events.yml b/Resources/Prototypes/GameRules/events.yml index d39079aa7d..d05099ffbe 100644 --- a/Resources/Prototypes/GameRules/events.yml +++ b/Resources/Prototypes/GameRules/events.yml @@ -147,7 +147,19 @@ minimumPlayers: 35 weight: 5 duration: 50 - - type: MouseMigrationRule + - type: VentCrittersRule + entries: + - id: MobMouse + prob: 0.015 + - id: MobMouse1 + prob: 0.015 + - id: MobMouse2 + prob: 0.015 + - id: MobRatServant + prob: 0.015 + specialEntries: + - id: SpawnPointGhostRatKing + prob: 0.005 - type: entity id: PowerGridCheck @@ -230,14 +242,11 @@ - type: VentCrittersRule entries: - id: MobMouse - amount: 4 - maxAmount: 12 + prob: 0.02 - id: MobMouse1 - amount: 4 - maxAmount: 12 + prob: 0.02 - id: MobMouse2 - amount: 4 - maxAmount: 12 + prob: 0.02 - type: entity id: SlimesSpawn @@ -251,15 +260,12 @@ duration: 60 - type: VentCrittersRule entries: - - id: MobAdultSlimesBlueAngry - amount: 6 - maxAmount: 10 - - id: MobAdultSlimesGreenAngry - amount: 6 - maxAmount: 10 - - id: MobAdultSlimesYellowAngry - amount: 6 - maxAmount: 10 + - id: MobAdultSlimesBlueAngry + prob: 0.02 + - id: MobAdultSlimesGreenAngry + prob: 0.02 + - id: MobAdultSlimesYellowAngry + prob: 0.02 - type: entity id: SpiderSpawn @@ -273,9 +279,8 @@ duration: 60 - type: VentCrittersRule entries: - - id: MobGiantSpiderAngry - amount: 4 - maxAmount: 8 + - id: MobGiantSpiderAngry + prob: 0.05 - type: entity id: SpiderClownSpawn @@ -289,9 +294,8 @@ duration: 60 - type: VentCrittersRule entries: - - id: MobClownSpider - amount: 4 - maxAmount: 8 + - id: MobClownSpider + prob: 0.05 - type: entity id: ZombieOutbreak