Merge pull request '10.0.2.1' (#573) from VincentVk/foundryvtt-reve-de-dragon:v10 into v10

Reviewed-on: #573
This commit is contained in:
uberwald 2022-11-13 23:15:44 +01:00
commit ff923ebab2
5 changed files with 44 additions and 27 deletions

View File

@ -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,18 +73,20 @@ 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) {
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;
@ -92,6 +94,7 @@ export class RdDActor extends Actor {
actor[callData.method](...args);
}
}
}
/* -------------------------------------------- */
static getParentActor(document) {
@ -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) {

View File

@ -27,7 +27,8 @@ export class DialogChronologie extends Dialog {
dateReel: DialogChronologie.getCurrentDateTime()
};
const html = await renderTemplate("systems/foundryvtt-reve-de-dragon/templates/dialog-chronologie.html", dialogData);
new DialogChronologie(html).render(true);
const dialog = new DialogChronologie(html);
dialog.render(true);
}
constructor(html) {

View File

@ -22,6 +22,7 @@ export class DialogItemAchat extends Dialog {
const prixLot = Monnaie.arrondiDeniers(button.attributes['data-prixLot']?.value ?? 0);
return {
item: json ? JSON.parse(json) : undefined,
actingUserId: game.user.id,
vendeurId: vendeurId,
vendeur: vendeur,
acheteur: acheteur,
@ -39,6 +40,7 @@ export class DialogItemAchat extends Dialog {
chatMessageIdVente: RdDUtility.findChatMessageId(button)
};
}
static async onAcheter(venteData) {
const html = await renderTemplate(`systems/foundryvtt-reve-de-dragon/templates/dialog-item-achat.html`, venteData);
const dialog = new DialogItemAchat(html, venteData);
@ -52,7 +54,7 @@ export class DialogItemAchat extends Dialog {
const actionAchat = venteData.prixLot > 0 ? "Acheter" : "Prendre";
const buttons = {};
if (isConsommable) {
buttons["consommer"] = { label: venteData.item.system.boisson ? "Boire" : "Manger", callback: it => { this.onAchatConsommer(); } }
buttons["consommer"] = { label: venteData.item.system.boisson ? "Boire" : "Manger", callback: it => this.onAchatConsommer() }
}
buttons[actionAchat] = { label: actionAchat, callback: it => { this.onAchat(); } };
buttons["decliner"] = { label: "Décliner", callback: it => { } };
@ -76,7 +78,8 @@ export class DialogItemAchat extends Dialog {
acheteurId: this.venteData.acheteur?.id,
prixTotal: this.venteData.prixTotal,
chatMessageIdVente: this.venteData.chatMessageIdVente,
choix: this.venteData.choix
choix: this.venteData.choix,
vente: this.venteData
});
}

View File

@ -3,9 +3,9 @@ import { Misc } from "./misc.js";
export class DialogRepos extends Dialog {
static async create(actor) {
let actorData = actor
const html = await renderTemplate("systems/foundryvtt-reve-de-dragon/templates/dialog-repos.html", actorData);
new DialogRepos(html, actor).render(true);
const html = await renderTemplate("systems/foundryvtt-reve-de-dragon/templates/dialog-repos.html", actor);
const dialog = new DialogRepos(html, actor);
dialog.render(true);
}
constructor(html, actor) {

View File

@ -133,7 +133,11 @@ export class Misc {
* @returns true pour un seul utilisateur: le premier GM connecté par ordre d'id
*/
static isUniqueConnectedGM() {
return game.user.id == Misc.firstConnectedGM()?.id;
return game.user.id == Misc.firstConnectedGMId();
}
static firstConnectedGMId() {
return Misc.firstConnectedGM()?.id;
}
/* -------------------------------------------- */