forked from public/foundryvtt-reve-de-dragon
Achat pour consommer
This commit is contained in:
@ -1816,7 +1816,7 @@ export class RdDActor extends Actor {
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async consommerNourritureboisson(item, choix = { doses: 1, seForcer: false }) {
|
||||
async consommerNourritureboisson(item, choix = { doses: 1, seForcer: false, supprimerSiZero: false }) {
|
||||
const itemData = Misc.data(item);
|
||||
if (itemData.type != 'nourritureboisson') {
|
||||
return;
|
||||
@ -1832,7 +1832,7 @@ export class RdDActor extends Actor {
|
||||
}
|
||||
await this.manger(item, choix.doses, { diminuerQuantite: false });
|
||||
await this.boire(item, choix.doses, { diminuerQuantite: false });
|
||||
await item.diminuerQuantite(choix.doses);
|
||||
await item.diminuerQuantite(choix.doses, choix);
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
@ -3549,7 +3549,7 @@ export class RdDActor extends Actor {
|
||||
const itemId = vente.item._id;
|
||||
|
||||
const coutDeniers = Math.floor((achat.prixTotal ?? 0) * 100);
|
||||
achat.quantiteTotal = (achat.nombreLots ?? 1) * (vente.tailleLot);
|
||||
achat.quantiteTotal = (achat.choix.nombreLots ?? 1) * (vente.tailleLot);
|
||||
if (acheteur) {
|
||||
let resteAcheteur = await acheteur.depenser(coutDeniers);
|
||||
if (resteAcheteur < 0) {
|
||||
@ -3560,7 +3560,7 @@ export class RdDActor extends Actor {
|
||||
const itemVendu = vendeur?.getObjet(itemId);
|
||||
if (itemVendu) {
|
||||
let itemVenduData = Misc.data(itemVendu);
|
||||
if ("quantite" in itemVenduData.data ? itemVenduData.data.quantite < achat.quantiteTotal : achat.nombreLots != 1) {
|
||||
if ("quantite" in itemVenduData.data ? itemVenduData.data.quantite < achat.quantiteTotal : achat.choix.nombreLots != 1) {
|
||||
await acheteur?.ajouterDeniers(coutDeniers);
|
||||
ui.notifications.warn(`Le vendeur n'a plus assez de ${vente.item.name} !`);
|
||||
return;
|
||||
@ -3582,7 +3582,11 @@ export class RdDActor extends Actor {
|
||||
data: vente.item.data
|
||||
}
|
||||
achatData.data.quantite = achat.quantiteTotal;
|
||||
await acheteur.createEmbeddedDocuments("Item", [achatData]);
|
||||
let items = await acheteur.createEmbeddedDocuments("Item", [achatData]);
|
||||
if (achat.choix.consommer && vente.item.type == 'nourritureboisson') {
|
||||
achat.choix.doses = achat.choix.nombreLots;
|
||||
await acheteur.consommerNourritureboisson(items[0], achat.choix);
|
||||
}
|
||||
}
|
||||
if (coutDeniers > 0) {
|
||||
RdDAudio.PlayContextAudio("argent");
|
||||
@ -3594,12 +3598,12 @@ export class RdDActor extends Actor {
|
||||
});
|
||||
|
||||
if (!vente.quantiteIllimite) {
|
||||
if (vente.quantiteNbLots <= achat.nombreLots) {
|
||||
if (vente.quantiteNbLots <= achat.choix.nombreLots) {
|
||||
ChatUtility.removeChatMessageId(achat.chatMessageIdVente);
|
||||
}
|
||||
else {
|
||||
vente["properties"] = new RdDItem(vente.item).getProprietes();
|
||||
vente.quantiteNbLots -= achat.nombreLots;
|
||||
vente.quantiteNbLots -= achat.choix.nombreLots;
|
||||
vente.jsondata = JSON.stringify(vente.item);
|
||||
messageVente.update({ content: await renderTemplate('systems/foundryvtt-reve-de-dragon/templates/chat-vente-item.html', vente) });
|
||||
messageVente.render(true);
|
||||
|
Reference in New Issue
Block a user