Files
noname-shuying/mengsan/cards/strike-counter.js
T
Diuse c448da39c2 fixed # 补全梦三怪物、卡牌
fixed # 修复天书乱斗中,过关技能不会重置次数的问题
2026-10-03 04:42:19 +08:00

28 lines
1.3 KiB
JavaScript

// Count current actor-owned combat cards; permanent save data is deliberately absent.
export function createStrikeCounter(game, getActiveBattle, lib) {
return (player, event) => {
const battle = getActiveBattle();
if (!battle?.session.active || !player?.isAlive()) return 0;
const piles = player === game.me ? battle.personalPiles : battle.monsterPiles?.get(player);
if (typeof piles?.battleCards !== "function") throw new Error("完美打击缺少个人战斗牌堆接口");
const playing = new Set(event?.cards || []);
const seen = new Set();
for (let parent = event?.parent; parent && !seen.has(parent); parent = parent.parent) {
seen.add(parent);
if (parent.name === "useCard" && parent.player === player) {
for (const card of parent.cards || []) playing.add(card);
}
}
// Nested native attacks may leave earlier originals in the playing zone.
for (const used of player.getHistory?.("useCard") || []) {
for (const card of used.cards || []) playing.add(card);
}
let count = 0;
for (const card of piles.battleCards(playing)) {
const name = lib.translate[card.name];
if (typeof name === "string" && name.includes("打击")) count++;
}
return count;
};
}