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:
parent
413893bc67
commit
c2f5229ca6
@ -48,6 +48,39 @@ export class RdDActor extends Actor {
|
|||||||
Hooks.on("updateActor", (actor, change, options, actorId) => actor.onUpdateActor(change, options, actorId));
|
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) {
|
static getParentActor(document) {
|
||||||
return document?.parent instanceof Actor ? document.parent : undefined
|
return document?.parent instanceof Actor ? document.parent : undefined
|
||||||
}
|
}
|
||||||
|
@ -47,11 +47,13 @@ export class Misc {
|
|||||||
const parsed = parseInt(value);
|
const parsed = parseInt(value);
|
||||||
return isNaN(parsed) ? 0 : parsed;
|
return isNaN(parsed) ? 0 : parsed;
|
||||||
}
|
}
|
||||||
|
|
||||||
static keepDecimals(num, decimals) {
|
static keepDecimals(num, decimals) {
|
||||||
if (decimals<=0 || decimals>6) return num;
|
if (decimals<=0 || decimals>6) return num;
|
||||||
const decimal = Math.pow(10, parseInt(decimals));
|
const decimal = Math.pow(10, parseInt(decimals));
|
||||||
return Math.round(num * decimal) / decimal;
|
return Math.round(num * decimal) / decimal;
|
||||||
}
|
}
|
||||||
|
|
||||||
static getFractionHtml(diviseur) {
|
static getFractionHtml(diviseur) {
|
||||||
if (!diviseur || diviseur <= 1) return undefined;
|
if (!diviseur || diviseur <= 1) return undefined;
|
||||||
switch (diviseur || 1) {
|
switch (diviseur || 1) {
|
||||||
@ -111,4 +113,9 @@ export class Misc {
|
|||||||
static templateData(it) {
|
static templateData(it) {
|
||||||
return Misc.data(it)?.data ?? {}
|
return Misc.data(it)?.data ?? {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static connectedGM()
|
||||||
|
{
|
||||||
|
return game.users.entities.find(u => u.isGM && u.active)?.id;
|
||||||
|
}
|
||||||
}
|
}
|
@ -1211,7 +1211,7 @@ export class RdDCombat {
|
|||||||
attackerId: this.attackerId,
|
attackerId: this.attackerId,
|
||||||
defenderTokenId: defenderTokenId,
|
defenderTokenId: defenderTokenId,
|
||||||
attackerRoll: attackerRoll,
|
attackerRoll: attackerRoll,
|
||||||
gmId: game.users.entities.find(u => u.isGM)?.id,
|
gmId: Misc.connectedGM(),
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -140,10 +140,11 @@ Hooks.once("init", async function () {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/* -------------------------------------------- */
|
/* -------------------------------------------- */
|
||||||
game.socket.on("system.foundryvtt-reve-de-dragon", data => {
|
game.socket.on("system.foundryvtt-reve-de-dragon", sockmsg => {
|
||||||
RdDUtility.onSocketMesssage(data);
|
RdDUtility.onSocketMesssage(sockmsg);
|
||||||
RdDCombat.onSocketMessage(data);
|
RdDCombat.onSocketMessage(sockmsg);
|
||||||
ChatUtility.onSocketMessage(data);
|
ChatUtility.onSocketMessage(sockmsg);
|
||||||
|
RdDActor.onSocketMessage(sockmsg);
|
||||||
});
|
});
|
||||||
|
|
||||||
/* -------------------------------------------- */
|
/* -------------------------------------------- */
|
||||||
|
Loading…
Reference in New Issue
Block a user