import { ROLL_TYPE } from "../config/system.mjs"
import LethalFantasyUtils from "../utils.mjs"
export default class LethalFantasyRoll extends Roll {
/**
* The HTML template path used to render dice checks of this type
* @type {string}
*/
static CHAT_TEMPLATE = "systems/fvtt-lethal-fantasy/templates/chat-message.hbs"
get type() {
return this.options.type
}
get isChallenge() {
return this.type === "challenge"
}
get isSave() {
return this.type === ROLL_TYPE.SAVE
}
get isResource() {
return this.type === ROLL_TYPE.RESOURCE
}
get isDamage() {
return this.type === ROLL_TYPE.DAMAGE
}
get target() {
return this.options.target
}
get value() {
return this.options.value
}
get treshold() {
return this.options.treshold
}
get actorId() {
return this.options.actorId
}
get actorName() {
return this.options.actorName
}
get actorImage() {
return this.options.actorImage
}
get introText() {
return this.options.introText
}
get introTextTooltip() {
return this.options.introTextTooltip
}
get modifier() {
return this.options.modifier
}
get resultType() {
return this.options.resultType
}
get isFailure() {
return this.resultType === "failure"
}
get hasTarget() {
return this.options.hasTarget
}
get targetName() {
return this.options.targetName
}
get targetArmor() {
return this.options.targetArmor
}
get targetMalus() {
return this.options.targetMalus
}
get realDamage() {
return this.options.realDamage
}
get rollTotal() {
return this.options.rollTotal
}
get diceResults() {
return this.options.diceResults
}
get rollTarget() {
return this.options.rollTarget
}
/**
* Generates introductory text based on the roll type.
*
* @returns {string} The formatted introductory text for the roll.
*/
_createIntroText() {
let text
switch (this.type) {
case ROLL_TYPE.SAVE:
const saveLabel = game.i18n.localize(`LETHALFANTASY.Character.FIELDS.caracteristiques.${this.target}.valeur.label`)
text = game.i18n.format("LETHALFANTASY.Roll.save", { save: saveLabel })
text = text.concat(" ").concat(`Seuil : ${this.treshold}`)
break
case ROLL_TYPE.RESOURCE:
const resourceLabel = game.i18n.localize(`LETHALFANTASY.Character.FIELDS.ressources.${this.target}.valeur.label`)
text = game.i18n.format("LETHALFANTASY.Roll.resource", { resource: resourceLabel })
break
case ROLL_TYPE.DAMAGE:
const damageLabel = this.target
text = game.i18n.format("LETHALFANTASY.Roll.damage", { item: damageLabel })
break
case ROLL_TYPE.ATTACK:
const attackLabel = this.target
text = game.i18n.format("LETHALFANTASY.Roll.attack", { item: attackLabel })
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("LETHALFANTASY.Tooltip.saveIntroTextTooltip", { value: this.value, aide: this.aide, gene: this.gene, modificateur: this.modificateur })
if (this.hasTarget) {
tooltip = tooltip.concat(` Cible : ${this.targetName}`)
}
return tooltip
}
/**
* Prompt the user with a dialog to configure and execute a roll.
*
* @param {Object} options Configuration options for the roll.
* @param {string} options.rollType The type of roll being performed (e.g., RESOURCE, DAMAGE, ATTACK, SAVE).
* @param {string} options.rollValue The initial value or formula for the roll.
* @param {string} options.rollTarget The target of the roll.
* @param {"="|"+"|"++"|"-"|"--"} options.rollAdvantage If there is an avantage (+), a disadvantage (-), a double advantage (++), a double disadvantage (--) or a normal roll (=).
* @param {string} options.actorId The ID of the actor performing the roll.
* @param {string} options.actorName The name of the actor performing the roll.
* @param {string} options.actorImage The image of the actor performing the roll.
* @param {boolean} options.hasTarget Whether the roll has a target.
* @param {Object} options.target The target of the roll, if any.
* @param {Object} options.data Additional data for the roll.
*
* @returns {Promise