Suppression de vente depuis un "service"

This commit is contained in:
2023-01-01 22:16:26 +01:00
parent d7e5a09540
commit 274009d3fa
8 changed files with 23 additions and 32 deletions

View File

@ -3661,12 +3661,11 @@ export class RdDActor extends RdDBaseActor {
const cout = Number(achat.prixTotal ?? 0);
const vendeur = achat.vendeurId ? game.actors.get(achat.vendeurId) : undefined;
const service = achat.serviceId ? (vendeur?.getItem(achat.serviceId) ?? game.items.get(achat.serviceId)) : undefined;
const acheteur = achat.acheteurId ? game.actors.get(achat.acheteurId) : undefined;
const vente = achat.vente;
const quantite = (achat.choix.nombreLots ?? 1) * (vente.tailleLot);
const itemVendu = vendeur?.getItem(vente.item._id) ?? (await RdDItem.getCorrespondingItem(vente.item));
if (!this.verifierQuantite(service, vente.serviceSubItem, vendeur, itemVendu, quantite)) {
if (!this.verifierQuantite(vendeur, itemVendu, quantite)) {
ChatUtility.notifyUser(achat.userId, 'warn', `Le vendeur n'a pas assez de ${itemVendu.name} !`);
return
}
@ -3675,7 +3674,7 @@ export class RdDActor extends RdDBaseActor {
ChatUtility.notifyUser(achat.userId, 'warn', `Vous n'avez pas assez d'argent pour payer ${Math.ceil(cout / 100)} sols !`);
return;
}
await this.decrementerVente(service, vendeur, itemVendu, quantite, cout);
await this.decrementerVente(vendeur, itemVendu, quantite, cout);
if (acheteur) {
await acheteur.depenserSols(cout);
let createdItemId = await acheteur.creerQuantiteItem(vente.item, quantite);
@ -3697,7 +3696,7 @@ export class RdDActor extends RdDBaseActor {
if (vente.quantiteNbLots <= achat.choix.nombreLots) {
ChatUtility.removeChatMessageId(achat.chatMessageIdVente);
}
else if (!service) {
else {
vente["properties"] = itemVendu.getProprietes();
vente.quantiteNbLots -= achat.choix.nombreLots;
vente.jsondata = JSON.stringify(vente.item);
@ -3708,18 +3707,15 @@ export class RdDActor extends RdDBaseActor {
}
}
async decrementerVente(service, vendeur, itemVendu, quantite, cout) {
if (service) {
await service.venteRefItem(itemVendu, quantite, cout)
}
else if (vendeur) {
async decrementerVente(vendeur, itemVendu, quantite, cout) {
if (vendeur) {
await vendeur.ajouterSols(cout);
await vendeur.decrementerQuantiteItem(itemVendu, quantite);
}
}
verifierQuantite(service, serviceSubItem, vendeur, item, quantiteTotal) {
const disponible = service ? service.getQuantiteDisponible(serviceSubItem, quantiteTotal) : (vendeur ? (item?.getQuantite() ?? 0) : quantiteTotal);
verifierQuantite(vendeur, item, quantiteTotal) {
const disponible = vendeur ? (item?.getQuantite() ?? 0) : quantiteTotal;
return disponible >= quantiteTotal;
}