Les auberges sont des commerces #600
@ -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;
|
||||
}
|
||||
|
||||
|
@ -153,7 +153,7 @@ export class RdDBaseActorSheet extends ActorSheet {
|
||||
RdDSheetUtility.splitItem(item, this.actor);
|
||||
});
|
||||
this.html.find('.item-delete').click(async event => RdDUtility.confirmActorItemDelete(this, RdDSheetUtility.getItem(event, this.actor)));
|
||||
this.html.find('.item-vendre').click(async event => RdDSheetUtility.getItem(event, this.actor)?.proposerVente());
|
||||
this.html.find('.item-vendre').click(async event => RdDSheetUtility.getItem(event, this.actor)?.proposerVente(this.getQuantiteMax(item)));
|
||||
|
||||
this.html.find('.creer-un-objet').click(async event => {
|
||||
this.selectObjetTypeToCreate();
|
||||
@ -170,6 +170,9 @@ export class RdDBaseActorSheet extends ActorSheet {
|
||||
|
||||
}
|
||||
|
||||
getQuantiteMax(item) {
|
||||
return item.system.quantite;
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
_getHeaderButtons() {
|
||||
|
@ -30,15 +30,13 @@ export class DialogItemAchat extends Dialog {
|
||||
}
|
||||
|
||||
|
||||
static async onAcheter({ item, vendeur, acheteur, service, serviceSubItem, tailleLot, prixLot, nbLots, quantiteIllimite, chatMessageIdVente }) {
|
||||
static async onAcheter({ item, vendeur, acheteur, tailleLot, prixLot, nbLots, quantiteIllimite, chatMessageIdVente }) {
|
||||
const venteData = {
|
||||
item,
|
||||
actingUserId: game.user.id,
|
||||
vendeurId: vendeur?.id,
|
||||
vendeur,
|
||||
acheteur,
|
||||
serviceSubItem: serviceSubItem,
|
||||
service,
|
||||
tailleLot,
|
||||
quantiteIllimite,
|
||||
quantiteNbLots: nbLots,
|
||||
@ -77,7 +75,7 @@ export class DialogItemAchat extends Dialog {
|
||||
buttons[actionAchat] = { label: actionAchat, callback: it => { this.onAchat(); } };
|
||||
buttons["decliner"] = { label: "Décliner", callback: it => { } };
|
||||
const acheteur = venteData.acheteur?.name ?? 'Un acheteur';
|
||||
const vendeur = (venteData.service ?? venteData.vendeur)?.name ?? 'Un vendeur';
|
||||
const vendeur = venteData.vendeur?.name ?? 'Un vendeur';
|
||||
let conf = {
|
||||
title: `${acheteur} - ${actionAchat} à ${vendeur}`,
|
||||
content: html,
|
||||
@ -93,7 +91,6 @@ export class DialogItemAchat extends Dialog {
|
||||
await this.html.find(".nombreLots").change();
|
||||
(this.venteData.vendeur ?? this.venteData.acheteur).achatVente({
|
||||
userId: game.user.id,
|
||||
serviceId: this.venteData.service?.id,
|
||||
vendeurId: this.venteData.vendeur?.id,
|
||||
acheteurId: this.venteData.acheteur?.id,
|
||||
prixTotal: this.venteData.prixTotal,
|
||||
|
@ -2,15 +2,13 @@ import { HtmlUtility } from "./html-utility.js";
|
||||
|
||||
export class DialogItemVente extends Dialog {
|
||||
|
||||
static async display({ item, callback, service = undefined, quantiteMax = undefined }) {
|
||||
const quantite = quantiteMax ?? item.getQuantite();
|
||||
static async display({ item, callback, quantiteMax = undefined }) {
|
||||
const quantite = quantiteMax ?? item.getQuantite() ?? 1;
|
||||
const isOwned = item.isOwned;
|
||||
// const isOwned = item.isOwned || service?.actor;
|
||||
const venteData = {
|
||||
item: item,
|
||||
alias: item.actor?.name ?? service?.name ?? game.user.name,
|
||||
serviceId: service?.id,
|
||||
vendeurId: item.actor?.id ?? service?.actor?.id,
|
||||
alias: item.actor?.name ?? game.user.name,
|
||||
vendeurId: item.actor?.id ,
|
||||
prixOrigine: item.system.cout,
|
||||
prixUnitaire: item.system.cout,
|
||||
prixLot: item.system.cout,
|
||||
@ -18,7 +16,7 @@ export class DialogItemVente extends Dialog {
|
||||
quantiteNbLots: quantite,
|
||||
quantiteMaxLots: quantite,
|
||||
quantiteMax: quantite,
|
||||
quantiteIllimite: (service && service.system && service.system.illimite) ? service.system.illimite : !isOwned,
|
||||
quantiteIllimite: !isOwned || quantiteMax == undefined,
|
||||
isOwned: isOwned,
|
||||
};
|
||||
const html = await renderTemplate(`systems/foundryvtt-reve-de-dragon/templates/dialog-item-vente.html`, venteData);
|
||||
|
@ -47,7 +47,7 @@ export class RdDItemService extends RdDItem {
|
||||
async vendre(subItem) {
|
||||
const item = await RdDItem.getCorrespondingItem(subItem);
|
||||
const quantiteMax = this.system.illimite ? undefined : subItem.system.quantite;
|
||||
await item.proposerVente({ service: this, quantiteMax });
|
||||
await item.proposerVente(quantiteMax);
|
||||
}
|
||||
|
||||
async acheter(acheteur, subItem) {
|
||||
|
@ -60,7 +60,7 @@ export class RdDItemSheet extends ItemSheet {
|
||||
buttons.unshift({
|
||||
class: "vendre",
|
||||
icon: "fas fa-comments-dollar",
|
||||
onclick: ev => this.item.proposerVente({service: this, quantiteMax: 1})
|
||||
onclick: ev => this.item.proposerVente(1)
|
||||
});
|
||||
}
|
||||
buttons.unshift({
|
||||
|
@ -420,7 +420,7 @@ export class RdDItem extends Item {
|
||||
return [true, undefined];
|
||||
}
|
||||
|
||||
async proposerVente({ service = undefined, quantiteMax = undefined }) {
|
||||
async proposerVente(quantiteMax = undefined) {
|
||||
console.log(this);
|
||||
if (this.isConteneurNonVide()) {
|
||||
ui.notifications.warn(`Votre ${this.name} n'est pas vide, pas possible de le proposer`);
|
||||
@ -428,7 +428,6 @@ export class RdDItem extends Item {
|
||||
}
|
||||
await DialogItemVente.display({
|
||||
item: this,
|
||||
service: service,
|
||||
quantiteMax,
|
||||
callback: async (vente) => {
|
||||
vente["properties"] = this.getProprietes();
|
||||
|
@ -2,9 +2,7 @@
|
||||
<div>
|
||||
<div class="flexrow flex-center">
|
||||
<div>
|
||||
{{#if service}}
|
||||
<img class="chat-icon" src="{{service.img}}" title="{{service.name}}" alt="{{service.name}}" />
|
||||
{{else if vendeur}}
|
||||
{{#if vendeur}}
|
||||
<img class="chat-icon" src="{{vendeur.img}}" title="{{vendeur.name}}" alt="{{vendeur.name}}" />
|
||||
{{else}}
|
||||
<img class="chat-icon" src="systems/foundryvtt-reve-de-dragon/styles/img/ui/icon_echoppe.webp" title="Un commerçant" alt="Vendeur MJ" />
|
||||
|
Loading…
Reference in New Issue
Block a user