Suppression de vente depuis un "service"
This commit is contained in:
parent
d7e5a09540
commit
274009d3fa
@ -3661,12 +3661,11 @@ export class RdDActor extends RdDBaseActor {
|
|||||||
|
|
||||||
const cout = Number(achat.prixTotal ?? 0);
|
const cout = Number(achat.prixTotal ?? 0);
|
||||||
const vendeur = achat.vendeurId ? game.actors.get(achat.vendeurId) : undefined;
|
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 acheteur = achat.acheteurId ? game.actors.get(achat.acheteurId) : undefined;
|
||||||
const vente = achat.vente;
|
const vente = achat.vente;
|
||||||
const quantite = (achat.choix.nombreLots ?? 1) * (vente.tailleLot);
|
const quantite = (achat.choix.nombreLots ?? 1) * (vente.tailleLot);
|
||||||
const itemVendu = vendeur?.getItem(vente.item._id) ?? (await RdDItem.getCorrespondingItem(vente.item));
|
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} !`);
|
ChatUtility.notifyUser(achat.userId, 'warn', `Le vendeur n'a pas assez de ${itemVendu.name} !`);
|
||||||
return
|
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 !`);
|
ChatUtility.notifyUser(achat.userId, 'warn', `Vous n'avez pas assez d'argent pour payer ${Math.ceil(cout / 100)} sols !`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
await this.decrementerVente(service, vendeur, itemVendu, quantite, cout);
|
await this.decrementerVente(vendeur, itemVendu, quantite, cout);
|
||||||
if (acheteur) {
|
if (acheteur) {
|
||||||
await acheteur.depenserSols(cout);
|
await acheteur.depenserSols(cout);
|
||||||
let createdItemId = await acheteur.creerQuantiteItem(vente.item, quantite);
|
let createdItemId = await acheteur.creerQuantiteItem(vente.item, quantite);
|
||||||
@ -3697,7 +3696,7 @@ export class RdDActor extends RdDBaseActor {
|
|||||||
if (vente.quantiteNbLots <= achat.choix.nombreLots) {
|
if (vente.quantiteNbLots <= achat.choix.nombreLots) {
|
||||||
ChatUtility.removeChatMessageId(achat.chatMessageIdVente);
|
ChatUtility.removeChatMessageId(achat.chatMessageIdVente);
|
||||||
}
|
}
|
||||||
else if (!service) {
|
else {
|
||||||
vente["properties"] = itemVendu.getProprietes();
|
vente["properties"] = itemVendu.getProprietes();
|
||||||
vente.quantiteNbLots -= achat.choix.nombreLots;
|
vente.quantiteNbLots -= achat.choix.nombreLots;
|
||||||
vente.jsondata = JSON.stringify(vente.item);
|
vente.jsondata = JSON.stringify(vente.item);
|
||||||
@ -3708,18 +3707,15 @@ export class RdDActor extends RdDBaseActor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async decrementerVente(service, vendeur, itemVendu, quantite, cout) {
|
async decrementerVente(vendeur, itemVendu, quantite, cout) {
|
||||||
if (service) {
|
if (vendeur) {
|
||||||
await service.venteRefItem(itemVendu, quantite, cout)
|
|
||||||
}
|
|
||||||
else if (vendeur) {
|
|
||||||
await vendeur.ajouterSols(cout);
|
await vendeur.ajouterSols(cout);
|
||||||
await vendeur.decrementerQuantiteItem(itemVendu, quantite);
|
await vendeur.decrementerQuantiteItem(itemVendu, quantite);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
verifierQuantite(service, serviceSubItem, vendeur, item, quantiteTotal) {
|
verifierQuantite(vendeur, item, quantiteTotal) {
|
||||||
const disponible = service ? service.getQuantiteDisponible(serviceSubItem, quantiteTotal) : (vendeur ? (item?.getQuantite() ?? 0) : quantiteTotal);
|
const disponible = vendeur ? (item?.getQuantite() ?? 0) : quantiteTotal;
|
||||||
return disponible >= quantiteTotal;
|
return disponible >= quantiteTotal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -153,7 +153,7 @@ export class RdDBaseActorSheet extends ActorSheet {
|
|||||||
RdDSheetUtility.splitItem(item, this.actor);
|
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-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.html.find('.creer-un-objet').click(async event => {
|
||||||
this.selectObjetTypeToCreate();
|
this.selectObjetTypeToCreate();
|
||||||
@ -170,6 +170,9 @@ export class RdDBaseActorSheet extends ActorSheet {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getQuantiteMax(item) {
|
||||||
|
return item.system.quantite;
|
||||||
|
}
|
||||||
|
|
||||||
/* -------------------------------------------- */
|
/* -------------------------------------------- */
|
||||||
_getHeaderButtons() {
|
_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 = {
|
const venteData = {
|
||||||
item,
|
item,
|
||||||
actingUserId: game.user.id,
|
actingUserId: game.user.id,
|
||||||
vendeurId: vendeur?.id,
|
vendeurId: vendeur?.id,
|
||||||
vendeur,
|
vendeur,
|
||||||
acheteur,
|
acheteur,
|
||||||
serviceSubItem: serviceSubItem,
|
|
||||||
service,
|
|
||||||
tailleLot,
|
tailleLot,
|
||||||
quantiteIllimite,
|
quantiteIllimite,
|
||||||
quantiteNbLots: nbLots,
|
quantiteNbLots: nbLots,
|
||||||
@ -77,7 +75,7 @@ export class DialogItemAchat extends Dialog {
|
|||||||
buttons[actionAchat] = { label: actionAchat, callback: it => { this.onAchat(); } };
|
buttons[actionAchat] = { label: actionAchat, callback: it => { this.onAchat(); } };
|
||||||
buttons["decliner"] = { label: "Décliner", callback: it => { } };
|
buttons["decliner"] = { label: "Décliner", callback: it => { } };
|
||||||
const acheteur = venteData.acheteur?.name ?? 'Un acheteur';
|
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 = {
|
let conf = {
|
||||||
title: `${acheteur} - ${actionAchat} à ${vendeur}`,
|
title: `${acheteur} - ${actionAchat} à ${vendeur}`,
|
||||||
content: html,
|
content: html,
|
||||||
@ -93,7 +91,6 @@ export class DialogItemAchat extends Dialog {
|
|||||||
await this.html.find(".nombreLots").change();
|
await this.html.find(".nombreLots").change();
|
||||||
(this.venteData.vendeur ?? this.venteData.acheteur).achatVente({
|
(this.venteData.vendeur ?? this.venteData.acheteur).achatVente({
|
||||||
userId: game.user.id,
|
userId: game.user.id,
|
||||||
serviceId: this.venteData.service?.id,
|
|
||||||
vendeurId: this.venteData.vendeur?.id,
|
vendeurId: this.venteData.vendeur?.id,
|
||||||
acheteurId: this.venteData.acheteur?.id,
|
acheteurId: this.venteData.acheteur?.id,
|
||||||
prixTotal: this.venteData.prixTotal,
|
prixTotal: this.venteData.prixTotal,
|
||||||
|
@ -2,15 +2,13 @@ import { HtmlUtility } from "./html-utility.js";
|
|||||||
|
|
||||||
export class DialogItemVente extends Dialog {
|
export class DialogItemVente extends Dialog {
|
||||||
|
|
||||||
static async display({ item, callback, service = undefined, quantiteMax = undefined }) {
|
static async display({ item, callback, quantiteMax = undefined }) {
|
||||||
const quantite = quantiteMax ?? item.getQuantite();
|
const quantite = quantiteMax ?? item.getQuantite() ?? 1;
|
||||||
const isOwned = item.isOwned;
|
const isOwned = item.isOwned;
|
||||||
// const isOwned = item.isOwned || service?.actor;
|
|
||||||
const venteData = {
|
const venteData = {
|
||||||
item: item,
|
item: item,
|
||||||
alias: item.actor?.name ?? service?.name ?? game.user.name,
|
alias: item.actor?.name ?? game.user.name,
|
||||||
serviceId: service?.id,
|
vendeurId: item.actor?.id ,
|
||||||
vendeurId: item.actor?.id ?? service?.actor?.id,
|
|
||||||
prixOrigine: item.system.cout,
|
prixOrigine: item.system.cout,
|
||||||
prixUnitaire: item.system.cout,
|
prixUnitaire: item.system.cout,
|
||||||
prixLot: item.system.cout,
|
prixLot: item.system.cout,
|
||||||
@ -18,7 +16,7 @@ export class DialogItemVente extends Dialog {
|
|||||||
quantiteNbLots: quantite,
|
quantiteNbLots: quantite,
|
||||||
quantiteMaxLots: quantite,
|
quantiteMaxLots: quantite,
|
||||||
quantiteMax: quantite,
|
quantiteMax: quantite,
|
||||||
quantiteIllimite: (service && service.system && service.system.illimite) ? service.system.illimite : !isOwned,
|
quantiteIllimite: !isOwned || quantiteMax == undefined,
|
||||||
isOwned: isOwned,
|
isOwned: isOwned,
|
||||||
};
|
};
|
||||||
const html = await renderTemplate(`systems/foundryvtt-reve-de-dragon/templates/dialog-item-vente.html`, venteData);
|
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) {
|
async vendre(subItem) {
|
||||||
const item = await RdDItem.getCorrespondingItem(subItem);
|
const item = await RdDItem.getCorrespondingItem(subItem);
|
||||||
const quantiteMax = this.system.illimite ? undefined : subItem.system.quantite;
|
const quantiteMax = this.system.illimite ? undefined : subItem.system.quantite;
|
||||||
await item.proposerVente({ service: this, quantiteMax });
|
await item.proposerVente(quantiteMax);
|
||||||
}
|
}
|
||||||
|
|
||||||
async acheter(acheteur, subItem) {
|
async acheter(acheteur, subItem) {
|
||||||
|
@ -60,7 +60,7 @@ export class RdDItemSheet extends ItemSheet {
|
|||||||
buttons.unshift({
|
buttons.unshift({
|
||||||
class: "vendre",
|
class: "vendre",
|
||||||
icon: "fas fa-comments-dollar",
|
icon: "fas fa-comments-dollar",
|
||||||
onclick: ev => this.item.proposerVente({service: this, quantiteMax: 1})
|
onclick: ev => this.item.proposerVente(1)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
buttons.unshift({
|
buttons.unshift({
|
||||||
|
@ -420,7 +420,7 @@ export class RdDItem extends Item {
|
|||||||
return [true, undefined];
|
return [true, undefined];
|
||||||
}
|
}
|
||||||
|
|
||||||
async proposerVente({ service = undefined, quantiteMax = undefined }) {
|
async proposerVente(quantiteMax = undefined) {
|
||||||
console.log(this);
|
console.log(this);
|
||||||
if (this.isConteneurNonVide()) {
|
if (this.isConteneurNonVide()) {
|
||||||
ui.notifications.warn(`Votre ${this.name} n'est pas vide, pas possible de le proposer`);
|
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({
|
await DialogItemVente.display({
|
||||||
item: this,
|
item: this,
|
||||||
service: service,
|
|
||||||
quantiteMax,
|
quantiteMax,
|
||||||
callback: async (vente) => {
|
callback: async (vente) => {
|
||||||
vente["properties"] = this.getProprietes();
|
vente["properties"] = this.getProprietes();
|
||||||
|
@ -2,9 +2,7 @@
|
|||||||
<div>
|
<div>
|
||||||
<div class="flexrow flex-center">
|
<div class="flexrow flex-center">
|
||||||
<div>
|
<div>
|
||||||
{{#if service}}
|
{{#if vendeur}}
|
||||||
<img class="chat-icon" src="{{service.img}}" title="{{service.name}}" alt="{{service.name}}" />
|
|
||||||
{{else if vendeur}}
|
|
||||||
<img class="chat-icon" src="{{vendeur.img}}" title="{{vendeur.name}}" alt="{{vendeur.name}}" />
|
<img class="chat-icon" src="{{vendeur.img}}" title="{{vendeur.name}}" alt="{{vendeur.name}}" />
|
||||||
{{else}}
|
{{else}}
|
||||||
<img class="chat-icon" src="systems/foundryvtt-reve-de-dragon/styles/img/ui/icon_echoppe.webp" title="Un commerçant" alt="Vendeur MJ" />
|
<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