forked from public/foundryvtt-reve-de-dragon
Compétences & herbes personalisées
* permettre d'ajouter des compétences dans un monde, qui seront ajoutés aux acteurs créés dans ce monde * les herbes de repos/soins du monde sont bien considérées comme des herbes pour les potions
This commit is contained in:
@ -1,76 +1,75 @@
|
||||
import { RdDUtility } from "./rdd-utility.js";
|
||||
import { RdDCalendrier } from "./rdd-calendrier.js";
|
||||
import { Grammar } from "./grammar.js";
|
||||
|
||||
/* -------------------------------------------- */
|
||||
export class RdDHerbes extends Item {
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static isHerbeSoin( botaniqueItem ) {
|
||||
return botaniqueItem.categorie == 'Soin';
|
||||
}
|
||||
/* -------------------------------------------- */
|
||||
static isHerbeRepos( botaniqueItem ) {
|
||||
return botaniqueItem.categorie == 'Repos';
|
||||
static async initializeHerbes() {
|
||||
this.herbesSoins = await RdDHerbes.listCategorieHerbes('Soin');
|
||||
this.herbesRepos = await RdDHerbes.listCategorieHerbes('Repos');
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
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 async listCategorieHerbes(categorie) {
|
||||
return await RdDUtility.loadItems(
|
||||
it => it.type == 'herbe' && it.system.categorie.toLowerCase() == categorie.toLowerCase(),
|
||||
'foundryvtt-reve-de-dragon.botanique');
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static buildHerbesList(listeHerbes, max) {
|
||||
let list = {}
|
||||
for ( let herbe of listeHerbes) {
|
||||
for (let herbe of listeHerbes) {
|
||||
let brins = max - herbe.system.niveau;
|
||||
list[herbe.system.name] = `${herbe.system.name} (Bonus: ${herbe.system.niveau}, Brins: ${brins})`;
|
||||
list[herbe.name] = `${herbe.name} (Bonus: ${herbe.system.niveau}, Brins: ${brins})`;
|
||||
}
|
||||
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);
|
||||
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);
|
||||
formData.jourMoisOptions = RdDCalendrier.buildJoursMois();
|
||||
formData.dateActuelle = game.system.rdd.calendrier.getDateFromIndex();
|
||||
formData.splitDate = game.system.rdd.calendrier.getNumericDateFromIndex(formData.system.prdate);
|
||||
|
||||
if (formData.system.categorie.includes('Soin') ) {
|
||||
formData.isHerbe = true;
|
||||
this.computeHerbeBonus(formData, this.herbesSoins, 12);
|
||||
} else if (formData.system.categorie.includes('Repos')) {
|
||||
formData.isRepos = true;
|
||||
this.computeHerbeBonus(formData, this.herbesRepos, 7);
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static calculePuissancePotion( potion ) {
|
||||
static calculPuissancePotion(potion) {
|
||||
return potion.system.herbebonus * potion.system.pr;
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static calculePointsRepos( potion ) {
|
||||
static calculPointsRepos(potion) {
|
||||
return potion.system.herbebonus * potion.system.pr;
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static calculePointsGuerison( potion ){
|
||||
static calculPointsGuerison(potion) {
|
||||
return potion.system.herbebonus * potion.system.pr;
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static computeHerbeBonus( formData, herbesList, max) {
|
||||
if ( Number(formData.system.herbebrins) ) {
|
||||
let herbe = herbesList.find(item => item.name.toLowerCase() == formData.system.herbe.toLowerCase() );
|
||||
if( herbe ) {
|
||||
let brinsBase = max - herbe.system.niveau;
|
||||
formData.system.herbebonus = Math.max(herbe.system.niveau - Math.max(brinsBase - formData.system.herbebrins, 0), 0);
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user