From c0b5bb3f356d7d7359ccbc79c67660f76106f1f7 Mon Sep 17 00:00:00 2001 From: Vincent Vandemeulebrouck Date: Sat, 29 Jan 2022 18:49:06 +0100 Subject: [PATCH] =?UTF-8?q?Fix=20jets=20encaissements=20faits=20par=20le?= =?UTF-8?q?=20d=C3=A9fenseur?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit => Les dés sont ceux du défenseur => Le message d'encaissement est visible par le joueur --- module/actor.js | 32 ++++++++++++++++++-------------- module/misc.js | 8 ++++++++ module/rdd-combat.js | 13 ++++++------- 3 files changed, 32 insertions(+), 21 deletions(-) diff --git a/module/actor.js b/module/actor.js index 0e076007..2c0a7ec7 100644 --- a/module/actor.js +++ b/module/actor.js @@ -62,26 +62,23 @@ export class RdDActor extends Actor { } } - static remoteActorCall(data) { - if (Misc.isUniqueConnectedGM()) { + static remoteActorCall(data, canExecuteLocally = () => Misc.isUniqueConnectedGM()) { + if (canExecuteLocally()) { RdDActor.onRemoteActorCall(data); + return false; } else { game.socket.emit("system.foundryvtt-reve-de-dragon", { msg: "msg_remote_actor_call", data: data }); + return true; } } static onRemoteActorCall(data) { - if (Misc.isUniqueConnectedGM()) { // Seul le joueur choisi effectue l'appel - const actor = game.actors.get(data?.actorId); - if (!actor) { - console.info("RdDActor.onRemoteActorCall: Pas d'Actor disponible ", data); - } - else { - const args = data.args; - console.info(`RdDActor.onRemoteActorCall: pour l'Actor ${data.actorId}, appel de RdDActor.${data.method}(`, ...args, ')'); - actor[data.method](...args); - } + const actor = game.actors.get(data?.actorId); + if (Misc.isOwnerPlayerOrUniqueConnectedGM(actor)) { // Seul le joueur choisi effectue l'appel: le joueur courant si propriétaire de l'actor, ou le MJ sinon + const args = data.args; + console.info(`RdDActor.onRemoteActorCall: pour l'Actor ${data.actorId}, appel de RdDActor.${data.method}(`, ...args, ')'); + actor[data.method](...args); } } @@ -3668,7 +3665,10 @@ export class RdDActor extends Actor { return; } if (fromActorId && !game.user.isGM) { - RdDActor.remoteActorCall({ userId: Misc.connectedGMOrUser(), actorId: this.id, method: 'ajouterDeniers', args: [gain, fromActorId] }); + RdDActor.remoteActorCall({ + userId: Misc.connectedGMOrUser(), + actorId: this.id, + method: 'ajouterDeniers', args: [gain, fromActorId] }); } else { const fromActor = game.actors.get(fromActorId) @@ -3700,7 +3700,11 @@ export class RdDActor extends Actor { return; } if (!Misc.isUniqueConnectedGM()) { - RdDActor.remoteActorCall({ actorId: achat.vendeurId ?? achat.acheteurId, method: 'achatVente', args: [achat] }); + RdDActor.remoteActorCall({ + actorId: achat.vendeurId ?? achat.acheteurId, + method: 'achatVente', + args: [achat] }, + ); return; } diff --git a/module/misc.js b/module/misc.js index 3f8fa2a9..59fc080c 100644 --- a/module/misc.js +++ b/module/misc.js @@ -147,6 +147,14 @@ export class Misc { } + static isOwnerPlayer(actor, user=undefined) { + return actor.testUserPermission(user ?? game.user, CONST.DOCUMENT_PERMISSION_LEVELS.OWNER) + } + + static isOwnerPlayerOrUniqueConnectedGM(actor, user =undefined){ + return Misc.isOwnerPlayer(actor, user) ?? Misc.isUniqueConnectedGM(); + } + /** * @returns true pour un seul utilisateur: le premier GM connecté par ordre d'id */ diff --git a/module/rdd-combat.js b/module/rdd-combat.js index 0c354d1a..b350c398 100644 --- a/module/rdd-combat.js +++ b/module/rdd-combat.js @@ -544,16 +544,15 @@ export class RdDCombat { /* -------------------------------------------- */ static onMsgEncaisser(data) { - if (Misc.isUniqueConnectedGM()) { + let defender = canvas.tokens.get(data.defenderTokenId).actor; + if (Misc.isOwnerPlayerOrUniqueConnectedGM()) { let attackerRoll = RdDCombat._getAttaque(data.attackerId); // Retrieve the rolldata from the store let attacker = data.attackerId ? game.actors.get(data.attackerId) : null; - let defender = canvas.tokens.get(data.defenderTokenId).actor; defender.encaisserDommages(attackerRoll, attacker); RdDCombat._deleteDefense(attackerRoll.passeArme); RdDCombat._deleteAttaque(data.attackerId); } - } /* -------------------------------------------- */ @@ -917,11 +916,11 @@ export class RdDCombat { dmg: attackerRoll.dmg, }; - if (!Misc.isUniqueConnectedGM()) { - this._socketSendMessageDefense(paramChatDefense, defenderRoll); + if (Misc.isUniqueConnectedGM()) { + await this._chatMessageDefense(paramChatDefense); } else { - await this._chatMessageDefense(paramChatDefense); + this._socketSendMessageDefense(paramChatDefense, defenderRoll); } } @@ -1295,7 +1294,7 @@ export class RdDCombat { this._onEchecTotal(defenderRoll); } - if (Misc.isUniqueConnectedGM()) { + if (Misc.isOwnerPlayerOrUniqueConnectedGM(this.defender)) { attackerRoll.attackerId = this.attackerId; attackerRoll.defenderTokenId = defenderTokenId;