Fix challenge rolls

This commit is contained in:
2024-12-30 08:52:58 +01:00
parent caf1985081
commit ddf547b959
29 changed files with 128 additions and 79 deletions

View File

@@ -550,6 +550,7 @@
},
"Roll": {
"save": "Save roll {save}",
"changeDice": "Change dice",
"damage": "Jet de dégâts <br> {item}",
"attack": "Jet d'attaque <br> {item}",
"roll": "Roll",

View File

@@ -67,6 +67,51 @@ export const DEFENSE_DICE_VALUES = {
"d10": "D10"
}
export const CHOICE_DICE = {
"D4": "D4",
"D6": "D6",
"D8": "D8",
"D10": "D10"
}
export const CHOICE_MODIFIERS = {
"-9": "-9",
"-8": "-8",
"-7": "-7",
"-6": "-6",
"-5": "-5",
"-4": "-4",
"-3": "-3",
"-2": "-2",
"-1": "-1",
"+0": "0",
"+1": "+1",
"+2": "+2",
"+3": "+3",
"+4": "+4",
"+5": "+5",
"+6": "+6",
"+7": "+7",
"+8": "+8",
"+9": "+9",
"+10": "+10",
"+11": "+11",
"+12": "+12",
"+13": "+13",
"+14": "+14",
"+15": "+15",
"+16": "+16",
"+17": "+17",
"+18": "+18",
"+19": "+19",
"+20": "+20",
"+21": "+21",
"+22": "+22",
"+23": "+23",
"+24": "+24",
"+25": "+25"
}
export const ASCII = `
······················································································································
: :
@@ -101,5 +146,7 @@ export const SYSTEM = {
MONEY,
ASCII,
ROLL_TYPE,
CHOICE_MODIFIERS,
CHOICE_DICE,
DEV_MODE,
}

View File

@@ -1,4 +1,4 @@
import { ROLL_TYPE } from "../config/system.mjs"
import { ROLL_TYPE, SYSTEM } from "../config/system.mjs"
import LethalFantasyUtils from "../utils.mjs"
export default class LethalFantasyRoll extends Roll {
@@ -165,16 +165,20 @@ export default class LethalFantasyRoll extends Roll {
* @returns {Promise<Object|null>} The roll result or null if the dialog was cancelled.
*/
static async prompt(options = {}) {
let dice = "1d20"
let dice = "1D20"
let maxValue = 20
let formula = "1d20"
let formula = "1D20"
let hasModifier = true
let hasChangeDice = false
if (options.rollType === "challenge") {
if ( options.rollTarget.rollKey === "dying") {
dice = options.rollTarget.value
maxValue = Number(options.rollTarget.value.match(/\d+/)[0])
formula = `${dice}`
hasModifier = false
hasChangeDice = true
} else {
dice = "1d20"
dice = "1D20"
maxValue = 20
}
}
@@ -186,43 +190,9 @@ export default class LethalFantasyRoll extends Roll {
default: "public",
})
const choiceModifier = {
"-9": "-9",
"-8": "-8",
"-7": "-7",
"-6": "-6",
"-5": "-5",
"-4": "-4",
"-3": "-3",
"-2": "-2",
"-1": "-1",
"+0": "0",
"+1": "+1",
"+2": "+2",
"+3": "+3",
"+4": "+4",
"+5": "+5",
"+6": "+6",
"+7": "+7",
"+8": "+8",
"+9": "+9",
"+10": "+10",
"+11": "+11",
"+12": "+12",
"+13": "+13",
"+14": "+14",
"+15": "+15",
"+16": "+16",
"+17": "+17",
"+18": "+18",
"+19": "+19",
"+20": "+20",
"+21": "+21",
"+22": "+22",
"+23": "+23",
"+24": "+24",
"+25": "+25"
}
const choiceModifier = SYSTEM.CHOICE_MODIFIERS
const choiceDice = SYSTEM.CHOICE_DICE
let modifier = "+0"
let targetName
@@ -232,8 +202,13 @@ export default class LethalFantasyRoll extends Roll {
isChallenge: options.rollType === "challenge",
rollTarget: options.rollTarget,
rollModes,
hasModifier,
hasChangeDice,
baseValue: options.rollTarget.value,
changeDice: `${dice}`,
fieldRollMode,
choiceModifier,
choiceDice,
formula,
dice,
hasTarget: options.hasTarget,
@@ -268,18 +243,25 @@ export default class LethalFantasyRoll extends Roll {
let treshold
let fullModifier = 0
dice = rollContext.changeDice || dice
if (options.rollType === "challenge") {
let bonus = (options.rollTarget.rollKey === "dying") ? 0 : options.rollTarget.bonus
fullModifier = rollContext.modifier === "" ? 0 : parseInt(rollContext.modifier, 10) + bonus
if (fullModifier < 0) {
let modAbs = Math.abs(fullModifier)
formula = `${dice} - (d${modAbs + 1} - 1)`
} else if (fullModifier > 0) {
formula = `${dice} + (d${fullModifier + 1} - 1)`
if (hasModifier) {
let bonus = (options.rollTarget.rollKey === "dying") ? 0 : Number(options.rollTarget.value)
fullModifier = rollContext.modifier === "" ? 0 : parseInt(rollContext.modifier, 10) + bonus
if (fullModifier < 0) {
let modAbs = Math.abs(fullModifier)
formula = `${dice} - (d${modAbs + 1} - 1)`
} else if (fullModifier > 0) {
formula = `${dice} + (d${fullModifier + 1} - 1)`
} else {
formula = `${dice} + 1d0`
}
} else {
formula = `${dice} + 1d0`
fullModifier = 0
formula = `${dice}`
}
}
maxValue = Number(dice.match(/\d+/)[0])
const rollData = {
type: options.rollType,
@@ -319,10 +301,13 @@ export default class LethalFantasyRoll extends Roll {
diceResults.push( {dice: `${dice}-1`, value: d20result-1})
d20sum += (d20result - 1)
}
let minus1 = (fullModifier === 0) ? 0 : 1
diceResults.push({ dice: `${roll.dice[1].formula}-${minus1}`, value: roll.dice[1].results[0].result - minus1 })
rollTotal = Math.max(d20sum + roll.dice[1].results[0].result - minus1, 0)
if (hasModifier) {
let minus1 = (fullModifier === 0) ? 0 : 1
diceResults.push({ dice: `${roll.dice[1].formula}-${minus1}`, value: roll.dice[1].results[0].result - minus1 })
rollTotal = Math.max(d20sum + roll.dice[1].results[0].result - minus1, 0)
} else {
rollTotal = d20sum
}
} else if (options.rollType === ROLL_TYPE.RESOURCE) {
//resultType = roll.total === 1 || roll.total === 2 ? "failure" : "success"
}

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
packs/lf-gifts/MANIFEST-000038 LFS Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
packs/lf-skills/MANIFEST-000042 LFS Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -6,7 +6,7 @@
"download": "#{DOWNLOAD}#",
"url": "#{URL}#",
"license": "LICENSE",
"version": "12.0.9",
"version": "12.0.10",
"authors": [
{
"name": "Uberwald",

View File

@@ -4,15 +4,31 @@
{{#if isChallenge}}
<fieldSet>
<legend>{{localize "LETHALFANTASY.Label.challenge"}}</legend>
{{log this}}
{{#if hasModifier}}
<div class="dialog-save">{{upperCase rollTarget.rollKey}} : {{formula}} + {{baseValue}}</div>
{{else}}
<div class="dialog-save">{{upperCase rollTarget.rollKey}} : {{formula}}</div>
{{/if}}
</fieldSet>
{{#if hasModifier}}
<fieldSet class="dialog-modifier">
<legend>{{localize "LETHALFANTASY.Roll.modifier"}}</legend>
<select name="modifier" data-tooltip-direction="UP">
{{selectOptions choiceModifier selected=modifier}}
</select>
</fieldSet>
{{/if}}
{{#if hasChangeDice}}
<fieldSet class="dialog-modifier">
<legend>{{localize "LETHALFANTASY.Roll.changeDice"}}</legend>
<select name="changeDice" data-tooltip-direction="UP">
{{selectOptions choiceDice selected=changeDice}}
</select>
</fieldSet>
{{/if}}
{{/if}}
<fieldSet>
<legend>{{localize "LETHALFANTASY.Roll.visibility"}}</legend>