diff --git a/lang/en.json b/lang/en.json index c62d621..7007ad5 100644 --- a/lang/en.json +++ b/lang/en.json @@ -168,6 +168,7 @@ "DG.Roll.For": "For", "DG.Roll.Damage": "Damage", "DG.Roll.Roll": "Roll", + "DG.Roll.CannotRollStat": "A statistic of 0 cannot be rolled.", "DG.Physical.Wounds": "Wounds", "DG.Physical.FirstAidLabel": "First Aid Has Already Been Attempted: ", "DG.Physical.ExhaustionPenalty": "Penalty:", diff --git a/module/roll/classes/dg-percentile-roll.js b/module/roll/classes/dg-percentile-roll.js index 57106a6..a247b81 100644 --- a/module/roll/classes/dg-percentile-roll.js +++ b/module/roll/classes/dg-percentile-roll.js @@ -255,6 +255,20 @@ export class DGPercentileRoll extends DGRoll { return { target, localizedKey, skillPath }; } + /** + * i18n key for a user-facing warning when this roll must not be made, or null if allowed. + * @returns {string|null} + */ + get blockedRollMessage() { + if (this.type !== "stat") return null; + + const x5 = Number(this.target); + if (!Number.isFinite(x5) || x5 < 1) { + return "DG.Roll.CannotRollStat"; + } + return null; + } + /** * Create label based on result of roll * @@ -392,7 +406,7 @@ export class DGPercentileRoll extends DGRoll { const { rollTargetModifier } = this; - if (!this.target || Number.isNaN(this.target)) { + if (this.target == null || Number.isNaN(this.target)) { return null; } diff --git a/module/roll/roll.js b/module/roll/roll.js index d622b66..e1ff5c5 100644 --- a/module/roll/roll.js +++ b/module/roll/roll.js @@ -100,6 +100,11 @@ export async function processDGRoll(event, roll) { const shiftKey = event?.shiftKey ?? false; const which = event?.which ?? 0; + if (roll instanceof DGPercentileRoll && roll.blockedRollMessage) { + ui.notifications.warn(roll.blockedRollMessage, { localize: true }); + return; + } + if (shiftKey || which === 3) { if (!(roll instanceof DGSanityDamageRoll)) { const dialogData = await roll.showDialog(); diff --git a/module/sheets/mixins/roll-sheet-mixin.js b/module/sheets/mixins/roll-sheet-mixin.js index 7367ac4..0f6edcb 100644 --- a/module/sheets/mixins/roll-sheet-mixin.js +++ b/module/sheets/mixins/roll-sheet-mixin.js @@ -36,8 +36,14 @@ export default function RollSheetMixin(Base) { * @private */ static async _onRoll(event, target) { - if (target.classList.contains("not-rollable") || event.which === 2) + if (event.which === 2) return; + + if (target.classList.contains("not-rollable")) { + if (target.dataset.rolltype === "stat") { + ui.notifications.warn("DG.Roll.CannotRollStat", { localize: true }); + } return; + } const item = this.actor.items.get(target.dataset.iid); const roll = createDGRollFromDataset(target.dataset, { diff --git a/templates/actor/partials/attributes-grid-partial.html b/templates/actor/partials/attributes-grid-partial.html index 6d9a53c..72802f4 100644 --- a/templates/actor/partials/attributes-grid-partial.html +++ b/templates/actor/partials/attributes-grid-partial.html @@ -7,7 +7,7 @@
-