diff --git a/module/actor.js b/module/actor.js index 9e02fc6c..a128e4b8 100644 --- a/module/actor.js +++ b/module/actor.js @@ -1235,16 +1235,14 @@ export class RdDActor extends RdDBaseActorSang { } /* -------------------------------------------- */ - async consommerNourritureboisson(itemId, choix = { doses: 1, seForcer: false, supprimerSiZero: false }, userId = undefined) { - if (userId != undefined && userId != game.user.id) { + async consommerNourritureboisson(itemId, choix = { doses: 1, seForcer: false, supprimerSiZero: false }) { + if (!this.isOwner) { RdDBaseActor.remoteActorCall({ tokenId: this.token?.id, actorId: this.id, - method: 'consommerNourritureboisson', - args: [itemId, choix, userId] - }, - userId) - return; + method: 'consommerNourritureboisson', args: [itemId, choix] + }) + return } const item = this.getItem(itemId) if (!item.getUtilisationCuisine()) { @@ -2519,7 +2517,11 @@ export class RdDActor extends RdDBaseActorSang { async onRollTachePremiersSoins(blessureId, rollData) { if (!this.isOwner) { - return RdDBaseActor.remoteActorCall({ tokenId: this.token?.id, actorId: this.id, method: 'onRollTachePremiersSoins', args: [blessureId, rollData] }); + return RdDBaseActor.remoteActorCall({ + tokenId: this.token?.id, + actorId: this.id, + method: 'onRollTachePremiersSoins', args: [blessureId, rollData] + }) } const blessure = this.getItem(blessureId, 'blessure') console.log('TODO update blessure', this, blessureId, rollData, rollData.tache); @@ -2549,7 +2551,11 @@ export class RdDActor extends RdDBaseActorSang { async onRollSoinsComplets(blessureId, rollData) { if (!this.isOwner) { - return RdDBaseActor.remoteActorCall({ tokenId: this.token?.id, actorId: this.id, method: 'onRollSoinsComplets', args: [blessureId, rollData] }); + return RdDBaseActor.remoteActorCall({ + tokenId: this.token?.id, + actorId: this.id, + method: 'onRollSoinsComplets', args: [blessureId, rollData] + }) } const blessure = this.getItem(blessureId, 'blessure') if (blessure && blessure.system.premierssoins.done && !blessure.system.soinscomplets.done) { diff --git a/module/actor/base-actor-reve.js b/module/actor/base-actor-reve.js index 72546304..1d2f1495 100644 --- a/module/actor/base-actor-reve.js +++ b/module/actor/base-actor-reve.js @@ -458,8 +458,7 @@ export class RdDBaseActorReve extends RdDBaseActor { RdDBaseActor.remoteActorCall({ tokenId: this.token?.id, actorId: this.id, - method: 'encaisserDommagesValidationGR', - args: [rollData, armure, show, attackerToken, defenderToken] + method: 'encaisserDommagesValidationGR', args: [rollData, armure, show, attackerToken, defenderToken] }) } else { DialogValidationEncaissement.validerEncaissement(this, rollData, armure, diff --git a/module/actor/base-actor.js b/module/actor/base-actor.js index f2482c77..0342c03c 100644 --- a/module/actor/base-actor.js +++ b/module/actor/base-actor.js @@ -56,29 +56,32 @@ export class RdDBaseActor extends Actor { } } - static remoteActorCall(callData, userId = undefined) { - userId = userId ?? Misc.firstConnectedGMId(); - if (userId == game.user.id) { - RdDBaseActor.onRemoteActorCall(callData, userId); - return false; + static remoteActorCall(callData) { + if (game.user.isGM) { + RdDBaseActor.onRemoteActorCall(callData, game.user.id) + return false } else { - game.socket.emit(SYSTEM_SOCKET_ID, { msg: "msg_remote_actor_call", data: callData, userId: userId }); - return true; + game.socket.emit(SYSTEM_SOCKET_ID, { + msg: "msg_remote_actor_call", + data: callData, + userId: Misc.firstConnectedGMId() + }) + return true } } static onRemoteActorCall(callData, userId) { + const actor = RdDBaseActor.getRealActor(callData?.actorId, callData?.tokenId); if (userId == game.user.id) { - const actor = RdDBaseActor.getRealActor(callData?.actorId, callData?.tokenId); - 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 = callData.args; - console.info(`RdDBaseActor.onRemoteActorCall: pour l'Actor ${callData.actorId}, appel de RdDBaseActor.${callData.method}(`, ...args, ')'); - actor[callData.method](...args); - } + // Seul le joueur choisi effectue l'appel: le joueur courant si propriƩtaire de l'actor, ou le MJ sinon + const args = callData.args; + console.info(`RdDBaseActor.onRemoteActorCall: pour l'Actor ${callData.actorId}, appel de RdDBaseActor.${callData.method}(`, ...args, ')'); + actor[callData.method](...args); } } + static getRealActor(actorId, tokenId) { if (tokenId) { let token = canvas.tokens.get(tokenId) @@ -249,21 +252,20 @@ export class RdDBaseActor extends Actor { } async creerObjetParMJ(object) { - if (!Misc.isFirstConnectedGM()) { - RdDBaseActor.remoteActorCall({ - tokenId: this.token?.id, - actorId: this.id, - method: 'creerObjetParMJ', - args: [object] - }); - return; + if (this.isOwner) { + await this.createEmbeddedDocuments('Item', [object]) + return } - await this.createEmbeddedDocuments('Item', [object]) + RdDBaseActor.remoteActorCall({ + tokenId: this.token?.id, + actorId: this.id, + method: 'creerObjetParMJ', args: [object] + }) } /* -------------------------------------------- */ async cleanupConteneurs() { - if (Misc.isOwnerPlayerOrUniqueConnectedGM(this)) { + if (Misc.isOwnerPlayer(this)) { let updates = this.itemTypes['conteneur'] .filter(c => c.system.contenu.filter(id => this.getItem(id) == undefined).length > 0) .map(c => { return { _id: c._id, 'system.contenu': c.system.contenu.filter(id => this.getItem(id) != undefined) } }); @@ -334,7 +336,7 @@ export class RdDBaseActor extends Actor { ui.notifications.error(`Impossible d'ajouter un gain de ${sols} <0`); return; } - if (fromActorId && !game.user.isGM) { + if (fromActorId && !this.isOwner) { RdDBaseActor.remoteActorCall({ userId: Misc.connectedGMOrUser(), tokenId: this.token?.id, @@ -369,10 +371,9 @@ export class RdDBaseActor extends Actor { if (!Misc.isFirstConnectedGM()) { RdDBaseActor.remoteActorCall({ actorId: achat.vendeurId ?? achat.acheteurId, - method: 'achatVente', - args: [achat] + method: 'achatVente', args: [achat] }); - return; + return } const cout = Number(achat.prixTotal ?? 0); const vendeur = achat.vendeurId ? game.actors.get(achat.vendeurId) : undefined; diff --git a/module/actor/commerce.js b/module/actor/commerce.js index ed075a6b..0b7f9a99 100644 --- a/module/actor/commerce.js +++ b/module/actor/commerce.js @@ -25,9 +25,6 @@ export class RdDCommerce extends RdDBaseActor { } await super.depenserSols(cout) } - async consommerNourritureboisson(itemId, choix, userId) { - // ne pas consommer pour un commerce - } async decrementerQuantiteItem(item, quantite) { if (this.system.illimite) { diff --git a/module/misc.js b/module/misc.js index 9ce50ac6..2829985a 100644 --- a/module/misc.js +++ b/module/misc.js @@ -200,11 +200,7 @@ export class Misc { if (!document.testUserPermission){ return false } - return game.users.filter(u => document.testUserPermission(u, CONST.DOCUMENT_OWNERSHIP_LEVELS.OWNER)) == game.user - } - - static isOwnerPlayerOrUniqueConnectedGM(actor) { - return Misc.isFirstOwnerPlayer(actor) ?? Misc.isFirstConnectedGM(); + return game.users.find(u => document.testUserPermission(u, CONST.DOCUMENT_OWNERSHIP_LEVELS.OWNER)) == game.user } /** diff --git a/module/rdd-combat.js b/module/rdd-combat.js index 9521828b..a888f653 100644 --- a/module/rdd-combat.js +++ b/module/rdd-combat.js @@ -436,7 +436,7 @@ export class RdDCombat { /* -------------------------------------------- */ static onMsgEncaisser(msg) { let defender = canvas.tokens.get(msg.defenderToken.id).actor; - if (Misc.isOwnerPlayerOrUniqueConnectedGM(defender)) { + if (Misc.isOwnerPlayer(defender)) { let attackerRoll = msg.attackerRoll; let attacker = msg.attackerId ? game.actors.get(msg.attackerId) : undefined; defender.encaisserDommages(attackerRoll, attacker, msg.attackerToken); @@ -1251,7 +1251,7 @@ export class RdDCombat { this._onEchecTotal(defenderRoll); } - if (Misc.isOwnerPlayerOrUniqueConnectedGM(this.defender)) { + if (Misc.isOwnerPlayer(this.defender)) { attackerRoll.attackerId = this.attackerId; attackerRoll.defenderTokenId = this.defenderToken.id;