forked from public/foundryvtt-reve-de-dragon
Big WIP...
This commit is contained in:
@ -3,8 +3,8 @@ import { Grammar } from "./grammar.js";
|
||||
import { Misc } from "./misc.js";
|
||||
import { RdDUtility } from "./rdd-utility.js";
|
||||
|
||||
const typesObjetsEquipement = ["objet", "arme", "armure", "gemme", "conteneur", "herbe", "ingredient", "livre", "potion", "munition", "nourritureboisson", "monnaie"];
|
||||
const typesObjetsOeuvres = ["oeuvre", "recettecuisine", "musique", "chant", "danse", "jeu"];
|
||||
const typesObjetsEquipement = ["objet", "arme", "armure", "gemme", "conteneur", "herbe", "ingredient", "livre", "potion", "munition", "nourritureboisson", "monnaie"]
|
||||
const typesObjetsOeuvres = ["oeuvre", "recettecuisine", "musique", "chant", "danse", "jeu"]
|
||||
const encBrin = 0.00005;// un brin = 1 décigramme = 1/10g = 1/10000kg = 1/20000 enc
|
||||
|
||||
export const defaultItemImg = {
|
||||
@ -34,7 +34,8 @@ export const defaultItemImg = {
|
||||
oeuvre: "systems/foundryvtt-reve-de-dragon/icons/competence_comedie.webp",
|
||||
nourritureboisson: "systems/foundryvtt-reve-de-dragon/icons/objets/provision_crue.webp",
|
||||
signedraconique: "systems/foundryvtt-reve-de-dragon/icons/tmr/signe_draconique.webp",
|
||||
gemme: "systems/foundryvtt-reve-de-dragon/icons/gemmes/almaze.webp"
|
||||
gemme: "systems/foundryvtt-reve-de-dragon/icons/gemmes/almaze.webp",
|
||||
possession: "systems/foundryvtt-reve-de-dragon/icons/entites/possession2.webp"
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
@ -48,11 +49,11 @@ export class RdDItem extends Item {
|
||||
}
|
||||
|
||||
static getTypeObjetsEquipement() {
|
||||
return typesObjetsEquipement;
|
||||
return typesObjetsEquipement
|
||||
}
|
||||
|
||||
static getTypesOeuvres() {
|
||||
return typesObjetsOeuvres;
|
||||
return typesObjetsOeuvres
|
||||
}
|
||||
|
||||
isCompetence() {
|
||||
@ -82,7 +83,7 @@ export class RdDItem extends Item {
|
||||
return this.type == 'herbe' && (this.system.categorie == 'Soin' || this.system.categorie == 'Repos');
|
||||
}
|
||||
isPotion() {
|
||||
return this.type == 'potion';
|
||||
return Misc.data(this).type == 'potion';
|
||||
}
|
||||
|
||||
isEquipement() {
|
||||
@ -94,20 +95,18 @@ export class RdDItem extends Item {
|
||||
}
|
||||
|
||||
isMagique() {
|
||||
return this.system.magique;
|
||||
return this.system.magique
|
||||
}
|
||||
|
||||
getEncTotal() {
|
||||
const itemData = this.system
|
||||
return Number(itemData.encombrement ?? 0) * Number(itemData.quantite ?? 1);
|
||||
return Number(this.system.encombrement ?? 0) * Number(this.system.quantite ?? 1)
|
||||
}
|
||||
getEnc() {
|
||||
const itemData = this.system
|
||||
switch (itemData.type) {
|
||||
switch (this.type) {
|
||||
case 'herbe':
|
||||
return encBrin;
|
||||
}
|
||||
return itemData.encombrement ?? 0
|
||||
return this.system.encombrement ?? 0;
|
||||
}
|
||||
|
||||
prepareDerivedData() {
|
||||
@ -118,50 +117,47 @@ export class RdDItem extends Item {
|
||||
if (this.isPotion()) {
|
||||
this.prepareDataPotion()
|
||||
}
|
||||
this.system.actionPrincipale = this.getActionPrincipale({ warnIfNot: false });
|
||||
this.actionPrincipale = this.getActionPrincipale({ warnIfNot: false });
|
||||
}
|
||||
}
|
||||
|
||||
prepareDataPotion() {
|
||||
const tplData = Misc.templateData(this);
|
||||
const categorie = Grammar.toLowerCaseNoAccent(tplData.categorie);
|
||||
tplData.magique = categorie.includes('enchante');
|
||||
if (tplData.magique) {
|
||||
const categorie = Grammar.toLowerCaseNoAccent(this.system.categorie);
|
||||
this.system.magique = categorie.includes('enchante');
|
||||
if (this.system.magique) {
|
||||
if (categorie.includes('soin') || categorie.includes('repos')) {
|
||||
tplData.puissance = tplData.herbebonus * tplData.pr;
|
||||
this.system.puissance = this.system.herbebonus * this.system.pr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_calculsEquipement() {
|
||||
const tplData = this.system
|
||||
const quantite = this.isConteneur() ? 1 : (tplData.quantite ?? 0);
|
||||
const quantite = this.isConteneur() ? 1 : (this.system.quantite ?? 0);
|
||||
const enc = this.getEnc();
|
||||
if (enc != undefined) {
|
||||
tplData.encTotal = Math.max(enc, 0) * quantite;
|
||||
this.system.encTotal = Math.max(enc, 0) * quantite;
|
||||
}
|
||||
if (tplData.cout != undefined) {
|
||||
tplData.prixTotal = Math.max(tplData.cout, 0) * quantite;
|
||||
if (this.cout != undefined) {
|
||||
this.system.prixTotal = Math.max(this.cout, 0) * quantite;
|
||||
}
|
||||
}
|
||||
|
||||
getActionPrincipale(options = { warnIfNot: true }) {
|
||||
const itemData = this.system
|
||||
if (!this.isConteneur() && (itemData.quantite ?? 0) <= 0) {
|
||||
if (!this.isConteneur() && (this.system.quantite ?? 0) <= 0) {
|
||||
if (options.warnIfNot) {
|
||||
ui.notifications.warn(`Vous n'avez plus de ${itemData.name}.`);
|
||||
ui.notifications.warn(`Vous n'avez plus de ${this.name}.`);
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
switch (itemData.type) {
|
||||
case 'nourritureboisson': return itemData.boisson ? 'Boire' : 'Manger';
|
||||
switch (this.type) {
|
||||
case 'nourritureboisson': return this.boisson ? 'Boire' : 'Manger';
|
||||
case 'potion': return 'Boire';
|
||||
case 'livre': return 'Lire';
|
||||
case 'conteneur': return 'Ouvrir';
|
||||
}
|
||||
if (this.isHerbeAPotion()) { return 'Décoction'; }
|
||||
if (options.warnIfNot) {
|
||||
ui.notifications.warn(`Impossible d'utiliser un ${itemData.name}, aucune action associée définie.`);
|
||||
ui.notifications.warn(`Impossible d'utiliser un ${this.name}, aucune action associée définie.`);
|
||||
}
|
||||
|
||||
return undefined;
|
||||
@ -173,18 +169,17 @@ export class RdDItem extends Item {
|
||||
}
|
||||
|
||||
async quantiteIncDec(nombre, options = { diminuerQuantite: true, supprimerSiZero: false }) {
|
||||
const itemData = this.system
|
||||
const quantite = Number(itemData.quantite ?? -1);
|
||||
const quantite = Number(this.system.quantite ?? -1);
|
||||
if (quantite >= 0) {
|
||||
const reste = Math.max(quantite + Number(nombre), 0);
|
||||
|
||||
if (reste == 0) {
|
||||
if (options.supprimerSiZero) {
|
||||
ui.notifications.notify(`${itemData.name} supprimé de votre équipement`);
|
||||
ui.notifications.notify(`${this.name} supprimé de votre équipement`);
|
||||
await this.delete();
|
||||
}
|
||||
else {
|
||||
ui.notifications.notify(`Il ne vous reste plus de ${itemData.name}, vous pouvez le supprimer de votre équipement, ou trouver un moyen de vous en procurer.`);
|
||||
ui.notifications.notify(`Il ne vous reste plus de ${this.name}, vous pouvez le supprimer de votre équipement, ou trouver un moyen de vous en procurer.`);
|
||||
await this.update({ "data.quantite": 0 });
|
||||
}
|
||||
}
|
||||
@ -197,10 +192,10 @@ export class RdDItem extends Item {
|
||||
/* -------------------------------------------- */
|
||||
// détermine si deux équipements sont similaires: de même type, et avec les même champs hormis la quantité
|
||||
isEquipementSimilaire(other) {
|
||||
const itemData = this.system
|
||||
const otherData = other.data
|
||||
const tplData = Misc.templateData(this);
|
||||
const otherTplData = Misc.templateData(other);
|
||||
const itemData = Misc.data(this)
|
||||
const otherData = Misc.data(other)
|
||||
const tplData = Misc.templateData(this)
|
||||
const otherTplData = Misc.templateData(other)
|
||||
if (!this.isEquipement()) return false;
|
||||
if (itemData.type != otherData.type) return false;
|
||||
if (itemData.name != otherData.name) return false;
|
||||
@ -246,7 +241,7 @@ export class RdDItem extends Item {
|
||||
|
||||
/* -------------------------------------------- */
|
||||
getProprietes() {
|
||||
return this[`_${this.type}ChatData`]();
|
||||
return this[`_${Misc.data(this).type}ChatData`]();
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
|
Reference in New Issue
Block a user