Fix: recherches incorrectes

* cas rare d'un personnage avec carac reve-actuel défini, mais sans
label, qui rend impossible de trouver une autre caractéristique, ce
qui empêche tout jet de caractéristique

* '/rdd <carac> <comp>', quand plusieurs compétences peuvent
correspondre, la première devrait être choisie... mais en pratique,
échec et rien ne se passe
This commit is contained in:
Vincent Vandemeulebrouck 2022-07-08 01:22:53 +02:00
parent 940baad04c
commit bafc52a151
4 changed files with 12 additions and 7 deletions

View File

@ -3148,7 +3148,7 @@ export class RdDActor extends Actor {
return carac.chance;
}
let entry = Misc.findFirstLike(name, Object.entries(carac), { mapper: it => it[1].label, description: 'caractéristique' });
return entry.length > 0 ? carac[entry[0]] : undefined;
return entry && entry.length > 0 ? carac[entry[0]] : undefined;
}
/* -------------------------------------------- */

View File

@ -212,8 +212,11 @@ export class RdDItemCompetence extends Item {
/* -------------------------------------------- */
static findCompetence(list, idOrName, options = {}) {
if (idOrName == undefined) {
return undefined;
}
options = mergeObject(options, {
filter: it => RdDItemCompetence.isCompetence(it),
preFilter: it => RdDItemCompetence.isCompetence(it),
description: 'compétence',
});
return list.find(it => it.id == idOrName && RdDItemCompetence.isCompetence(it))

View File

@ -192,7 +192,7 @@ export class Misc {
if (!single) {
single = subset[0];
const choices = Misc.join(subset.map(it => options.mapper(it)), '<br>');
options.info(`Plusieurs choix de ${options.description}s possibles:<br>${choices}<br>Le premier sera choisi: ${mapToValue(single)}`);
options.onMessage(`Plusieurs choix de ${options.description}s possibles:<br>${choices}<br>Le premier sera choisi: ${options.mapper(single)}`);
}
return single;
}
@ -211,7 +211,7 @@ export class Misc {
}
value = Grammar.toLowerCaseNoAccent(value);
const subset = elements.filter(options.preFilter)
.filter(it => Grammar.toLowerCaseNoAccent(options.mapper(it)).includes(value));
.filter(it => Grammar.toLowerCaseNoAccent(options.mapper(it))?.includes(value));
if (subset.length == 0) {
options.onMessage(`Pas de ${options.description} correspondant à ${value}`);
}

View File

@ -276,9 +276,11 @@ export class RdDCommands {
diff = 0;
}
const caracName = params[0];
const compName = length > 1 ? Misc.join(params.slice(1, length), ' ') : undefined;
for (let actor of actors) {
await actor.rollCaracCompetence(caracName, compName, diff);
let competence = length > 1 ? actors[0].getCompetence(Misc.join(params.slice(1, length), ' ')) : undefined;
if (competence) {
for (let actor of actors) {
await actor.rollCaracCompetence(caracName, competence.name, diff);
}
}
return;
}