Configuration de la recherche
This commit is contained in:
parent
f4d074fa31
commit
4df04fe06f
@ -1,109 +1,78 @@
|
||||
import { SYSTEM_RDD } from "./constants.js";
|
||||
import { Grammar } from "./grammar.js";
|
||||
import { HtmlUtility } from "./html-utility.js";
|
||||
import { Misc } from "./misc.js";
|
||||
import { CompendiumTableHelpers, CompendiumTable } from "./settings/system-compendiums.js";
|
||||
import { CompendiumTableHelpers, CompendiumTable, SystemCompendiums } from "./settings/system-compendiums.js";
|
||||
import { RdDRaretes } from "./tirage/raretes.js";
|
||||
|
||||
const SETTINGS_LISTE_MILIEUX = "liste-milieux";
|
||||
const MILIEUX = [
|
||||
"Collines",
|
||||
"Cours d'eau",
|
||||
"Déserts",
|
||||
"Forêts",
|
||||
"Marais",
|
||||
"Maritimes",
|
||||
"Montagnes",
|
||||
"Plaines",
|
||||
"Sous-sols"
|
||||
]
|
||||
const ITEM_ENVIRONNEMENT_TYPES = [
|
||||
'herbe', 'plante', 'ingredient', 'faune'
|
||||
]
|
||||
|
||||
const COMPENDIUMS_RECHERCHE = 'compendiums-recherche';
|
||||
const TYPE_ITEMS_NATURELS = ["faune", "herbe", "plante", "ingredient"];
|
||||
|
||||
export class Environnement {
|
||||
|
||||
static typesEnvironnement() {
|
||||
return ITEM_ENVIRONNEMENT_TYPES
|
||||
}
|
||||
|
||||
static init() {
|
||||
game.settings.register(SYSTEM_RDD, SETTINGS_LISTE_MILIEUX, {
|
||||
name: "Liste des milieux proposés",
|
||||
hint: "Liste des milieux proposés pour la faune&flore, séparés par des virgules",
|
||||
game.settings.register(SYSTEM_RDD, COMPENDIUMS_RECHERCHE, {
|
||||
name: COMPENDIUMS_RECHERCHE,
|
||||
default: [
|
||||
SystemCompendiums.getCompendium('faune-flore-mineraux'),
|
||||
SystemCompendiums.getCompendium('equipement')
|
||||
],
|
||||
scope: "world",
|
||||
config: true,
|
||||
default: MILIEUX.reduce(Misc.joining(',')),
|
||||
type: String
|
||||
config: false,
|
||||
type: Object
|
||||
});
|
||||
|
||||
game.system.rdd.environnement = new Environnement();
|
||||
Hooks.once('ready', () => game.system.rdd.environnement.onReady());
|
||||
}
|
||||
|
||||
constructor() {
|
||||
this.table = new CompendiumTable('faune-flore-mineraux', 'Item', ITEM_ENVIRONNEMENT_TYPES)
|
||||
this.compendiums = [];
|
||||
this.compendiumTables = [];
|
||||
this.mapMilieux = {}
|
||||
}
|
||||
|
||||
async onReady() {
|
||||
await this.$prepareCompendiums()
|
||||
}
|
||||
|
||||
async milieux() {
|
||||
return Object.values(await this.mapMilieux());
|
||||
return Object.values(this.mapMilieux);
|
||||
}
|
||||
|
||||
async mapMilieux() {
|
||||
const compendiumItems = await this.getElements(it => 1, it => ITEM_ENVIRONNEMENT_TYPES.includes(it.type));
|
||||
return Misc.indexLowercase(this.getMilieuxSettings().concat(Environnement.listMilieux(compendiumItems)));
|
||||
async saveCompendiums(compendiumIds) {
|
||||
game.settings.set(SYSTEM_RDD, COMPENDIUMS_RECHERCHE, compendiumIds);
|
||||
await this.$prepareCompendiums();
|
||||
}
|
||||
|
||||
static listMilieux(items) {
|
||||
return Misc.concat(items.map(it => Environnement.$itemToMilieux(it).filter(m => m)));
|
||||
async $prepareCompendiums() {
|
||||
this.compendiums = game.settings.get(SYSTEM_RDD, COMPENDIUMS_RECHERCHE);
|
||||
this.compendiumTables = this.compendiums.map(it => new CompendiumTable(it, 'Item'));
|
||||
const compendiumItems = await this.getElements(it => 1, it => it.isInventaire());
|
||||
const fromCompendiums = Misc.concat(compendiumItems.map(it => it.getMilieux().filter(m => m)));
|
||||
this.mapMilieux = Misc.indexLowercase(fromCompendiums);
|
||||
}
|
||||
|
||||
async autresMilieux(item) {
|
||||
const mapMilieux = await this.mapMilieux();
|
||||
const milieuxExistants = Environnement.$itemToMilieux(item).map(it => Grammar.toLowerCaseNoAccent(it));
|
||||
return Object.keys(mapMilieux)
|
||||
const milieuxExistants = item.getMilieux().map(it => Grammar.toLowerCaseNoAccent(it));
|
||||
return Object.keys(this.mapMilieux)
|
||||
.filter(it => !milieuxExistants.includes(it))
|
||||
.map(it => mapMilieux[it]);
|
||||
}
|
||||
|
||||
static $itemToMilieux(item) {
|
||||
return item.system.environnement.map(env => env.milieu);
|
||||
}
|
||||
|
||||
getMilieuxSettings() {
|
||||
return game.settings.get(SYSTEM_RDD, SETTINGS_LISTE_MILIEUX).split(',').map(it => it.trim()).filter(it => it != '');
|
||||
}
|
||||
|
||||
async findEnvironnementsLike(search) {
|
||||
const milieux = await this.mapMilieux();
|
||||
const searchLower = Grammar.toLowerCaseNoAccent(search);
|
||||
const keys = Object.keys(milieux).filter(it => it.includes(searchLower));
|
||||
if (keys.length > 1) {
|
||||
const milieuExact = milieux[searchLower];
|
||||
if (milieuExact) {
|
||||
return [milieuExact];
|
||||
}
|
||||
}
|
||||
return keys.map(k => milieux[k]);
|
||||
}
|
||||
|
||||
async searchToChatMessage(milieux, typeName) {
|
||||
const table = await this.buildEnvironnementTable(milieux, it => it.isEnvironnement());
|
||||
await CompendiumTableHelpers.tableToChatMessage(table, 'Item', ITEM_ENVIRONNEMENT_TYPES, typeName);
|
||||
return true
|
||||
}
|
||||
|
||||
async getRandom(milieux, typeName) {
|
||||
const table = await this.buildEnvironnementTable(milieux, it => it.isEnvironnement());
|
||||
return await CompendiumTableHelpers.getRandom(table, 'Item', ITEM_ENVIRONNEMENT_TYPES, undefined, typeName);
|
||||
}
|
||||
|
||||
async buildEnvironnementTable(milieux, filter) {
|
||||
if (!milieux) {
|
||||
milieux = await this.milieux()
|
||||
}
|
||||
return await this.table.buildTable(it => it.getFrequence(), filter);
|
||||
.map(it => this.mapMilieux[it]);
|
||||
}
|
||||
|
||||
async getElements(itemFrequence, filter) {
|
||||
return await this.table.getContent(itemFrequence, filter);
|
||||
const compendiumsElement = await Promise.all(
|
||||
this.compendiumTables.map(async compTable => await compTable.getContent(itemFrequence, filter))
|
||||
);
|
||||
return compendiumsElement.reduce((a, b) => a.concat(b))
|
||||
}
|
||||
|
||||
async buildTable(itemFrequence, filter = it => true) {
|
||||
if (!itemFrequence) {
|
||||
itemFrequence = it => it.getFrequence()
|
||||
}
|
||||
const elements = await this.getElements(itemFrequence, filter);;
|
||||
return CompendiumTableHelpers.buildTable(elements, itemFrequence);
|
||||
}
|
||||
}
|
||||
|
||||
@ -130,6 +99,8 @@ export class EnvironmentSheetHelper {
|
||||
}
|
||||
|
||||
static activateListeners(sheet) {
|
||||
HtmlUtility.showControlWhen(sheet.html.find("div.description-milieu"), TYPE_ITEMS_NATURELS.includes(sheet.item.type));
|
||||
|
||||
if (!sheet.options.editable) return;
|
||||
|
||||
sheet.html.find("input.input-selection-milieu").keypress(event => {
|
||||
|
@ -35,7 +35,7 @@ const typesObjetsConnaissance = ["meditation", "recettealchimique", "sort"]
|
||||
const typesObjetsEffet = ["possession", "poison", "maladie"]
|
||||
const typesObjetsCompetence = ["competence", "competencecreature"]
|
||||
const typesObjetsTemporels = ["poison", "maladie", "queue", "ombre", "souffle", "signedraconique", "rencontre"]
|
||||
const typesEnvironnement = Environnement.typesEnvironnement();
|
||||
const typesEnvironnement = typesInventaireMateriel;
|
||||
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/
|
||||
@ -174,25 +174,27 @@ export class RdDItem extends Item {
|
||||
isConnaissance() { return typesObjetsConnaissance.includes(this.type) }
|
||||
|
||||
isInventaire(mode = 'materiel') { return RdDItem.getItemTypesInventaire(mode).includes(this.type); }
|
||||
isBoisson() { return this.isNourritureBoisson() && this.system.boisson; }
|
||||
isAlcool() { return this.isNourritureBoisson() && this.system.boisson && this.system.alcoolise; }
|
||||
isHerbeAPotion() { return this.type == 'herbe' && (this.system.categorie == 'Soin' || this.system.categorie == 'Repos'); }
|
||||
isEnvironnement() { return RdDItem.getItemTypesEnvironnement().includes(this.type) }
|
||||
|
||||
isPresentDansMilieux(milieux) {
|
||||
return this.getEnvironnements(milieux).length > 0
|
||||
}
|
||||
getEnvironnements(milieux = undefined) {
|
||||
return this.isEnvironnement()
|
||||
? this.system?.environnement.filter(env => !milieux || milieux.includes(env.milieu))
|
||||
: []
|
||||
return this.getEnvironnement(milieux).length > 0
|
||||
}
|
||||
|
||||
getRarete(milieux = undefined) {
|
||||
if (this.isEnvironnement()) {
|
||||
return RdDRaretes.rareteEnvironnement(this, milieux)
|
||||
getEnvironnement(milieux = undefined) {
|
||||
const environnements = this.isInventaire() ? this.system?.environnement ?? [] : [];
|
||||
return environnements.filter(env => !milieux || milieux.includes(env.milieu))
|
||||
}
|
||||
|
||||
getMilieux() {
|
||||
return this.getEnvironnement().map(env => env.milieu);
|
||||
}
|
||||
|
||||
|
||||
getRarete(milieux = undefined) {
|
||||
if (this.isInventaire()) {
|
||||
return RdDRaretes.rareteEquipement(this)
|
||||
return RdDRaretes.selonEnvironnement(this, milieux)
|
||||
}
|
||||
return RdDRaretes.rareteFrequente();
|
||||
}
|
||||
@ -249,6 +251,7 @@ export class RdDItem extends Item {
|
||||
console.log(`${this.actor.name}: l'objet ${this.name} a expiré et été supprimé`);
|
||||
await this.actor?.deleteEmbeddedDocuments('Item', [this.id]);
|
||||
}
|
||||
|
||||
getUtilisation() {
|
||||
switch (this.type) {
|
||||
case 'nourritureboisson':
|
||||
@ -268,6 +271,7 @@ export class RdDItem extends Item {
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
getUtilisationCuisine() {
|
||||
if (this.getUtilisation() == 'cuisine') {
|
||||
switch (this.type) {
|
||||
|
@ -85,6 +85,7 @@ export class Misc {
|
||||
list.forEach(it => addToObj(obj, it))
|
||||
return obj;
|
||||
}
|
||||
|
||||
static concat(lists) {
|
||||
return lists.reduce((a, b) => a.concat(b), []);
|
||||
}
|
||||
|
@ -64,7 +64,6 @@ export class RdDCommands {
|
||||
<br><strong>/table rencontre deso</strong> affiche la table des rencontres en Désolation
|
||||
<br><strong>/table rencontre mauvaise</strong> affiche la table des mauvaises rencontres`
|
||||
});
|
||||
this.registerCommand({ path: ["/table", "milieu"], func: (content, msg, params) => this.tableMilieu(msg, params, 'liste'), descr: "Affiche la table des ressource naturelles pour un milieu donné" });
|
||||
|
||||
this.registerCommand({ path: ["/tirer", "comp"], func: (content, msg, params) => RdDRollTables.getCompetence('chat'), descr: "Tire une compétence au hasard" });
|
||||
this.registerCommand({ path: ["/tirer", "queue"], func: (content, msg, params) => RdDRollTables.getQueue('chat'), descr: "Tire une Queue de Dragon" });
|
||||
@ -76,7 +75,6 @@ export class RdDCommands {
|
||||
this.registerCommand({ path: ["/tirer", "ideefixe"], func: (content, msg, params) => RdDRollTables.getIdeeFixe('chat'), descr: "Tire une Idée fixe" });
|
||||
this.registerCommand({ path: ["/tirer", "desir"], func: (content, msg, params) => RdDRollTables.getDesirLancinant('chat'), descr: "Tire un Désir Lancinant" });
|
||||
this.registerCommand({ path: ["/tirer", "rencontre"], func: (content, msg, params) => this.getRencontreTMR(params), descr: `Détermine une rencontre dans les TMR (synonyme de "/tmrr")` });
|
||||
this.registerCommand({ path: ["/tirer", "milieu"], func: (content, msg, params) => this.tableMilieu(msg, params, 'chat'), descr: "Effectue un tirage dans la table des ressource naturelles pour un milieu donné" });
|
||||
this.registerCommand({ path: ["/tirage"], func: (content, msg, params) => this.tirage(), descr: "Ouvre la fenêtre de recherche et tirage" });
|
||||
|
||||
this.registerCommand({ path: ["/meteo"], func: (content, msg, params) => this.getMeteo(msg, params), descr: "Propose une météo marine" });
|
||||
@ -397,32 +395,6 @@ export class RdDCommands {
|
||||
return false;
|
||||
}
|
||||
|
||||
async tableMilieu(msg, params, toChat) {
|
||||
if (params && params.length > 0) {
|
||||
const search = Misc.join(params, ' ');
|
||||
const milieux = await game.system.rdd.environnement.findEnvironnementsLike(search);
|
||||
if (milieux.length == 0) {
|
||||
const tous = Object.values(await game.system.rdd.environnement.milieux());
|
||||
return RdDCommands._chatAnswer(msg, `<strong>Aucun milieu correspondant à '${search}'.</strong>
|
||||
<br>Milieux disponibles:
|
||||
<br><ul class="chat-list"><li>${tous.reduce(Misc.joining('</li><li>'))}</li></ul>`);
|
||||
}
|
||||
if (milieux.length > 1) {
|
||||
ui.notifications.warn(`<strong>Plusieurs milieux correspondent à '${search}'</strong>:
|
||||
<br><ul class="chat-list"><li>${milieux.reduce(Misc.joining('</li><li>'))}</li></ul>`);
|
||||
}
|
||||
const tableName = `ressources en ${milieux.reduce(Misc.joining(', '))}`;
|
||||
if (toChat == 'liste') {
|
||||
return await game.system.rdd.environnement.searchToChatMessage(milieux, tableName);
|
||||
}
|
||||
else {
|
||||
const row = await game.system.rdd.environnement.getRandom(milieux, tableName);
|
||||
await CompendiumTableHelpers.tableRowToChatMessage(row, 'Item');
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
/* -------------------------------------------- */
|
||||
getCoutXpComp(msg, params) {
|
||||
if (params && (params.length == 1 || params.length == 2)) {
|
||||
|
@ -183,7 +183,6 @@ export class SystemReveDeDragon {
|
||||
RdDPossession.init();
|
||||
TMRRencontres.init();
|
||||
Environnement.init();
|
||||
FenetreRechercheTirage.init();
|
||||
|
||||
Hooks.once('ready', () => this.onReady());
|
||||
}
|
||||
|
@ -1,9 +1,8 @@
|
||||
import { RdDItem } from '../item.js';
|
||||
import { HtmlUtility } from '../html-utility.js';
|
||||
import { Misc } from "../misc.js";
|
||||
import { CompendiumTable, CompendiumTableHelpers, SystemCompendiums } from '../settings/system-compendiums.js';
|
||||
import { CompendiumTableHelpers } from '../settings/system-compendiums.js';
|
||||
import { RdDRaretes } from './raretes.js';
|
||||
import { SYSTEM_RDD } from '../constants.js';
|
||||
|
||||
const FILTER_GROUPS = [
|
||||
{ group: 'type', label: "Type d'objet" },
|
||||
@ -17,18 +16,17 @@ const FILTER_GROUPS = [
|
||||
]
|
||||
|
||||
const FILTERS = [
|
||||
{ group: 'comestible', code: 'pret', label: 'Préparé', check: item => item.getUtilisationCuisine() == 'pret' },
|
||||
{ group: 'comestible', code: 'comestible', label: 'Comestible', check: item => item.getUtilisation() == 'cuisine' },
|
||||
{ group: 'comestible', code: 'boisson', label: 'Boisson', check: item => item.isNourritureBoisson() && item.system.boisson },
|
||||
{ group: 'comestible', code: 'alcool', label: 'Alcool', check: item => item.isAlcool() },
|
||||
{ group: 'comestible', code: 'pret', label: 'Préparé', check: item => item.getUtilisationCuisine() == 'pret' },
|
||||
{ group: 'comestible', code: 'brut', label: 'A préparer', check: item => item.getUtilisationCuisine() == 'brut' },
|
||||
{ group: 'comestible', code: 'non', label: 'Immangeable', check: item => item.isEnvironnement() && !item.getUtilisationCuisine() },
|
||||
{ group: 'comestible', code: 'boisson', label: 'Boisson', check: item => item.isBoisson() },
|
||||
{ group: 'comestible', code: 'alcool', label: 'Alcool', check: item => item.isAlcool() },
|
||||
{ group: 'comestible', code: 'immangeable', label: 'Immangeable', check: item => item.isInventaire() && item.getUtilisation() != 'cuisine' },
|
||||
|
||||
{ group: 'categorie', code: 'alchimie', label: 'Alchimique', check: item => item.isEnvironnement() && item.getUtilisation() == 'alchimie' },
|
||||
{ group: 'categorie', code: 'cuisine', label: 'Cuisine', check: item => item.isEnvironnement() && item.getUtilisation() == 'cuisine' },
|
||||
{ group: 'categorie', code: 'soins', label: 'Médical', check: item => item.isEnvironnement() && item.getUtilisation() == 'soins' },
|
||||
{ group: 'categorie', code: 'cpoison', label: 'Toxique', check: item => item.isEnvironnement() && item.getUtilisation() == 'poison' },
|
||||
{ group: 'categorie', code: 'autres', label: 'Autres', check: item => !item.isEnvironnement() || item.getUtilisation() == '' },
|
||||
{ group: 'categorie', code: 'alchimie', label: 'Alchimique', check: item => item.isInventaire() && item.getUtilisation() == 'alchimie' },
|
||||
{ group: 'categorie', code: 'soins', label: 'Médical', check: item => item.isInventaire() && item.getUtilisation() == 'soins' },
|
||||
{ group: 'categorie', code: 'poison', label: 'Toxique', check: item => item.isInventaire() && item.getUtilisation() == 'poison' },
|
||||
{ group: 'categorie', code: 'autres', label: 'Autres', check: item => !item.isInventaire() || item.getUtilisation() == '' },
|
||||
|
||||
{ group: "qualite", code: "mauvaise", label: "Mauvaise (négative)", check: item => item.isInventaire() && item.system.qualite < 0 },
|
||||
{ group: "qualite", code: "quelconque", label: "Quelconque (0)", check: item => item.isInventaire() && item.system.qualite == 0 },
|
||||
@ -45,13 +43,12 @@ const FILTERS = [
|
||||
{ group: "enc", code: "anemort", label: "Un âne mort (plus de 10)", check: item => item.isInventaire() && 10 < item.system.encombrement },
|
||||
|
||||
{ group: "prix", code: "gratuit", label: "Gratuit", check: item => item.isInventaire() && item.system.cout == 0 },
|
||||
{ group: "prix", code: "deniers", label: "Deniers (étain) 1-9", check: item => item.isInventaire() && 0 < item.system.cout && item.system.cout < 0.1 },
|
||||
{ group: "prix", code: "bronze", label: "Bronzes 1-9", check: item => item.isInventaire() && 0.1 <= item.system.cout && item.system.cout < 1 },
|
||||
{ group: "prix", code: "sols", label: "Sols (argent) 1-9", check: item => item.isInventaire() && 1 <= item.system.cout && item.system.cout < 10 },
|
||||
{ group: "prix", code: "dragons", label: "Dragons (or) 1+ ", check: item => item.isInventaire() && 10 <= item.system.cout },
|
||||
{ group: "prix", code: "deniers", label: "Deniers (étain)", check: item => item.isInventaire() && 0 < item.system.cout && item.system.cout < 0.1 },
|
||||
{ group: "prix", code: "bronze", label: "Sous (bronze)", check: item => item.isInventaire() && 0.1 <= item.system.cout && item.system.cout < 1 },
|
||||
{ group: "prix", code: "sols", label: "Sols (argent)", check: item => item.isInventaire() && 1 <= item.system.cout && item.system.cout < 10 },
|
||||
{ group: "prix", code: "dragons", label: "Dragons (or)", check: item => item.isInventaire() && 10 <= item.system.cout },
|
||||
]
|
||||
|
||||
const COMPENDIUMS_RECHERCHE = 'compendiums-recherche';
|
||||
|
||||
function $typeToFilter(type) { return { group: 'type', code: type, label: Misc.typeName('Item', type), check: item => item.type == type }; }
|
||||
|
||||
@ -66,12 +63,7 @@ function $filterRarete() {
|
||||
}
|
||||
|
||||
function $filterTypes() {
|
||||
return [
|
||||
{ group: 'type', code: 'inventaire', label: 'Inventaire', check: item => item.isInventaire() && !item.isEnvironnement() },
|
||||
]
|
||||
.concat(['arme', 'armure'].map(it => $typeToFilter(it)))
|
||||
.concat([{ group: 'type', code: 'environement', label: 'Faune, Flore, Ingrédients', check: item => item.isEnvironnement() }])
|
||||
.concat(RdDItem.getItemTypesEnvironnement().map(it => $typeToFilter(it)))
|
||||
return RdDItem.getItemTypesInventaire().map(it => $typeToFilter(it));
|
||||
}
|
||||
|
||||
function $getAllFilters(milieux) {
|
||||
@ -106,20 +98,6 @@ function $loadFilters(parameters) {
|
||||
|
||||
|
||||
export class FenetreRechercheTirage extends Application {
|
||||
|
||||
static init() {
|
||||
game.settings.register(SYSTEM_RDD, COMPENDIUMS_RECHERCHE, {
|
||||
name: COMPENDIUMS_RECHERCHE,
|
||||
default: [
|
||||
SystemCompendiums.getCompendium('faune-flore-mineraux'),
|
||||
SystemCompendiums.getCompendium('equipement')
|
||||
],
|
||||
scope: "world",
|
||||
config: false,
|
||||
type: Object
|
||||
});
|
||||
}
|
||||
|
||||
static get defaultOptions() {
|
||||
return mergeObject(super.defaultOptions, {
|
||||
template: "systems/foundryvtt-reve-de-dragon/templates/tirage/fenetre-recherche-tirage.hbs",
|
||||
@ -146,12 +124,6 @@ export class FenetreRechercheTirage extends Application {
|
||||
constructor(parameters, options) {
|
||||
super(options);
|
||||
this.parameters = parameters;
|
||||
this.buildCompendiumTables();
|
||||
}
|
||||
|
||||
buildCompendiumTables() {
|
||||
this.parameters.compendiums = game.settings.get(SYSTEM_RDD, COMPENDIUMS_RECHERCHE);
|
||||
this.parameters.compendiumTables = this.parameters.compendiums.map(it => new CompendiumTable(it, 'Item'));
|
||||
}
|
||||
|
||||
async getData() {
|
||||
@ -219,11 +191,7 @@ export class FenetreRechercheTirage extends Application {
|
||||
}
|
||||
|
||||
async buildTable() {
|
||||
const filter = this.buildCheckedItemsFilter();
|
||||
const allTables = await Promise.all(
|
||||
this.parameters.compendiumTables.map(async compTable => await compTable.buildTable(it => it.getFrequence(), filter))
|
||||
);
|
||||
return CompendiumTableHelpers.concatTables(...allTables);
|
||||
return await game.system.rdd.environnement.buildTable(it => it.getFrequence(), this.buildCheckedItemsFilter())
|
||||
}
|
||||
|
||||
buildCheckedItemsFilter() {
|
||||
@ -271,30 +239,21 @@ export class FenetreRechercheTirage extends Application {
|
||||
}
|
||||
|
||||
async configurer() {
|
||||
const itemPacks = game.packs.filter(it => it.metadata.type == 'Item');
|
||||
console.log('packs1', itemPacks);
|
||||
|
||||
const configuration = {
|
||||
compendiums: itemPacks.map(it => duplicate(it.metadata)).map(it => mergeObject(it, { selected: this.parameters.compendiums.includes(it.id) }))
|
||||
FenetreRechercheConfiguration.create();
|
||||
}
|
||||
FenetreRechercheConfiguration.create(configuration, c => this.setConfiguration(c));
|
||||
}
|
||||
|
||||
setConfiguration(configuration) {
|
||||
const compendiums = configuration.compendiums.filter(it => it.selected).map(it => it.id);
|
||||
game.settings.set(SYSTEM_RDD, COMPENDIUMS_RECHERCHE, compendiums);
|
||||
this.buildCompendiumTables()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class FenetreRechercheConfiguration extends Dialog {
|
||||
static async create(configuration, onSave) {
|
||||
static async create() {
|
||||
const configuration = {
|
||||
compendiums: game.packs.filter(it => it.metadata.type == 'Item').map(it => it.metadata)
|
||||
.map(it => mergeObject({ selected: game.system.rdd.environnement.compendiums.includes(it.id) }, it))
|
||||
}
|
||||
const html = await renderTemplate("systems/foundryvtt-reve-de-dragon/templates/tirage/fenetre-recherche-configuration.hbs", configuration);
|
||||
new FenetreRechercheConfiguration(html, configuration, onSave).render(true);
|
||||
new FenetreRechercheConfiguration(html).render(true);
|
||||
}
|
||||
|
||||
constructor(html, configuration, onSave) {
|
||||
constructor(html) {
|
||||
const options = {
|
||||
classes: ["fenetre-recherche-configuration"],
|
||||
width: 600,
|
||||
@ -307,12 +266,12 @@ class FenetreRechercheConfiguration extends Dialog {
|
||||
title: 'Configuration de la recherche',
|
||||
content: html,
|
||||
buttons: {
|
||||
"Sauvegarder": { label: "Sauvegarder", callback: async it => { await this.sauvegarder(); } }
|
||||
}
|
||||
};
|
||||
super(conf, options)
|
||||
this.configuration = configuration;
|
||||
this.onSave = onSave;
|
||||
}
|
||||
|
||||
activateListeners(html) {
|
||||
this.html = html;
|
||||
super.activateListeners(html);
|
||||
@ -323,9 +282,7 @@ class FenetreRechercheConfiguration extends Dialog {
|
||||
const compendiumIds = jQuery.map(this.html.find("input.select-compendium:checked"), it => {
|
||||
return this.html.find(it).data('id');
|
||||
});
|
||||
this.configuration.compendiums.forEach(c => {
|
||||
c.selected = compendiumIds.includes(c.id)
|
||||
})
|
||||
this.onSave(this.configuration)
|
||||
await game.system.rdd.environnement.saveCompendiums(compendiumIds);
|
||||
this.close();
|
||||
}
|
||||
}
|
||||
|
@ -1,3 +1,4 @@
|
||||
|
||||
const RARETE_COMMUNE = { code: 'Commune', label: 'Commune', frequence: 54, min: 27, max: 108 };
|
||||
const RARETE_FREQUENTE = { code: 'Frequente', label: 'Fréquente', frequence: 18, min: 9, max: 36 };
|
||||
const RARETE_RARE = { code: 'Rare', label: 'Rare', frequence: 6, min: 3, max: 12 };
|
||||
@ -31,19 +32,20 @@ export class RdDRaretes {
|
||||
return RARETES;
|
||||
}
|
||||
|
||||
static frequenceEquipement(item) {
|
||||
return RdDRaretes.rareteEquipement(item).frequence
|
||||
}
|
||||
|
||||
|
||||
static rareteEnvironnement(item, milieux = undefined) {
|
||||
const list = item.getEnvironnements(milieux);
|
||||
static selonEnvironnement(item, milieux = undefined) {
|
||||
const list = item.getEnvironnement(milieux);
|
||||
const freqMax = Math.max(0, ...list.map(env => env.frequence));
|
||||
const env = list.find(env => env.frequence == freqMax);
|
||||
return env ? RdDRaretes.getRarete(env.rarete) : RARETE_INEXISTANT;
|
||||
|
||||
if (env) {
|
||||
return RdDRaretes.getRarete(env.rarete)
|
||||
}
|
||||
static rareteEquipement(item) {
|
||||
if (milieux == undefined) {
|
||||
return RdDRaretes.selonQualite(item)
|
||||
}
|
||||
return RARETE_INEXISTANT;
|
||||
}
|
||||
|
||||
static selonQualite(item) {
|
||||
const qualite = item.system.qualite ?? 0;
|
||||
if (qualite <= 0) {
|
||||
return RARETE_COMMUNE
|
||||
|
@ -1,6 +1,6 @@
|
||||
{{>'systems/foundryvtt-reve-de-dragon/templates/scripts/autocomplete-script.hbs'}}
|
||||
<div class="tab items" data-group="primary" data-tab="environnement">
|
||||
<div class="form-group">
|
||||
<div class="form-group description-milieu">
|
||||
<label>Description du milieu</label>
|
||||
<span class="flexrow">
|
||||
<input class="attribute-value" type="text" name="system.milieu" value="{{system.milieu}}" data-dtype="String" />
|
||||
|
@ -15,8 +15,5 @@
|
||||
{{/each}}
|
||||
</ul>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<button class="configuration-save">Sauvegarder</button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user