Minor fixes
This commit is contained in:
@ -30,6 +30,7 @@ import { Monnaie } from "./item-monnaie.js";
|
||||
import { DialogConsommer } from "./dialog-item-consommer.js";
|
||||
import { DialogFabriquerPotion } from "./dialog-fabriquer-potion.js";
|
||||
import { RollDataAjustements } from "./rolldata-ajustements.js";
|
||||
import { DialogItemAchat } from "./dialog-item-achat.js";
|
||||
|
||||
|
||||
/* -------------------------------------------- */
|
||||
@ -1940,7 +1941,7 @@ export class RdDActor extends Actor {
|
||||
const itemData = Misc.data(item);
|
||||
const exotisme = Math.min(itemData.data.exotisme, itemData.data.qualite, 0);
|
||||
if (exotisme < 0) {
|
||||
const rolled = await this.rollCaracCompetence('volonte', 'cuisine', exotisme, { title: `surmonte l'exotisme de ${itemData.name}` });
|
||||
const rolled = await this.rollCaracCompetence('volonte', 'cuisine', exotisme, { title: `tente de surmonter l'exotisme de ${itemData.name}` });
|
||||
if (rolled.isEchec) {
|
||||
if (!choix.seForcer) {
|
||||
return false;
|
||||
@ -3511,61 +3512,61 @@ export class RdDActor extends Actor {
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async achatVente(vendeurId, acheteurId, venteData, chatMessageIdVente) {
|
||||
if (vendeurId == acheteurId) {
|
||||
async achatVente(achat) {
|
||||
if (achat.vendeurId == achat.acheteurId) {
|
||||
ui.notifications.info("Inutile de se vendre à soi-même");
|
||||
return;
|
||||
}
|
||||
if (!Misc.isElectedUser()) {
|
||||
RdDActor.remoteActorCall({
|
||||
actorId: vendeurId ?? acheteurId,
|
||||
method: 'achatVente', args: [vendeurId, acheteurId, venteData, chatMessageIdVente]
|
||||
actorId: achat.vendeurId ?? achat.acheteurId,
|
||||
method: 'achatVente', args: [achat]
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
const acheteur = acheteurId ? game.actors.get(acheteurId) : undefined;
|
||||
const vendeur = vendeurId ? game.actors.get(vendeurId) : undefined;
|
||||
const itemId = venteData.item._id;
|
||||
const acheteur = achat.acheteurId ? game.actors.get(achat.acheteurId) : undefined;
|
||||
const vendeur = achat.vendeurId ? game.actors.get(achat.vendeurId) : undefined;
|
||||
const messageVente = game.messages.get(achat.chatMessageIdVente);
|
||||
const html = await messageVente.getHTML();
|
||||
const buttonAcheter = html.find(".button-acheter")[0];
|
||||
const vente = DialogItemAchat.prepareVenteData(buttonAcheter, achat.vendeurId, vendeur, acheteur);
|
||||
const itemId = vente.item._id;
|
||||
|
||||
const coutDeniers = Math.floor((venteData.prixTotal ?? 0) * 100);
|
||||
venteData.quantiteTotal = (venteData.nombreLots ?? 1) * (venteData.tailleLot);
|
||||
const coutDeniers = Math.floor((achat.prixTotal ?? 0) * 100);
|
||||
achat.quantiteTotal = (achat.nombreLots ?? 1) * (vente.tailleLot);
|
||||
if (acheteur) {
|
||||
let resteAcheteur = await acheteur.depenser(coutDeniers);
|
||||
if (resteAcheteur < 0) {
|
||||
ui.notifications.warn(`Vous n'avez pas assez d'argent pour payer ${venteData.prixTotal} sols !`);
|
||||
ui.notifications.warn(`Vous n'avez pas assez d'argent pour payer ${vente.prixTotal} sols !`);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (vendeur) {
|
||||
let itemData = Misc.data(vendeur.getObjet(itemId));
|
||||
// diminuer QuantiteVendeur
|
||||
if ("quantite" in itemData.data ?
|
||||
itemData.data.quantite < venteData.quantiteTotal : venteData.nombreLots != 1) {
|
||||
// pas assez de quantite
|
||||
let itemVenduData = Misc.data(vendeur.getObjet(itemId));
|
||||
if ("quantite" in itemVenduData.data ? itemVenduData.data.quantite < achat.quantiteTotal : achat.nombreLots != 1) {
|
||||
await acheteur?.ajouterDeniers(coutDeniers);
|
||||
ui.notifications.warn(`Le vendeur n'a plus assez de ${venteData.item.name} !`);
|
||||
ui.notifications.warn(`Le vendeur n'a plus assez de ${vente.item.name} !`);
|
||||
return;
|
||||
}
|
||||
vendeur.ajouterDeniers(coutDeniers);
|
||||
let qtReste = (itemData.data.quantite ?? 1) - venteData.quantiteTotal;
|
||||
if (qtReste == 0) {
|
||||
let resteQuantite = (itemVenduData.data.quantite ?? 1) - achat.quantiteTotal;
|
||||
if (resteQuantite == 0) {
|
||||
vendeur.deleteEmbeddedDocuments("Item", itemId);
|
||||
}
|
||||
else {
|
||||
vendeur.updateEmbeddedDocuments("Item", [{ _id: itemId, 'data.quantite': qtReste }]);
|
||||
vendeur.updateEmbeddedDocuments("Item", [{ _id: itemId, 'data.quantite': resteQuantite }]);
|
||||
}
|
||||
}
|
||||
|
||||
if (acheteur) {
|
||||
const achat = {
|
||||
type: venteData.item.type,
|
||||
img: venteData.item.img,
|
||||
name: venteData.item.name,
|
||||
data: venteData.item.data
|
||||
const achatData = {
|
||||
type: vente.item.type,
|
||||
img: vente.item.img,
|
||||
name: vente.item.name,
|
||||
data: vente.item.data
|
||||
}
|
||||
achat.data.quantite = venteData.quantiteTotal;
|
||||
await acheteur.createEmbeddedDocuments("Item", [achat]);
|
||||
achatData.data.quantite = achat.quantiteTotal;
|
||||
await acheteur.createEmbeddedDocuments("Item", [achatData]);
|
||||
}
|
||||
if (coutDeniers > 0) {
|
||||
RdDAudio.PlayContextAudio("argent");
|
||||
@ -3573,19 +3574,16 @@ export class RdDActor extends Actor {
|
||||
|
||||
ChatMessage.create({
|
||||
whisper: ChatUtility.getWhisperRecipientsAndGMs(this.name),
|
||||
content: await renderTemplate('systems/foundryvtt-reve-de-dragon/templates/chat-achat-item.html', venteData)
|
||||
content: await renderTemplate('systems/foundryvtt-reve-de-dragon/templates/chat-achat-item.html', vente)
|
||||
});
|
||||
|
||||
if (!venteData.quantiteIllimite) {
|
||||
if (venteData.quantiteNbLots <= venteData.nombreLots) {
|
||||
if (!vente.quantiteIllimite) {
|
||||
if (vente.quantiteNbLots <= achat.nombreLots) {
|
||||
ChatUtility.removeChatMessageId(chatMessageIdVente);
|
||||
}
|
||||
else {
|
||||
venteData.quantiteNbLots -= venteData.nombreLots;
|
||||
venteData.jsondata = JSON.stringify(venteData.item);
|
||||
let newMessageVente = await renderTemplate('systems/foundryvtt-reve-de-dragon/templates/chat-vente-item.html', venteData);
|
||||
const messageVente = game.messages.get(chatMessageIdVente);
|
||||
messageVente.update({ content: newMessageVente });
|
||||
vente.quantiteNbLots -= achat.nombreLots;
|
||||
messageVente.update({ content: await renderTemplate('systems/foundryvtt-reve-de-dragon/templates/chat-vente-item.html', vente) });
|
||||
messageVente.render(true);
|
||||
}
|
||||
}
|
||||
@ -4081,7 +4079,7 @@ export class RdDActor extends Actor {
|
||||
if (Misc.isElectedUser()) {
|
||||
let draconique = Draconique.all().find(it => it.isCase(item));
|
||||
if (draconique) {
|
||||
draconique.onActorDeleteCaseTmr(this, item)
|
||||
draconique.onActorDeleteCaseTmr(this, Misc.data(item))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user