diff --git a/module/rdd-combat.js b/module/rdd-combat.js index e8de4d6e..4fb9e504 100644 --- a/module/rdd-combat.js +++ b/module/rdd-combat.js @@ -626,11 +626,13 @@ export class RdDCombat { const defenderTokenId = event.currentTarget.attributes['data-defenderTokenId']?.value; const armeParadeId = event.currentTarget.attributes['data-armeid']?.value; + const competence = event.currentTarget.attributes['data-competence']?.value; + const compId = event.currentTarget.attributes['data-compid']?.value; switch (button) { case '#particuliere-attaque': return await this.choixParticuliere(attackerRoll, event.currentTarget.attributes['data-mode'].value); - case '#parer-button': return this.parade(attackerRoll, armeParadeId); - case '#esquiver-button': return this.esquive(attackerRoll); + case '#parer-button': return this.parade(attackerRoll, armeParadeId, competence); + case '#esquiver-button': return this.esquive(attackerRoll, compId, competence); case '#encaisser-button': return this.encaisser(attackerRoll, defenderTokenId); case '#echec-total-attaque': return this._onEchecTotal(attackerRoll); @@ -872,7 +874,7 @@ export class RdDCombat { await this._sendMessageDefense(attackerRoll, defenderRoll); } } - + /* -------------------------------------------- */ isPossession( attackerRoll) { return attackerRoll.selectedCarac.label.toLowerCase() == 'possession'; @@ -888,18 +890,18 @@ export class RdDCombat { } // # utilisation esquive - const esquive = Misc.data(this.defender.getCompetence("esquive")); - const corpsACorps = Misc.data(this.defender.getCompetence("Corps à corps")); - const esquiveUsage = esquive ? this.defender.getItemUse(esquive._id) : 0; + const corpsACorps = Misc.data(this.defender.getCompetence("Corps à corps", { onMessage: it => console.info(it, this.defender) })); + const esquives = duplicate(this.defender.getCompetences("esquive", { onMessage: it => console.info(it, this.defender) }).map(c => Misc.data(c))); + esquives.forEach(e => e.usages = e?.id ? this.defender.getItemUse(e.id) : 0); const paramChatDefense = { passeArme: attackerRoll.passeArme, essais: attackerRoll.essais, - isPossession: this.isPossession( attackerRoll), + isPossession: this.isPossession(attackerRoll), defender: Misc.data(this.defender), attacker: Misc.data(this.attacker), attackerId: this.attackerId, - esquiveUsage: esquiveUsage, + esquives: esquives, defenderTokenId: this.defenderTokenId, mainsNues: attackerRoll.dmg.mortalite != 'mortel' && corpsACorps, armes: this._filterArmesParade(this.defender, attackerRoll.competence, attackerRoll.arme), @@ -1014,12 +1016,12 @@ export class RdDCombat { } /* -------------------------------------------- */ - async parade(attackerRoll, armeParadeId) { + async parade(attackerRoll, armeParadeId, competence) { let arme = this.defender.getArmeParade(armeParadeId); console.log("RdDCombat.parade >>>", attackerRoll, armeParadeId, arme); - let rollData = this._prepareParade(attackerRoll, arme); + let rollData = this._prepareParade(attackerRoll, arme, competence); const dialog = await RdDRoll.create(this.defender, rollData, { @@ -1042,20 +1044,16 @@ export class RdDCombat { } /* -------------------------------------------- */ - _prepareParade(attackerRoll, armeParade) { - const compName = armeParade.data.competence; - const armeAttaque = attackerRoll.arme; - const parade = Misc.data(this.defender.getCompetence(compName)); - + _prepareParade(attackerRoll, armeParade, competenceParade) { let defenderRoll = { passeArme: attackerRoll.passeArme, diffLibre: attackerRoll.diffLibre, attackerRoll: attackerRoll, - competence: parade, + competence: Misc.data(this.defender.getCompetence(competenceParade)), arme: armeParade, surprise: this.defender.getSurprise(true), needParadeSignificative: ReglesOptionelles.isUsing('categorieParade') && RdDItemArme.needParadeSignificative(armeAttaque, armeParade), - needResist: RdDItemArme.needArmeResist(armeAttaque, armeParade), + needResist: RdDItemArme.needArmeResist(attackerRoll.arme, armeParade), carac: Misc.templateData(this.defender).carac, show: {} }; @@ -1101,10 +1099,10 @@ export class RdDCombat { } /* -------------------------------------------- */ - async esquive(attackerRoll) { - const esquive = Misc.data(this.defender.getCompetence("esquive")); + async esquive(attackerRoll, compId, compName) { + const esquive = Misc.data(this.defender.getCompetence(compId) ?? this.defender.getCompetence(compName)); if (esquive == undefined) { - ui.notifications.error(this.defender.name + " n'a pas de compétence 'esquive'"); + ui.notifications.error(this.defender.name + " n'a pas de compétence " + compName); return; } console.log("RdDCombat.esquive >>>", attackerRoll, esquive); diff --git a/templates/actor-sheet.html b/templates/actor-sheet.html index a739487c..fc36ed3b 100644 --- a/templates/actor-sheet.html +++ b/templates/actor-sheet.html @@ -290,13 +290,22 @@ {{numberFormat arme.data.dommagesReels decimals=0 sign=true}} {{/each}} -