diff --git a/module/actor.js b/module/actor.js index ce368bd6..af6f9760 100644 --- a/module/actor.js +++ b/module/actor.js @@ -48,6 +48,39 @@ export class RdDActor extends Actor { Hooks.on("updateActor", (actor, change, options, actorId) => actor.onUpdateActor(change, options, actorId)); } + static onSocketMessage(sockmsg) { + switch (sockmsg.msg) { + case "msg_remote_actor_call": + return RdDActor.onRemoteActorCall(sockmsg.data); + } + } + + 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 onRemoteActorCall(data) { + if (game.user.id == data.gmId) { // Seul le GM connecté choisi effectue l'appel + const actor = game.actors.get(data?.toActorId); + 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, ')'); + actor[data.method](...args); + } + } + } + static getParentActor(document) { return document?.parent instanceof Actor ? document.parent : undefined } diff --git a/module/misc.js b/module/misc.js index e0a07c61..1d71fab7 100644 --- a/module/misc.js +++ b/module/misc.js @@ -47,11 +47,13 @@ export class Misc { const parsed = parseInt(value); return isNaN(parsed) ? 0 : parsed; } + static keepDecimals(num, decimals) { if (decimals<=0 || decimals>6) return num; const decimal = Math.pow(10, parseInt(decimals)); return Math.round(num * decimal) / decimal; } + static getFractionHtml(diviseur) { if (!diviseur || diviseur <= 1) return undefined; switch (diviseur || 1) { @@ -111,4 +113,9 @@ export class Misc { static templateData(it) { return Misc.data(it)?.data ?? {} } + + static connectedGM() + { + return game.users.entities.find(u => u.isGM && u.active)?.id; + } } \ No newline at end of file diff --git a/module/rdd-combat.js b/module/rdd-combat.js index a8ae51e3..4b78d9c5 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: game.users.entities.find(u => u.isGM)?.id, + gmId: Misc.connectedGM(), } }); } diff --git a/module/rdd-main.js b/module/rdd-main.js index 822b9b4b..f76c177c 100644 --- a/module/rdd-main.js +++ b/module/rdd-main.js @@ -140,10 +140,11 @@ Hooks.once("init", async function () { }; /* -------------------------------------------- */ - game.socket.on("system.foundryvtt-reve-de-dragon", data => { - RdDUtility.onSocketMesssage(data); - RdDCombat.onSocketMessage(data); - ChatUtility.onSocketMessage(data); + game.socket.on("system.foundryvtt-reve-de-dragon", sockmsg => { + RdDUtility.onSocketMesssage(sockmsg); + RdDCombat.onSocketMessage(sockmsg); + ChatUtility.onSocketMessage(sockmsg); + RdDActor.onSocketMessage(sockmsg); }); /* -------------------------------------------- */