From 862ad1faec50911a017ce7f16abeaac34bfba5d6 Mon Sep 17 00:00:00 2001 From: Vincent Vandemeulebrouck Date: Thu, 20 May 2021 02:49:48 +0200 Subject: [PATCH] =?UTF-8?q?achat=20quantite=20illimit=C3=A9e?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- module/actor.js | 35 ++++++++++++++++++-------------- module/dialog-item-achat.js | 1 + templates/dialog-item-achat.html | 8 +++++--- 3 files changed, 26 insertions(+), 18 deletions(-) diff --git a/module/actor.js b/module/actor.js index 1e8ccceb..869d1ed8 100644 --- a/module/actor.js +++ b/module/actor.js @@ -3386,7 +3386,7 @@ export class RdDActor extends Actor { ui.notifications.info("Inutile de se vendre à soi-même"); return; } - if (!game.user.isGM) { + if (!Misc.isElectedUser()) { RdDActor.remoteActorCall({ userId: Misc.connectedGMOrUser(), actorId: this.vendeur?.id ?? this.acheteur?.id, @@ -3430,10 +3430,14 @@ export class RdDActor extends Actor { if (acheteur) { // TODO: achat depuis un compendium - const achat = duplicate(Misc.data(vendeur?.getObjet(itemId) ?? game.items.get(itemId))); + const itemData = Misc.data(vendeur?.getObjet(itemId) ?? game.items.get(itemId)); + const achat = { + type: itemData.type, + img: itemData.img, + name: itemData.name, + data: itemData.data + } achat.data.quantite = venteData.quantiteTotal; - achat._id = undefined; - // TODO: investigate bug - création marche mal... await acheteur.createEmbeddedDocuments("Item", [achat]); } if (coutDeniers > 0) { @@ -3445,18 +3449,19 @@ export class RdDActor extends Actor { content: await renderTemplate('systems/foundryvtt-reve-de-dragon/templates/chat-achat-item.html', venteData) }); - if (venteData.quantiteNbLots <= venteData.nombreLots) { - ChatUtility.removeChatMessageId(chatMessageIdVente); + if (!venteData.quantiteIllimite) { + if (venteData.quantiteNbLots <= venteData.nombreLots) { + ChatUtility.removeChatMessageId(chatMessageIdVente); + } + else { + venteData.quantiteNbLots -= venteData.nombreLots; + venteData.jsondata = JSON.stringify(venteData.item); + let newMessageVente = await renderTemplate('systems/foundryvtt-reve-de-dragon/templates/chat-vente-item.html', venteData); + const messageVente = game.messages.get(chatMessageIdVente); + messageVente.update({ content: newMessageVente }); + messageVente.render(true); + } } - else { - venteData.quantiteNbLots -= venteData.nombreLots; - venteData.jsondata = JSON.stringify(venteData.item); - let newMessageVente = await renderTemplate('systems/foundryvtt-reve-de-dragon/templates/chat-vente-item.html', venteData); - const messageVente = game.messages.get(chatMessageIdVente); - messageVente.update({ content: newMessageVente }); - messageVente.render(true); - } - } /* -------------------------------------------- */ diff --git a/module/dialog-item-achat.js b/module/dialog-item-achat.js index 9fe32cab..a6948347 100644 --- a/module/dialog-item-achat.js +++ b/module/dialog-item-achat.js @@ -29,6 +29,7 @@ export class DialogItemAchat extends Dialog { vendeur: Misc.data(vendeur), acheteur: Misc.data(acheteur), tailleLot: event.currentTarget.attributes['data-tailleLot']?.value ?? 1, + quantiteIllimite : event.currentTarget.attributes['data-quantiteIllimite']?.value == 'true', quantiteNbLots: event.currentTarget.attributes['data-quantiteNbLots']?.value, nombreLots: 1, prixLot: prixLot, diff --git a/templates/dialog-item-achat.html b/templates/dialog-item-achat.html index c5256965..2f2ef0b9 100644 --- a/templates/dialog-item-achat.html +++ b/templates/dialog-item-achat.html @@ -15,13 +15,15 @@ {{item.name}} - {{#unless quantiteIllimite}}
- +
- {{/unless}}