IMprove tresor management
Release Creation / build (release) Successful in 1m40s

This commit is contained in:
2026-07-07 21:21:50 +02:00
parent ce5dbebd76
commit fdbbda28f4
68 changed files with 529 additions and 178 deletions
+61 -14
View File
@@ -955,6 +955,11 @@ var CharacterDataModel = class extends foundry.abstract.TypeDataModel {
threetreasures: new fields.SchemaField({
heiyang: new fields.SchemaField({ value: numberField(0, { min: 0 }), max: numberField(0, { min: 0 }) }),
heiyin: new fields.SchemaField({ value: numberField(0, { min: 0 }), max: numberField(0, { min: 0 }) }),
recoverybonus: new fields.SchemaField({
san: boolField(),
zing: boolField(),
hei: boolField()
}),
dicelevel: new fields.SchemaField({
level0d: treasureLevel(),
level1d: treasureLevel(),
@@ -2437,34 +2442,75 @@ var CDECharacterSheet = class _CDECharacterSheet extends CDEBaseActorSheet {
const results = roll.dice[0].results.map((r) => r.result);
const evenCount = results.filter((r) => r % 2 === 0).length;
const oddCount = results.filter((r) => r % 2 !== 0).length;
const boostSan = sys.threetreasures?.recoverybonus?.san ?? false;
const boostZing = sys.threetreasures?.recoverybonus?.zing ?? false;
const boostHei = sys.threetreasures?.recoverybonus?.hei ?? false;
const applyBoost = (count, enabled) => enabled && count > 0 ? count + 1 : count;
const sanTotal = applyBoost(evenCount, boostSan);
const zingTotal = applyBoost(oddCount, boostZing);
const heiYangCount = applyBoost(evenCount, boostHei);
const heiYinCount = applyBoost(oddCount, boostHei);
const cap = (max) => max > 0 ? max : Infinity;
const heiYang = Math.min(
(sys.threetreasures?.heiyang?.value ?? 0) + evenCount,
(sys.threetreasures?.heiyang?.value ?? 0) + heiYangCount,
cap(sys.threetreasures?.heiyang?.max)
);
const heiYin = Math.min(
(sys.threetreasures?.heiyin?.value ?? 0) + oddCount,
(sys.threetreasures?.heiyin?.value ?? 0) + heiYinCount,
cap(sys.threetreasures?.heiyin?.max)
);
const san = Math.min(
(sys.threetreasures?.dicelevel?.level0d?.san?.value ?? 0) + evenCount,
cap(sys.threetreasures?.dicelevel?.level0d?.san?.max)
);
const zing = Math.min(
(sys.threetreasures?.dicelevel?.level0d?.zing?.value ?? 0) + oddCount,
cap(sys.threetreasures?.dicelevel?.level0d?.zing?.max)
);
const poolDeltas = {
level2d: { san: 0, zing: 0 },
level1d: { san: 0, zing: 0 },
level0d: { san: 0, zing: 0 }
};
const fillPool = (branch, count) => {
let remaining = count;
for (const key of ["level2d", "level1d", "level0d"]) {
const slot = sys.threetreasures?.dicelevel?.[key]?.[branch];
if (!slot) continue;
const space = cap(slot.max) - (slot.value ?? 0);
if (space <= 0) continue;
const toAdd = Math.min(remaining, space);
remaining -= toAdd;
poolDeltas[key][branch] = toAdd;
if (remaining <= 0) break;
}
return count - remaining;
};
fillPool("san", sanTotal);
fillPool("zing", zingTotal);
await actor.update({
"system.threetreasures.heiyang.value": heiYang,
"system.threetreasures.heiyin.value": heiYin,
"system.threetreasures.dicelevel.level0d.san.value": san,
"system.threetreasures.dicelevel.level0d.zing.value": zing
"system.threetreasures.dicelevel.level2d.san.value": (sys.threetreasures?.dicelevel?.level2d?.san?.value ?? 0) + poolDeltas.level2d.san,
"system.threetreasures.dicelevel.level2d.zing.value": (sys.threetreasures?.dicelevel?.level2d?.zing?.value ?? 0) + poolDeltas.level2d.zing,
"system.threetreasures.dicelevel.level1d.san.value": (sys.threetreasures?.dicelevel?.level1d?.san?.value ?? 0) + poolDeltas.level1d.san,
"system.threetreasures.dicelevel.level1d.zing.value": (sys.threetreasures?.dicelevel?.level1d?.zing?.value ?? 0) + poolDeltas.level1d.zing,
"system.threetreasures.dicelevel.level0d.san.value": (sys.threetreasures?.dicelevel?.level0d?.san?.value ?? 0) + poolDeltas.level0d.san,
"system.threetreasures.dicelevel.level0d.zing.value": (sys.threetreasures?.dicelevel?.level0d?.zing?.value ?? 0) + poolDeltas.level0d.zing
});
const rollLabel = `${game.i18n.localize("CDE.Recovery")} \u2014 ${aspectLabel}`;
const diceStr = results.join(" \xB7 ");
const typeOfThrow = Number(sys.prefs?.typeofthrow?.choice ?? 0);
const ROLL_MODES2 = ["roll", "gmroll", "blindroll", "selfroll"];
const rollMode = ROLL_MODES2[typeOfThrow] ?? "roll";
const poolLine = (key, label) => {
const s = poolDeltas[key].san;
const z = poolDeltas[key].zing;
if (!s && !z) return "";
return `<div class="cde-chat-recovery-pool-row">${label} \u2192 San +${s}, Zing +${z}</div>`;
};
const poolRows = [
poolLine("level2d", "\u22122 d\xE9s"),
poolLine("level1d", "\u22121 d\xE9"),
poolLine("level0d", "0 d\xE9")
].filter(Boolean).join("");
const poolBoostHtml = [
boostSan ? `<div class="cde-chat-recovery-pool-boost">+1 ${game.i18n.localize("CDE.RecoveryBoostSan")}</div>` : "",
boostZing ? `<div class="cde-chat-recovery-pool-boost">+1 ${game.i18n.localize("CDE.RecoveryBoostZing")}</div>` : ""
].filter(Boolean).join("");
const poolHtml = poolBoostHtml + poolRows;
await ChatMessage.create({
user: game.user.id,
speaker: ChatMessage.getSpeaker({ actor }),
@@ -2482,14 +2528,15 @@ var CDECharacterSheet = class _CDECharacterSheet extends CDEBaseActorSheet {
<div class="cde-chat-recovery-even">
<span class="cde-chat-recovery-count">${evenCount}</span>
<span><strong>${game.i18n.localize("CDE.RecoveryEvenLabel")}</strong></span>
<span>\u2192 +${evenCount} Hei Yang, +${evenCount} San</span>
<span>\u2192 Hei Yang +${heiYangCount}${heiYang !== (sys.threetreasures?.heiyang?.value ?? 0) + heiYangCount ? ` (${game.i18n.localize("CDE.ClampedTo")} ${sys.threetreasures?.heiyang?.max})` : ""}${boostHei && evenCount > 0 ? ` (+1 ${game.i18n.localize("CDE.RecoveryBoostHeiLabel")})` : ""}</span>
</div>
<div class="cde-chat-recovery-odd">
<span class="cde-chat-recovery-count">${oddCount}</span>
<span><strong>${game.i18n.localize("CDE.RecoveryOddLabel")}</strong></span>
<span>\u2192 +${oddCount} Hei Yin, +${oddCount} Zing</span>
<span>\u2192 Hei Yin +${heiYinCount}${heiYin !== (sys.threetreasures?.heiyin?.value ?? 0) + heiYinCount ? ` (${game.i18n.localize("CDE.ClampedTo")} ${sys.threetreasures?.heiyin?.max})` : ""}${boostHei && oddCount > 0 ? ` (+1 ${game.i18n.localize("CDE.RecoveryBoostHeiLabel")})` : ""}</span>
</div>
</div>
<div class="cde-chat-recovery-pools">${poolHtml}</div>
</div>`,
rolls: [roll],
rollMode
+2 -2
View File
File diff suppressed because one or more lines are too long