import { ChatUtility } from "../chat-utility.js" import RollDialog from "./roll-dialog.mjs" import { RdDCarac } from "../rdd-carac.js"; export class ChatRollResult { static onReady() { foundry.applications.handlebars.loadTemplates({ 'partial-appel-chance': 'systems/foundryvtt-reve-de-dragon/templates/roll/result/partial-appel-chance.hbs', 'partial-encaissement': 'systems/foundryvtt-reve-de-dragon/templates/roll/result/partial-encaissement.hbs', 'partial-recul-choc': 'systems/foundryvtt-reve-de-dragon/templates/roll/result/partial-recul-choc.hbs', 'partial-info-appel-moral': 'systems/foundryvtt-reve-de-dragon/templates/roll/result/partial-info-appel-moral.hbs', }) } async display(roll) { roll.show = roll.show || {}; roll.show.chance = this.isAppelChancePossible(roll) roll.show.encaissement = this.isShowEncaissement(roll) roll.show.recul = this.isShowReculChoc(roll) const chatMessage = await ChatUtility.createChatWithRollMode( { content: await this.buildRollHtml(roll) }, roll.active.actor, roll.current?.rollmode?.key ) if (roll.show.chance) { const save = RollDialog.saveParts(roll) console.log("Store message roll", save) ChatUtility.setMessageData(chatMessage, 'rollData', save) } return chatMessage } isAppelChancePossible(roll) { return roll.active.actor.isPersonnage() && roll.rolled.isEchec && RdDCarac.isActionPhysique(roll.current.carac?.key) } isShowEncaissement(roll) { return roll.rolled.isEchec && roll.attackerRoll?.dmg.mortalite != 'empoignade' } isShowReculChoc(roll) { return roll.rolled.isEchec && roll.attackerRoll && !roll.current.defense.isEsquive && (roll.attackerRoll.particuliere == 'force' || 'charge' == attackerRoll.tactique?.key) } async buildRollHtml(roll) { const template = `systems/foundryvtt-reve-de-dragon/templates/roll/result/chat-${roll.type.current}.hbs` return await foundry.applications.handlebars.renderTemplate(template, roll) } }