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
This commit is contained in:
@@ -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<string> SpawnedPrototypeChoices = new() //we double up for that ez fake probability
|
||||
{
|
||||
"MobMouse",
|
||||
"MobMouse1",
|
||||
"MobMouse2",
|
||||
"MobRatServant"
|
||||
};
|
||||
}
|
||||
@@ -8,4 +8,10 @@ public sealed class VentCrittersRuleComponent : Component
|
||||
{
|
||||
[DataField("entries")]
|
||||
public List<EntitySpawnEntry> Entries = new();
|
||||
|
||||
/// <summary>
|
||||
/// At least one special entry is guaranteed to spawn
|
||||
/// </summary>
|
||||
[DataField("specialEntries")]
|
||||
public List<EntitySpawnEntry> SpecialEntries = new();
|
||||
}
|
||||
|
||||
@@ -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<MouseMigrationRuleComponent>
|
||||
{
|
||||
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<VentCritterSpawnLocationComponent, TransformComponent>().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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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<VentCrittersRuleCompon
|
||||
{
|
||||
base.Started(uid, component, gameRule, args);
|
||||
|
||||
var spawnChoice = RobustRandom.Pick(component.Entries);
|
||||
// TODO: What we should actually do is take the component count and then multiply a prob by that
|
||||
// then just iterate until we get it
|
||||
// This will be on average twice as fast.
|
||||
var spawnLocations = EntityManager.EntityQuery<VentCritterSpawnLocationComponent>().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<VentCritterSpawnLocationComponent, TransformComponent>();
|
||||
var validLocations = new List<EntityCoordinates>();
|
||||
while (locations.MoveNext(out _, out _, out var transform))
|
||||
{
|
||||
if (CompOrNull<StationMemberComponent>(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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user