diff --git a/module/system/dialogs/rollDialog.mjs b/module/system/dialogs/rollDialog.mjs index dbba353..68b1ff9 100644 --- a/module/system/dialogs/rollDialog.mjs +++ b/module/system/dialogs/rollDialog.mjs @@ -121,7 +121,8 @@ export default class RollDialog extends HandlebarsApplicationMixin(foundry.appli const specChecked = this.#el.querySelector("#usingSpecialization")?.checked; const helped = this.#el.querySelector("#helped")?.checked; const tools = this.#el.querySelector("input[name='usingTools']:checked")?.value !== "0"; - const bonuses = (specChecked ? 1 : 0) + (helped ? 1 : 0) + (tools ? 1 : 0); + const group = parseInt(this.#el.querySelector("#group")?.value, 10) || 0; + const bonuses = (specChecked ? 1 : 0) + (helped ? 1 : 0) + (tools ? 1 : 0) + group; return (abilVal + sc + skillPool + bonuses) || 0; } @@ -212,10 +213,6 @@ export default class RollDialog extends HandlebarsApplicationMixin(foundry.appli b += parseInt(this.#getSelfCtrl()?.value, 10) || 0; const tools = this.#el.querySelector("input[name='usingTools']:checked"); if (tools && tools.value !== "0") b += 1; - const human = this.#el.querySelector("#human-totem"); - if (human?.checked) b += parseInt(this.#actor?.system?.adaptation?.totems?.human?.value, 10) || 0; - const adapted = this.#el.querySelector("#adapted-totem"); - if (adapted?.checked) b += parseInt(this.#actor?.system?.adaptation?.totems?.adapted?.value, 10) || 0; if (this.hasSpecialtySelected()) b += 1; return b; } diff --git a/module/system/handlebars-manager.mjs b/module/system/handlebars-manager.mjs index c458a7d..f161dfd 100644 --- a/module/system/handlebars-manager.mjs +++ b/module/system/handlebars-manager.mjs @@ -388,4 +388,15 @@ export const registerHandlebarsHelpers = function () { Handlebars.registerHelper("setVar", function (varName, varValue, options) { options.data.root[varName] = varValue; }); + + // assign local variables in the current context (used by roll-message.hbs) + Handlebars.registerHelper("set", function (options) { + const ctx = (this && typeof this === "object") ? this : options.contexts?.[0]; + if ( ctx && typeof ctx === "object" ) { + for ( const [key, value] of Object.entries(options.hash) ) { + ctx[key] = value; + } + } + return ""; + }); } \ No newline at end of file diff --git a/module/system/roll.mjs b/module/system/roll.mjs index 1fa7f86..5a688ea 100644 --- a/module/system/roll.mjs +++ b/module/system/roll.mjs @@ -49,22 +49,13 @@ export class VermineUtils { totemBonus = this._calculateTotemDomainBonuses(skillCategory, actor); } - // Apply auto-successes and auto-thresholds - let autoSuccesses = 0; + // Apply automatic successes from skill mastery let adjustedDifficulty = difficulty; - if (skillLevel !== null && skillLevel !== undefined) { - autoSuccesses = this._calculateAutoSuccesses(skillLevel, hasSpecialty); - const autoThreshold = this._getAutoThreshold(skillLevel); - if (autoThreshold !== null) { - adjustedDifficulty = autoThreshold; - } - } - // Handle human totem if (totems.human) { NoD--; - const humanDifficulty = skillLevel !== null ? Math.max(adjustedDifficulty, difficulty) : adjustedDifficulty; + const humanDifficulty = adjustedDifficulty; const humanFormula = `(1D10cs>=${humanDifficulty}[human_${safeUserName}]*2)`; // Apply domain bonus/malus @@ -78,7 +69,7 @@ export class VermineUtils { // Handle adapted totem if (totems.adapted) { NoD--; - const adaptedDifficulty = skillLevel !== null ? Math.max(adjustedDifficulty, difficulty) : adjustedDifficulty; + const adaptedDifficulty = adjustedDifficulty; const adaptedFormula = `(1D10cs>=${adaptedDifficulty}[adapted_${safeUserName}]*2)`; // Apply domain bonus/malus @@ -105,8 +96,8 @@ export class VermineUtils { } } - // Apply handicap (wounds/maluses reduce dice pool) - NoD = Math.max(1, NoD - handicap) + // Ensure the dice pool cannot go below zero + NoD = Math.max(0, NoD) // Build base formula const baseFormula = `${NoD}d10cs>=${adjustedDifficulty}[regular_${safeUserName}]`; @@ -126,7 +117,6 @@ export class VermineUtils { skillCategory: skillCategory, skillLevel: skillLevel, hasSpecialty: hasSpecialty, - autoSuccesses: autoSuccesses, totemBonuses: { ...totemBonus }, baseNoD: NoD, rerolls: Reroll, @@ -205,63 +195,6 @@ export class VermineUtils { return bonuses; } - /** - * Calculates automatic successes based on skill mastery level. - * @param {number} skillLevel - Skill level (0-5) - * @param {boolean} [hasSpecialty=false] - Whether a specialty is used - * @returns {number} Number of automatic successes - */ - static _calculateAutoSuccesses(skillLevel, hasSpecialty = false) { - // According to Vermine2047 rules, automatic successes are based on mastery level: - // Level 0 (Incompetent): 0 automatic successes - // Level 1 (Beginner): 0 automatic successes - // Level 2 (Proficient): 1 automatic success if specialty is used - // Level 3 (Expert): 1 automatic success - // Level 4 (Master): 1 automatic success + 1 if specialty is used - // Level 5 (Legend): 2 automatic successes - - if (!skillLevel) return 0; - - let autoSuccesses = 0; - - switch (skillLevel) { - case 2: // Compétent - if (hasSpecialty) autoSuccesses = 1; - break; - case 3: // Expert - autoSuccesses = 1; - break; - case 4: // Maître - autoSuccesses = 1; - if (hasSpecialty) autoSuccesses += 1; - break; - case 5: // Légende - autoSuccesses = 2; - break; - default: - autoSuccesses = 0; - } - - return autoSuccesses; - } - - /** - * Determines the automatic threshold if the skill is not mastered. - * @param {number} skillLevel - Skill level - * @returns {number|null} Automatic threshold or null if skill is mastered - */ - static _getAutoThreshold(skillLevel) { - // If the skill is not mastered (level 0 or 1), use a default threshold - // Level 0 (Incompetent): threshold = 9 (very hard) - // Level 1 (Beginner): threshold = 7 (hard) - // Level >= 2: null (use normal threshold) - - if (skillLevel === 0) return 9; // Very hard - if (skillLevel === 1) return 7; // Hard - - return null; // Utiliser le seuil normal - } - /** * Handles reroll events on dice in chat messages. * @param {Object} message - The chat message containing the reroll event diff --git a/templates/dialogs/roll-dialog.hbs b/templates/dialogs/roll-dialog.hbs index d74475d..82ac445 100644 --- a/templates/dialogs/roll-dialog.hbs +++ b/templates/dialogs/roll-dialog.hbs @@ -280,7 +280,7 @@ class="totem-checkbox" /> {{localize 'TOTEMS.human.name'}} - (+{{@root.actor.system.adaptation.totems.human.value}}D) + ({{@root.actor.system.adaptation.totems.human.value}}D) {{localize 'VERMINE.totem_hint'}} @@ -309,7 +309,7 @@ value="1" /> {{localize 'TOTEMS.human.name'}} - (+{{@root.actor.system.adaptation.totems.human.value}}D) + ({{@root.actor.system.adaptation.totems.human.value}}D) {{/ifgt}} @@ -326,7 +326,7 @@ value="1" /> {{localize 'TOTEMS.adapted.name'}} - (+{{@root.actor.system.adaptation.totems.adapted.value}}D) + ({{@root.actor.system.adaptation.totems.adapted.value}}D) {{/ifgt}} diff --git a/templates/roll-message.hbs b/templates/roll-message.hbs index ac3b32e..83e8b52 100644 --- a/templates/roll-message.hbs +++ b/templates/roll-message.hbs @@ -6,6 +6,7 @@ {{param.difficulty}} +

{{localize "VERMINE.rerolls_possible"}} : {{param.Reroll}}

@@ -56,7 +57,7 @@

{{localize "VERMINE.success_required"}}:

- {{param.handicap}} + {{math_add 1 param.handicap}}
\ No newline at end of file