Gestion du dé d'usure des degats des armes, gestion des munitions, gestion de la limute dégats vs DV
Release Creation / build (release) Successful in 1m11s

This commit is contained in:
2026-05-22 09:50:48 +02:00
parent 09f2349bab
commit 6742830f40
31 changed files with 372 additions and 58 deletions
+94 -1
View File
@@ -119,6 +119,87 @@ export class DonjonEtCieUtility {
};
}
static parseDieFormula(formula) {
const normalized = String(formula ?? "").trim();
if (!normalized) return null;
const dieMatch = normalized.match(/(?<count>\d*)d(?<sides>\d+)/i);
if (dieMatch?.groups?.sides) {
return {
formula: normalized,
count: Number(dieMatch.groups.count || 1),
countRaw: dieMatch.groups.count ?? "",
sides: Number(dieMatch.groups.sides),
match: dieMatch[0],
index: dieMatch.index ?? 0
};
}
if (/^\d+$/.test(normalized)) {
const sides = Number(normalized);
if ([4, 6, 8, 10, 12, 20].includes(sides)) {
return {
formula: normalized,
count: 1,
countRaw: "",
sides,
match: normalized,
index: 0
};
}
}
return null;
}
static getMartialDamageContext(actor, item) {
const isUsageDie = Boolean(item?.system?.degatsEstUsageDe);
const degatsDelta = Number(item?.system?.degatsDelta ?? 0);
const baseFormula = isUsageDie
? (degatsDelta > 0 ? `1d${degatsDelta}` : "")
: String(item?.system?.degats ?? "").trim();
const baseContext = {
baseFormula,
effectiveFormula: baseFormula,
capped: false,
martialDvFormula: String(actor?.system?.sante?.dv ?? "").trim(),
martialDvSides: 0,
weaponSides: 0,
isUsageDie
};
if (actor?.type !== "employe" || item?.type !== "arme" || !baseFormula) {
return baseContext;
}
const damageDie = this.parseDieFormula(baseFormula);
const martialDie = this.parseDieFormula(actor.system.sante?.dv);
if (!damageDie || !martialDie?.sides) return baseContext;
const cappedSides = Math.min(damageDie.sides, martialDie.sides);
if (cappedSides >= damageDie.sides) {
return {
...baseContext,
martialDvSides: martialDie.sides,
weaponSides: damageDie.sides
};
}
const replacement = `${damageDie.countRaw || ""}d${cappedSides}`;
const effectiveFormula = damageDie.match === damageDie.formula
? replacement
: `${damageDie.formula.slice(0, damageDie.index)}${replacement}${damageDie.formula.slice(damageDie.index + damageDie.match.length)}`;
return {
...baseContext,
effectiveFormula,
capped: true,
martialDvSides: martialDie.sides,
weaponSides: damageDie.sides
};
}
static getFavorLabel(key) {
return DONJON_ET_CIE.favorDepartments[key] ?? key;
}
@@ -173,12 +254,20 @@ export class DonjonEtCieUtility {
const system = item.system;
const delta = Number(system.delta ?? 0);
const deltaMax = Number(system.deltaMax ?? delta ?? 0);
const ammunitionDelta = Number(system.munitionsDelta ?? 0);
const isUsageDie = Boolean(system.degatsEstUsageDe);
const degatsDelta = Number(system.degatsDelta ?? 0);
const usageLabel = item.type === "entrainement" && deltaMax > 0
? `${this.formatUsageDie(delta)} / ${this.formatUsageDie(deltaMax)}`
: delta > 0
? this.formatUsageDie(delta)
: null;
const damageUsageLabel = isUsageDie
? (degatsDelta > 0 ? this.formatUsageDie(degatsDelta) : game.i18n.localize("DNC.UI.DamageExhausted"))
: null;
const damageLabel = isUsageDie ? damageUsageLabel : (system.degats || null);
return {
id: item.id,
name: item.name,
@@ -187,11 +276,15 @@ export class DonjonEtCieUtility {
system,
uuid: item.uuid,
usageLabel,
ammunitionUsageLabel: item.type === "arme" && ammunitionDelta > 0 ? this.formatUsageDie(ammunitionDelta) : null,
protectionLabel: item.type === "armure" && Number(system.resultatProtection ?? 0) > 0 ? `Protection ${system.resultatProtection}` : null,
weaponCharacteristicLabel: item.type === "arme" ? this.getWeaponCharacteristicLabel(system.categorie) : null,
canRoll: ["arme", "sortilege"].includes(item.type),
canUse: delta > 0,
canRollDamage: Boolean(system.degats),
hasTrackedAmmunition: item.type === "arme" && ammunitionDelta > 0,
damageUsageLabel,
damageLabel,
canRollDamage: item.type === "arme" && (isUsageDie ? degatsDelta > 0 : Boolean(system.degats)),
rollAction: item.type === "sortilege" ? "rollSpell" : "rollWeapon",
damageAction: "rollDamage",
isEquipped: Boolean(system.equipee),