Fix jets encaissements faits par le défenseur

=> Les dés sont ceux du défenseur
=> Le message d'encaissement est visible par le joueur
This commit is contained in:
Vincent Vandemeulebrouck 2022-01-29 18:49:06 +01:00
parent 67b4070c27
commit c0b5bb3f35
3 changed files with 32 additions and 21 deletions

View File

@ -62,26 +62,23 @@ export class RdDActor extends Actor {
} }
} }
static remoteActorCall(data) { static remoteActorCall(data, canExecuteLocally = () => Misc.isUniqueConnectedGM()) {
if (Misc.isUniqueConnectedGM()) { if (canExecuteLocally()) {
RdDActor.onRemoteActorCall(data); RdDActor.onRemoteActorCall(data);
return false;
} }
else { else {
game.socket.emit("system.foundryvtt-reve-de-dragon", { msg: "msg_remote_actor_call", data: data }); game.socket.emit("system.foundryvtt-reve-de-dragon", { msg: "msg_remote_actor_call", data: data });
return true;
} }
} }
static onRemoteActorCall(data) { static onRemoteActorCall(data) {
if (Misc.isUniqueConnectedGM()) { // Seul le joueur choisi effectue l'appel const actor = game.actors.get(data?.actorId);
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
if (!actor) { const args = data.args;
console.info("RdDActor.onRemoteActorCall: Pas d'Actor disponible ", data); console.info(`RdDActor.onRemoteActorCall: pour l'Actor ${data.actorId}, appel de RdDActor.${data.method}(`, ...args, ')');
} actor[data.method](...args);
else {
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; return;
} }
if (fromActorId && !game.user.isGM) { 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 { else {
const fromActor = game.actors.get(fromActorId) const fromActor = game.actors.get(fromActorId)
@ -3700,7 +3700,11 @@ export class RdDActor extends Actor {
return; return;
} }
if (!Misc.isUniqueConnectedGM()) { 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; return;
} }

View File

@ -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 * @returns true pour un seul utilisateur: le premier GM connecté par ordre d'id
*/ */

View File

@ -544,16 +544,15 @@ export class RdDCombat {
/* -------------------------------------------- */ /* -------------------------------------------- */
static onMsgEncaisser(data) { 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 attackerRoll = RdDCombat._getAttaque(data.attackerId); // Retrieve the rolldata from the store
let attacker = data.attackerId ? game.actors.get(data.attackerId) : null; let attacker = data.attackerId ? game.actors.get(data.attackerId) : null;
let defender = canvas.tokens.get(data.defenderTokenId).actor;
defender.encaisserDommages(attackerRoll, attacker); defender.encaisserDommages(attackerRoll, attacker);
RdDCombat._deleteDefense(attackerRoll.passeArme); RdDCombat._deleteDefense(attackerRoll.passeArme);
RdDCombat._deleteAttaque(data.attackerId); RdDCombat._deleteAttaque(data.attackerId);
} }
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
@ -917,11 +916,11 @@ export class RdDCombat {
dmg: attackerRoll.dmg, dmg: attackerRoll.dmg,
}; };
if (!Misc.isUniqueConnectedGM()) { if (Misc.isUniqueConnectedGM()) {
this._socketSendMessageDefense(paramChatDefense, defenderRoll); await this._chatMessageDefense(paramChatDefense);
} }
else { else {
await this._chatMessageDefense(paramChatDefense); this._socketSendMessageDefense(paramChatDefense, defenderRoll);
} }
} }
@ -1295,7 +1294,7 @@ export class RdDCombat {
this._onEchecTotal(defenderRoll); this._onEchecTotal(defenderRoll);
} }
if (Misc.isUniqueConnectedGM()) { if (Misc.isOwnerPlayerOrUniqueConnectedGM(this.defender)) {
attackerRoll.attackerId = this.attackerId; attackerRoll.attackerId = this.attackerId;
attackerRoll.defenderTokenId = defenderTokenId; attackerRoll.defenderTokenId = defenderTokenId;