mirror of
https://github.com/Shu-Ying/noname-shuying.git
synced 2026-10-17 20:59:58 +08:00
fixed # 补全部分卡牌
fixed # 修复部分已知BUG
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
import { validateBattlePlan } from "../battle/battle-director.js";
|
||||
|
||||
export function chooseEncounterEntry(list, random) {
|
||||
if (!Array.isArray(list) || !list.length || typeof random !== "function") {
|
||||
throw new Error("梦三遭遇池为空或缺少随机数接口");
|
||||
}
|
||||
const value = random();
|
||||
if (!Number.isFinite(value) || value < 0 || value >= 1) throw new RangeError("遭遇随机数必须在[0,1)内");
|
||||
return list[Math.floor(value * list.length)];
|
||||
}
|
||||
|
||||
export function createEncounterPlan(definition, random) {
|
||||
if (!definition) throw new Error("梦三遭遇定义不存在");
|
||||
const plan = typeof definition.createBattlePlan === "function"
|
||||
? definition.createBattlePlan(random)
|
||||
: { units: JSON.parse(JSON.stringify(chooseEncounterEntry(definition.variants, random))), rules: [] };
|
||||
return validateBattlePlan(plan);
|
||||
}
|
||||
Reference in New Issue
Block a user