make sure adventurers for hire don't duplicate on arrival

This commit is contained in:
2025-06-02 20:49:19 +02:00
parent 4de7ac97d1
commit ae65ff9d51
2 changed files with 11 additions and 3 deletions
+6 -2
View File
@@ -4,10 +4,14 @@ import type {Adventurer} from "@/classes/Adventurer";
/**
* Get a random adventurer from the pool
* @param adventurerPool
* @param exceptions
* @returns {Adventurer|null} null if the pool is empty
*/
export function getNewAdventurerForHire(adventurerPool: Array<Adventurer>): Adventurer|null {
export function getNewAdventurerForHire(adventurerPool: Array<Adventurer>, exceptions: Array<Adventurer> = []): Adventurer|null {
if (adventurerPool.length <= 0) return null;
const pool = Array.from(adventurerPool);
const exceptionSet = new Set(exceptions);
pool.filter((adventurer) => !exceptionSet.has(adventurer));
const randomId = adventurerPool.length * Math.random() << 0;
return adventurerPool[randomId];
}
}