Fix challenge rolls
This commit is contained in:
@ -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"
|
||||
}
|
||||
|
Reference in New Issue
Block a user