Fix dice values + miracle/spell roll

This commit is contained in:
2025-01-30 13:40:01 +01:00
parent 560b2eb5ac
commit b78cdb0c10
36 changed files with 160 additions and 91 deletions

View File

@ -117,13 +117,14 @@ export default class LethalFantasyRoll extends Roll {
let dice = "1D20"
let maxValue = 20
let baseFormula = "1D20"
let modifierFormula = "1d0"
let modifierFormula = "1D0"
let hasModifier = true
let hasChangeDice = false
let hasD30 = false
let hasFavor = false
let hasMaxValue = true
let hasGrantedDice = false
let hasStaticModifier = false
if (options.rollType === "challenge" || options.rollType === "save") {
options.rollName = game.i18n.localize(`LETHALFANTASY.Label.${options.rollTarget.rollKey}`)
@ -204,7 +205,7 @@ export default class LethalFantasyRoll extends Roll {
options.rollTarget.charModifier = options.rollTarget.combat.defenseModifier
}
} else if (options.rollType === "spell") {
} else if (options.rollType === "spell" || options.rollType === "spell-attack" || options.rollType === "spell-power") {
hasD30 = true
options.rollName = options.rollTarget.name
dice = "1D20"
@ -214,8 +215,10 @@ export default class LethalFantasyRoll extends Roll {
hasChangeDice = false
options.rollTarget.value = options.rollTarget.actorModifiers.levelSpellModifier + options.rollTarget.actorModifiers.intSpellModifier
options.rollTarget.charModifier = options.rollTarget.actorModifiers.intSpellModifier
hasStaticModifier = options.rollType === "spell-power"
options.rollTarget.staticModifier = options.rollTarget.actorLevel
} else if (options.rollType === "miracle") {
} else if (options.rollType === "miracle" || options.rollType === "miracle-attack" || options.rollType === "spell-power") {
hasD30 = true
options.rollName = options.rollTarget.name
dice = "1D20"
@ -225,6 +228,8 @@ export default class LethalFantasyRoll extends Roll {
hasChangeDice = false
options.rollTarget.value = options.rollTarget.actorModifiers.levelMiracleModifier + options.rollTarget.actorModifiers.chaMiracleModifier
options.rollTarget.charModifier = options.rollTarget.actorModifiers.chaMiracleModifier
hasStaticModifier = options.rollType === "spell-power"
options.rollTarget.staticModifier = options.rollTarget.actorLevel
} else if (options.rollType.includes("weapon-damage")) {
options.rollName = options.rollTarget.name
@ -343,9 +348,12 @@ export default class LethalFantasyRoll extends Roll {
modifierFormula = `${fullModifier}`
} else {
let modAbs = Math.abs(fullModifier)
modifierFormula = `d${modAbs + 1} - 1`
modifierFormula = `D${modAbs + 1} - 1`
}
}
if (hasStaticModifier) {
modifierFormula += ` + ${options.rollTarget.staticModifier}`
}
let sign = fullModifier < 0 ? "-" : "+"
titleFormula = `${dice}E ${sign} ${modifierFormula}`
} else {
@ -407,7 +415,7 @@ export default class LethalFantasyRoll extends Roll {
rollFavor = new this(baseFormula, options.data, rollData)
await rollFavor.evaluate()
if (game?.dice3d) {
await game.dice3d.showForRoll(rollFavor, game.user, true)
game.dice3d.showForRoll(rollFavor, game.user, true)
}
if (rollFavor.result > rollBase.result) {
badResult = rollBase.result
@ -421,7 +429,7 @@ export default class LethalFantasyRoll extends Roll {
rollFavor = new this(baseFormula, options.data, rollData)
await rollFavor.evaluate()
if (game?.dice3d) {
await game.dice3d.showForRoll(rollFavor, game.user, true)
game.dice3d.showForRoll(rollFavor, game.user, true)
}
if (rollFavor.result < rollBase.result) {
badResult = rollBase.result
@ -434,7 +442,7 @@ export default class LethalFantasyRoll extends Roll {
if (hasD30) {
let rollD30 = await new Roll("1D30").evaluate()
if (game?.dice3d) {
await game.dice3d.showForRoll(rollD30, game.user, true)
game.dice3d.showForRoll(rollD30, game.user, true)
}
options.D30result = rollD30.total
}
@ -448,7 +456,7 @@ export default class LethalFantasyRoll extends Roll {
for (let i = 0; i < rollBase.dice.length; i++) {
for (let j = 0; j < rollBase.dice[i].results.length; j++) {
let diceResult = rollBase.dice[i].results[j].result
diceResults.push({ dice: `${singleDice}`, value: diceResult })
diceResults.push({ dice: `${singleDice.toUpperCase()}`, value: diceResult })
diceSum += diceResult
if (hasMaxValue) {
while (diceResult === maxValue) {
@ -457,7 +465,7 @@ export default class LethalFantasyRoll extends Roll {
await game.dice3d.showForRoll(r, game.user, true)
}
diceResult = r.dice[0].results[0].result
diceResults.push({ dice: `${singleDice}-1`, value: diceResult - 1 })
diceResults.push({ dice: `${singleDice.toUpperCase()}-1`, value: diceResult - 1 })
diceSum += (diceResult - 1)
}
}
@ -470,12 +478,12 @@ export default class LethalFantasyRoll extends Roll {
if (game?.dice3d) {
await game.dice3d.showForRoll(grantedRoll, game.user, true)
}
diceResults.push({ dice: `${options.rollTarget.grantedDice}`, value: grantedRoll.total })
diceResults.push({ dice: `${options.rollTarget.grantedDice.toUpperCase()}`, value: grantedRoll.total })
rollTotal += grantedRoll.total
}
if (fullModifier !== 0) {
diceResults.push({ dice: `${rollModifier.formula}`, value: rollModifier.total })
diceResults.push({ dice: `${rollModifier.formula.toUpperCase()}`, value: rollModifier.total })
if (fullModifier < 0) {
rollTotal = Math.max(diceSum - rollModifier.total, 0)
} else {
@ -713,7 +721,7 @@ export default class LethalFantasyRoll extends Roll {
modifierFormula = "0"
} else {
let modAbs = Math.abs(fullModifier)
modifierFormula = `d${modAbs + 1} - 1`
modifierFormula = `D${modAbs + 1} - 1`
}
// If the user cancels the dialog, exit
@ -737,16 +745,16 @@ export default class LethalFantasyRoll extends Roll {
let resultType
let diceResult = rollBase.dice[0].results[0].result
diceResults.push({ dice: `${dice}`, value: diceResult })
diceResults.push({ dice: `${dice.toUpperCase()}`, value: diceResult })
let diceSum = diceResult
while (diceResult === maxValue) {
let r = await new Roll(baseFormula).evaluate()
diceResult = r.dice[0].results[0].result
diceResults.push({ dice: `${dice}-1`, value: diceResult - 1 })
diceResults.push({ dice: `${dice.toUpperCase()}-1`, value: diceResult - 1 })
diceSum += (diceResult - 1)
}
if (fullModifier !== 0) {
diceResults.push({ dice: `${rollModifier.formula}`, value: rollModifier.total })
diceResults.push({ dice: `${rollModifier.formula.toUpperCase()}`, value: rollModifier.total })
if (fullModifier < 0) {
rollTotal = Math.max(diceSum - rollModifier.total, 0)
} else {
@ -802,7 +810,13 @@ export default class LethalFantasyRoll extends Roll {
case "weapon-damage-medium":
return `${game.i18n.localize("LETHALFANTASY.Label.weapon-damage-medium")}`
case "spell":
case "spell-attack":
case "spell-power":
return `${game.i18n.localize("LETHALFANTASY.Label.spell")}`
case "miracle":
case "miracle-attack":
case "miracle-power":
return `${game.i18n.localize("LETHALFANTASY.Label.miracle")}`
default:
return game.i18n.localize("LETHALFANTASY.Label.titleStandard")
}