Correction des monnaies
* Des deniers sont créés si on n'a rien d'autre * Gagner ou dépenser de l'argent fonctionne même si on n'a pas tous les types de pièces * Tous les acteurs peuvent acheter/vendre s'ils ont de l'argent => Pratique pour créer une auberge! * Seuls les personnages peuvent boire et manger * plus de problèmes de monnaies manquantes
This commit is contained in:
@ -1,34 +1,52 @@
|
||||
|
||||
import { Monnaie } from "./item-monnaie.js";
|
||||
import { Misc } from "./misc.js";
|
||||
import { RdDUtility } from "./rdd-utility.js";
|
||||
|
||||
export class DialogItemAchat extends Dialog {
|
||||
|
||||
static async onButtonAcheter(event) {
|
||||
const buttonAcheter = event.currentTarget;
|
||||
if (!buttonAcheter.attributes['data-jsondata']?.value) {
|
||||
ui.notifications.warn("Impossible d'acheter: informations sur l'objet manquantes")
|
||||
return;
|
||||
}
|
||||
const chatMessageIdVente = RdDUtility.findChatMessageId(buttonAcheter);
|
||||
|
||||
const vendeurId = buttonAcheter.attributes['data-vendeurId']?.value;
|
||||
static venteData(button) {
|
||||
const vendeurId = button.attributes['data-vendeurId']?.value;
|
||||
const vendeur = vendeurId ? game.actors.get(vendeurId) : undefined;
|
||||
const acheteur = RdDUtility.getSelectedActor();
|
||||
|
||||
const json = button.attributes['data-jsondata']?.value;
|
||||
if (!acheteur && !vendeur) {
|
||||
ui.notifications.info("Pas d'acheteur ni de vendeur, aucun changement");
|
||||
return;
|
||||
return undefined;
|
||||
}
|
||||
if (!json) {
|
||||
ui.notifications.warn("Impossible d'acheter: informations sur l'objet manquantes")
|
||||
return undefined;
|
||||
}
|
||||
|
||||
let venteData = DialogItemAchat.prepareVenteData(buttonAcheter, vendeurId, vendeur, acheteur);
|
||||
const prixLot = Monnaie.arrondiDeniers(button.attributes['data-prixLot']?.value ?? 0);
|
||||
return {
|
||||
item: json ? JSON.parse(json) : undefined,
|
||||
vendeurId: vendeurId,
|
||||
vendeur: vendeur,
|
||||
acheteur: acheteur,
|
||||
tailleLot: parseInt(button.attributes['data-tailleLot']?.value ?? 1),
|
||||
quantiteIllimite: button.attributes['data-quantiteIllimite']?.value == 'true',
|
||||
quantiteNbLots: parseInt(button.attributes['data-quantiteNbLots']?.value),
|
||||
choix: {
|
||||
nombreLots: 1,
|
||||
seForcer: false,
|
||||
supprimerSiZero: true
|
||||
},
|
||||
prixLot: prixLot,
|
||||
prixTotal: prixLot,
|
||||
isVente: prixLot > 0,
|
||||
chatMessageIdVente: RdDUtility.findChatMessageId(button)
|
||||
};
|
||||
}
|
||||
static async onAcheter(venteData) {
|
||||
const html = await renderTemplate(`systems/foundryvtt-reve-de-dragon/templates/dialog-item-achat.html`, venteData);
|
||||
const dialog = new DialogItemAchat(html, vendeur, acheteur, venteData, chatMessageIdVente);
|
||||
const dialog = new DialogItemAchat(html, venteData);
|
||||
dialog.render(true);
|
||||
}
|
||||
|
||||
constructor(html, vendeur, acheteur, venteData, chatMessageIdVente) {
|
||||
const isConsommable = venteData.item.type == 'nourritureboisson';
|
||||
constructor(html, venteData) {
|
||||
const isConsommable = venteData.item.type == 'nourritureboisson' && venteData.acheteur?.isPersonnage();
|
||||
let options = { classes: ["dialogachat"], width: 400, height: isConsommable ? 450 : 350, 'z-index': 99999 };
|
||||
|
||||
const actionAchat = venteData.prixLot > 0 ? "Acheter" : "Prendre";
|
||||
@ -47,42 +65,17 @@ export class DialogItemAchat extends Dialog {
|
||||
|
||||
super(conf, options);
|
||||
|
||||
this.vendeur = vendeur;
|
||||
this.acheteur = acheteur;
|
||||
this.chatMessageIdVente = chatMessageIdVente;
|
||||
this.venteData = venteData;
|
||||
}
|
||||
|
||||
static prepareVenteData(buttonAcheter, vendeurId, vendeur, acheteur) {
|
||||
const jsondata = buttonAcheter.attributes['data-jsondata']?.value;
|
||||
const prixLot = parseInt(buttonAcheter.attributes['data-prixLot']?.value ?? 0);
|
||||
return {
|
||||
item: JSON.parse(jsondata),
|
||||
vendeurId: vendeurId,
|
||||
vendeur: vendeur,
|
||||
acheteur: acheteur,
|
||||
tailleLot: parseInt(buttonAcheter.attributes['data-tailleLot']?.value ?? 1),
|
||||
quantiteIllimite: buttonAcheter.attributes['data-quantiteIllimite']?.value == 'true',
|
||||
quantiteNbLots: parseInt(buttonAcheter.attributes['data-quantiteNbLots']?.value),
|
||||
choix: {
|
||||
nombreLots: 1,
|
||||
seForcer: false,
|
||||
supprimerSiZero: true
|
||||
},
|
||||
prixLot: prixLot,
|
||||
prixTotal: prixLot,
|
||||
isVente: prixLot > 0
|
||||
};
|
||||
}
|
||||
|
||||
async onAchat() {
|
||||
await $(".nombreLots").change();
|
||||
(this.vendeur ?? this.acheteur).achatVente({
|
||||
(this.venteData.vendeur ?? this.venteData.acheteur).achatVente({
|
||||
userId: game.user.id,
|
||||
vendeurId: this.vendeur?.id,
|
||||
acheteurId: this.acheteur?.id,
|
||||
vendeurId: this.venteData.vendeur?.id,
|
||||
acheteurId: this.venteData.acheteur?.id,
|
||||
prixTotal: this.venteData.prixTotal,
|
||||
chatMessageIdVente: this.chatMessageIdVente,
|
||||
chatMessageIdVente: this.venteData.chatMessageIdVente,
|
||||
choix: this.venteData.choix
|
||||
});
|
||||
}
|
||||
|
Reference in New Issue
Block a user