improve weighted role pick

This commit is contained in:
Gurge44 committed 2026-01-03 11:33:02 +01:00
1 parent f6e866c2b8
commit 464a931df3
2 files changed
+7 -2

No files matched your search

+6 -2
View File
@@ -438,7 +438,11 @@ internal static class CustomRoleSelector
static RoleAssignInfo PickWeighted(List<RoleAssignInfo> pool, IRandom rng)
{
int totalWeight = pool.Sum(t => t.SpawnChance);
int totalWeight = 0;
foreach (var info in pool)
totalWeight += info.SpawnChance * (info.MaxCount - info.AssignedCount);
if (totalWeight <= 0) return null;
int roll = rng.Next(totalWeight);
@@ -446,7 +450,7 @@ internal static class CustomRoleSelector
foreach (var info in pool)
{
cumulative += info.SpawnChance;
cumulative += info.SpawnChance * (info.MaxCount - info.AssignedCount);
if (roll < cumulative) return info;
}
+1
View File
@@ -2,6 +2,7 @@ using System;
using System.Linq;
using AmongUs.GameOptions;
using EHR.Modules;
using EHR.Neutral;
using Hazel;
using UnityEngine;