Update sheet again...
This commit is contained in:
@ -122,6 +122,8 @@ export default class LethalFantasyRoll extends Roll {
|
||||
let hasChangeDice = false
|
||||
let hasD30 = false
|
||||
let hasFavor = false
|
||||
let hasMaxValue = true
|
||||
let hasGrantedDice = false
|
||||
|
||||
if (options.rollType === "challenge" || options.rollType === "save") {
|
||||
options.rollName = options.rollTarget.rollKey
|
||||
@ -138,6 +140,17 @@ export default class LethalFantasyRoll extends Roll {
|
||||
hasFavor = true
|
||||
}
|
||||
|
||||
} else if (options.rollType === "granted") {
|
||||
hasD30 = false
|
||||
options.rollName = `Granted ${options.rollTarget.rollKey}`
|
||||
dice = options.rollTarget.formula
|
||||
baseFormula = options.rollTarget.formula
|
||||
hasModifier = false
|
||||
maxValue = 100
|
||||
hasMaxValue = false
|
||||
hasChangeDice = false
|
||||
hasFavor = false
|
||||
|
||||
} else if (options.rollType === "monster-attack" || options.rollType === "monster-defense") {
|
||||
hasD30 = true
|
||||
options.rollName = options.rollTarget.name
|
||||
@ -148,10 +161,10 @@ export default class LethalFantasyRoll extends Roll {
|
||||
hasChangeDice = false
|
||||
hasFavor = true
|
||||
if (options.rollType === "monster-attack") {
|
||||
options.rollTarget.value = options.rollTarget.attackModifier
|
||||
options.rollTarget.value = options.rollTarget.attackModifier
|
||||
options.rollTarget.charModifier = 0
|
||||
} else {
|
||||
options.rollTarget.value = options.rollTarget.defenseModifier
|
||||
options.rollTarget.value = options.rollTarget.defenseModifier
|
||||
options.rollTarget.charModifier = 0
|
||||
}
|
||||
|
||||
@ -170,7 +183,7 @@ export default class LethalFantasyRoll extends Roll {
|
||||
hasFavor = 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
|
||||
@ -224,7 +237,7 @@ export default class LethalFantasyRoll extends Roll {
|
||||
dice = dice.replace("E", "")
|
||||
baseFormula = dice
|
||||
maxValue = 20
|
||||
|
||||
|
||||
} else if (options.rollType.includes("monster-damage")) {
|
||||
options.rollName = options.rollTarget.name
|
||||
hasModifier = true
|
||||
@ -277,10 +290,9 @@ export default class LethalFantasyRoll extends Roll {
|
||||
hasTarget: options.hasTarget,
|
||||
modifier,
|
||||
saveSpell: false,
|
||||
favor : "none",
|
||||
favor: "none",
|
||||
targetName
|
||||
}
|
||||
console.log("dialogContext", dialogContext)
|
||||
const content = await renderTemplate("systems/fvtt-lethal-fantasy/templates/roll-dialog.hbs", dialogContext)
|
||||
|
||||
const title = LethalFantasyRoll.createTitle(options.rollType, options.rollTarget)
|
||||
@ -301,26 +313,32 @@ export default class LethalFantasyRoll extends Roll {
|
||||
},
|
||||
},
|
||||
],
|
||||
actions: {
|
||||
"selectGranted": (event, button, dialog) => {
|
||||
hasGrantedDice = true
|
||||
}
|
||||
},
|
||||
rejectClose: false // Click on Close button will not launch an error
|
||||
})
|
||||
|
||||
// If the user cancels the dialog, exit
|
||||
if (rollContext === null) return
|
||||
console.log("rollContext", rollContext, hasGrantedDice)
|
||||
|
||||
let fullModifier = 0
|
||||
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
|
||||
fullModifier += (rollContext.saveSpell) ? options.rollTarget.actorModifiers.saveModifier : 0
|
||||
|
||||
if (fullModifier === 0) {
|
||||
modifierFormula = "0"
|
||||
} else {
|
||||
if (options.rollType === "skill") {
|
||||
if (options.rollType === "skill") {
|
||||
modifierFormula = `${fullModifier}`
|
||||
} else {
|
||||
} else {
|
||||
let modAbs = Math.abs(fullModifier)
|
||||
modifierFormula = `d${modAbs + 1} - 1`
|
||||
}
|
||||
@ -346,7 +364,7 @@ export default class LethalFantasyRoll extends Roll {
|
||||
if (options.rollType === "save" && (options.rollTarget.rollKey === "pain" || options.rollTarget.rollKey === "poison" || options.rollTarget.rollKey === "contagion")) {
|
||||
hasD30 = false
|
||||
}
|
||||
|
||||
|
||||
maxValue = Number(baseFormula.match(/\d+$/)[0]) // Update the max value agains
|
||||
|
||||
const rollData = {
|
||||
@ -359,6 +377,7 @@ export default class LethalFantasyRoll extends Roll {
|
||||
actorImage: options.actorImage,
|
||||
rollMode: rollContext.visibility,
|
||||
hasTarget: options.hasTarget,
|
||||
hasGrantedDice,
|
||||
titleFormula,
|
||||
targetName,
|
||||
...rollContext,
|
||||
@ -378,7 +397,7 @@ export default class LethalFantasyRoll extends Roll {
|
||||
const rollModifier = new Roll(modifierFormula, options.data, rollData)
|
||||
await rollModifier.evaluate()
|
||||
await rollBase.evaluate()
|
||||
|
||||
|
||||
let rollFavor
|
||||
let badResult
|
||||
if (rollContext.favor === "favor") {
|
||||
@ -412,7 +431,7 @@ export default class LethalFantasyRoll extends Roll {
|
||||
if (hasD30) {
|
||||
let rollD30 = await new Roll("1D30").evaluate()
|
||||
if (game?.dice3d) {
|
||||
game.dice3d.showForRoll(rollD30, game.user, true)
|
||||
await game.dice3d.showForRoll(rollD30, game.user, true)
|
||||
}
|
||||
options.D30result = rollD30.total
|
||||
}
|
||||
@ -428,14 +447,30 @@ export default class LethalFantasyRoll extends Roll {
|
||||
let diceResult = rollBase.dice[i].results[j].result
|
||||
diceResults.push({ dice: `${singleDice}`, value: diceResult })
|
||||
diceSum += diceResult
|
||||
while (diceResult === maxValue) {
|
||||
let r = await new Roll(baseFormula).evaluate()
|
||||
diceResult = r.dice[0].results[0].result
|
||||
diceResults.push({ dice: `${singleDice}-1`, value: diceResult - 1 })
|
||||
diceSum += (diceResult - 1)
|
||||
if (hasMaxValue) {
|
||||
while (diceResult === maxValue) {
|
||||
let r = await new Roll(baseFormula).evaluate()
|
||||
if (game?.dice3d) {
|
||||
await game.dice3d.showForRoll(r, game.user, true)
|
||||
}
|
||||
diceResult = r.dice[0].results[0].result
|
||||
diceResults.push({ dice: `${singleDice}-1`, value: diceResult - 1 })
|
||||
diceSum += (diceResult - 1)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( hasGrantedDice) {
|
||||
let grantedRoll = new Roll(options.rollTarget.grantedDice)
|
||||
await grantedRoll.evaluate()
|
||||
if (game?.dice3d) {
|
||||
await game.dice3d.showForRoll(grantedRoll, game.user, true)
|
||||
}
|
||||
diceResults.push({ dice: `${options.rollTarget.grantedDice}`, value: grantedRoll.total })
|
||||
rollTotal += grantedRoll.total
|
||||
}
|
||||
|
||||
if (fullModifier !== 0) {
|
||||
diceResults.push({ dice: `${rollModifier.formula}`, value: rollModifier.total })
|
||||
if (fullModifier < 0) {
|
||||
@ -477,9 +512,9 @@ export default class LethalFantasyRoll extends Roll {
|
||||
default: "public",
|
||||
})
|
||||
|
||||
if ( SYSTEM.INITIATIVE_DICE_CHOICES_PER_CLASS[options.actorClass] ) {
|
||||
if (SYSTEM.INITIATIVE_DICE_CHOICES_PER_CLASS[options.actorClass]) {
|
||||
options.initiativeDiceChoice = SYSTEM.INITIATIVE_DICE_CHOICES_PER_CLASS[options.actorClass]
|
||||
} else {
|
||||
} else {
|
||||
options.initiativeDiceChoice = SYSTEM.INITIATIVE_DICE_CHOICES_PER_CLASS["untrained"]
|
||||
}
|
||||
|
||||
@ -492,7 +527,7 @@ export default class LethalFantasyRoll extends Roll {
|
||||
rollModes
|
||||
}
|
||||
console.log("CTX", dialogContext)
|
||||
|
||||
|
||||
const content = await renderTemplate("systems/fvtt-lethal-fantasy/templates/roll-initiative-dialog.hbs", dialogContext)
|
||||
|
||||
const label = game.i18n.localize("LETHALFANTASY.Label.initiative")
|
||||
@ -517,31 +552,33 @@ export default class LethalFantasyRoll extends Roll {
|
||||
|
||||
let initRoll = new Roll(`min(${rollContext.initiativeDice}, ${options.maxInit})`, options.data, rollContext)
|
||||
await initRoll.evaluate()
|
||||
let msg = await initRoll.toMessage( {flavor: `Initiative for ${options.actorName}`}, {rollMode: rollContext.visibility} )
|
||||
await game.dice3d.waitFor3DAnimationByMessageID(msg.id)
|
||||
let msg = await initRoll.toMessage({ flavor: `Initiative for ${options.actorName}` }, { rollMode: rollContext.visibility })
|
||||
if (game?.dice3d) {
|
||||
await game.dice3d.waitFor3DAnimationByMessageID(msg.id)
|
||||
}
|
||||
|
||||
if (options.combatId && options.combatantId) {
|
||||
let combat = game.combats.get(options.combatId)
|
||||
combat.updateEmbeddedDocuments("Combatant", [ { _id: options.combatantId, initiative: initRoll.total, 'system.progressionCount': 0 } ]);
|
||||
combat.updateEmbeddedDocuments("Combatant", [{ _id: options.combatantId, initiative: initRoll.total, 'system.progressionCount': 0 }]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static async promptProgressionDice(options = {}) {
|
||||
|
||||
|
||||
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 = {
|
||||
let dialogContext = {
|
||||
progressionDiceId: "",
|
||||
fieldRollMode,
|
||||
rollModes,
|
||||
...options
|
||||
}
|
||||
|
||||
|
||||
console.log("CTX PROGRESSION", dialogContext)
|
||||
|
||||
const content = await renderTemplate("systems/fvtt-lethal-fantasy/templates/roll-progression-dice-dialog.hbs", dialogContext)
|
||||
@ -565,23 +602,23 @@ export default class LethalFantasyRoll extends Roll {
|
||||
},
|
||||
{
|
||||
action: "cancel",
|
||||
label: "Other action, no progression dice",
|
||||
callback: (event, button, dialog) => {
|
||||
return null;
|
||||
}
|
||||
label: "Other action, no progression dice",
|
||||
callback: (event, button, dialog) => {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
],
|
||||
rejectClose: false // Click on Close button will not launch an error
|
||||
})
|
||||
|
||||
|
||||
console.log("RollContext", rollContext)
|
||||
if (rollContext === null || !rollContext?.progressionDiceId) {
|
||||
if (rollContext === null || !rollContext?.progressionDiceId) {
|
||||
let combat = game.combats.get(options.combatId)
|
||||
let combatant = combat.combatants.get(options.combatantId)
|
||||
combatant.update({ 'system.progressionCount': 1 })
|
||||
combatant.update({ 'system.progressionCount': 1 })
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
// Get the weapons from the actor items
|
||||
let actor = game.actors.get(options.actorId)
|
||||
let weapon = actor.items.find(i => i.type === "weapon" && i.id === rollContext.progressionDiceId)
|
||||
@ -590,20 +627,22 @@ export default class LethalFantasyRoll extends Roll {
|
||||
let formula = weapon.system.combatProgressionDice
|
||||
let roll = new Roll(formula)
|
||||
await roll.evaluate()
|
||||
|
||||
|
||||
let max = roll.dice[0].faces - 1
|
||||
max = Math.min(options.rollProgressionCount, max)
|
||||
let msg = await roll.toMessage( {flavor: `Progression Roll for ${weapon.name}, progression count : ${options.rollProgressionCount}/${max}`}, {rollMode: rollContext.visibility} )
|
||||
await game.dice3d.waitFor3DAnimationByMessageID(msg.id)
|
||||
let msg = await roll.toMessage({ flavor: `Progression Roll for ${weapon.name}, progression count : ${options.rollProgressionCount}/${max}` }, { rollMode: rollContext.visibility })
|
||||
if (game?.dice3d) {
|
||||
await game.dice3d.waitFor3DAnimationByMessageID(msg.id)
|
||||
}
|
||||
|
||||
if (roll.total <= max ) {
|
||||
if (roll.total <= max) {
|
||||
// Notify that the player can act now with a chat message
|
||||
let message = game.i18n.format("LETHALFANTASY.Notifications.messageProgressionOK", { isMonster, name: actor.name, weapon: weapon.name, roll: roll.total })
|
||||
ChatMessage.create({ content: message, speaker: ChatMessage.getSpeaker({ actor: actor }) })
|
||||
// Update the combatant progression count
|
||||
let combat = game.combats.get(options.combatId)
|
||||
let combatant = combat.combatants.get(options.combatantId)
|
||||
combatant.update({ 'system.progressionCount': 0 })
|
||||
combatant.update({ 'system.progressionCount': 0 })
|
||||
} else {
|
||||
// Notify that the player cannot act now with a chat message
|
||||
let message = game.i18n.format("LETHALFANTASY.Notifications.messageProgressionKO", { isMonster, name: actor.name, weapon: weapon.name, roll: roll.total })
|
||||
@ -612,7 +651,7 @@ export default class LethalFantasyRoll extends Roll {
|
||||
}
|
||||
|
||||
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,
|
||||
@ -621,11 +660,11 @@ export default class LethalFantasyRoll extends Roll {
|
||||
})
|
||||
|
||||
let dialogContext = {
|
||||
movementChoices : SYSTEM.MOVEMENT_CHOICES,
|
||||
moveDirectionChoices : SYSTEM.MOVE_DIRECTION_CHOICES,
|
||||
sizeChoices : SYSTEM.SIZE_CHOICES,
|
||||
rangeChoices : SYSTEM.RANGE_CHOICES,
|
||||
attackerAimChoices : SYSTEM.ATTACKER_AIM_CHOICES,
|
||||
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",
|
||||
@ -657,15 +696,15 @@ export default class LethalFantasyRoll extends Roll {
|
||||
],
|
||||
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) +
|
||||
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"
|
||||
@ -677,8 +716,8 @@ export default class LethalFantasyRoll extends Roll {
|
||||
// If the user cancels the dialog, exit
|
||||
if (rollContext === null) return
|
||||
|
||||
let rollData = {...rollContext}
|
||||
let options = {...rollContext}
|
||||
let rollData = { ...rollContext }
|
||||
let options = { ...rollContext }
|
||||
options.rollName = "Ranged Defense"
|
||||
|
||||
const rollBase = new this(rollContext.movement, options.data, rollData)
|
||||
@ -758,7 +797,7 @@ 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":
|
||||
case "spell":
|
||||
return `${game.i18n.localize("LETHALFANTASY.Label.spell")}`
|
||||
default:
|
||||
return game.i18n.localize("LETHALFANTASY.Label.titleStandard")
|
||||
|
Reference in New Issue
Block a user