Les commerces peuvent appliquer un pourcentage

This commit is contained in:
Vincent Vandemeulebrouck 2023-01-03 01:37:50 +01:00
parent d5453c9b04
commit ceacee8e6c
9 changed files with 45 additions and 13 deletions

View File

@ -3,6 +3,7 @@ import { RdDItem } from "../item.js";
import { RdDSheetUtility } from "../rdd-sheet-utility.js"; import { RdDSheetUtility } from "../rdd-sheet-utility.js";
import { RdDUtility } from "../rdd-utility.js"; import { RdDUtility } from "../rdd-utility.js";
import { RdDBaseActorSheet } from "./base-actor-sheet.js"; import { RdDBaseActorSheet } from "./base-actor-sheet.js";
import { RdDCommerce } from "./commerce.js";
/** /**
* Extend the basic ActorSheet with some very simple modifications * Extend the basic ActorSheet with some very simple modifications
@ -67,7 +68,7 @@ export class RdDCommerceSheet extends RdDBaseActorSheet {
quantiteIllimite: disponible == undefined, quantiteIllimite: disponible == undefined,
nbLots: disponible ?? 1, nbLots: disponible ?? 1,
tailleLot: 1, tailleLot: 1,
prixLot: item.system.cout prixLot: item.calculerPrixCommercant()
}); });
} }
} }

View File

@ -1,3 +1,4 @@
import { Misc } from "../misc.js";
import { RdDBaseActor } from "./base-actor.js"; import { RdDBaseActor } from "./base-actor.js";
export class RdDCommerce extends RdDBaseActor { export class RdDCommerce extends RdDBaseActor {
@ -45,4 +46,8 @@ export class RdDCommerce extends RdDBaseActor {
await super.decrementerQuantiteItem(itemVendu, quantite, {supprimerSiZero: false}); 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);
}
} }

View File

@ -9,9 +9,9 @@ export class DialogItemVente extends Dialog {
item: item, item: item,
alias: item.actor?.name ?? game.user.name, alias: item.actor?.name ?? game.user.name,
vendeurId: item.actor?.id , vendeurId: item.actor?.id ,
prixOrigine: item.system.cout, prixOrigine: item.calculerPrixCommercant(),
prixUnitaire: item.system.cout, prixUnitaire: item.calculerPrixCommercant(),
prixLot: item.system.cout, prixLot: item.calculerPrixCommercant(),
tailleLot: 1, tailleLot: 1,
quantiteNbLots: quantite, quantiteNbLots: quantite,
quantiteMaxLots: quantite, quantiteMaxLots: quantite,

View File

@ -11,7 +11,7 @@ export class RdDItemService extends RdDItem {
return [ return [
RdDItem.propertyIfDefined('Qualité', this.system.qualite, this.system.qualite != 0), RdDItem.propertyIfDefined('Qualité', this.system.qualite, this.system.qualite != 0),
RdDItem.propertyIfDefined('Moral', 'Situation heureuse', this.system.moral), RdDItem.propertyIfDefined('Moral', 'Situation heureuse', this.system.moral),
RdDItem.propertyIfDefined('Coût', `${this.system.cout} sols`), RdDItem.propertyIfDefined('Coût', `${this.calculerPrixCommercant()} sols`),
]; ];
} }
} }

View File

@ -171,7 +171,6 @@ export class RdDItem extends Item {
return typesObjetsConnaissance.includes(this.type) return typesObjetsConnaissance.includes(this.type)
} }
getItemGroup() { getItemGroup() {
if (this.isInventaire()) return "equipement"; if (this.isInventaire()) return "equipement";
if (this.isOeuvre()) return "oeuvre"; if (this.isOeuvre()) return "oeuvre";
@ -258,6 +257,14 @@ export class RdDItem extends Item {
return this.system.cout ?? 0 return this.system.cout ?? 0
} }
calculerPrixCommercant() {
if (this.parent?.type == 'commerce') {
// appliquer le pourcentage
return this.parent.calculerPrix(this);
}
return this.system.cout;
}
prepareDerivedData() { prepareDerivedData() {
super.prepareDerivedData(); super.prepareDerivedData();
if (this.isInventaire()) { if (this.isInventaire()) {

View File

@ -16,6 +16,7 @@ import { RdDCalendrier } from "./rdd-calendrier.js";
import { Environnement } from "./environnement.js"; import { Environnement } from "./environnement.js";
import { RdDItemCompetence } from "./item-competence.js"; import { RdDItemCompetence } from "./item-competence.js";
import { RdDResolutionTable } from "./rdd-resolution-table.js"; import { RdDResolutionTable } from "./rdd-resolution-table.js";
import { RdDCommerce } from "./actor/commerce.js";
/* -------------------------------------------- */ /* -------------------------------------------- */
// This table starts at 0 -> niveau -10 // 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('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('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('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-label', coord => TMRUtility.getTMRLabel(coord));
Handlebars.registerHelper('caseTmr-type', coord => TMRUtility.getTMRType(coord)); Handlebars.registerHelper('caseTmr-type', coord => TMRUtility.getTMRType(coord));
Handlebars.registerHelper('typeTmr-name', type => TMRUtility.typeTmrName(type)); Handlebars.registerHelper('typeTmr-name', type => TMRUtility.typeTmrName(type));

View File

@ -557,6 +557,7 @@
}, },
"commerce":{ "commerce":{
"templates": [ "description" ], "templates": [ "description" ],
"pourcentage": 100,
"illimite": false "illimite": false
} }
}, },

View File

@ -10,7 +10,15 @@
{{#if @root.options.isObserver}} {{#if @root.options.isObserver}}
<div class="form-group"> <div class="form-group">
<input {{@root.disabled}} class="attribute-value" type="checkbox" name="system.illimite" {{#if system.illimite}}checked{{/if}}/> <input {{@root.disabled}} class="attribute-value" type="checkbox" name="system.illimite" {{#if system.illimite}}checked{{/if}}/>
<span for="system.illimite">Quantité illimitée en vente</span> <label for="system.illimite">Quantité illimitée en vente</label>
</div>
<div class="form-group">
<span>
<label for="system.pourcentage">Appliquer un pourcentage sur les prix</label>
<input {{@root.disabled}} class="attribute-value" type="number" data-dtype="Number"
name="system.pourcentage" value="{{system.pourcentage}}"
min="20" max="500" step="5"/>
</span>
</div> </div>
{{/if}} {{/if}}
</div> </div>

View File

@ -1,7 +1,7 @@
{{#if (ne item.type 'monnaie')}} {{#if (ne item.type 'monnaie')}}
<li class="item flexrow list-item" data-item-id="{{item._id}}" draggable="true"> <li class="item flexrow list-item" data-item-id="{{item._id}}" draggable="true">
<span class="equipement-nom {{#if (eq item.type 'conteneur')}}conteneur-name{{/if}} "> <span class="equipement-nom {{#if (eq item.type 'conteneur')}}conteneur-name{{/if}} ">
<a{{#if (ne item.type 'conteneur')}} class="item-edit"{{/if}} > <a{{#if (and (ne item.type 'conteneur') options.isObserver)}} class="item-edit"{{/if}} >
{{#if (eq item.type 'conteneur')}} {{#if (eq item.type 'conteneur')}}
<i class="{{~#if vide}}far fa-square <i class="{{~#if vide}}far fa-square
{{else if ouvert}}far fa-minus-square {{else if ouvert}}far fa-minus-square
@ -16,11 +16,13 @@
{{#unless item.parent.system.illimite}} {{#unless item.parent.system.illimite}}
<span class="equipement-detail flexrow"> <span class="equipement-detail flexrow">
{{#unless (or (eq item.type 'service') (and (eq item.type 'conteneur') (not vide)))}} {{#unless (or (eq item.type 'service') (and (eq item.type 'conteneur') (not vide)))}}
{{#if @root.options.isOwner}} {{#if options.isOwner}}
<a class="item-quantite-moins"><i class="fas fa-minus-square"></i></a> <a class="item-quantite-moins"><i class="fas fa-minus-square"></i></a>
{{/if}} {{/if}}
<input {{#unless @root.options.isOwner}}disabled{{/unless}} type="number" class="item-quantite" name="items[{{key}}].system.quantite" value="{{item.system.quantite}}" data-dtype="Number" /> <input {{#unless options.isOwner}}disabled{{/unless}} type="number" data-dtype="Number"
{{#if @root.options.isOwner}} class="item-quantite" name="items[{{key}}].system.quantite"
value="{{item.system.quantite}}" />
{{#if options.isOwner}}
<a class="item-quantite-plus"><i class="fas fa-plus-square"></i></a> <a class="item-quantite-plus"><i class="fas fa-plus-square"></i></a>
{{/if}} {{/if}}
{{/unless}} {{/unless}}
@ -28,12 +30,18 @@
{{/unless}} {{/unless}}
<span class="equipement-detail"> <span class="equipement-detail">
{{#unless (and (eq item.type 'conteneur') (not vide))}} {{#unless (and (eq item.type 'conteneur') (not vide))}}
<input {{#unless @root.options.isOwner}}disabled{{/unless}} type="number" class="input-prix number-x3 item-cout" name="items[{{key}}].system.cout" value="{{numberFormat item.system.cout decimals=2 sign=false}}" data-dtype="Number" /> <input {{#unless options.isOwner}}disabled{{/unless}} type="number" data-dtype="Number"
class="input-prix number-x3 item-cout" name="items[{{key}}].system.cout"
{{#if options.isObserver}}
value="{{numberFormat item.system.cout decimals=2 sign=false}}"
{{else}}
value="{{numberFormat (calculerPrixCommercant item) decimals=2 sign=false}}"
{{/if}} />
{{/unless}} {{/unless}}
</span> </span>
<span class="equipement-actions item-controls"> <span class="equipement-actions item-controls">
{{#unless (and (eq item.type 'conteneur') (not vide))}} {{#unless (and (eq item.type 'conteneur') (not vide))}}
{{#if @root.options.isOwner}} {{#if options.isOwner}}
<a class="item-edit" title="Editer"><i class="fas fa-edit"></i></a> <a class="item-edit" title="Editer"><i class="fas fa-edit"></i></a>
<a class="item-delete" title="Supprimer"><i class="fas fa-trash"></i></a> <a class="item-delete" title="Supprimer"><i class="fas fa-trash"></i></a>
{{#if (or item.parent.system.illimite (ne item.system.quantite 0))}} {{#if (or item.parent.system.illimite (ne item.system.quantite 0))}}