Basic dice roll support
This commit is contained in:
@ -5,7 +5,7 @@ export default class CthulhuEternalProtagonistSheet extends CthulhuEternalActorS
|
||||
static DEFAULT_OPTIONS = {
|
||||
classes: ["protagonist"],
|
||||
position: {
|
||||
width: 820,
|
||||
width: 840,
|
||||
height: 620,
|
||||
},
|
||||
window: {
|
||||
|
@ -34,14 +34,6 @@ export default class CthulhuEternalRoll extends Roll {
|
||||
return this.options.actorImage
|
||||
}
|
||||
|
||||
get introText() {
|
||||
return this.options.introText
|
||||
}
|
||||
|
||||
get introTextTooltip() {
|
||||
return this.options.introTextTooltip
|
||||
}
|
||||
|
||||
get help() {
|
||||
return this.options.help
|
||||
}
|
||||
@ -82,37 +74,6 @@ export default class CthulhuEternalRoll extends Roll {
|
||||
return this.options.realDamage
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates introductory text based on the roll type.
|
||||
*
|
||||
* @returns {string} The formatted introductory text for the roll.
|
||||
*/
|
||||
_createIntroText() {
|
||||
let text
|
||||
|
||||
switch (this.type) {
|
||||
case "skill":
|
||||
const skillLabel = game.i18n.localize(`CTHULHUETERNAL.Character.FIELDS.caracteristiques.${this.target}.valeur.label`)
|
||||
text = game.i18n.format("CTHULHUETERNAL.Roll.skill", { skill: "skill" })
|
||||
text = text.concat("<br>").concat(`Seuil : ${this.treshold}`)
|
||||
break
|
||||
}
|
||||
return text
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates an introductory text tooltip with characteristics and modifiers.
|
||||
*
|
||||
* @returns {string} A formatted string containing the value, help, hindrance, and modifier.
|
||||
*/
|
||||
_createIntroTextTooltip() {
|
||||
let tooltip = game.i18n.format("CTHULHUETERNAL.Tooltip.saveIntroTextTooltip", { value: this.value, help: this.help, gene: this.gene, modifier: this.modifier })
|
||||
if (this.hasTarget) {
|
||||
tooltip = tooltip.concat(`<br>Target : ${this.targetName}`)
|
||||
}
|
||||
return tooltip
|
||||
}
|
||||
|
||||
/**
|
||||
* Prompt the user with a dialog to configure and execute a roll.
|
||||
*
|
||||
@ -132,13 +93,13 @@ export default class CthulhuEternalRoll extends Roll {
|
||||
switch (options.rollType) {
|
||||
case "skill":
|
||||
console.log(options.rollItem)
|
||||
options.targetScore = options.rollItem.system.computeScore()
|
||||
options.initialScore = options.rollItem.system.computeScore()
|
||||
break
|
||||
case "characteristic":
|
||||
options.targetScore = options.rollItem.value * 5
|
||||
options.initialScore = options.rollItem.value * 5
|
||||
break
|
||||
default:
|
||||
options.targetScore = 50
|
||||
options.initialScore = 50
|
||||
break
|
||||
}
|
||||
|
||||
@ -167,7 +128,8 @@ export default class CthulhuEternalRoll extends Roll {
|
||||
let dialogContext = {
|
||||
rollType: options.rollType,
|
||||
rollItem: foundry.utils.duplicate(options.rollItem), // Object only, no class
|
||||
targetScore: options.targetScore,
|
||||
initialScore: options.initialScore,
|
||||
targetScore: options.initialScore,
|
||||
rollModes,
|
||||
fieldRollMode,
|
||||
choiceModifier,
|
||||
@ -213,6 +175,7 @@ export default class CthulhuEternalRoll extends Roll {
|
||||
actorImage: options.actorImage,
|
||||
rollMode: rollContext.visibility,
|
||||
hasTarget: options.hasTarget,
|
||||
initialScore: options.initialScore,
|
||||
targetName,
|
||||
targetArmor,
|
||||
targetMalus,
|
||||
@ -220,7 +183,7 @@ export default class CthulhuEternalRoll extends Roll {
|
||||
}
|
||||
|
||||
// Update target score
|
||||
rollData.targetScore = options.targetScore + Number(rollData.modifier)
|
||||
rollData.targetScore = Math.min( Math.max(options.initialScore + Number(rollData.modifier), 0), 100)
|
||||
|
||||
/**
|
||||
* A hook event that fires before the roll is made.
|
||||
@ -230,14 +193,27 @@ export default class CthulhuEternalRoll extends Roll {
|
||||
const roll = new this(formula, options.data, rollData)
|
||||
await roll.evaluate()
|
||||
|
||||
let resultType = "failure"
|
||||
// Compute the result quality
|
||||
let resultType = "failure"
|
||||
let dec = Math.floor(roll.total/10)
|
||||
let unit = roll.total - (dec*10)
|
||||
if (roll.total <= rollData.targetScore) {
|
||||
resultType = "success"
|
||||
// Detect if decimal == unit in the dire total result
|
||||
if (dec === unit || roll.total == 1) {
|
||||
resultType = "successCritical"
|
||||
}
|
||||
} else {
|
||||
// Detect if decimal == unit in the dire total result
|
||||
if (dec === unit || roll.total == 100) {
|
||||
resultType = "failureCritical"
|
||||
}
|
||||
}
|
||||
|
||||
roll.options.resultType = resultType
|
||||
roll.options.introText = roll._createIntroText()
|
||||
roll.options.introTextTooltip = roll._createIntroTextTooltip()
|
||||
roll.options.isSuccess = resultType === "success" || resultType === "successCritical"
|
||||
roll.options.isFailure = resultType === "failure" || resultType === "failureCritical"
|
||||
roll.options.isCritical = resultType === "successCritical" || resultType === "failureCritical"
|
||||
|
||||
/**
|
||||
* A hook event that fires after the roll has been made.
|
||||
@ -284,8 +260,6 @@ export default class CthulhuEternalRoll extends Roll {
|
||||
* @property {string} actorId - The ID of the actor performing the roll.
|
||||
* @property {string} actingCharName - The name of the character performing the roll.
|
||||
* @property {string} actingCharImg - The image of the character performing the roll.
|
||||
* @property {string} introText - Introductory text for the roll.
|
||||
* @property {string} introTextTooltip - Tooltip for the introductory text.
|
||||
* @property {string} resultType - The type of result (e.g., success, failure).
|
||||
* @property {boolean} hasTarget - Indicates if the roll has a target.
|
||||
* @property {string} targetName - The name of the target.
|
||||
@ -302,16 +276,18 @@ export default class CthulhuEternalRoll extends Roll {
|
||||
diceTotal: this.dice.reduce((t, d) => t + d.total, 0),
|
||||
isGM: game.user.isGM,
|
||||
rollItem: this.options.rollItem,
|
||||
initialScore: this.options.initialScore,
|
||||
targetScore: this.options.targetScore,
|
||||
rollType: this.options.rollType,
|
||||
modifier: this.options.modifier,
|
||||
formula: this.formula,
|
||||
total: this.total,
|
||||
isFailure: this.isFailure,
|
||||
isSuccess: this.options.isSuccess,
|
||||
isFailure: this.options.isFailure,
|
||||
isCritical: this.options.isCritical,
|
||||
actorId: this.actorId,
|
||||
actingCharName: this.actorName,
|
||||
actingCharImg: this.actorImage,
|
||||
introText: this.introText,
|
||||
introTextTooltip: this.introTextTooltip,
|
||||
resultType: this.resultType,
|
||||
hasTarget: this.hasTarget,
|
||||
targetName: this.targetName,
|
||||
@ -338,8 +314,6 @@ export default class CthulhuEternalRoll extends Roll {
|
||||
super.toMessage(
|
||||
{
|
||||
isFailure: this.resultType === "failure",
|
||||
introText: this.introText,
|
||||
introTextTooltip: this.introTextTooltip,
|
||||
actingCharName: this.actorName,
|
||||
actingCharImg: this.actorImage,
|
||||
hasTarget: this.hasTarget,
|
||||
|
Reference in New Issue
Block a user