forked from public/foundryvtt-reve-de-dragon
Corrections prix et enc. équipement
Affichage de la valeur si option activée Utilisation de boutons au lieu des liens
This commit is contained in:
@ -1,12 +1,27 @@
|
||||
import { DialogItemVente } from "./dialog-item-vente.js";
|
||||
import { Grammar } from "./grammar.js";
|
||||
import { Misc } from "./misc.js";
|
||||
import { RdDHerbes } from "./rdd-herbes.js";
|
||||
import { RdDUtility } from "./rdd-utility.js";
|
||||
|
||||
const typesObjetsEquipement = ["objet", "arme", "armure", "gemme", "conteneur", "herbe", "ingredient", "livre", "potion", "munition", "nourritureboisson", "monnaie"]
|
||||
const typesObjetsEquipement = [
|
||||
"arme",
|
||||
"armure",
|
||||
"conteneur",
|
||||
"gemme",
|
||||
"herbe",
|
||||
"ingredient",
|
||||
"livre",
|
||||
"monnaie",
|
||||
"munition",
|
||||
"nourritureboisson",
|
||||
"objet",
|
||||
"potion",
|
||||
]
|
||||
const typesObjetsOeuvres = ["oeuvre", "recettecuisine", "musique", "chant", "danse", "jeu"]
|
||||
const encBrin = 0.00005;// un brin = 1 décigramme = 1/10g = 1/10000kg = 1/20000 enc
|
||||
const encBrin = 0.00005; // un brin = 1 décigramme = 1/10g = 1/10000kg = 1/20000 enc
|
||||
const encPepin = 0.0007; /* un pépin de gemme = 1/10 cm3 = 1/1000 l = 3.5/1000 kg = 7/2000 kg = 7/1000 enc
|
||||
densité 3.5 (~2.3 à 4, parfois plus) -- https://www.juwelo.fr/guide-des-pierres/faits-et-chiffres/
|
||||
*/
|
||||
|
||||
export const defaultItemImg = {
|
||||
competence: "systems/foundryvtt-reve-de-dragon/icons/competence_defaut.webp",
|
||||
@ -50,7 +65,7 @@ export class RdDItem extends Item {
|
||||
super(itemData, context);
|
||||
}
|
||||
|
||||
static getTypeObjetsEquipement() {
|
||||
static getTypesObjetsEquipement() {
|
||||
return typesObjetsEquipement
|
||||
}
|
||||
|
||||
@ -62,6 +77,9 @@ export class RdDItem extends Item {
|
||||
return this.type == 'competence';
|
||||
}
|
||||
|
||||
isEquipement() {
|
||||
return typesObjetsEquipement.includes(this.type)
|
||||
}
|
||||
isConteneur() {
|
||||
return this.type == 'conteneur';
|
||||
}
|
||||
@ -87,11 +105,6 @@ export class RdDItem extends Item {
|
||||
isPotion() {
|
||||
return this.type == 'potion';
|
||||
}
|
||||
|
||||
isEquipement() {
|
||||
return RdDItem.getTypeObjetsEquipement().includes(this.type)
|
||||
}
|
||||
|
||||
isCristalAlchimique() {
|
||||
return this.type == 'objet' && Grammar.toLowerCaseNoAccent(this.name) == 'cristal alchimique' && this.system.quantite > 0;
|
||||
}
|
||||
@ -100,22 +113,36 @@ export class RdDItem extends Item {
|
||||
return this.system.magique
|
||||
}
|
||||
|
||||
getEncTotal() {
|
||||
return Number(this.system.encombrement ?? 0) * Number(this.system.quantite ?? 1)
|
||||
getQuantite() {
|
||||
return Math.round(this.isConteneur() ? 1 : (this.system.quantite ?? 0))
|
||||
}
|
||||
|
||||
getEncTotal() {
|
||||
return this.getEnc() * this.getQuantite();
|
||||
}
|
||||
|
||||
getEnc() {
|
||||
switch (this.type) {
|
||||
case 'herbe':
|
||||
return encBrin;
|
||||
case 'gemme':
|
||||
return encPepin * this.system.taille;
|
||||
}
|
||||
return this.system.encombrement ?? 0;
|
||||
return Math.max(this.system.encombrement ?? 0, 0);
|
||||
}
|
||||
|
||||
prixTotalDeniers() {
|
||||
return this.getQuantite() * this.valeurDeniers()
|
||||
}
|
||||
|
||||
valeurDeniers() {
|
||||
return Math.max(Math.round(this.system.cout ? (this.system.cout * 100) : (this.system.valeur_deniers ?? 0)), 0)
|
||||
}
|
||||
|
||||
prepareDerivedData() {
|
||||
super.prepareDerivedData();
|
||||
if (this.isEquipement()) {
|
||||
this._calculsEquipement();
|
||||
|
||||
this.system.encTotal = this.getEncTotal();
|
||||
if (this.isPotion()) {
|
||||
this.prepareDataPotion()
|
||||
}
|
||||
@ -134,17 +161,6 @@ export class RdDItem extends Item {
|
||||
}
|
||||
}
|
||||
|
||||
_calculsEquipement() {
|
||||
const quantite = this.isConteneur() ? 1 : (this.system.quantite ?? 0);
|
||||
const enc = this.getEnc();
|
||||
if (enc != undefined) {
|
||||
this.system.encTotal = Math.max(enc, 0) * quantite;
|
||||
}
|
||||
if (this.cout != undefined) {
|
||||
this.system.prixTotal = Math.max(this.cout, 0) * quantite;
|
||||
}
|
||||
}
|
||||
|
||||
getActionPrincipale(options = { warnIfNot: true }) {
|
||||
const warn = options.warnIfNot;
|
||||
switch (this.type) {
|
||||
@ -202,18 +218,18 @@ export class RdDItem extends Item {
|
||||
if (!other || !this.isEquipement()) return undefined;
|
||||
|
||||
let message = undefined;
|
||||
if (this.type != other.type) {
|
||||
message = `Impossible de regrouper ${this.type} avec ${other.type}`;
|
||||
if (this.system.quantite == undefined) {
|
||||
message = `Impossible de regrouper des ${this.type}, ils ne sont pas empilables`;
|
||||
}
|
||||
else if (this.type != other.type) {
|
||||
message = `Impossible de regrouper des ${this.type} avec des ${other.type}`;
|
||||
}
|
||||
else if (this.name != other.name) {
|
||||
message = `Impossible de regrouper ${this.name} avec ${other.name}`;
|
||||
}
|
||||
else if (this.system.quantite == undefined) {
|
||||
message = `Impossible de regrouper des ${this.type}, ils ne sont pas empilables`;
|
||||
}
|
||||
else {
|
||||
const differences = Object.entries(this.system)
|
||||
.filter(([key, value]) => !['quantite', 'encTotal', 'prixTotal', 'cout'].includes(key) && value != other.system[key]);
|
||||
.filter(([key, value]) => !['quantite', 'cout'].includes(key) && value != other.system[key]);
|
||||
if (differences.length > 0) {
|
||||
message = `Impossible de regrouper les ${this.type} ${this.name}: `;
|
||||
for (const [key, value] of differences) {
|
||||
|
Reference in New Issue
Block a user