diff --git a/changelog.md b/changelog.md index ac57dcb5..bd15a1c3 100644 --- a/changelog.md +++ b/changelog.md @@ -1,4 +1,17 @@ # 13.0 +## 13.0.13 - L'épanouissement d'Illysis + +- Fix d'erreur au chargement de templates RollDialog +- Nouvelle fenêtre de jets de dés + - Fix: affichage des points de tâche + - Fix: affichage des ajustements cohérent + - L'ouverture depuis les caractéristiques permet plusieurs types de jets + - On peut créer ou modifier les tâches dans la fenêtre de jets de tâches + - attaque/défense + - les maladresses sont affichées dans le résultat du jet + - le message au défenseur s'affiche correctement + - la difficulté d'attaque s'applique à la défense + - on peut choisir les particulières en rapidité ## 13.0.12 - La méditation d'Illysis diff --git a/css/foundryvtt-reve-de-dragon.css b/css/foundryvtt-reve-de-dragon.css index 52b95706..ff117aac 100644 --- a/css/foundryvtt-reve-de-dragon.css +++ b/css/foundryvtt-reve-de-dragon.css @@ -707,6 +707,10 @@ select, display: flex; flex-direction: column; } +.system-foundryvtt-reve-de-dragon .chat-message div.roll-chat div.chat-details div, +.system-foundryvtt-reve-de-dragon .dialog-content div.roll-chat div.chat-details div { + display: block; +} .system-foundryvtt-reve-de-dragon .chat-message div.roll-chat div.chat-actions, .system-foundryvtt-reve-de-dragon .dialog-content div.roll-chat div.chat-actions { grid-area: actions; @@ -757,7 +761,10 @@ select, .system-foundryvtt-reve-de-dragon .window-header { background: rgba(0, 0, 0, 0.75); } -.system-foundryvtt-reve-de-dragon .application .window-content, +.system-foundryvtt-reve-de-dragon .application .window-content { + margin: 0; + padding: 0.2rem; +} .system-foundryvtt-reve-de-dragon .window-app.sheet .window-content { margin: 0.2rem; padding: 0; @@ -1640,8 +1647,9 @@ select, height: 2rem; } .system-foundryvtt-reve-de-dragon .window-app .window-content, -.system-foundryvtt-reve-de-dragon .window-app.sheet .window-content .sheet-body { - background: #f5f5f0 url(../assets/ui/bg_left.webp) no-repeat left top; +.system-foundryvtt-reve-de-dragon .window-app.sheet .window-content .sheet-body, +.system-foundryvtt-reve-de-dragon .application .window-content { + background: url(../assets/ui/bg_left.webp) no-repeat left top; } .system-foundryvtt-reve-de-dragon section.sheet-body { padding: 0.25rem 0.5rem; @@ -2316,7 +2324,7 @@ select, pointer-events: all; } .system-foundryvtt-reve-de-dragon div.horloge-roue div.horloge-cercle { - background: hsl(60, 20%, 95%) url(../assets/ui/bg_left.webp) no-repeat left top; + background: hsla(60, 20%, 90%, 0.8); top: 2%; left: 2%; width: 96%; diff --git a/less/foundryvtt-reve-de-dragon.less b/less/foundryvtt-reve-de-dragon.less index 125de5ec..fd96d073 100644 --- a/less/foundryvtt-reve-de-dragon.less +++ b/less/foundryvtt-reve-de-dragon.less @@ -12,7 +12,10 @@ background: rgba(0,0,0,0.75); } - .application .window-content, + .application .window-content { + margin: 0; + padding: 0.2rem; + } .window-app.sheet .window-content { margin: 0.2rem; padding: 0; @@ -955,8 +958,10 @@ } } - .window-app .window-content, .window-app.sheet .window-content .sheet-body{ - background: rgb(245,245,240) url(../assets/ui/bg_left.webp) no-repeat left top; + .window-app .window-content, + .window-app.sheet .window-content .sheet-body, + .application .window-content { + background: url(../assets/ui/bg_left.webp) no-repeat left top; } section.sheet-body { @@ -1677,7 +1682,7 @@ } div.horloge-roue div.horloge-cercle { - background: hsl(60, 20%, 95%) url(../assets/ui/bg_left.webp) no-repeat left top; + background: hsla(60, 20%, 90%, 0.8); top: 2%; left: 2%; width: 96%; height: 96%; border-radius: 50%; } diff --git a/less/roll-chat.less b/less/roll-chat.less index 69eb436e..aa77534d 100644 --- a/less/roll-chat.less +++ b/less/roll-chat.less @@ -37,6 +37,9 @@ text-align: justify; display: flex; flex-direction: column; + div { + display: block; + } } div.chat-actions { grid-area: actions; diff --git a/module/actor-sheet.js b/module/actor-sheet.js index 27f658b8..6fdbdc07 100644 --- a/module/actor-sheet.js +++ b/module/actor-sheet.js @@ -342,7 +342,7 @@ export class RdDActorSheet extends RdDBaseActorSangSheet { /* -------------------------------------------- */ async createEmptyTache() { - await this.actor.createItem('tache', 'Nouvelle tache'); + await this.actor.createItem(ITEM_TYPES.tache, 'Nouvelle tache') } _getActionCombat(event) { diff --git a/module/actor/base-actor-reve.js b/module/actor/base-actor-reve.js index bc9b256b..65dd8f57 100644 --- a/module/actor/base-actor-reve.js +++ b/module/actor/base-actor-reve.js @@ -387,7 +387,7 @@ export class RdDBaseActorReve extends RdDBaseActor { if (OptionsAvancees.isUsing(ROLL_DIALOG_V2)) { const rollData = { ids: { actorId: this.id }, - type: { allowed: [PART_COMP], current: PART_COMP }, + type: { allowed: DEFAULT_ROLL_TYPES, current: PART_COMP }, selected: { carac: { key: caracName }, comp: options.resistance ? { key: undefined, forced: true } : undefined diff --git a/module/constants.js b/module/constants.js index 7bfb3481..20eb0b4b 100644 --- a/module/constants.js +++ b/module/constants.js @@ -55,7 +55,7 @@ export const RDD_CONFIG = { particuliere: { force: { key: 'force', descr: 'en force', img: 'systems/foundryvtt-reve-de-dragon/assets/ui/part-force.svg'}, finesse: { key: 'finesse', descr: 'en finesse', img: 'systems/foundryvtt-reve-de-dragon/assets/ui/part-finesse.svg'}, - rapidite: { key: 'finesse', descr: 'en rapidité', img: 'systems/foundryvtt-reve-de-dragon/assets/ui/part-rapidite.svg'}, + rapidite: { key: 'rapidite', descr: 'en rapidité', img: 'systems/foundryvtt-reve-de-dragon/assets/ui/part-rapidite.svg'}, } } diff --git a/module/rdd-bonus.js b/module/rdd-bonus.js index f808768e..ff755333 100644 --- a/module/rdd-bonus.js +++ b/module/rdd-bonus.js @@ -47,7 +47,7 @@ export class RdDBonus { penetration: RdDBonus._peneration(rollData), dmgTactique: RdDBonus.dmgBonus(rollData.tactique), dmgParticuliere: RdDBonus._dmgParticuliere(rollData), - dmgSurprise: RdDBonus.dmgBonus(rollData.ajustements?.attaqueDefenseurSurpris.used), + dmgSurprise: RdDBonus.dmgBonus(rollData.ajustements?.attaqueDefenseurSurpris?.used), mortalite: RdDBonus._calculMortalite(rollData, isEntiteIncarnee), dmgActor: RdDBonus.bonusDmg(actor, rollData.selectedCarac?.label.toLowerCase(), dmgArme), dmgForceInsuffisante: Math.min(0, actor.getForce() - forceRequise) diff --git a/module/rdd-combat.js b/module/rdd-combat.js index 821adf98..6bb9c2b0 100644 --- a/module/rdd-combat.js +++ b/module/rdd-combat.js @@ -15,9 +15,8 @@ import { RdDItemCompetence } from "./item-competence.js"; import { MAP_PHASE, RdDInitiative } from "./initiative.mjs"; import RollDialog from "./roll/roll-dialog.mjs"; import { PART_DEFENSE } from "./roll/roll-part-defense.mjs"; -import { RollDialogAdapter } from "./roll/roll-dialog-adapter.mjs"; -import { ROLL_TYPE_ATTAQUE, ROLL_TYPE_DEFENSE } from "./roll/roll-constants.mjs"; -import { OptionsAvancees, ROLL_DIALOG_V2, ROLL_DIALOG_V2_TEST } from "./settings/options-avancees.js"; +import { DIFF, ROLL_TYPE_ATTAQUE, ROLL_TYPE_DEFENSE } from "./roll/roll-constants.mjs"; +import { OptionsAvancees, ROLL_DIALOG_V2 } from "./settings/options-avancees.js"; import { MappingCreatureArme } from "./item/mapping-creature-arme.mjs"; import { RollBasicParts } from "./roll/roll-basic-parts.mjs"; @@ -380,7 +379,7 @@ export class RdDCombat { if (defenderToken && Misc.isFirstConnectedGM()) { const rddCombat = RdDCombat.rddCombatForAttackerAndDefender(msg.attackerId, msg.attackerToken.id, msg.defenderToken.id) rddCombat?.removeChatMessageActionsPasseArme(msg.paramChatDefense.attackerRoll.passeArme) - if (msg.defenderRoll.ids) {/* TODO: delete roll V1 */ + if (msg.defenderRoll.v2) {/* TODO: delete roll V1 */ RollDialog.loadRollData(msg.paramChatDefense) rddCombat?._chatMessageDefenseV2(msg.paramChatDefense) } else { @@ -561,7 +560,7 @@ export class RdDCombat { /* -------------------------------------------- */ static isEchecTotal(rollData) { - if (rollData.ids /* roll V2*/) { + if (rollData.v2 /* roll V2*/) { // TODO: en cas de demi-surprise à l'attaque, tout échec est un echec total. // TODO: en cas de demi-surprise en défense, pas de changement à la règle de base return rollData.rolled.isETotal @@ -575,7 +574,7 @@ export class RdDCombat { /* -------------------------------------------- */ static isParticuliere(rollData) { - if (rollData.ids /* roll V2*/) { + if (rollData.v2 /* roll V2*/) { return rollData.rolled.isPart } if (rollData.attackerRoll || !rollData.ajustements.surprise.used) { @@ -586,7 +585,7 @@ export class RdDCombat { /* -------------------------------------------- */ static isReussite(rollData) { - if (rollData.ids /* roll V2*/) { + if (rollData.v2 /* roll V2*/) { return rollData.rolled.isSuccess } if (!rollData.ajustements.surprise.used) { @@ -686,11 +685,7 @@ export class RdDCombat { async doRollAttaque(rollData, callbacks = []) { // TODO V2 await this.proposerAjustementTirLancer(rollData) await RollDialog.create(rollData, { - onRollDone: (dialog) => { - if (!OptionsAvancees.isUsing(ROLL_DIALOG_V2_TEST)) - dialog.close() - }, - customChatMessage: true, + onRollDone: RollDialog.onRollDoneClose, callbacks: [ async (roll) => await this.onAttaqueV2(roll), ...callbacks @@ -892,7 +887,10 @@ export class RdDCombat { /* -------------------------------------------- */ isPossession(attackerRoll) { - return attackerRoll.selectedCarac.label.toLowerCase() == 'possession'; + const carac = attackerRoll.v2 + ? attackerRoll.current.carac?.label + : attackerRoll.selectedCarac.label + return carac?.toLowerCase() == 'possession'; } /* -------------------------------------------- */ @@ -1067,7 +1065,7 @@ export class RdDCombat { opponentId: this.attackerId, }, type: { allowed: [ROLL_TYPE_DEFENSE], current: ROLL_TYPE_DEFENSE }, - attackerRoll: RollDialogAdapter.mapActionAttaque(attackerRoll), + attackerRoll: attackerRoll, passeArme: attackerRoll.passeArme, }) } @@ -1075,7 +1073,6 @@ export class RdDCombat { async doRollDefense(rollData, callbacks = []) { await RollDialog.create(rollData, { onRollDone: RollDialog.onRollDoneClose, - customChatMessage: true, callbacks: [ async (roll) => { this.removeChatMessageActionsPasseArme(roll.passeArme); diff --git a/module/roll/chat-roll-result.mjs b/module/roll/chat-roll-result.mjs index 8ebd592e..d64212bd 100644 --- a/module/roll/chat-roll-result.mjs +++ b/module/roll/chat-roll-result.mjs @@ -1,5 +1,5 @@ import { ChatUtility } from "../chat-utility.js" -import RollDialog from "./roll-dialog.mjs" +import RollDialog, { ALL_ROLL_TYPES } from "./roll-dialog.mjs" import { RdDCarac } from "../rdd-carac.js" import { RdDCombat } from "../rdd-combat.js" import { ROLL_TYPE_ATTAQUE, ROLL_TYPE_DEFENSE } from "./roll-constants.mjs" @@ -22,8 +22,10 @@ export default class ChatRollResult { static onReady() { foundry.applications.handlebars.loadTemplates({ + 'partial-infojet': 'systems/foundryvtt-reve-de-dragon/templates/roll/result/partial-infojet.hbs', 'partial-appel-chance': 'systems/foundryvtt-reve-de-dragon/templates/roll/result/partial-appel-chance.hbs', 'partial-attaque-particuliere': 'systems/foundryvtt-reve-de-dragon/templates/roll/result/partial-attaque-particuliere.hbs', + 'partial-choix-maladresse': 'systems/foundryvtt-reve-de-dragon/templates/roll/result/partial-choix-maladresse.hbs', 'partial-maladresse': 'systems/foundryvtt-reve-de-dragon/templates/roll/result/partial-maladresse.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', @@ -122,7 +124,7 @@ export default class ChatRollResult { } async buildRollHtml(roll) { - const template = `systems/foundryvtt-reve-de-dragon/templates/roll/result/chat-${roll.type.current}.hbs` + const template = ALL_ROLL_TYPES.find(it => it.code == roll.type.current).chatResultTemplate const html = await renderTemplate(template, roll) return await RdDTextEditor.enrichHTML(html, undefined, { showLink: false }) } @@ -137,7 +139,6 @@ export default class ChatRollResult { $(html).on("click", '.monter-tmr-normale', event => this.onClickMonteeTMR(event, 'normal')) $(html).on("click", '.monter-tmr-rapide', event => this.onClickMonteeTMR(event, 'rapide')) $(html).on("click", '.tirer-maladresse', event => this.onClickTirerMaladresse(event)) - } getCombat(roll) { @@ -145,7 +146,7 @@ export default class ChatRollResult { case ROLL_TYPE_DEFENSE: return RdDCombat.rddCombatForAttackerAndDefender(roll.ids.opponentId, roll.ids.opponentTokenId, roll.ids.actorTokenId) case ROLL_TYPE_ATTAQUE: - return RdDCombat.rddCombatForAttackerAndDefender(roll.ids.actorId, roll.ids.actorTokenId, roll.ids.opponentId) + return RdDCombat.rddCombatForAttackerAndDefender(roll.ids.actorId, roll.ids.actorTokenId, roll.ids.opponentTokenId) } return undefined } @@ -162,6 +163,7 @@ export default class ChatRollResult { await this.saveChatMessageRoll(chatMessage, savedRoll) const copy = foundry.utils.duplicate(savedRoll) RollDialog.loadRollData(copy) + savedRoll.dmg = copy.current.attaque?.dmg this.prepareDisplay(copy) chatMessage.update({ content: await this.buildRollHtml(copy) }) chatMessage.render(true) @@ -248,7 +250,7 @@ export default class ChatRollResult { savedRoll.particuliere = choix savedRoll.particulieres = [RDD_CONFIG.particuliere[choix]] await this.updateChatMessage(chatMessage, savedRoll) - await this.getCombat(savedRoll)?.onAttaqueV2(savedRoll, callbacks) + await this.getCombat(savedRoll)?.onAttaqueV2(savedRoll) } async onClickFaireGouter(event) { @@ -273,8 +275,7 @@ export default class ChatRollResult { const chatMessage = ChatUtility.getChatMessage(event) const typeMaladresse = event.currentTarget.attributes['data-maladresse'].value const savedRoll = this.loadChatMessageRoll(chatMessage) - await RdDRollTables.getMaladresse({ arme: typeMaladresse == 'avec-arme' }) - savedRoll.type.maladresse = true + savedRoll.maladresse = await RdDRollTables.getMaladresse({ arme: typeMaladresse == 'avec-arme', toChat: false }) savedRoll.type.retry = true await this.updateChatMessage(chatMessage, savedRoll) } diff --git a/module/roll/roll-constants.mjs b/module/roll/roll-constants.mjs index 7eedf6d5..5a44584b 100644 --- a/module/roll/roll-constants.mjs +++ b/module/roll/roll-constants.mjs @@ -13,7 +13,6 @@ export const ATTAQUE_ROLL_TYPES = [ROLL_TYPE_ATTAQUE] export const COMBAT_ROLL_TYPES = [ROLL_TYPE_ATTAQUE, ROLL_TYPE_DEFENSE] export const DEMIREVE_ROLL_TYPES = [ROLL_TYPE_SORT] export const DEFAULT_ROLL_TYPES = [ROLL_TYPE_COMP, ROLL_TYPE_TACHE, ROLL_TYPE_MEDITATION, ROLL_TYPE_CUISINE, ROLL_TYPE_OEUVRE, ROLL_TYPE_JEU] -export const ALL_ROLL_TYPES = [...DEFAULT_ROLL_TYPES, ...COMBAT_ROLL_TYPES, ...DEMIREVE_ROLL_TYPES] export const DIFF = { diff --git a/module/roll/roll-dialog-adapter.mjs b/module/roll/roll-dialog-adapter.mjs index e6252591..6f5a7c9a 100644 --- a/module/roll/roll-dialog-adapter.mjs +++ b/module/roll/roll-dialog-adapter.mjs @@ -8,7 +8,7 @@ import { RdDItemArme } from "../item/arme.js"; import { RdDBonus } from "../rdd-bonus.js"; import { ITEM_TYPES, RDD_CONFIG } from "../constants.js"; import { CARACS } from "../rdd-carac.js"; -import { ROLL_TYPE_ATTAQUE, ROLL_TYPE_OEUVRE } from "./roll-constants.mjs"; +import { ROLL_TYPE_ATTAQUE, ROLL_TYPE_DEFENSE, ROLL_TYPE_OEUVRE } from "./roll-constants.mjs"; import { PART_ATTAQUE } from "./roll-part-attaque.mjs"; /* -------------------------------------------- */ @@ -27,8 +27,8 @@ export class RollDialogAdapter { RollDialogAdapter.setRollDataRolled(rollData, rolled, rollTitle) RollDialogAdapter.adjustRollDataForV1(rollData) RollDialogAdapter.adjustAttaqueParticuliere(rollData) + RollDialogAdapter.adjustAttaqueDmg(rollData) RollDialogAdapter.adjustDemiSurprise(rollData) - return rolled } @@ -96,14 +96,7 @@ export class RollDialogAdapter { rolled.niveauNecessaire = RdDResolutionTable.findNiveauNecessaire(rollData.selectedCarac.value, rolled.roll) rolled.ajustementNecessaire = rolled.niveauNecessaire - diff } - rollData.ajustements = rollData.ajustements.map(aj => { - return { - used: true, - label: aj.label, - value: aj.diff, - descr: aj.diff == undefined ? aj.label : undefined - } - }) + rollData.ajustements = rollData.ajustements.map(aj => { return { label: aj.label, value: aj.value } }) } static adjustDemiSurprise(rollData) { @@ -112,6 +105,18 @@ export class RollDialogAdapter { } } + static adjustAttaqueDmg(rollData) { + switch (rollData.type.current) { + case ROLL_TYPE_ATTAQUE: + rollData.dmg = RdDBonus.dmgRollV2(rollData, rollData.current.attaque) + break + case ROLL_TYPE_DEFENSE: + rollData.dmg = RdDBonus.dmgRollV2(rollData.attackerRoll, rollData.attackerRoll.current.attaque) + break + } + } + + static adjustAttaqueParticuliere(rollData) { if (rollData.type.current != ROLL_TYPE_ATTAQUE || !rollData.rolled.isPart) { return diff --git a/module/roll/roll-dialog.mjs b/module/roll/roll-dialog.mjs index deffa22a..d2eefe70 100644 --- a/module/roll/roll-dialog.mjs +++ b/module/roll/roll-dialog.mjs @@ -48,7 +48,7 @@ import { ActorImpacts } from "../technical/actor-impacts.mjs"; const { HandlebarsApplicationMixin, ApplicationV2 } = foundry.applications.api -const ALL_ROLL_TYPES = [ +export const ALL_ROLL_TYPES = [ new RollTypeComp(), new RollTypeTache(), new RollTypeAttaque(), @@ -175,11 +175,11 @@ export default class RollDialog extends HandlebarsApplicationMixin(ApplicationV2 { static onCloseDoNothing() { } - static onRollDoneDoNothing(dialog) { + static onRollDoneDoNothing(dialog, roll) { dialog.render() } - static onRollDoneClose(dialog) { - if (!OptionsAvancees.isUsing(ROLL_DIALOG_V2_TEST)) + static onRollDoneClose(dialog, roll) { + if (roll.type.retry || !OptionsAvancees.isUsing(ROLL_DIALOG_V2_TEST)) dialog.close() } @@ -199,7 +199,7 @@ export default class RollDialog extends HandlebarsApplicationMixin(ApplicationV2 ChatRollResult.onReady() - foundry.applications.handlebars.loadTemplates(ALL_ROLL_TYPES.map(m => m.template)) + foundry.applications.handlebars.loadTemplates(ALL_ROLL_TYPES.map(m => m.chatResultTemplate)) foundry.applications.handlebars.loadTemplates(ROLL_PARTS.map(p => p.template)) ROLL_PARTS.forEach(p => p.onReady()) @@ -316,6 +316,7 @@ export default class RollDialog extends HandlebarsApplicationMixin(ApplicationV2 constructor(rollData, rollOptions) { super() + this.hooks = [] this.rollData = RollDialog.$prepareRollData(rollData) this.rollOptions = { callbacks: [ @@ -323,14 +324,28 @@ export default class RollDialog extends HandlebarsApplicationMixin(ApplicationV2 async r => await r.active.actor.appliquerAppelMoral(r), ...(rollOptions.callbacks ?? []) ], - customChatMessage: rollOptions.customChatMessage, onRollDone: rollOptions.onRollDone ?? RollDialog.onRollDoneDoNothing, onClose: rollOptions.onClose ?? RollDialog.onCloseDoNothing } - this.chatRollResult = new ChatRollResult(); + this.chatRollResult = new ChatRollResult() this.selectType() + this.registerHooks(rollData); } + registerHooks(rollData) { + ROLL_PARTS.filter(p => p.isValid(rollData)) + .forEach(p => p.getHooks(this).forEach(h => { + const hook = h.hook; + const id = Hooks.on(hook, h.fn) + this.hooks.push({ hook, id }) + })) + } + + unregisterHooks() { + this.hooks.forEach(h => Hooks.off(h.hook, h.id)) + } + + selectType() { const selectedType = this.getSelectedType(); this.rollData.type.label = selectedType.title(this.rollData) @@ -386,7 +401,7 @@ export default class RollDialog extends HandlebarsApplicationMixin(ApplicationV2 return RollDialog.getActiveParts(rollData) .map(p => p.getAjustements(rollData)) .reduce((a, b) => a.concat(b)) - .sort((a, b) => a.diff == undefined ? 1 : b.diff == undefined ? -1 : 0) + .sort((a, b) => a.value == undefined ? 1 : b.value == undefined ? -1 : 0) } async buildHTMLTable(carac, diff) { @@ -408,7 +423,7 @@ export default class RollDialog extends HandlebarsApplicationMixin(ApplicationV2 visibleRollParts.forEach(p => p.prepareContext(rollData)) - RollDialog.calculAjustements(rollData) + RollDialog.calculAjustement(rollData) const templates = RollDialog.getActiveParts(rollData).map(p => p.toTemplateData()) const context = await super._prepareContext() @@ -430,12 +445,11 @@ export default class RollDialog extends HandlebarsApplicationMixin(ApplicationV2 } } - static calculAjustements(rollData) { + static calculAjustement(rollData) { rollData.ajustements = RollDialog.getAjustements(rollData) - rollData.ajustements.forEach(it => it.isDiff = it.diff != undefined) rollData.current.totaldiff = rollData.ajustements - .map(adj => adj.diff) - .filter(d => d != undefined) + .filter(a => a.value != undefined) + .map(a => a.value) .reduce(Misc.sum(), 0) } @@ -443,13 +457,14 @@ export default class RollDialog extends HandlebarsApplicationMixin(ApplicationV2 return ALL_ROLL_TYPES.find(m => m.code == this.rollData.type.current) } - async close(options){ - if (this.rollOptions.onClose){ + async close(options) { + if (this.rollOptions.onClose) { this.rollOptions.onClose() } + this.unregisterHooks() return await super.close(options) } - + async roll() { const roll = RollDialog.saveParts(this.rollData) @@ -475,13 +490,14 @@ export default class RollDialog extends HandlebarsApplicationMixin(ApplicationV2 await impacts.applyImpacts() selectedRollType.onApplyImpacts(roll, impacts) await this.chatRollResult.display(roll, impacts) - this.rollOptions.onRollDone(this) + this.rollOptions.onRollDone(this, roll) } static loadRollData(roll) { RollDialog.$prepareRollData(roll) - RollDialog.calculAjustements(roll) + RollDialog.calculAjustement(roll) roll.v2 = true + return roll } async defaultCallback(roll, rolled) { diff --git a/module/roll/roll-part-attaque.mjs b/module/roll/roll-part-attaque.mjs index 4eedb0ad..5519ede1 100644 --- a/module/roll/roll-part-attaque.mjs +++ b/module/roll/roll-part-attaque.mjs @@ -63,14 +63,9 @@ export class RollPartAttaque extends RollPartSelect { getAjustements(rollData) { const current = this.getCurrent(rollData) - const ajustements = [] - if (current.tactique) { - ajustements.push({ label: current.tactique.label, diff: current.tactique.attaque }) - } - if (rollData.opponent?.surprise) { - ajustements.push({ label: rollData.opponent.surprise.label, diff: rollData.opponent.surprise.attaque }) - } - return ajustements + const tactique = current.tactique ? [{ label: current.tactique.label, value: current.tactique.attaque }] : [] + const surprise = rollData.opponent?.surprise ? [{ label: rollData.opponent.surprise.label, value: rollData.opponent.surprise.attaque }] : [] + return [...tactique, ...surprise] } diff --git a/module/roll/roll-part-checkbox.mjs b/module/roll/roll-part-checkbox.mjs index c5476ab0..a55975c4 100644 --- a/module/roll/roll-part-checkbox.mjs +++ b/module/roll/roll-part-checkbox.mjs @@ -35,7 +35,7 @@ export class RollPartCheckbox extends RollPart { getAjustements(rollData) { const current = this.getCurrent(rollData) if (current.checked) { - return [{ label: this.getCheckboxLabelAjustement(rollData), diff: current.value }] + return [{ label: this.getCheckboxLabelAjustement(rollData), value: current.value }] } return [] } diff --git a/module/roll/roll-part-coeur.mjs b/module/roll/roll-part-coeur.mjs index 4465ae82..bd525fb8 100644 --- a/module/roll/roll-part-coeur.mjs +++ b/module/roll/roll-part-coeur.mjs @@ -47,7 +47,7 @@ export class RollPartCoeur extends RollPartSelect { if (current.key != '') { return [{ label: "Coeur pour " + current.label, - diff: current.value + value: current.value }] } return [] diff --git a/module/roll/roll-part-conditions.mjs b/module/roll/roll-part-conditions.mjs index 909d7233..9cfdf732 100644 --- a/module/roll/roll-part-conditions.mjs +++ b/module/roll/roll-part-conditions.mjs @@ -57,7 +57,7 @@ export class RollPartConditions extends RollPart { getAjustements(rollData) { const current = this.getCurrent(rollData) if (current.value != 0) { - return [{ label: DESCR_CONDITIONS, diff: current.value }] + return [{ label: DESCR_CONDITIONS, value: current.value }] } return [] } diff --git a/module/roll/roll-part-defense.mjs b/module/roll/roll-part-defense.mjs index 5b63e7ef..63ef5dcd 100644 --- a/module/roll/roll-part-defense.mjs +++ b/module/roll/roll-part-defense.mjs @@ -110,7 +110,7 @@ export class RollPartDefense extends RollPartSelect { isArmeDisparate(rollData) { const armeDefense = this.getCurrent(rollData).arme if (armeDefense) { - const armeAttaque = rollData.attackerRoll?.arme + const armeAttaque = rollData.attackerRoll?.current.attaque.arme return RdDItemArme.defenseArmeParade(armeAttaque, armeDefense) == 'sign' } return false @@ -123,7 +123,11 @@ export class RollPartDefense extends RollPartSelect { return { diff: 0, type: DIFF.LIBRE } } else { - return { diff: rollData.attackerRoll.diff ?? 0, type: DIFF.DEFENSE } + const attackerRoll = rollData.attackerRoll + const diff = attackerRoll.v2 + ? attackerRoll.selected.diff.value + : attackerRoll.diff + return { diff: diff ?? 0, type: DIFF.DEFENSE } } } } diff --git a/module/roll/roll-part-diff.mjs b/module/roll/roll-part-diff.mjs index d54fb4f2..031fb6e4 100644 --- a/module/roll/roll-part-diff.mjs +++ b/module/roll/roll-part-diff.mjs @@ -66,7 +66,7 @@ export class RollPartDiff extends RollPart { const current = this.getCurrent(rollData) return [{ label: current.label, - diff: current.value + value: current.value }] } diff --git a/module/roll/roll-part-meditation.mjs b/module/roll/roll-part-meditation.mjs index 0e55646e..90b971dd 100644 --- a/module/roll/roll-part-meditation.mjs +++ b/module/roll/roll-part-meditation.mjs @@ -72,9 +72,10 @@ export class RollPartMeditation extends RollPartSelect { } getAjustements(rollData) { - const malusEchecs = { label: "Méditation", diff: this.getMalusEchecs(rollData) } - const malusConditions = { label: "Conditions", diff: this.getMalusConditions(rollData) } - return [malusConditions, ...(malusEchecs.diff == 0 ? [] : [malusEchecs])] + const malus = this.getMalusEchecs(rollData) + const malusEchecs = malusEchecs == 0 ? [] : [{ label: "Méditation", value: malus }] + const malusConditions = { label: "Conditions", value: this.getMalusConditions(rollData) } + return [malusConditions, ...malusEchecs] } $selectMeditation(rollData, key) { diff --git a/module/roll/roll-part-select.mjs b/module/roll/roll-part-select.mjs index c681fb65..5b0d0473 100644 --- a/module/roll/roll-part-select.mjs +++ b/module/roll/roll-part-select.mjs @@ -16,7 +16,7 @@ export class RollPartSelect extends RollPart { getAjustements(rollData) { const current = this.getCurrent(rollData) if (current) { - return [{ label: current.label, diff: current.value }] + return [{ label: current.label, value: current.value }] } return [] } diff --git a/module/roll/roll-part-sign.mjs b/module/roll/roll-part-sign.mjs index befb28e9..8dd24c11 100644 --- a/module/roll/roll-part-sign.mjs +++ b/module/roll/roll-part-sign.mjs @@ -76,8 +76,8 @@ export class RollPartSign extends RollPart { const current = this.getCurrent(rollData) if (current.surprise == 'demi') { return [ - { label: 'Significative requise ' + Misc.getFractionOneN(current.diviseur), diff: undefined }, - ...current.reasons.map(it => { return { label: ' ' + it, diff: undefined } }) + { label: 'Significative requise ' + Misc.getFractionOneN(current.diviseur) }, + ...current.reasons.map(it => { return { label: ' ' + it } }) ] } return [] diff --git a/module/roll/roll-part-sort.mjs b/module/roll/roll-part-sort.mjs index ac7627a4..182f7e79 100644 --- a/module/roll/roll-part-sort.mjs +++ b/module/roll/roll-part-sort.mjs @@ -94,16 +94,11 @@ export class RollPartSort extends RollPartSelect { getAjustements(rollData) { const current = this.getCurrent(rollData) if (current) { - const reserve = current.isReserve ? - [{ label: `Mise en réserve en ${this.getCoord(rollData)}` }] : [] - const bonusCase = current.bonusCase ? - [{ label: `Bonus case +${current.bonusCase}%` }] : [] - return [ - { label: current.label, diff: current.value }, - ...bonusCase, - { label: `Rêve ${current.ptreve}` }, - ...reserve - ] + const sort = { label: current.label, value: current.value } + const reserve = current.isReserve ? [{ label: `Mise en réserve en ${this.getCoord(rollData)}` }] : [] + const bonusCase = current.bonusCase ? [{ label: `Bonus case +${current.bonusCase}%` }] : [] + const reve = { label: `Rêve ${current.ptreve}` } + return [sort, ...bonusCase, reve, ...reserve] } return [] } diff --git a/module/roll/roll-part-tache.mjs b/module/roll/roll-part-tache.mjs index 1abb670e..cfde3f82 100644 --- a/module/roll/roll-part-tache.mjs +++ b/module/roll/roll-part-tache.mjs @@ -18,10 +18,12 @@ export class RollPartTache extends RollPartSelect { loadRefs(rollData) { const refs = this.getRefs(rollData) const selected = this.getSelected(rollData) + refs.forced = selected.forced refs.all = rollData.active.actor.itemTypes[ITEM_TYPES.tache] .filter(tache => !selected.forced || tache.id == selected.key) .filter(tache => tache.system.points_de_tache_courant < tache.system.points_de_tache) .map(tache => RollPartTache.$extractTache(tache, rollData.active.actor)) + refs.taches = refs.all if (refs.taches.length > 0) { this.$selectTache(rollData) @@ -46,6 +48,8 @@ export class RollPartTache extends RollPartSelect { async _onRender(rollDialog, context, options) { const selectTache = rollDialog.element.querySelector(`roll-section[name="${this.code}"] select[name="select-tache"]`) + const buttonCreate = rollDialog.element.querySelector(`roll-section[name="${this.code}"] button[name="create-tache"]`) + const buttonEdit = rollDialog.element.querySelector(`roll-section[name="${this.code}"] button[name="edit-tache"]`) selectTache.addEventListener("change", e => { const selectOptions = e.currentTarget.options @@ -53,14 +57,43 @@ export class RollPartTache extends RollPartSelect { this.$selectTache(rollDialog.rollData, selectOptions[index]?.value) rollDialog.render() }) + + buttonCreate?.addEventListener( + "click", async e => { + e.preventDefault() + await rollDialog.rollData.active.actor.createItem(ITEM_TYPES.tache, 'Nouvelle tache') + }) + + buttonEdit?.addEventListener( + "click", e => { + e.preventDefault() + const current = this.getCurrent(rollDialog.rollData) + current.tache?.sheet.render(true) + }) + } + + getHooks(rollDialog) { + return [ + { hook: "createItem", fn: (item, options, id) => this.onCreateUpdateItem(rollDialog, item, options, id) }, + { hook: "updateItem", fn: (item, options, id) => this.onCreateUpdateItem(rollDialog, item, options, id) } + ] + } + + onCreateUpdateItem(rollDialog, item, options, id) { + if (item.type == ITEM_TYPES.tache && item.parent?.id == rollDialog.rollData.active.actor.id) { + this.loadRefs(rollDialog.rollData) + rollDialog.render() + } } impactOtherPart(part, rollData) { if (this.visible(rollData)) { const current = this.getCurrent(rollData) - switch (part.code) { - case PART_CARAC: return part.filterCaracs(rollData, [current?.tache.system.carac]) - case PART_COMP: return part.filterComps(rollData, [current.comp?.name]) + if (current.tache) { + switch (part.code) { + case PART_CARAC: return part.filterCaracs(rollData, [current?.tache.system.carac]) + case PART_COMP: return part.filterComps(rollData, [current.comp?.name]) + } } } return undefined diff --git a/module/roll/roll-part-tricher.mjs b/module/roll/roll-part-tricher.mjs index c0e869c8..0b9c7bb5 100644 --- a/module/roll/roll-part-tricher.mjs +++ b/module/roll/roll-part-tricher.mjs @@ -15,10 +15,6 @@ export class RollPartTricher extends RollPart { current.resultat = Misc.inRange(current.resultat == undefined ? -1 : current.resultat, -1, 100) } - getAjustements(rollData) { - return [] - } - async _onRender(rollDialog, context, options) { const input = rollDialog.element.querySelector(`roll-section[name="${this.code}"] input[name="${this.code}"]`) diff --git a/module/roll/roll-part.mjs b/module/roll/roll-part.mjs index dc7dfb9d..386cc709 100644 --- a/module/roll/roll-part.mjs +++ b/module/roll/roll-part.mjs @@ -6,6 +6,8 @@ export const ROLLDIALOG_SECTION = { CONDITIONS: 'conditions', AJUSTEMENTS: 'ajustements', } + + export class RollPart { static settingKey(rollPart, key) { return `roll-part-${rollPart.code}.${key}` } @@ -104,10 +106,9 @@ export class RollPart { return { code: this.code, name: this.name, template: this.template, section: this.section } } - getAjustements(rollData) { - return [] - } + getAjustements(rollData) { return [] } async _onRender(rollDialog, context, options) { } + getHooks() { return [] } } \ No newline at end of file diff --git a/module/roll/roll-type-tache.mjs b/module/roll/roll-type-tache.mjs index 3e2e19a0..644af0df 100644 --- a/module/roll/roll-type-tache.mjs +++ b/module/roll/roll-type-tache.mjs @@ -12,7 +12,7 @@ export class RollTypeTache extends RollType { title(rollData) { const current = rollData.current[PART_TACHE] const tache = current?.tache - return `travaille à sa tâche: ${tache.name ?? ''}` + return tache ? `travaille à sa tâche: ${tache.name}` : `n'a pas de tâches à travailler` } onSelect(rollData) { diff --git a/templates/chat-infojet.hbs b/templates/chat-infojet.hbs index bc94b4c1..2724a8da 100644 --- a/templates/chat-infojet.hbs +++ b/templates/chat-infojet.hbs @@ -1,4 +1,3 @@ -{{log rolled}}
{{> "systems/foundryvtt-reve-de-dragon/templates/chat-info-appel-au-moral.hbs"}}
-Qualité {{rolled.ptQualite}}, points de tâche {{rolled.ptQualite}} +
Qualité {{rolled.ptQualite}}, points de tâche {{rolled.ptTache}}
{{> 'partial-info-appel-moral'}}