Ajout des "boutiques"

Une boutique est un Item service permettant de définir l'inventaire
en vente, et de le vendre facilement.

Les boutiques peuvent être accédées par les joueurs (avec le lien)
pour y faire leurs courses.
This commit is contained in:
Vincent Vandemeulebrouck
2022-12-23 00:34:17 +01:00
parent f397c82c6d
commit 7c70e944b1
15 changed files with 506 additions and 98 deletions

View File

@ -188,17 +188,17 @@ export class RdDActor extends Actor {
canReceive(item) {
if (this.isCreature()) {
return item.type == 'competencecreature' || RdDItem.isItemInventaire(item);
return item.type == 'competencecreature' || item.isInventaire();
}
if (this.isEntite()) {
return item.type == 'competencecreature';
}
if (this.isVehicule()) {
return RdDItem.isItemInventaire(item);
return item.isInventaire();
}
if (this.isPersonnage()) {
switch (item.type) {
case 'competencecreature': case 'tarot':
case 'competencecreature': case 'tarot': case 'service':
return false;
}
return true;
@ -461,7 +461,7 @@ export class RdDActor extends Actor {
selectedCaracName: 'apparence',
competences: this.itemTypes['competence']
};
const dialog = await RdDRoll.create(this, rollData,
{ html: 'systems/foundryvtt-reve-de-dragon/templates/dialog-roll.html' },
{
@ -3770,35 +3770,32 @@ export class RdDActor extends Actor {
}
const cout = Number(achat.prixTotal ?? 0);
const vente = achat.vente;
const acheteur = achat.acheteurId ? game.actors.get(achat.acheteurId) : undefined;
const vendeur = achat.vendeurId ? game.actors.get(achat.vendeurId) : undefined;
let itemVendu = vendeur?.getObjet(vente.item._id);
if (vendeur && (itemVendu?.getQuantite() ?? 0) < achat.quantiteTotal) {
ChatUtility.notifyUser(achat.userId, 'warn', `Le vendeur n'a plus assez de ${vente.item.name} !`);
return;
const service = achat.serviceId ? (vendeur?.getObjet(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?.getObjet(vente.item._id) ?? (await RdDItem.getCorrespondingItem(vente.item));
if (!this.verifierQuantite(service, vendeur, itemVendu, quantite)) {
ChatUtility.notifyUser(achat.userId, 'warn', `Le vendeur n'a pas assez de ${itemVendu.name} !`);
return
}
if (Monnaie.getFortune(acheteur) < Number(cout)) {
ChatUtility.notifyUser(achat.userId, 'warn', `Vous n'avez pas assez d'argent pour payer ${Math.ceil(cout / 100)} sols !`);
return;
}
achat.quantiteTotal = (achat.choix.nombreLots ?? 1) * (vente.tailleLot);
if (vendeur) {
await vendeur.ajouterSols(cout);
await vendeur.decrementerQuantiteItem(itemVendu, achat.quantiteTotal,);
}
await this.decrementerVente(service, vendeur, itemVendu, quantite, cout);
if (acheteur) {
await acheteur.depenserSols(cout);
let createdItemId = await acheteur.creerQuantiteItem(vente.item, achat.quantiteTotal);
let createdItemId = await acheteur.creerQuantiteItem(vente.item, quantite);
await acheteur.consommerNourritureAchetee(achat, vente, createdItemId);
}
if (cout > 0) {
RdDAudio.PlayContextAudio("argent");
}
const chatAchatItem = duplicate(vente);
chatAchatItem.quantiteTotal = achat.quantiteTotal;
chatAchatItem.quantiteTotal = quantite;
ChatMessage.create({
user: achat.userId,
speaker: { alias: (acheteur ?? vendeur).name },
@ -3810,8 +3807,8 @@ export class RdDActor extends Actor {
if (vente.quantiteNbLots <= achat.choix.nombreLots) {
ChatUtility.removeChatMessageId(achat.chatMessageIdVente);
}
else {
vente["properties"] = new RdDItem(vente.item).getProprietes();
else if (!service) {
vente["properties"] = itemVendu.getProprietes();
vente.quantiteNbLots -= achat.choix.nombreLots;
vente.jsondata = JSON.stringify(vente.item);
const messageVente = game.messages.get(achat.chatMessageIdVente);
@ -3821,6 +3818,21 @@ export class RdDActor extends Actor {
}
}
async decrementerVente(service, vendeur, itemVendu, quantite, cout) {
if (service) {
await service.venteRefItem(itemVendu, quantite, cout)
}
else if (vendeur) {
await vendeur.ajouterSols(cout);
await vendeur.decrementerQuantiteItem(itemVendu, quantite);
}
}
verifierQuantite(service, vendeur, item, quantiteTotal) {
const disponible = service ? service.getQuantiteDisponible(item, quantiteTotal) : (vendeur ? (item?.getQuantite() ?? 0) : quantiteTotal);
return disponible >= quantiteTotal;
}
async consommerNourritureAchetee(achat, vente, createdItemId) {
if (achat.choix.consommer && vente.item.type == 'nourritureboisson' && createdItemId != undefined) {
achat.choix.doses = achat.choix.nombreLots;