From 68dc643457be3e85883fb067d2ec19e5963c8a74 Mon Sep 17 00:00:00 2001 From: Vincent Vandemeulebrouck Date: Fri, 16 Apr 2021 23:07:09 +0200 Subject: [PATCH] =?UTF-8?q?Emp=C3=AAcher=20doublons=20sur=20t=C3=AAte/souf?= =?UTF-8?q?fle=20#175?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Lors de l'ajout de la tête présents des cités, le présent de chaque cité était ajouté par tous les joueurs connectés qui traitaient le hook --- module/actor.js | 66 ++++++++++++++++++++---------------------- module/chat-utility.js | 4 +-- module/misc.js | 7 +++-- module/rdd-combat.js | 2 +- 4 files changed, 40 insertions(+), 39 deletions(-) diff --git a/module/actor.js b/module/actor.js index e6172a13..18345245 100644 --- a/module/actor.js +++ b/module/actor.js @@ -55,27 +55,21 @@ export class RdDActor extends Actor { } } - static remoteActorCall(actorId, method, ...args) { - game.socket.emit("system.foundryvtt-reve-de-dragon", { - msg: "msg_remote_actor_call", - data: { - gmId: Misc.connectedGM(), - toActorId: actorId, - method: method, - args: args - } - }); + static remoteActorCall(options) { + console.log("remoteActorCall ", options) + options.userId = options.userId ?? Misc.connectedGMOrUser(); + game.socket.emit("system.foundryvtt-reve-de-dragon", { msg: "msg_remote_actor_call", data: options }); } static onRemoteActorCall(data) { - if (game.user.id == data.gmId) { // Seul le GM connecté choisi effectue l'appel - const actor = game.actors.get(data?.toActorId); + if (game.user.id == data.userId) { // 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.toActorId}, appel de RdDActor.${data.method}(`, ...args, ')'); + console.info(`RdDActor.onRemoteActorCall: pour l'Actor ${data.actorId}, appel de RdDActor.${data.method}(`, ...args, ')'); actor[data.method](...args); } } @@ -3185,7 +3179,7 @@ export class RdDActor extends Actor { async ajouterDeniers(gain, fromActorId = undefined) { if (fromActorId && !game.user.isGM) { - RdDActor.remoteActorCall(this.id, 'ajouterDeniers', gain, fromActorId); + RdDActor.remoteActorCall({ userId: Misc.connectedGMOrUser(), actorId: this.id, method: 'ajouterDeniers', args: [gain, fromActorId] }); } else { const fromActor = game.actors.get(fromActorId) @@ -3616,6 +3610,14 @@ export class RdDActor extends Actor { await this.createEmbeddedDocuments('ActiveEffect', [effet]); } + /* -------------------------------------------- */ + async onPreUpdateItem(item, change, options, id) { + const itemData = Misc.data(item); + if (itemData.type == 'competence' && itemData.data.defaut_carac && itemData.data.xp) { + await this.checkCompetenceXP(itemData.name, itemData.data.xp); + } + } + /* -------------------------------------------- */ async onCreateItem(item, options, id) { switch (item.type) { @@ -3628,13 +3630,6 @@ export class RdDActor extends Actor { } } - async onPreUpdateItem(item, change, options, id) { - const itemData = Misc.data(item); - if (itemData.type == 'competence' && itemData.data.defaut_carac && itemData.data.xp) { - await this.checkCompetenceXP(itemData.name, itemData.data.xp); - } - } - async onDeleteItem(item, options, id) { switch (item.type) { case 'tete': @@ -3650,27 +3645,30 @@ export class RdDActor extends Actor { } async onCreateOwnedDraconique(item, options, id) { - - let draconique = Draconique.all().find(it => it.match(item)); - if (draconique) { - draconique.onActorCreateOwned(this, item) - - this.notifyGestionTeteSouffleQueue(item, draconique.manualMessage()); + if (game.user.id == Misc.connectedGMOrUser()) { + let draconique = Draconique.all().find(it => it.match(item)); + if (draconique) { + draconique.onActorCreateOwned(this, item) + this.notifyGestionTeteSouffleQueue(item, draconique.manualMessage()); + } } } async onDeleteOwnedDraconique(item, options, id) { - - let draconique = Draconique.all().find(it => it.match(item)); - if (draconique) { - draconique.onActorDeleteOwned(this, item) + if (game.user.id != Misc.connectedGMOrUser()) { + let draconique = Draconique.all().find(it => it.match(item)); + if (draconique) { + draconique.onActorDeleteOwned(this, item) + } } } async onDeleteOwnedCaseTmr(item, options, id) { - let draconique = Draconique.all().find(it => it.isCase(item)); - if (draconique) { - draconique.onActorDeleteCaseTmr(this, item) + if (game.user.id != Misc.connectedGMOrUser()) { + let draconique = Draconique.all().find(it => it.isCase(item)); + if (draconique) { + draconique.onActorDeleteCaseTmr(this, item) + } } } diff --git a/module/chat-utility.js b/module/chat-utility.js index 38cc2733..f90fc05c 100644 --- a/module/chat-utility.js +++ b/module/chat-utility.js @@ -29,7 +29,7 @@ export class ChatUtility { static removeChatMessageContaining(part) { const removeMessageData = { part: part, - gmId: Misc.connectedGM() + gmId: Misc.connectedGMOrUser() }; if (game.user.isGM) { @@ -41,7 +41,7 @@ export class ChatUtility { } static removeChatMessageId(messageId) { - const removeMessageData = { messageId: messageId, gmId: Misc.connectedGM() }; + const removeMessageData = { messageId: messageId, gmId: Misc.connectedGMOrUser() }; if (game.user.isGM) { ChatUtility.onRemoveMessages(removeMessageData); } diff --git a/module/misc.js b/module/misc.js index 2faa6f8d..d458e3b5 100644 --- a/module/misc.js +++ b/module/misc.js @@ -114,7 +114,10 @@ export class Misc { return Misc.data(it)?.data ?? {} } - static connectedGM() { - return game.user.isGM ? game.user.id : game.users.entities.find(u => u.isGM && u.active)?.id; + static connectedGMOrUser(ownerId = undefined) { + if (ownerId && game.user.id == ownerId){ + return ownerId; + } + return (game.user.isGM ? game.user.id : game.users.entities.find(u => u.isGM && u.active)?.id) ?? game.user.id; } } \ No newline at end of file diff --git a/module/rdd-combat.js b/module/rdd-combat.js index 6d1137d7..094fc023 100644 --- a/module/rdd-combat.js +++ b/module/rdd-combat.js @@ -1211,7 +1211,7 @@ export class RdDCombat { attackerId: this.attackerId, defenderTokenId: defenderTokenId, attackerRoll: attackerRoll, - gmId: Misc.connectedGM(), + gmId: Misc.connectedGMOrUser(), } }); }