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) {
if (Misc.isUniqueConnectedGM()) {
static remoteActorCall(data, canExecuteLocally = () => Misc.isUniqueConnectedGM()) {
if (canExecuteLocally()) {
RdDActor.onRemoteActorCall(data);
return false;
}
else {
game.socket.emit("system.foundryvtt-reve-de-dragon", { msg: "msg_remote_actor_call", data: data });
return true;
}
}
static onRemoteActorCall(data) {
if (Misc.isUniqueConnectedGM()) { // 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.actorId}, appel de RdDActor.${data.method}(`, ...args, ')');
actor[data.method](...args);
}
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
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;
}
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 {
const fromActor = game.actors.get(fromActorId)
@ -3700,7 +3700,11 @@ export class RdDActor extends Actor {
return;
}
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;
}

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
*/

View File

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