diff --git a/module/actor/commerce-sheet.js b/module/actor/commerce-sheet.js index 6df94ed5..0aa89a2a 100644 --- a/module/actor/commerce-sheet.js +++ b/module/actor/commerce-sheet.js @@ -3,6 +3,7 @@ import { RdDItem } from "../item.js"; import { RdDSheetUtility } from "../rdd-sheet-utility.js"; import { RdDUtility } from "../rdd-utility.js"; import { RdDBaseActorSheet } from "./base-actor-sheet.js"; +import { RdDCommerce } from "./commerce.js"; /** * Extend the basic ActorSheet with some very simple modifications @@ -67,7 +68,7 @@ export class RdDCommerceSheet extends RdDBaseActorSheet { quantiteIllimite: disponible == undefined, nbLots: disponible ?? 1, tailleLot: 1, - prixLot: item.system.cout + prixLot: item.calculerPrixCommercant() }); } } diff --git a/module/actor/commerce.js b/module/actor/commerce.js index c29b318d..2735ac5e 100644 --- a/module/actor/commerce.js +++ b/module/actor/commerce.js @@ -1,3 +1,4 @@ +import { Misc } from "../misc.js"; import { RdDBaseActor } from "./base-actor.js"; export class RdDCommerce extends RdDBaseActor { @@ -45,4 +46,8 @@ export class RdDCommerce extends RdDBaseActor { await super.decrementerQuantiteItem(itemVendu, quantite, {supprimerSiZero: false}); } + calculerPrix(item) { + const pourcentage = this.system.pourcentage ?? 100; + return Misc.keepDecimals(Math.ceil(item.system.cout * pourcentage)/100, 2); + } } \ No newline at end of file diff --git a/module/dialog-item-vente.js b/module/dialog-item-vente.js index a027ef61..78698d2a 100644 --- a/module/dialog-item-vente.js +++ b/module/dialog-item-vente.js @@ -9,9 +9,9 @@ export class DialogItemVente extends Dialog { item: item, alias: item.actor?.name ?? game.user.name, vendeurId: item.actor?.id , - prixOrigine: item.system.cout, - prixUnitaire: item.system.cout, - prixLot: item.system.cout, + prixOrigine: item.calculerPrixCommercant(), + prixUnitaire: item.calculerPrixCommercant(), + prixLot: item.calculerPrixCommercant(), tailleLot: 1, quantiteNbLots: quantite, quantiteMaxLots: quantite, diff --git a/module/item-service.js b/module/item-service.js index 6d116dfa..95e192b7 100644 --- a/module/item-service.js +++ b/module/item-service.js @@ -11,7 +11,7 @@ export class RdDItemService extends RdDItem { return [ RdDItem.propertyIfDefined('Qualité', this.system.qualite, this.system.qualite != 0), RdDItem.propertyIfDefined('Moral', 'Situation heureuse', this.system.moral), - RdDItem.propertyIfDefined('Coût', `${this.system.cout} sols`), + RdDItem.propertyIfDefined('Coût', `${this.calculerPrixCommercant()} sols`), ]; } } \ No newline at end of file diff --git a/module/item.js b/module/item.js index ac7ed712..5e9944bc 100644 --- a/module/item.js +++ b/module/item.js @@ -171,7 +171,6 @@ export class RdDItem extends Item { return typesObjetsConnaissance.includes(this.type) } - getItemGroup() { if (this.isInventaire()) return "equipement"; if (this.isOeuvre()) return "oeuvre"; @@ -258,6 +257,14 @@ export class RdDItem extends Item { return this.system.cout ?? 0 } + calculerPrixCommercant() { + if (this.parent?.type == 'commerce') { + // appliquer le pourcentage + return this.parent.calculerPrix(this); + } + return this.system.cout; + } + prepareDerivedData() { super.prepareDerivedData(); if (this.isInventaire()) { diff --git a/module/rdd-utility.js b/module/rdd-utility.js index 0e739fb7..be4091d0 100644 --- a/module/rdd-utility.js +++ b/module/rdd-utility.js @@ -16,6 +16,7 @@ import { RdDCalendrier } from "./rdd-calendrier.js"; import { Environnement } from "./environnement.js"; import { RdDItemCompetence } from "./item-competence.js"; import { RdDResolutionTable } from "./rdd-resolution-table.js"; +import { RdDCommerce } from "./actor/commerce.js"; /* -------------------------------------------- */ // This table starts at 0 -> niveau -10 @@ -274,6 +275,7 @@ export class RdDUtility { Handlebars.registerHelper('accord', (genre, ...args) => Grammar.accord(genre, args)); Handlebars.registerHelper('buildConteneur', (objet, templateItem, options) => { return new Handlebars.SafeString(RdDUtility.buildConteneur(objet, 1, templateItem, options)); }); Handlebars.registerHelper('buildContenu', (objet) => { return new Handlebars.SafeString(RdDUtility.buildContenu(objet, 1, true)); }); + Handlebars.registerHelper('calculerPrixCommercant', item => item.calculerPrixCommercant()); Handlebars.registerHelper('caseTmr-label', coord => TMRUtility.getTMRLabel(coord)); Handlebars.registerHelper('caseTmr-type', coord => TMRUtility.getTMRType(coord)); Handlebars.registerHelper('typeTmr-name', type => TMRUtility.typeTmrName(type)); diff --git a/template.json b/template.json index ed26bd06..7abda35a 100644 --- a/template.json +++ b/template.json @@ -557,6 +557,7 @@ }, "commerce":{ "templates": [ "description" ], + "pourcentage": 100, "illimite": false } }, diff --git a/templates/actor/commerce-actor-sheet.html b/templates/actor/commerce-actor-sheet.html index 1f80cfbd..4792bbe7 100644 --- a/templates/actor/commerce-actor-sheet.html +++ b/templates/actor/commerce-actor-sheet.html @@ -10,7 +10,15 @@ {{#if @root.options.isObserver}}