Fixes mineurs #583
@ -58,7 +58,7 @@ export class Environnement {
|
||||
const milieux = new Set(this.getMilieuxSettings());
|
||||
const elements = await this.getElements(it => 1, it => ITEM_ENVIRONNEMENT_TYPES.includes(it.type));
|
||||
elements.forEach(it => it.system.environnement.forEach(env => milieux.add(env.milieu)))
|
||||
return [...milieux];
|
||||
return [...milieux].filter(env => env);
|
||||
}
|
||||
|
||||
getMilieuxSettings() {
|
||||
@ -66,22 +66,34 @@ export class Environnement {
|
||||
}
|
||||
|
||||
async findEnvironnementsLike(search) {
|
||||
return (await this.milieux()).filter(it => Grammar.includesLowerCaseNoAccent(it, search));
|
||||
const milieux = (await this.milieux()).filter(it => Grammar.includesLowerCaseNoAccent(it, search));
|
||||
if (milieux.length > 1){
|
||||
const milieuExact = milieux.find(it => Grammar.equalsInsensitive(it, search));
|
||||
if (milieuExact) {
|
||||
return [milieuExact];
|
||||
}
|
||||
}
|
||||
return milieux;
|
||||
}
|
||||
|
||||
async searchToChatMessage(search) {
|
||||
const table = await this.buildEnvironnementTable(search);
|
||||
await CompendiumTableHelpers.tableToChatMessage(table, 'Item', ITEM_ENVIRONNEMENT_TYPES, `ressources en "${search}"`);
|
||||
async searchToChatMessage(milieux, typeName) {
|
||||
const table = await this.buildEnvironnementTable(milieux);
|
||||
await CompendiumTableHelpers.tableToChatMessage(table, 'Item', ITEM_ENVIRONNEMENT_TYPES, typeName);
|
||||
return true
|
||||
}
|
||||
|
||||
async getRandom(search) {
|
||||
const table = await this.buildEnvironnementTable(search);
|
||||
return await CompendiumTableHelpers.getRandom(table, 'Item', ITEM_ENVIRONNEMENT_TYPES, undefined, `ressources en "${search}"`);
|
||||
async getRandom(milieux, typeName) {
|
||||
const table = await this.buildEnvironnementTable(milieux);
|
||||
return await CompendiumTableHelpers.getRandom(table, 'Item', ITEM_ENVIRONNEMENT_TYPES, undefined, typeName);
|
||||
}
|
||||
|
||||
async buildEnvironnementTable(search) {
|
||||
const itemRareteEnMilieu = item => item.system?.environnement.find(env => Grammar.includesLowerCaseNoAccent(env.milieu, search));
|
||||
async buildEnvironnementTable(milieux) {
|
||||
const filterMilieux = item => item.system?.environnement.filter(env => milieux.includes(env.milieu));
|
||||
const itemRareteEnMilieu = item => {
|
||||
const raretes = filterMilieux(item);
|
||||
const frequenceMax = Math.max(raretes.map(env => env.frequence));
|
||||
return raretes.find(env => env.frequence == frequenceMax);
|
||||
}
|
||||
const itemFrequenceEnMilieu = item => itemRareteEnMilieu(item)?.frequence ?? 0;
|
||||
const isPresentEnMilieu = item => itemFrequenceEnMilieu(item) > 0;
|
||||
return await this.table.buildTable(itemFrequenceEnMilieu, isPresentEnMilieu);
|
||||
|
@ -382,15 +382,20 @@ export class RdDCommands {
|
||||
async tableMilieu(msg, params, toChat) {
|
||||
if (params && params.length > 0) {
|
||||
const search = Misc.join(params, ' ');
|
||||
const searches = game.system.rdd.environnement.findEnvironnementsLike(search);
|
||||
if (searches.length == 0) {
|
||||
const milieux = await game.system.rdd.environnement.findEnvironnementsLike(search);
|
||||
if (milieux.length == 0) {
|
||||
return RdDCommands._chatAnswer(msg, 'Aucun milieu correspondant à ' + search);
|
||||
}
|
||||
if (milieux.length > 1) {
|
||||
ui.notifications.warn(`<strong>Plusieurs milieux correspondent à '${search}'</strong>:
|
||||
<br><ul><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(search);
|
||||
return await game.system.rdd.environnement.searchToChatMessage(milieux, tableName);
|
||||
}
|
||||
else {
|
||||
const row = await game.system.rdd.environnement.getRandom(search);
|
||||
const row = await game.system.rdd.environnement.getRandom(milieux, tableName);
|
||||
await CompendiumTableHelpers.tableRowToChatMessage(row, 'Item');
|
||||
return true;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user