dvize / Donuts

MIT License
16 stars 12 forks source link

[FR] Progressive backoff for spawns, with optional total match spawn limit #43

Closed GavinRay97 closed 3 months ago

GavinRay97 commented 4 months ago

Yesterday I got pinned down on Scav Island on Shoreline because it kept spawning 2-3 scavs just over the horizon near Village Left with 30 scav kills.

Ideally, I'd love to play where once I've started "thinning the horde" I have to deal with less and less scavs spawning in, until eventually they stop spawning at all (so I can safely loot what I killed, at least).

I didn't get to check most of their bodies because of the continual waves


I'm not familiar with the codebase, but something along the lines of this maybe?

// In "public class DonutComponent"
private int totalScavsKilled = 0;
private int totalSpawnAttempts = 0;
private const int maxScavsKilled = 14;

private bool CanSpawn(HotspotTimer hotspotTimer, Vector3 coordinate)
{
    if (totalScavsKilled >= maxScavsKilled ) return false;

    // Exponential backoff based on spawn attempts
    double spawnProbability = Math.Exp(-0.05 * totalSpawnAttempts) * hotspotTimer.Hotspot.SpawnChance;

    if (BotSpawn.IsWithinBotActivationDistance(hotspotTimer.Hotspot, coordinate) && maplocation == hotspotTimer.Hotspot.MapName)
    {
        if ((hotspotTimer.Hotspot.WildSpawnType == "pmc" && hotspotBoostPMC.Value) ||
            (hotspotTimer.Hotspot.WildSpawnType == "scav" && hotspotBoostSCAV.Value))
        {
            hotspotTimer.Hotspot.SpawnChance = 100;
        }

        return UnityEngine.Random.Range(0, 100) < spawnProbability;
    }

    return false;
}

private async UniTask TriggerSpawn(HotspotTimer hotspotTimer, Vector3 coordinate)
{
    totalSpawnAttempts++;
    // ...
}
p-kossa commented 3 months ago

closing since since there have been major changes since