Files
noname-shuying/mengsan/cards/packs/index.js
T
Diuse 9e1732d2f8 fixed # 补全部分卡牌
fixed # 修复部分已知BUG
2026-10-04 19:32:38 +08:00

20 lines
1.1 KiB
JavaScript

import { LiuBeiCardPack } from "./liubei/index.js";
import { ColorlessCardPack } from "./colorless/index.js";
// 后续角色各有目录和牌组类,仅在此登记,不扩张 mode-cards.js。
const packTypes = Object.freeze([LiuBeiCardPack,ColorlessCardPack]);
export function createCardPackRuntime(context) {
const result={cards:{},translate:{},skills:{},names:[]}, runtimes=[];
for(const Pack of packTypes){
const runtime=new Pack(context).createRuntime();runtimes.push(runtime);
for(const key of ["cards","skills"]){
for(const name of Object.keys(runtime[key] || {}))if(Object.hasOwn(result[key],name))throw new Error(`重复的牌组定义:${Pack.id}/${name}`);
Object.assign(result[key],runtime[key]);
}
Object.assign(result.translate,runtime.translate);result.names.push(...runtime.names);
}
result.vulnerableBonus=(source,target)=>runtimes.reduce((sum,r)=>sum+(r.vulnerableBonus?.(source,target)||0),0);
result.onDeath=async event=>{for(const runtime of runtimes)await runtime.onDeath?.(event);};
return result;
}