2021-04-07 22:46:57 +02:00
|
|
|
import { RdDUtility } from "./rdd-utility.js";
|
|
|
|
import { RdDCalendrier } from "./rdd-calendrier.js";
|
2022-10-08 14:25:31 +02:00
|
|
|
import { Grammar } from "./grammar.js";
|
2022-11-23 22:39:48 +01:00
|
|
|
import { SystemCompendiums } from "./settings/system-compendiums.js";
|
2021-04-07 22:46:57 +02:00
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
export class RdDHerbes extends Item {
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
2022-10-08 14:25:31 +02:00
|
|
|
static async initializeHerbes() {
|
|
|
|
this.herbesSoins = await RdDHerbes.listCategorieHerbes('Soin');
|
|
|
|
this.herbesRepos = await RdDHerbes.listCategorieHerbes('Repos');
|
2021-04-07 22:46:57 +02:00
|
|
|
}
|
|
|
|
|
2022-10-08 14:25:31 +02:00
|
|
|
static async listCategorieHerbes(categorie) {
|
2022-11-30 01:11:31 +01:00
|
|
|
const herbes = await SystemCompendiums.getWorldOrCompendiumItems('herbe', 'faune-flore-mineraux');
|
2022-11-23 22:39:48 +01:00
|
|
|
return herbes.filter(it => Grammar.equalsInsensitive(it.system.categorie, categorie));
|
2021-04-07 22:46:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
2022-09-07 18:47:56 +02:00
|
|
|
static buildHerbesList(listeHerbes, max) {
|
2021-04-07 22:46:57 +02:00
|
|
|
let list = {}
|
2022-10-08 14:25:31 +02:00
|
|
|
for (let herbe of listeHerbes) {
|
2022-09-07 18:47:56 +02:00
|
|
|
let brins = max - herbe.system.niveau;
|
2022-10-08 14:25:31 +02:00
|
|
|
list[herbe.name] = `${herbe.name} (Bonus: ${herbe.system.niveau}, Brins: ${brins})`;
|
2021-04-07 22:46:57 +02:00
|
|
|
}
|
|
|
|
list['Autre'] = 'Autre (Bonus: variable, Brins: variable)'
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
2022-10-08 14:25:31 +02:00
|
|
|
static async updatePotionData(formData) {
|
|
|
|
formData.isSoins = formData.system.categorie.includes('Soin');
|
|
|
|
formData.isRepos = formData.system.categorie.includes('Repos');
|
|
|
|
if (formData.isSoins) {
|
|
|
|
RdDHerbes.calculBonusHerbe(formData, this.herbesSoins, 12);
|
|
|
|
}
|
|
|
|
if (formData.isRepos) {
|
|
|
|
RdDHerbes.calculBonusHerbe(formData, this.herbesRepos, 7);
|
|
|
|
}
|
|
|
|
formData.herbesSoins = RdDHerbes.buildHerbesList(this.herbesSoins, 12);
|
|
|
|
formData.herbesRepos = RdDHerbes.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();
|
2022-11-04 20:41:16 +01:00
|
|
|
formData.splitDate = game.system.rdd.calendrier.getDayMonthFromIndex(formData.system.prdate);
|
2021-04-07 22:46:57 +02:00
|
|
|
}
|
|
|
|
|
2021-04-09 15:23:48 +02:00
|
|
|
/* -------------------------------------------- */
|
2022-10-08 14:25:31 +02:00
|
|
|
static calculPuissancePotion(potion) {
|
2022-09-07 18:47:56 +02:00
|
|
|
return potion.system.herbebonus * potion.system.pr;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
2022-10-08 14:25:31 +02:00
|
|
|
static calculPointsRepos(potion) {
|
2022-09-07 18:47:56 +02:00
|
|
|
return potion.system.herbebonus * potion.system.pr;
|
2021-04-09 15:23:48 +02:00
|
|
|
}
|
|
|
|
|
2021-04-07 22:46:57 +02:00
|
|
|
/* -------------------------------------------- */
|
2022-10-08 14:25:31 +02:00
|
|
|
static calculPointsGuerison(potion) {
|
2022-09-07 18:47:56 +02:00
|
|
|
return potion.system.herbebonus * potion.system.pr;
|
2021-04-07 22:46:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
2022-10-08 14:25:31 +02:00
|
|
|
static calculBonusHerbe(formData, herbesList, max) {
|
|
|
|
if (Number(formData.system.herbebrins)) {
|
|
|
|
let herbe = herbesList.find(item => item.name.toLowerCase() == formData.system.herbe.toLowerCase());
|
|
|
|
if (herbe) {
|
|
|
|
const brinsRequis = max - herbe.system.niveau;
|
|
|
|
const brinsManquants = Math.max(brinsRequis - formData.system.herbebrins, 0);
|
|
|
|
formData.system.herbebonus = Math.max(herbe.system.niveau - brinsManquants, 0);
|
2021-04-07 22:46:57 +02:00
|
|
|
}
|
|
|
|
}
|
2022-10-08 14:25:31 +02:00
|
|
|
}
|
2021-04-07 22:46:57 +02:00
|
|
|
|
|
|
|
}
|