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) {
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) {

View File

@ -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,

View File

@ -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;

View File

@ -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) {

View File

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

View File

@ -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;