Add D30, spells, miracles and ranged defense roll
This commit is contained in:
@ -88,6 +88,10 @@ export default class LethalFantasyRoll extends Roll {
|
||||
return this.options.rollTarget
|
||||
}
|
||||
|
||||
get D30result() {
|
||||
return this.options.D30result
|
||||
}
|
||||
|
||||
/**
|
||||
* Prompt the user with a dialog to configure and execute a roll.
|
||||
*
|
||||
@ -112,8 +116,11 @@ export default class LethalFantasyRoll extends Roll {
|
||||
let modifierFormula = "1d0"
|
||||
let hasModifier = true
|
||||
let hasChangeDice = false
|
||||
let hasD30 = false
|
||||
|
||||
if (options.rollType === "challenge" || options.rollType === "save") {
|
||||
options.rollName = options.rollTarget.rollKey
|
||||
hasD30 = options.rollType === "save"
|
||||
if (options.rollTarget.rollKey === "dying") {
|
||||
dice = options.rollTarget.value
|
||||
maxValue = Number(options.rollTarget.value.match(/\d+/)[0])
|
||||
@ -123,6 +130,7 @@ export default class LethalFantasyRoll extends Roll {
|
||||
dice = "1D20"
|
||||
maxValue = 20
|
||||
}
|
||||
|
||||
} else if (options.rollType === "skill") {
|
||||
options.rollName = options.rollTarget.name
|
||||
dice = "1D100"
|
||||
@ -131,7 +139,9 @@ export default class LethalFantasyRoll extends Roll {
|
||||
hasModifier = true
|
||||
hasChangeDice = false
|
||||
options.rollTarget.value = options.rollTarget.system.skillTotal
|
||||
|
||||
} else if (options.rollType === "weapon-attack" || options.rollType === "weapon-defense") {
|
||||
hasD30 = true
|
||||
options.rollName = options.rollTarget.name
|
||||
dice = "1D20"
|
||||
baseFormula = "D20"
|
||||
@ -145,6 +155,29 @@ export default class LethalFantasyRoll extends Roll {
|
||||
options.rollTarget.value = options.rollTarget.combat.defenseModifier + options.rollTarget.weaponSkillModifier
|
||||
options.rollTarget.charModifier = options.rollTarget.combat.defenseModifier
|
||||
}
|
||||
|
||||
} else if (options.rollType === "spell") {
|
||||
hasD30 = true
|
||||
options.rollName = options.rollTarget.name
|
||||
dice = "1D20"
|
||||
baseFormula = "D20"
|
||||
maxValue = 20
|
||||
hasModifier = true
|
||||
hasChangeDice = false
|
||||
options.rollTarget.value = options.rollTarget.actorModifiers.levelSpellModifier + options.rollTarget.actorModifiers.intSpellModifier
|
||||
options.rollTarget.charModifier = options.rollTarget.actorModifiers.intSpellModifier
|
||||
|
||||
} else if (options.rollType === "miracle") {
|
||||
hasD30 = true
|
||||
options.rollName = options.rollTarget.name
|
||||
dice = "1D20"
|
||||
baseFormula = "D20"
|
||||
maxValue = 20
|
||||
hasModifier = true
|
||||
hasChangeDice = false
|
||||
options.rollTarget.value = options.rollTarget.actorModifiers.levelMiracleModifier + options.rollTarget.actorModifiers.chaMiracleModifier
|
||||
options.rollTarget.charModifier = options.rollTarget.actorModifiers.chaMiracleModifier
|
||||
|
||||
} else if (options.rollType.includes("weapon-damage")) {
|
||||
options.rollName = options.rollTarget.name
|
||||
hasModifier = true
|
||||
@ -174,7 +207,6 @@ export default class LethalFantasyRoll extends Roll {
|
||||
default: "public",
|
||||
})
|
||||
|
||||
|
||||
const choiceModifier = SYSTEM.CHOICE_MODIFIERS
|
||||
const choiceDice = SYSTEM.CHOICE_DICE
|
||||
|
||||
@ -197,6 +229,7 @@ export default class LethalFantasyRoll extends Roll {
|
||||
dice,
|
||||
hasTarget: options.hasTarget,
|
||||
modifier,
|
||||
saveSpell: false,
|
||||
targetName
|
||||
}
|
||||
console.log("dialogContext", dialogContext)
|
||||
@ -230,8 +263,10 @@ export default class LethalFantasyRoll extends Roll {
|
||||
let titleFormula = ""
|
||||
dice = rollContext.changeDice || dice
|
||||
if (hasModifier) {
|
||||
let bonus = Number(options.rollTarget.value)
|
||||
let bonus = Number(options.rollTarget.value)
|
||||
fullModifier = rollContext.modifier === "" ? 0 : parseInt(rollContext.modifier, 10) + bonus
|
||||
fullModifier += (rollContext.saveSpell) ? options.rollTarget.actorModifiers.saveModifier : 0
|
||||
|
||||
if (fullModifier === 0) {
|
||||
modifierFormula = "0"
|
||||
} else {
|
||||
@ -282,13 +317,18 @@ export default class LethalFantasyRoll extends Roll {
|
||||
if (Hooks.call("fvtt-lethal-fantasy.preRoll", options, rollData) === false) return
|
||||
|
||||
const rollBase = new this(baseFormula, options.data, rollData)
|
||||
await rollBase.evaluate()
|
||||
const rollModifier = new Roll(modifierFormula, options.data, rollData)
|
||||
await rollModifier.evaluate()
|
||||
rollModifier.evaluate()
|
||||
await rollBase.evaluate()
|
||||
if (hasD30) {
|
||||
let rollD30 = await new Roll("1D30").evaluate()
|
||||
options.D30result = rollD30.total
|
||||
}
|
||||
|
||||
let rollTotal = -1
|
||||
let diceResults = []
|
||||
let resultType
|
||||
|
||||
let diceResult = rollBase.dice[0].results[0].result
|
||||
diceResults.push({ dice: `${dice}`, value: diceResult })
|
||||
let diceSum = diceResult
|
||||
@ -314,6 +354,7 @@ export default class LethalFantasyRoll extends Roll {
|
||||
rollBase.options.diceResults = diceResults
|
||||
rollBase.options.rollTarget = options.rollTarget
|
||||
rollBase.options.titleFormula = titleFormula
|
||||
rollBase.options.D30result = options.D30result
|
||||
|
||||
/**
|
||||
* A hook event that fires after the roll has been made.
|
||||
@ -329,6 +370,130 @@ export default class LethalFantasyRoll extends Roll {
|
||||
return rollBase
|
||||
}
|
||||
|
||||
static async promptRangedDefense(rollTarget) {
|
||||
|
||||
const rollModes = Object.fromEntries(Object.entries(CONFIG.Dice.rollModes).map(([key, value]) => [key, game.i18n.localize(value)]))
|
||||
const fieldRollMode = new foundry.data.fields.StringField({
|
||||
choices: rollModes,
|
||||
blank: false,
|
||||
default: "public",
|
||||
})
|
||||
|
||||
let dialogContext = {
|
||||
movementChoices : SYSTEM.MOVEMENT_CHOICES,
|
||||
moveDirectionChoices : SYSTEM.MOVE_DIRECTION_CHOICES,
|
||||
sizeChoices : SYSTEM.SIZE_CHOICES,
|
||||
rangeChoices : SYSTEM.RANGE_CHOICES,
|
||||
attackerAimChoices : SYSTEM.ATTACKER_AIM_CHOICES,
|
||||
movement: "none",
|
||||
moveDirection: "none",
|
||||
size: "medium",
|
||||
range: "short",
|
||||
attackerAim: "simple",
|
||||
fieldRollMode,
|
||||
rollModes
|
||||
}
|
||||
console.log("CTX", dialogContext)
|
||||
|
||||
const content = await renderTemplate("systems/fvtt-lethal-fantasy/templates/range-defense-dialog.hbs", dialogContext)
|
||||
|
||||
const label = game.i18n.localize("LETHALFANTASY.Label.rangeDefenseRoll")
|
||||
const rollContext = await foundry.applications.api.DialogV2.wait({
|
||||
window: { title: "Range Defense" },
|
||||
classes: ["lethalfantasy"],
|
||||
content,
|
||||
buttons: [
|
||||
{
|
||||
label: label,
|
||||
callback: (event, button, dialog) => {
|
||||
const output = Array.from(button.form.elements).reduce((obj, input) => {
|
||||
if (input.name) obj[input.name] = input.value
|
||||
return obj
|
||||
}, {})
|
||||
return output
|
||||
},
|
||||
},
|
||||
],
|
||||
rejectClose: false // Click on Close button will not launch an error
|
||||
})
|
||||
|
||||
console.log("RollContext", rollContext)
|
||||
// Build the final modifier
|
||||
let fullModifier = Number(rollContext.moveDirection) +
|
||||
Number(rollContext.size) +
|
||||
Number(rollContext.range) +
|
||||
Number(rollContext.attackerAim)
|
||||
console.log("Modifier", fullModifier)
|
||||
|
||||
let modifierFormula
|
||||
if (fullModifier === 0) {
|
||||
modifierFormula = "0"
|
||||
} else {
|
||||
let modAbs = Math.abs(fullModifier)
|
||||
modifierFormula = `d${modAbs + 1} - 1`
|
||||
}
|
||||
|
||||
// If the user cancels the dialog, exit
|
||||
if (rollContext === null) return
|
||||
|
||||
let rollData = {...rollContext}
|
||||
let options = {...rollContext}
|
||||
options.rollName = "Ranged Defense"
|
||||
|
||||
const rollBase = new this(rollContext.movement, options.data, rollData)
|
||||
const rollModifier = new Roll(modifierFormula, options.data, rollData)
|
||||
rollModifier.evaluate()
|
||||
await rollBase.evaluate()
|
||||
let rollD30 = await new Roll("1D30").evaluate()
|
||||
options.D30result = rollD30.total
|
||||
|
||||
let dice = rollContext.movement
|
||||
let maxValue = Number(dice.match(/\d+$/)[0]) // Update the max value agains
|
||||
let rollTotal = -1
|
||||
let diceResults = []
|
||||
let resultType
|
||||
|
||||
let diceResult = rollBase.dice[0].results[0].result
|
||||
diceResults.push({ dice: `${dice}`, 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 })
|
||||
diceSum += (diceResult - 1)
|
||||
}
|
||||
if (fullModifier !== 0) {
|
||||
diceResults.push({ dice: `${rollModifier.formula}`, value: rollModifier.total })
|
||||
if (fullModifier < 0) {
|
||||
rollTotal = Math.max(diceSum - rollModifier.total, 0)
|
||||
} else {
|
||||
rollTotal = diceSum + rollModifier.total
|
||||
}
|
||||
} else {
|
||||
rollTotal = diceSum
|
||||
}
|
||||
|
||||
rollBase.options.resultType = resultType
|
||||
rollBase.options.rollTotal = rollTotal
|
||||
rollBase.options.diceResults = diceResults
|
||||
rollBase.options.rollTarget = options.rollTarget
|
||||
rollBase.options.titleFormula = `${dice}E + ${modifierFormula}`
|
||||
rollBase.options.D30result = options.D30result
|
||||
rollBase.options.rollName = "Ranged Defense"
|
||||
|
||||
/**
|
||||
* A hook event that fires after the roll has been made.
|
||||
* @function
|
||||
* @memberof hookEvents
|
||||
* @param {Object} options Options for the roll.
|
||||
* @param {Object} rollData All data related to the roll.
|
||||
@param {LethalFantasyRoll} roll The resulting roll.
|
||||
* @returns {boolean} Explicitly return `false` to prevent roll to be made.
|
||||
*/
|
||||
|
||||
return rollBase
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a title based on the given type.
|
||||
*
|
||||
@ -352,6 +517,8 @@ export default class LethalFantasyRoll extends Roll {
|
||||
return `${game.i18n.localize("LETHALFANTASY.Label.weapon-damage-small")}`
|
||||
case "weapon-damage-medium":
|
||||
return `${game.i18n.localize("LETHALFANTASY.Label.weapon-damage-medium")}`
|
||||
case "spell":
|
||||
return `${game.i18n.localize("LETHALFANTASY.Label.spell")}`
|
||||
default:
|
||||
return game.i18n.localize("LETHALFANTASY.Label.titleStandard")
|
||||
}
|
||||
@ -409,6 +576,7 @@ export default class LethalFantasyRoll extends Roll {
|
||||
hasTarget: this.hasTarget,
|
||||
targetName: this.targetName,
|
||||
targetArmor: this.targetArmor,
|
||||
D30result: this.D30result,
|
||||
isPrivate: isPrivate
|
||||
}
|
||||
cardData.cssClass = cardData.css.join(" ")
|
||||
|
Reference in New Issue
Block a user