From d2b612c11c9d7e5d0fccc3140f7eb1ff34218b58 Mon Sep 17 00:00:00 2001 From: Vincent Vandemeulebrouck Date: Tue, 1 Jun 2021 00:07:31 +0200 Subject: [PATCH] Fix: regression combat MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Notifier tous les postes clients des données de passe d'arme --- module/rdd-combat.js | 42 +++++++++++++++++++++++++++++++++--------- 1 file changed, 33 insertions(+), 9 deletions(-) diff --git a/module/rdd-combat.js b/module/rdd-combat.js index 0fb909b4..7698a484 100644 --- a/module/rdd-combat.js +++ b/module/rdd-combat.js @@ -357,6 +357,8 @@ export class RdDCombat { return RdDCombat.onMsgEncaisser(sockmsg.data); case "msg_defense": return RdDCombat.onMsgDefense(sockmsg.data); + case "msg_combat_passearme": + return RdDCombat.onMsgPasseArme(sockmsg.data); } } @@ -427,9 +429,31 @@ export class RdDCombat { return undefined; } + static messagePasseArme(data) { + game.socket.emit("system.foundryvtt-reve-de-dragon", { msg: "msg_combat_passearme", data: data }); + RdDCombat.onMsgPasseArme(data); + } + + static onMsgPasseArme(data) { + switch (data.actionPasseArme) { + case "store-attaque": + game.system.rdd.combatStore.attaques[data.id] = data.rollData; + break; + case "store-defense": + game.system.rdd.combatStore.defenses[data.id] = data.rollData; + break; + case "delete-attaque": + delete game.system.rdd.combatStore.attaques[data.id]; + break; + case "delete-defense": + delete game.system.rdd.combatStore.defenses[data.id]; + break; + } + } + /* -------------------------------------------- */ static _storeAttaque(attackerId, attackerRoll) { - game.system.rdd.combatStore.attaques[attackerId] = duplicate(attackerRoll); + RdDCombat.messagePasseArme({ actionPasseArme: "store-attaque", id: attackerId, rollData: attackerRoll }); } /* -------------------------------------------- */ @@ -439,12 +463,12 @@ export class RdDCombat { /* -------------------------------------------- */ static _deleteAttaque(attackerId) { - delete game.system.rdd.combatStore.attaques[attackerId]; + RdDCombat.messagePasseArme({ actionPasseArme: "delete-attaque", id: attackerId }); } /* -------------------------------------------- */ - static _storeDefense(defenderRoll) { - game.system.rdd.combatStore.defenses[defenderRoll.passeArme] = duplicate(defenderRoll); + static _storeDefense(passeArme, defenderRoll) { + RdDCombat.messagePasseArme({ actionPasseArme: "store-defense", id: passeArme, rollData: defenderRoll }); } /* -------------------------------------------- */ @@ -454,7 +478,7 @@ export class RdDCombat { /* -------------------------------------------- */ static _deleteDefense(passeArme) { - delete game.system.rdd.combatStore.defenses[passeArme]; + RdDCombat.messagePasseArme({ actionPasseArme: "delete-defense", id: passeArme }); } /* -------------------------------------------- */ @@ -496,7 +520,7 @@ export class RdDCombat { if (rddCombat) { const defenderRoll = msg.defenderRoll; RdDCombat._storeAttaque(msg.attackerId, defenderRoll.attackerRoll); - RdDCombat._storeDefense(defenderRoll); + RdDCombat._storeDefense(defenderRoll.passeArme, defenderRoll); rddCombat.removeChatMessageActionsPasseArme(defenderRoll.passeArme); rddCombat._chatMessageDefense(msg.paramChatDefense); } @@ -761,7 +785,7 @@ export class RdDCombat { let defenderRoll = { attackerRoll: attackerRoll, passeArme: attackerRoll.passeArme, show: {} } // Save rollData for defender RdDCombat._storeAttaque(this.attackerId, attackerRoll); - RdDCombat._storeDefense(defenderRoll) + RdDCombat._storeDefense(defenderRoll.passeArme, defenderRoll); attackerRoll.show = { cible: this.target ? this.defender.data.name : 'la cible', @@ -996,7 +1020,7 @@ export class RdDCombat { this.removeChatMessageActionsPasseArme(defenderRoll.passeArme); this._sendMessageDefense(defenderRoll.attackerRoll, defenderRoll, { defense: true }); - RdDCombat._storeDefense(defenderRoll); + RdDCombat._storeDefense(defenderRoll.passeArme, defenderRoll); } /* -------------------------------------------- */ @@ -1068,7 +1092,7 @@ export class RdDCombat { this.removeChatMessageActionsPasseArme(defenderRoll.passeArme); this._sendMessageDefense(defenderRoll.attackerRoll, defenderRoll, { defense: true }) - RdDCombat._storeDefense(defenderRoll); + RdDCombat._storeDefense(defenderRoll.passeArme, defenderRoll); } /* -------------------------------------------- */