Add skill+weapon rolls
This commit is contained in:
@ -11,11 +11,15 @@ export default class LethalFantasyRoll extends Roll {
|
||||
get type() {
|
||||
return this.options.type
|
||||
}
|
||||
|
||||
|
||||
get titleFormula() {
|
||||
return this.options.titleFormula
|
||||
}
|
||||
|
||||
|
||||
get rollName() {
|
||||
return this.options.rollName
|
||||
}
|
||||
|
||||
get target() {
|
||||
return this.options.target
|
||||
}
|
||||
@ -83,7 +87,7 @@ export default class LethalFantasyRoll extends Roll {
|
||||
get rollTotal() {
|
||||
return this.options.rollTotal
|
||||
}
|
||||
|
||||
|
||||
get diceResults() {
|
||||
return this.options.diceResults
|
||||
}
|
||||
@ -160,15 +164,44 @@ export default class LethalFantasyRoll extends Roll {
|
||||
let hasModifier = true
|
||||
let hasChangeDice = false
|
||||
if (options.rollType === "challenge" || options.rollType === "save") {
|
||||
if ( options.rollTarget.rollKey === "dying") {
|
||||
options.rollName = options.rollTarget.rollKey
|
||||
if (options.rollTarget.rollKey === "dying") {
|
||||
dice = options.rollTarget.value
|
||||
maxValue = Number(options.rollTarget.value.match(/\d+/)[0])
|
||||
hasModifier = false
|
||||
hasChangeDice = true
|
||||
hasChangeDice = true
|
||||
} else {
|
||||
dice = "1D20"
|
||||
maxValue = 20
|
||||
}
|
||||
}
|
||||
} else if (options.rollType === "skill") {
|
||||
options.rollName = options.rollTarget.name
|
||||
dice = "1D100"
|
||||
baseFormula = "D100"
|
||||
maxValue = 100
|
||||
hasModifier = true
|
||||
hasChangeDice = false
|
||||
options.rollTarget.value = options.rollTarget.system.skillTotal
|
||||
} else if (options.rollType === "weapon-attack" || options.rollType === "weapon-defense") {
|
||||
options.rollName = options.rollTarget.name
|
||||
dice = "1D20"
|
||||
baseFormula = "D20"
|
||||
maxValue = 20
|
||||
hasModifier = true
|
||||
hasChangeDice = false
|
||||
if (options.rollType === "weapon-attack") {
|
||||
options.rollTarget.value = options.rollTarget.combat.attackModifier + options.rollTarget.weaponSkillModifier
|
||||
options.rollTarget.charModifier = options.rollTarget.combat.attackModifier
|
||||
} else {
|
||||
options.rollTarget.value = options.rollTarget.combat.defenseModifier + options.rollTarget.weaponSkillModifier
|
||||
options.rollTarget.charModifier = options.rollTarget.combat.defenseModifier
|
||||
}
|
||||
}
|
||||
|
||||
if (options.rollType === "save" && options.rollTarget.rollKey === "pain") {
|
||||
dice = options.rollTarget.rollDice
|
||||
baseFormula = options.rollTarget.rollDice
|
||||
hasModifier = false
|
||||
}
|
||||
|
||||
const rollModes = Object.fromEntries(Object.entries(CONFIG.Dice.rollModes).map(([key, value]) => [key, game.i18n.localize(value)]))
|
||||
@ -188,6 +221,7 @@ export default class LethalFantasyRoll extends Roll {
|
||||
let dialogContext = {
|
||||
rollType: options.rollType,
|
||||
rollTarget: options.rollTarget,
|
||||
rollName: options.rollName,
|
||||
rollModes,
|
||||
hasModifier,
|
||||
hasChangeDice,
|
||||
@ -202,6 +236,7 @@ export default class LethalFantasyRoll extends Roll {
|
||||
modifier,
|
||||
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)
|
||||
@ -231,31 +266,38 @@ export default class LethalFantasyRoll extends Roll {
|
||||
let fullModifier = 0
|
||||
let titleFormula = ""
|
||||
dice = rollContext.changeDice || dice
|
||||
if (options.rollType === "challenge" || options.rollType === "save") {
|
||||
if (hasModifier) {
|
||||
let bonus = Number(options.rollTarget.value)
|
||||
fullModifier = rollContext.modifier === "" ? 0 : parseInt(rollContext.modifier, 10) + bonus
|
||||
if (fullModifier === 0) {
|
||||
modifierFormula = "0"
|
||||
} else {
|
||||
let modAbs = Math.abs(fullModifier)
|
||||
modifierFormula = `d${modAbs + 1} - 1`
|
||||
}
|
||||
let sign = fullModifier < 0 ? "-" : "+"
|
||||
titleFormula = `${dice}E ${sign} ${modifierFormula}`
|
||||
} else {
|
||||
if (hasModifier) {
|
||||
let bonus = Number(options.rollTarget.value)
|
||||
fullModifier = rollContext.modifier === "" ? 0 : parseInt(rollContext.modifier, 10) + bonus
|
||||
if (fullModifier === 0) {
|
||||
modifierFormula = "0"
|
||||
fullModifier = 0
|
||||
baseFormula = `${dice}`
|
||||
titleFormula = `${dice}E`
|
||||
} else {
|
||||
let modAbs = Math.abs(fullModifier)
|
||||
modifierFormula = `d${modAbs + 1} - 1`
|
||||
}
|
||||
let sign = fullModifier < 0 ? "-" : "+"
|
||||
titleFormula = `${dice}E ${sign} ${modifierFormula}`
|
||||
} else {
|
||||
modifierFormula = "0"
|
||||
fullModifier = 0
|
||||
baseFormula = `${dice}`
|
||||
titleFormula = `${dice}E`
|
||||
}
|
||||
|
||||
if (options.rollType === "save" && options.rollTarget.rollKey === "pain") {
|
||||
baseFormula = options.rollTarget.rollDice
|
||||
titleFormula = `${dice}`
|
||||
modifierFormula = "0"
|
||||
fullModifier = 0
|
||||
}
|
||||
|
||||
maxValue = Number(baseFormula.match(/\d+$/)[0]) // Update the max value agains
|
||||
|
||||
const rollData = {
|
||||
type: options.rollType,
|
||||
rollType: options.rollType,
|
||||
target: options.rollTarget,
|
||||
rollName: options.rollName,
|
||||
actorId: options.actorId,
|
||||
actorName: options.actorName,
|
||||
actorImage: options.actorImage,
|
||||
@ -284,28 +326,22 @@ export default class LethalFantasyRoll extends Roll {
|
||||
let rollTotal = -1
|
||||
let diceResults = []
|
||||
let resultType
|
||||
if (options.rollType === "challenge" || options.rollType === "save") {
|
||||
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
|
||||
}
|
||||
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
|
||||
}
|
||||
} else if (options.rollType === ROLL_TYPE.RESOURCE) {
|
||||
//resultType = roll.total === 1 || roll.total === 2 ? "failure" : "success"
|
||||
rollTotal = diceSum + rollModifier.total
|
||||
}
|
||||
}
|
||||
|
||||
rollBase.options.resultType = resultType
|
||||
@ -343,12 +379,16 @@ export default class LethalFantasyRoll extends Roll {
|
||||
return `${game.i18n.localize("LETHALFANTASY.Label.titleChallenge")}`
|
||||
case "save":
|
||||
return `${game.i18n.localize("LETHALFANTASY.Label.titleSave")}`
|
||||
case ROLL_TYPE.DAMAGE:
|
||||
return `${game.i18n.localize("LETHALFANTASY.Dialog.titleDamage")} : ${target}`
|
||||
case ROLL_TYPE.ATTACK:
|
||||
return `${game.i18n.localize("LETHALFANTASY.Dialog.titleAttack")} : ${target}`
|
||||
case "skill":
|
||||
return `${game.i18n.localize("LETHALFANTASY.Label.titleSkill")}`
|
||||
case "weapon-attack":
|
||||
return `${game.i18n.localize("LETHALFANTASY.Label.weapon-attack")}`
|
||||
case "weapon-defense":
|
||||
return `${game.i18n.localize("LETHALFANTASY.Label.weapon-defense")}`
|
||||
case "weapon-damage":
|
||||
return `${game.i18n.localize("LETHALFANTASY.Label.weapon-damage")}`
|
||||
default:
|
||||
return game.i18n.localize("LETHALFANTASY.Dialog.titleStandard")
|
||||
return game.i18n.localize("LETHALFANTASY.Label.titleStandard")
|
||||
}
|
||||
}
|
||||
|
||||
@ -393,6 +433,7 @@ export default class LethalFantasyRoll extends Roll {
|
||||
isGM: game.user.isGM,
|
||||
formula: this.formula,
|
||||
titleFormula: this.titleFormula,
|
||||
rollName: this.rollName,
|
||||
rollType: this.type,
|
||||
rollTarget: this.rollTarget,
|
||||
total: this.rollTotal,
|
||||
|
Reference in New Issue
Block a user