mirror of
https://github.com/Gurge44/EndlessHostRoles.git
synced 2026-10-19 15:51:58 +00:00
improve weighted role pick
This commit is contained in:
1 parent
f6e866c2b8
commit
464a931df3
2 files changed
+7
-2
No files matched your search
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ using System;
|
||||
using System.Linq;
|
||||
using AmongUs.GameOptions;
|
||||
using EHR.Modules;
|
||||
using EHR.Neutral;
|
||||
using Hazel;
|
||||
using UnityEngine;
|
||||
|
||||
|
||||
Reference in new issue
Block a user