From 2546b89b4404bef79ea7e18dc519ca636f5c4e42 Mon Sep 17 00:00:00 2001 From: Vincent Vandemeulebrouck Date: Fri, 30 Dec 2022 02:28:17 +0100 Subject: [PATCH] =?UTF-8?q?Fix:=20vente=20de=20service=20avec=20quantit?= =?UTF-8?q?=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- module/actor.js | 6 +++--- module/dialog-item-achat.js | 3 ++- module/item-service.js | 3 ++- module/item.js | 2 +- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/module/actor.js b/module/actor.js index e3a955ee..30908c8b 100644 --- a/module/actor.js +++ b/module/actor.js @@ -3776,7 +3776,7 @@ export class RdDActor extends Actor { const vente = achat.vente; const quantite = (achat.choix.nombreLots ?? 1) * (vente.tailleLot); const itemVendu = vendeur?.getObjet(vente.item._id) ?? (await RdDItem.getCorrespondingItem(vente.item)); - if (!this.verifierQuantite(service, vendeur, itemVendu, quantite)) { + if (!this.verifierQuantite(service, vente.serviceSubItem, vendeur, itemVendu, quantite)) { ChatUtility.notifyUser(achat.userId, 'warn', `Le vendeur n'a pas assez de ${itemVendu.name} !`); return } @@ -3828,8 +3828,8 @@ export class RdDActor extends Actor { } } - verifierQuantite(service, vendeur, item, quantiteTotal) { - const disponible = service ? service.getQuantiteDisponible(item, quantiteTotal) : (vendeur ? (item?.getQuantite() ?? 0) : quantiteTotal); + verifierQuantite(service, serviceSubItem, vendeur, item, quantiteTotal) { + const disponible = service ? service.getQuantiteDisponible(serviceSubItem, quantiteTotal) : (vendeur ? (item?.getQuantite() ?? 0) : quantiteTotal); return disponible >= quantiteTotal; } diff --git a/module/dialog-item-achat.js b/module/dialog-item-achat.js index 5509b178..12648644 100644 --- a/module/dialog-item-achat.js +++ b/module/dialog-item-achat.js @@ -30,13 +30,14 @@ export class DialogItemAchat extends Dialog { } - static async onAcheter({ item, vendeur, acheteur, service, tailleLot, prixLot, nbLots, quantiteIllimite, chatMessageIdVente }) { + static async onAcheter({ item, vendeur, acheteur, service, serviceSubItem, tailleLot, prixLot, nbLots, quantiteIllimite, chatMessageIdVente }) { const venteData = { item, actingUserId: game.user.id, vendeurId: vendeur?.id, vendeur, acheteur, + serviceSubItem: serviceSubItem, service, tailleLot, quantiteIllimite, diff --git a/module/item-service.js b/module/item-service.js index 17fc6ab5..bc00ded4 100644 --- a/module/item-service.js +++ b/module/item-service.js @@ -23,7 +23,7 @@ export class RdDItemService extends RdDItem { getProprietes() { return []; } getServiceItem(itemRef) { - if (this.isService()) { + if (itemRef && this.isService()) { return this.system.items.find(it => it.id == itemRef.id && it.pack == itemRef.pack); } return undefined; @@ -64,6 +64,7 @@ export class RdDItemService extends RdDItem { await DialogItemAchat.onAcheter({ item: await RdDItem.getCorrespondingItem(subItem), acheteur, + serviceSubItem: subItem, service: this, quantiteIllimite: this.system.illimite, nbLots, diff --git a/module/item.js b/module/item.js index 6a2b5fed..7bcbeda6 100644 --- a/module/item.js +++ b/module/item.js @@ -428,7 +428,7 @@ export class RdDItem extends Item { } await DialogItemVente.display({ item: this, - service, + service: service, quantiteMax, callback: async (vente) => { vente["properties"] = this.getProprietes();