From e71c03abb0f4698eaefde1866ffe6cbf2f4e2b1d Mon Sep 17 00:00:00 2001 From: Vincent Vandemeulebrouck Date: Thu, 18 Mar 2021 23:55:59 +0100 Subject: [PATCH] Fix erreur en cas d'attaque sans cible --- module/actor.js | 2 +- module/rdd-combat.js | 26 ++++++++++++++++---------- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/module/actor.js b/module/actor.js index 30a01d16..659a971d 100644 --- a/module/actor.js +++ b/module/actor.js @@ -2546,7 +2546,7 @@ export class RdDActor extends Actor { let competence = this.getCompetence(compName); if (arme || armeName || (competence.type == 'competencecreature' && competence.data.iscombat)) { - RdDCombat.createUsingTarget(this).attaque(competence, arme); + RdDCombat.createUsingTarget(this)?.attaque(competence, arme); } else { this.rollCompetence(competence.name); } diff --git a/module/rdd-combat.js b/module/rdd-combat.js index db85f5c1..e668de44 100644 --- a/module/rdd-combat.js +++ b/module/rdd-combat.js @@ -413,9 +413,11 @@ export class RdDCombat { ? "Vous devez choisir une seule cible à attaquer!" : "Vous devez choisir une cible à attaquer!"); } - const defender = target?.actor; - const defenderTokenId = target?.data._id; - return this.create(attacker, defender, defenderTokenId, target) + else { + const defender = target?.actor; + const defenderTokenId = target?.data._id; + return this.create(attacker, defender, defenderTokenId, target) + } } /* -------------------------------------------- */ @@ -500,11 +502,13 @@ export class RdDCombat { } if ((game.user.isGM && !defenderToken.actor.hasPlayerOwner) || (defenderToken.actor.hasPlayerOwner && (game.user.character._id == defenderToken.actor.data._id))) { const rddCombat = RdDCombat.createForAttackerAndDefender(msg.attackerId, msg.defenderTokenId); - const defenderRoll = msg.defenderRoll; - RdDCombat._storeAttaque(msg.attackerId, defenderRoll.attackerRoll); - RdDCombat._storeDefense(defenderRoll); - rddCombat.removeChatMessageActionsPasseArme(defenderRoll.passeArme); - rddCombat._chatMessageDefense(msg.paramChatDefense); + if (rddCombat) { + const defenderRoll = msg.defenderRoll; + RdDCombat._storeAttaque(msg.attackerId, defenderRoll.attackerRoll); + RdDCombat._storeDefense(defenderRoll); + rddCombat.removeChatMessageActionsPasseArme(defenderRoll.passeArme); + rddCombat._chatMessageDefense(msg.paramChatDefense); + } } } } @@ -533,9 +537,11 @@ export class RdDCombat { const rddCombat = RdDCombat.createForAttackerAndDefender( event.currentTarget.attributes['data-attackerId']?.value, event.currentTarget.attributes['data-defenderTokenId']?.value); + if (rddCombat) { - rddCombat.onEvent(button, event); - event.preventDefault(); + rddCombat.onEvent(button, event); + event.preventDefault(); + } }); } html.on("click", '#chat-jet-vie', event => {