Permettre de déléguer un appel au MJ

permettre de poster un message au MJ pour que du code soit exécuté par
le MJ.

Ceci permet par exemple à un joueur de payer un objet posté par un autre
joueur, et que l'argent soit transféré à l'autre joueur
This commit is contained in:
Vincent Vandemeulebrouck 2021-04-15 00:13:50 +02:00
parent 413893bc67
commit c2f5229ca6
4 changed files with 46 additions and 5 deletions

View File

@ -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
}

View File

@ -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;
}
}

View File

@ -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(),
}
});
}

View File

@ -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);
});
/* -------------------------------------------- */