forked from public/foundryvtt-reve-de-dragon
Fix: Nourriture consommée par le bon user
This commit is contained in:
@ -65,7 +65,7 @@ export class RdDActor extends Actor {
|
||||
static onSocketMessage(sockmsg) {
|
||||
switch (sockmsg.msg) {
|
||||
case "msg_remote_actor_call":
|
||||
return RdDActor.onRemoteActorCall(sockmsg.data);
|
||||
return RdDActor.onRemoteActorCall(sockmsg.data, sockmsg.userId);
|
||||
case "msg_reset_nombre_astral":
|
||||
console.log("RESET ASTRAL", game.user.character);
|
||||
game.user.character.resetNombreAstral();
|
||||
@ -73,23 +73,26 @@ export class RdDActor extends Actor {
|
||||
}
|
||||
}
|
||||
|
||||
static remoteActorCall(callData, canExecuteLocally = () => Misc.isUniqueConnectedGM()) {
|
||||
if (canExecuteLocally()) {
|
||||
RdDActor.onRemoteActorCall(callData);
|
||||
static remoteActorCall(callData, userId = undefined) {
|
||||
userId = userId ?? Misc.firstConnectedGMId();
|
||||
if (userId == game.user.id) {
|
||||
RdDActor.onRemoteActorCall(callData, userId);
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
game.socket.emit(SYSTEM_SOCKET_ID, { msg: "msg_remote_actor_call", data: callData });
|
||||
game.socket.emit(SYSTEM_SOCKET_ID, { msg: "msg_remote_actor_call", data: callData, userId: userId });
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
static onRemoteActorCall(callData) {
|
||||
const actor = game.actors.get(callData?.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 = callData.args;
|
||||
console.info(`RdDActor.onRemoteActorCall: pour l'Actor ${callData.actorId}, appel de RdDActor.${callData.method}(`, ...args, ')');
|
||||
actor[callData.method](...args);
|
||||
static onRemoteActorCall(callData, userId) {
|
||||
if (userId == game.user.id) {
|
||||
const actor = game.actors.get(callData?.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 = callData.args;
|
||||
console.info(`RdDActor.onRemoteActorCall: pour l'Actor ${callData.actorId}, appel de RdDActor.${callData.method}(`, ...args, ')');
|
||||
actor[callData.method](...args);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -299,7 +302,7 @@ export class RdDActor extends Actor {
|
||||
|
||||
/* -------------------------------------------- */
|
||||
getObjet(id) {
|
||||
return id ? this.items.find(it => it.id == id) : undefined;
|
||||
return this.getEmbeddedDocument('Item', id);
|
||||
}
|
||||
|
||||
listItemsData(type) {
|
||||
@ -1932,15 +1935,24 @@ export class RdDActor extends Actor {
|
||||
async consommer(item, choix) {
|
||||
switch (item.type) {
|
||||
case 'nourritureboisson':
|
||||
return await this.consommerNourritureboisson(item, choix);
|
||||
return await this.consommerNourritureboisson(item.id, choix);
|
||||
case 'potion':
|
||||
return await this.consommerPotion(item)
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async consommerNourritureboisson(item, choix = { doses: 1, seForcer: false, supprimerSiZero: false }) {
|
||||
|
||||
async consommerNourritureboisson(itemId, choix = { doses: 1, seForcer: false, supprimerSiZero: false}, userId = undefined) {
|
||||
if (userId != undefined && userId != game.user.id) {
|
||||
RdDActor.remoteActorCall({
|
||||
actorId: this.id,
|
||||
method: 'consommerNourritureboisson',
|
||||
args: [itemId, choix, userId]
|
||||
},
|
||||
userId)
|
||||
return;
|
||||
}
|
||||
const item = this.getObjet(itemId)
|
||||
if (item.type != 'nourritureboisson') {
|
||||
return;
|
||||
}
|
||||
@ -3649,10 +3661,7 @@ export class RdDActor extends Actor {
|
||||
|
||||
const acheteur = achat.acheteurId ? game.actors.get(achat.acheteurId) : undefined;
|
||||
const vendeur = achat.vendeurId ? game.actors.get(achat.vendeurId) : undefined;
|
||||
const messageVente = game.messages.get(achat.chatMessageIdVente);
|
||||
const html = await messageVente.getHTML();
|
||||
const button = html.find(".button-acheter")[0];
|
||||
const vente = DialogItemAchat.venteData(button);
|
||||
const vente = achat.vente;
|
||||
const itemId = vente.item._id;
|
||||
const isItemEmpilable = "quantite" in vente.item.system;
|
||||
|
||||
@ -3692,7 +3701,7 @@ export class RdDActor extends Actor {
|
||||
let items = await acheteur.createEmbeddedDocuments("Item", listeAchat);
|
||||
if (achat.choix.consommer && vente.item.type == 'nourritureboisson') {
|
||||
achat.choix.doses = achat.choix.nombreLots;
|
||||
await acheteur.consommerNourritureboisson(items[0], achat.choix);
|
||||
await acheteur.consommerNourritureboisson(items[0].id, achat.choix, vente.actingUserId);
|
||||
}
|
||||
}
|
||||
if (coutDeniers > 0) {
|
||||
|
Reference in New Issue
Block a user