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")]
|
[DataField("entries")]
|
||||||
public List<EntitySpawnEntry> Entries = new();
|
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 Content.Server.StationEvents.Components;
|
||||||
using Robust.Shared.Random;
|
|
||||||
using System.Linq;
|
|
||||||
using Content.Server.GameTicking.Rules.Components;
|
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;
|
namespace Content.Server.StationEvents.Events;
|
||||||
|
|
||||||
@@ -16,23 +18,41 @@ public sealed class VentCrittersRule : StationEventSystem<VentCrittersRuleCompon
|
|||||||
{
|
{
|
||||||
base.Started(uid, component, gameRule, args);
|
base.Started(uid, component, gameRule, args);
|
||||||
|
|
||||||
var spawnChoice = RobustRandom.Pick(component.Entries);
|
if (!TryGetRandomStation(out var station))
|
||||||
// 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 (spawnAmount-- == 0)
|
return;
|
||||||
break;
|
}
|
||||||
|
|
||||||
var coords = Transform(location.Owner);
|
var locations = EntityQueryEnumerator<VentCritterSpawnLocationComponent, TransformComponent>();
|
||||||
Spawn(spawnChoice.PrototypeId, coords.Coordinates);
|
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
|
minimumPlayers: 35
|
||||||
weight: 5
|
weight: 5
|
||||||
duration: 50
|
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
|
- type: entity
|
||||||
id: PowerGridCheck
|
id: PowerGridCheck
|
||||||
@@ -230,14 +242,11 @@
|
|||||||
- type: VentCrittersRule
|
- type: VentCrittersRule
|
||||||
entries:
|
entries:
|
||||||
- id: MobMouse
|
- id: MobMouse
|
||||||
amount: 4
|
prob: 0.02
|
||||||
maxAmount: 12
|
|
||||||
- id: MobMouse1
|
- id: MobMouse1
|
||||||
amount: 4
|
prob: 0.02
|
||||||
maxAmount: 12
|
|
||||||
- id: MobMouse2
|
- id: MobMouse2
|
||||||
amount: 4
|
prob: 0.02
|
||||||
maxAmount: 12
|
|
||||||
|
|
||||||
- type: entity
|
- type: entity
|
||||||
id: SlimesSpawn
|
id: SlimesSpawn
|
||||||
@@ -252,14 +261,11 @@
|
|||||||
- type: VentCrittersRule
|
- type: VentCrittersRule
|
||||||
entries:
|
entries:
|
||||||
- id: MobAdultSlimesBlueAngry
|
- id: MobAdultSlimesBlueAngry
|
||||||
amount: 6
|
prob: 0.02
|
||||||
maxAmount: 10
|
|
||||||
- id: MobAdultSlimesGreenAngry
|
- id: MobAdultSlimesGreenAngry
|
||||||
amount: 6
|
prob: 0.02
|
||||||
maxAmount: 10
|
|
||||||
- id: MobAdultSlimesYellowAngry
|
- id: MobAdultSlimesYellowAngry
|
||||||
amount: 6
|
prob: 0.02
|
||||||
maxAmount: 10
|
|
||||||
|
|
||||||
- type: entity
|
- type: entity
|
||||||
id: SpiderSpawn
|
id: SpiderSpawn
|
||||||
@@ -274,8 +280,7 @@
|
|||||||
- type: VentCrittersRule
|
- type: VentCrittersRule
|
||||||
entries:
|
entries:
|
||||||
- id: MobGiantSpiderAngry
|
- id: MobGiantSpiderAngry
|
||||||
amount: 4
|
prob: 0.05
|
||||||
maxAmount: 8
|
|
||||||
|
|
||||||
- type: entity
|
- type: entity
|
||||||
id: SpiderClownSpawn
|
id: SpiderClownSpawn
|
||||||
@@ -290,8 +295,7 @@
|
|||||||
- type: VentCrittersRule
|
- type: VentCrittersRule
|
||||||
entries:
|
entries:
|
||||||
- id: MobClownSpider
|
- id: MobClownSpider
|
||||||
amount: 4
|
prob: 0.05
|
||||||
maxAmount: 8
|
|
||||||
|
|
||||||
- type: entity
|
- type: entity
|
||||||
id: ZombieOutbreak
|
id: ZombieOutbreak
|
||||||
|
|||||||
Reference in New Issue
Block a user