diff --git a/module/actor.js b/module/actor.js index e0d09e07..17f3432e 100644 --- a/module/actor.js +++ b/module/actor.js @@ -1758,7 +1758,7 @@ export class RdDActor extends Actor { } /* -------------------------------------------- */ - async rollAppelChance( onSuccess = () => {}, onEchec= ()=>{}) + async rollAppelChance(onSuccess = () => {}, onEchec = () => {}) { let rollData = { selectedCarac: this.getCaracByName('chance-actuelle'), surprise: '' }; const dialog = await RdDRoll.create(this, rollData, @@ -1768,21 +1768,23 @@ export class RdDActor extends Actor { label: 'Appel à la chance', callbacks: [ this.createCallbackExperience(), - { action: r => this._appelChanceResult(r) }, - { condition: r=> r.rolled.isSuccess, action: r => onSuccess() }, - { condition: r=> r.rolled.isEchec, action: r => onEchec() } + { action: r => this._appelChanceResult(r, onSuccess, onEchec) }, ] } - ); - dialog.render(true); - } - - /* -------------------------------------------- */ - async _appelChanceResult(rollData) { - if (rollData.rolled.isSuccess) { - await this.chanceActuelleIncDec(-1) + ); + dialog.render(true); } - RdDResolutionTable.displayRollData(rollData, this, 'chat-resultat-appelchance.html') + + /* -------------------------------------------- */ + async _appelChanceResult(rollData, onSuccess = () => {}, onEchec= ()=>{}) { + await RdDResolutionTable.displayRollData(rollData, this, 'chat-resultat-appelchance.html') + if (rollData.rolled.isSuccess) { + await this.chanceActuelleIncDec(-1) + onSuccess(); + } + else { + onEchec(); + } } /* -------------------------------------------- */ diff --git a/module/chat-utility.js b/module/chat-utility.js index 39bd8f67..6535d1f1 100644 --- a/module/chat-utility.js +++ b/module/chat-utility.js @@ -5,8 +5,8 @@ export class ChatUtility { static removeMyChatMessageContaining(part) { const toDelete = game.messages.filter(it => it.user._id == game.user._id) - .filter(it => it.data.content.includes(part)) - .forEach(it => it.delete()); + .filter(it => it.data.content.includes(part)); + toDelete.forEach(it => it.delete()); } diff --git a/module/rdd-combat.js b/module/rdd-combat.js index 59aef090..9616299a 100644 --- a/module/rdd-combat.js +++ b/module/rdd-combat.js @@ -101,6 +101,9 @@ export class RdDCombat { '#encaisser-button', '#appel-chance-defense', '#appel-destinee-defense', + '#appel-chance-attaque', + '#appel-destinee-attaque', + '#echec-total-attaque', ]) { html.on("click", button, event => { event.preventDefault(); @@ -133,72 +136,96 @@ export class RdDCombat { } const defenderTokenId = event.currentTarget.attributes['data-defenderTokenId'].value; - let defenderRoll = this._consumeDefense(attackerRoll.passeArme); + let defenderRoll = this._getDefense(attackerRoll.passeArme); + const armeParadeId = event.currentTarget.attributes['data-armeid']?.value; switch (button) { case '#particuliere-attaque': return await this.choixParticuliere(attackerRoll, event.currentTarget.attributes['data-mode'].value); - case '#parer-button': { - const armeId = event.currentTarget.attributes['data-armeid']; - return this.parade(attackerRoll, armeId?.value); - } + case '#parer-button': return this.parade(attackerRoll, armeParadeId); case '#esquiver-button': return this.esquive(attackerRoll); case '#encaisser-button': return this.encaisser(attackerRoll, defenderTokenId); + case '#echec-total-attaque': return this._onEchecTotal(attackerRoll); + case '#appel-chance-attaque': return this.attacker.rollAppelChance( + () => this.attaqueChanceuse(attackerRoll), + () => this._onEchecTotal(attackerRoll)); case '#appel-chance-defense': return this.defender.rollAppelChance( - () => this.rejouerDefense(defenderRoll, { chance: true }), - () => this.afficherOptionsDefense(attackerRoll, { chance: true })); - - case '#appel-destinee-defense': return this.defender.appelDestinee( - () => this.defenseSignificative(defenderRoll), - () => this.afficherOptionsDefense(attackerRoll, { destinee: true })); + () => this.defenseChanceuse(attackerRoll, defenderRoll), + () => this.afficherOptionsDefense(attackerRoll, { defenseChance: true })); + case '#appel-destinee-attaque': return this.attacker.appelDestinee( + () => this.attaqueSignificative(attackerRoll), + () => { }); + case '#appel-destinee-defense': return this.defender.appelDestinee( + () => this.defenseDestinee(defenderRoll), + () => { }); } } + /* -------------------------------------------- */ _consumeDefense(passeArme) { - let defenderRoll = game.system.rdd.rollDataHandler.defenses[passeArme]; + let defenderRoll = this._getDefense(passeArme); game.system.rdd.rollDataHandler.defenses[passeArme] = undefined; return defenderRoll; } + /* -------------------------------------------- */ + _getDefense(passeArme) { + return game.system.rdd.rollDataHandler.defenses[passeArme]; + } + + /* -------------------------------------------- */ _storeDefense(defenderRoll) { game.system.rdd.rollDataHandler.defenses[defenderRoll.passeArme] = defenderRoll; } - rejouerDefense(defenderRoll, tentatives) { + /* -------------------------------------------- */ + attaqueChanceuse(attackerRoll) { + ui.notifications.info("L'attaque est rejouée grâce à la chance") + attackerRoll.essais.attaqueChance = true; + this.attaque(attackerRoll, attackerRoll.arme); + } + + /* -------------------------------------------- */ + attaqueDestinee(attackerRoll) { + ui.notifications.info('Attaque significative grâce à la destinée') + RdDResolutionTable.forceSignificative(attackerRoll.rolled); + this.removeChatMessageActionsPasseArme(attackerRoll.passeArme); + this._onAttaqueNormale(attackerRoll); + } + + /* -------------------------------------------- */ + defenseChanceuse(attackerRoll, defenderRoll) { ui.notifications.info("La défense est rejouée grâce à la chance") - const attackerRoll = defenderRoll.attackerRoll; + attackerRoll.essais.defenseChance = true; + attackerRoll.essais.defense = false; this.removeChatMessageActionsPasseArme(attackerRoll.passeArme); - this.addTentatives(attackerRoll, tentatives); - - if (defenderRoll.arme) { - this.parade(attackerRoll, defenderRoll.arme._id); - } - else{ - this.esquive(attackerRoll); - } + this._sendMessageDefense(attackerRoll); } - afficherOptionsDefense(attackerRoll, tentatives) { - ui.notifications.info("La chance n'est pas avec vous") - this._sendMessageDefense(attackerRoll, tentatives); - } - - defenseSignificative(defenderRoll){ - ui.notifications.info('defense significative grâce à la destinée') - const attackerRoll = defenderRoll.attackerRoll; + /* -------------------------------------------- */ + defenseDestinee(defenderRoll) { + ui.notifications.info('Défense significative grâce à la destinée') RdDResolutionTable.forceSignificative(defenderRoll.rolled); - this.removeChatMessageActionsPasseArme(attackerRoll.passeArme); + this.removeChatMessageActionsPasseArme(defenderRoll.passeArme); if (defenderRoll.arme) { this._onParadeNormale(defenderRoll); } - else{ + else { this._onEsquiveNormale(defenderRoll); } } + /* -------------------------------------------- */ + afficherOptionsDefense(attackerRoll, essais) { + ui.notifications.info("La chance n'est pas avec vous"); + this._sendMessageDefense(attackerRoll, essais); + } + /* -------------------------------------------- */ removeChatMessageActionsPasseArme(passeArme) { - ChatUtility.removeMyChatMessageContaining(`