Adds optional "maxAmount" parameter to EntitySpawnEntry. (#7721)
This commit is contained in:
committed by
GitHub
parent
1ec56d8309
commit
d161c208cc
@@ -45,9 +45,17 @@ public struct EntitySpawnEntry : IPopulateDefaultValues
|
||||
|
||||
[DataField("amount")] public int Amount;
|
||||
|
||||
/// <summary>
|
||||
/// How many of this can be spawned, in total.
|
||||
/// If this is lesser or equal to <see cref="Amount"/>, it will spawn <see cref="Amount"/> exactly.
|
||||
/// Otherwise, it chooses a random value between <see cref="Amount"/> and <see cref="MaxAmount"/> on spawn.
|
||||
/// </summary>
|
||||
[DataField("maxAmount")] public int MaxAmount;
|
||||
|
||||
public void PopulateDefaultValues()
|
||||
{
|
||||
Amount = 1;
|
||||
MaxAmount = 1;
|
||||
SpawnProbability = 1;
|
||||
}
|
||||
}
|
||||
@@ -100,7 +108,12 @@ public static class EntitySpawnCollection
|
||||
// ReSharper disable once CompareOfFloatsByEqualityOperator
|
||||
if (entry.SpawnProbability != 1f && !random.Prob(entry.SpawnProbability)) continue;
|
||||
|
||||
for (var i = 0; i < entry.Amount; i++)
|
||||
var amount = entry.Amount;
|
||||
|
||||
if (entry.MaxAmount > amount)
|
||||
amount = random.Next(amount, entry.MaxAmount);
|
||||
|
||||
for (var i = 0; i < amount; i++)
|
||||
{
|
||||
spawned.Add(entry.PrototypeId);
|
||||
}
|
||||
@@ -118,7 +131,13 @@ public static class EntitySpawnCollection
|
||||
cumulative += entry.SpawnProbability;
|
||||
if (diceRoll > cumulative) continue;
|
||||
// Dice roll succeeded, add item and break loop
|
||||
for (var index = 0; index < entry.Amount; index++)
|
||||
|
||||
var amount = entry.Amount;
|
||||
|
||||
if (entry.MaxAmount > amount)
|
||||
amount = random.Next(amount, entry.MaxAmount);
|
||||
|
||||
for (var index = 0; index < amount; index++)
|
||||
{
|
||||
spawned.Add(entry.PrototypeId);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user