Fix: échanges achat-vente "prendre"

simplification des tests de droits pour savoir si on transmet
l'appel de méthode à un MJ connecté.

De manière générale, si on est le owner: pas besoin d'appel remote.
Donc si MJ pas besoin.

Si on a un appel remote, seul un MJ le traite.
This commit is contained in:
Vincent Vandemeulebrouck 2024-12-04 18:55:34 +01:00
parent d9af32b168
commit d9cdfef688
6 changed files with 47 additions and 48 deletions

View File

@ -1235,16 +1235,14 @@ export class RdDActor extends RdDBaseActorSang {
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
async consommerNourritureboisson(itemId, choix = { doses: 1, seForcer: false, supprimerSiZero: false }, userId = undefined) { async consommerNourritureboisson(itemId, choix = { doses: 1, seForcer: false, supprimerSiZero: false }) {
if (userId != undefined && userId != game.user.id) { if (!this.isOwner) {
RdDBaseActor.remoteActorCall({ RdDBaseActor.remoteActorCall({
tokenId: this.token?.id, tokenId: this.token?.id,
actorId: this.id, actorId: this.id,
method: 'consommerNourritureboisson', method: 'consommerNourritureboisson', args: [itemId, choix]
args: [itemId, choix, userId] })
}, return
userId)
return;
} }
const item = this.getItem(itemId) const item = this.getItem(itemId)
if (!item.getUtilisationCuisine()) { if (!item.getUtilisationCuisine()) {
@ -2519,7 +2517,11 @@ export class RdDActor extends RdDBaseActorSang {
async onRollTachePremiersSoins(blessureId, rollData) { async onRollTachePremiersSoins(blessureId, rollData) {
if (!this.isOwner) { 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') const blessure = this.getItem(blessureId, 'blessure')
console.log('TODO update blessure', this, blessureId, rollData, rollData.tache); console.log('TODO update blessure', this, blessureId, rollData, rollData.tache);
@ -2549,7 +2551,11 @@ export class RdDActor extends RdDBaseActorSang {
async onRollSoinsComplets(blessureId, rollData) { async onRollSoinsComplets(blessureId, rollData) {
if (!this.isOwner) { 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') const blessure = this.getItem(blessureId, 'blessure')
if (blessure && blessure.system.premierssoins.done && !blessure.system.soinscomplets.done) { if (blessure && blessure.system.premierssoins.done && !blessure.system.soinscomplets.done) {

View File

@ -458,8 +458,7 @@ export class RdDBaseActorReve extends RdDBaseActor {
RdDBaseActor.remoteActorCall({ RdDBaseActor.remoteActorCall({
tokenId: this.token?.id, tokenId: this.token?.id,
actorId: this.id, actorId: this.id,
method: 'encaisserDommagesValidationGR', method: 'encaisserDommagesValidationGR', args: [rollData, armure, show, attackerToken, defenderToken]
args: [rollData, armure, show, attackerToken, defenderToken]
}) })
} else { } else {
DialogValidationEncaissement.validerEncaissement(this, rollData, armure, DialogValidationEncaissement.validerEncaissement(this, rollData, armure,

View File

@ -56,29 +56,32 @@ export class RdDBaseActor extends Actor {
} }
} }
static remoteActorCall(callData, userId = undefined) { static remoteActorCall(callData) {
userId = userId ?? Misc.firstConnectedGMId(); if (game.user.isGM) {
if (userId == game.user.id) { RdDBaseActor.onRemoteActorCall(callData, game.user.id)
RdDBaseActor.onRemoteActorCall(callData, userId); return false
return false;
} }
else { else {
game.socket.emit(SYSTEM_SOCKET_ID, { msg: "msg_remote_actor_call", data: callData, userId: userId }); game.socket.emit(SYSTEM_SOCKET_ID, {
return true; msg: "msg_remote_actor_call",
data: callData,
userId: Misc.firstConnectedGMId()
})
return true
} }
} }
static onRemoteActorCall(callData, userId) { static onRemoteActorCall(callData, userId) {
const actor = RdDBaseActor.getRealActor(callData?.actorId, callData?.tokenId);
if (userId == game.user.id) { if (userId == game.user.id) {
const actor = RdDBaseActor.getRealActor(callData?.actorId, callData?.tokenId); // Seul le joueur choisi effectue l'appel: le joueur courant si propriétaire de l'actor, ou le MJ sinon
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;
const args = callData.args; console.info(`RdDBaseActor.onRemoteActorCall: pour l'Actor ${callData.actorId}, appel de RdDBaseActor.${callData.method}(`, ...args, ')');
console.info(`RdDBaseActor.onRemoteActorCall: pour l'Actor ${callData.actorId}, appel de RdDBaseActor.${callData.method}(`, ...args, ')'); actor[callData.method](...args);
actor[callData.method](...args);
}
} }
} }
static getRealActor(actorId, tokenId) { static getRealActor(actorId, tokenId) {
if (tokenId) { if (tokenId) {
let token = canvas.tokens.get(tokenId) let token = canvas.tokens.get(tokenId)
@ -249,21 +252,20 @@ export class RdDBaseActor extends Actor {
} }
async creerObjetParMJ(object) { async creerObjetParMJ(object) {
if (!Misc.isFirstConnectedGM()) { if (this.isOwner) {
RdDBaseActor.remoteActorCall({ await this.createEmbeddedDocuments('Item', [object])
tokenId: this.token?.id, return
actorId: this.id,
method: 'creerObjetParMJ',
args: [object]
});
return;
} }
await this.createEmbeddedDocuments('Item', [object]) RdDBaseActor.remoteActorCall({
tokenId: this.token?.id,
actorId: this.id,
method: 'creerObjetParMJ', args: [object]
})
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
async cleanupConteneurs() { async cleanupConteneurs() {
if (Misc.isOwnerPlayerOrUniqueConnectedGM(this)) { if (Misc.isOwnerPlayer(this)) {
let updates = this.itemTypes['conteneur'] let updates = this.itemTypes['conteneur']
.filter(c => c.system.contenu.filter(id => this.getItem(id) == undefined).length > 0) .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) } }); .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`); ui.notifications.error(`Impossible d'ajouter un gain de ${sols} <0`);
return; return;
} }
if (fromActorId && !game.user.isGM) { if (fromActorId && !this.isOwner) {
RdDBaseActor.remoteActorCall({ RdDBaseActor.remoteActorCall({
userId: Misc.connectedGMOrUser(), userId: Misc.connectedGMOrUser(),
tokenId: this.token?.id, tokenId: this.token?.id,
@ -369,10 +371,9 @@ export class RdDBaseActor extends Actor {
if (!Misc.isFirstConnectedGM()) { if (!Misc.isFirstConnectedGM()) {
RdDBaseActor.remoteActorCall({ RdDBaseActor.remoteActorCall({
actorId: achat.vendeurId ?? achat.acheteurId, actorId: achat.vendeurId ?? achat.acheteurId,
method: 'achatVente', method: 'achatVente', args: [achat]
args: [achat]
}); });
return; return
} }
const cout = Number(achat.prixTotal ?? 0); const cout = Number(achat.prixTotal ?? 0);
const vendeur = achat.vendeurId ? game.actors.get(achat.vendeurId) : undefined; const vendeur = achat.vendeurId ? game.actors.get(achat.vendeurId) : undefined;

View File

@ -25,9 +25,6 @@ export class RdDCommerce extends RdDBaseActor {
} }
await super.depenserSols(cout) await super.depenserSols(cout)
} }
async consommerNourritureboisson(itemId, choix, userId) {
// ne pas consommer pour un commerce
}
async decrementerQuantiteItem(item, quantite) { async decrementerQuantiteItem(item, quantite) {
if (this.system.illimite) { if (this.system.illimite) {

View File

@ -200,11 +200,7 @@ export class Misc {
if (!document.testUserPermission){ if (!document.testUserPermission){
return false return false
} }
return game.users.filter(u => document.testUserPermission(u, CONST.DOCUMENT_OWNERSHIP_LEVELS.OWNER)) == game.user return game.users.find(u => document.testUserPermission(u, CONST.DOCUMENT_OWNERSHIP_LEVELS.OWNER)) == game.user
}
static isOwnerPlayerOrUniqueConnectedGM(actor) {
return Misc.isFirstOwnerPlayer(actor) ?? Misc.isFirstConnectedGM();
} }
/** /**

View File

@ -436,7 +436,7 @@ export class RdDCombat {
/* -------------------------------------------- */ /* -------------------------------------------- */
static onMsgEncaisser(msg) { static onMsgEncaisser(msg) {
let defender = canvas.tokens.get(msg.defenderToken.id).actor; let defender = canvas.tokens.get(msg.defenderToken.id).actor;
if (Misc.isOwnerPlayerOrUniqueConnectedGM(defender)) { if (Misc.isOwnerPlayer(defender)) {
let attackerRoll = msg.attackerRoll; let attackerRoll = msg.attackerRoll;
let attacker = msg.attackerId ? game.actors.get(msg.attackerId) : undefined; let attacker = msg.attackerId ? game.actors.get(msg.attackerId) : undefined;
defender.encaisserDommages(attackerRoll, attacker, msg.attackerToken); defender.encaisserDommages(attackerRoll, attacker, msg.attackerToken);
@ -1251,7 +1251,7 @@ export class RdDCombat {
this._onEchecTotal(defenderRoll); this._onEchecTotal(defenderRoll);
} }
if (Misc.isOwnerPlayerOrUniqueConnectedGM(this.defender)) { if (Misc.isOwnerPlayer(this.defender)) {
attackerRoll.attackerId = this.attackerId; attackerRoll.attackerId = this.attackerId;
attackerRoll.defenderTokenId = this.defenderToken.id; attackerRoll.defenderTokenId = this.defenderToken.id;