foundryvtt-reve-de-dragon/module/rdd-herbes.js

76 lines
2.9 KiB
JavaScript
Raw Normal View History

2021-04-07 22:46:57 +02:00
import { RdDUtility } from "./rdd-utility.js";
import { RdDCalendrier } from "./rdd-calendrier.js";
/* -------------------------------------------- */
export class RdDHerbes extends Item {
/* -------------------------------------------- */
static isHerbeSoin( botaniqueItem ) {
2022-06-12 08:17:59 +02:00
return botaniqueItem.categorie == 'Soin';
2021-04-07 22:46:57 +02:00
}
/* -------------------------------------------- */
static isHerbeRepos( botaniqueItem ) {
2022-06-12 08:17:59 +02:00
return botaniqueItem.categorie == 'Repos';
2021-04-07 22:46:57 +02:00
}
/* -------------------------------------------- */
static async initializeHerbes( ) {
this.herbesSoins = await RdDUtility.loadCompendium('foundryvtt-reve-de-dragon.botanique', item => this.isHerbeSoin(item));
this.herbesRepos = await RdDUtility.loadCompendium('foundryvtt-reve-de-dragon.botanique', item => this.isHerbeRepos(item));
}
/* -------------------------------------------- */
static buildHerbesList(listeHerbes, max) {
2021-04-07 22:46:57 +02:00
let list = {}
for ( let herbe of listeHerbes) {
let brins = max - herbe.system.niveau;
list[herbe.system.name] = `${herbe.system.name} (Bonus: ${herbe.system.niveau}, Brins: ${brins})`;
2021-04-07 22:46:57 +02:00
}
list['Autre'] = 'Autre (Bonus: variable, Brins: variable)'
return list;
}
/* -------------------------------------------- */
static updatePotionData( formData ) {
formData.herbesSoins = this.buildHerbesList(this.herbesSoins, 12);
formData.herbesRepos = this.buildHerbesList(this.herbesRepos, 7);
2021-06-09 00:00:15 +02:00
formData.jourMoisOptions = RdDCalendrier.buildJoursMois();
2021-04-07 22:46:57 +02:00
formData.dateActuelle = game.system.rdd.calendrier.getDateFromIndex();
formData.splitDate = game.system.rdd.calendrier.getNumericDateFromIndex(formData.system.prdate);
2021-04-07 22:46:57 +02:00
if (formData.system.categorie.includes('Soin') ) {
2021-04-07 22:46:57 +02:00
formData.isHerbe = true;
this.computeHerbeBonus(formData, this.herbesSoins, 12);
} else if (formData.system.categorie.includes('Repos')) {
2021-04-07 22:46:57 +02:00
formData.isRepos = true;
this.computeHerbeBonus(formData, this.herbesRepos, 7);
}
}
2021-04-09 15:23:48 +02:00
/* -------------------------------------------- */
static calculePuissancePotion( potion ) {
return potion.system.herbebonus * potion.system.pr;
}
/* -------------------------------------------- */
static calculePointsRepos( potion ) {
return potion.system.herbebonus * potion.system.pr;
2021-04-09 15:23:48 +02:00
}
2021-04-07 22:46:57 +02:00
/* -------------------------------------------- */
static calculePointsGuerison( potion ){
return potion.system.herbebonus * potion.system.pr;
2021-04-07 22:46:57 +02:00
}
/* -------------------------------------------- */
static computeHerbeBonus( formData, herbesList, max) {
if ( Number(formData.system.herbebrins) ) {
let herbe = herbesList.find(item => item.name.toLowerCase() == formData.system.herbe.toLowerCase() );
2021-04-07 22:46:57 +02:00
if( herbe ) {
let brinsBase = max - herbe.system.niveau;
formData.system.herbebonus = Math.max(herbe.system.niveau - Math.max(brinsBase - formData.system.herbebrins, 0), 0);
2021-04-07 22:46:57 +02:00
}
}
}
}