forked from public/foundryvtt-reve-de-dragon
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:
@ -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;
|
||||
|
Reference in New Issue
Block a user