Fix: filterItem ne marchait plus sans type

This commit is contained in:
Vincent Vandemeulebrouck 2023-07-12 00:39:21 +02:00
parent 631ee0b801
commit e58d88fab6
2 changed files with 11 additions and 9 deletions

View File

@ -298,7 +298,7 @@ export class RdDActor extends RdDBaseActor {
/* -------------------------------------------- */ /* -------------------------------------------- */
async verifierPotionsEnchantees() { async verifierPotionsEnchantees() {
let potionsEnchantees = this.filterItems(it => it.type == 'potion' && it.system.categorie.toLowerCase().includes('enchant')); let potionsEnchantees = this.filterItems(it => it.system.categorie.toLowerCase().includes('enchant'), 'potion');
for (let potion of potionsEnchantees) { for (let potion of potionsEnchantees) {
if (!potion.system.prpermanent) { if (!potion.system.prpermanent) {
console.log(potion); console.log(potion);
@ -1124,7 +1124,7 @@ export class RdDActor extends RdDBaseActor {
/* -------------------------------------------- */ /* -------------------------------------------- */
async computeMalusArmure() { async computeMalusArmure() {
if (this.isPersonnage()) { if (this.isPersonnage()) {
const malusArmure = this.filterItems(it => it.type == 'armure' && it.system.equipe) const malusArmure = this.filterItems(it => it.system.equipe, 'armure')
.map(it => it.system.malus ?? 0) .map(it => it.system.malus ?? 0)
.reduce(Misc.sum(), 0); .reduce(Misc.sum(), 0);
// Mise à jour éventuelle du malus armure // Mise à jour éventuelle du malus armure
@ -1297,8 +1297,7 @@ export class RdDActor extends RdDBaseActor {
/* -------------------------------------------- */ /* -------------------------------------------- */
buildTMRInnaccessible() { buildTMRInnaccessible() {
const tmrInnaccessibles = this.filterItems(it => Draconique.isCaseTMR(it) && const tmrInnaccessibles = this.filterItems(it => Draconique.isCaseTMR(it) && EffetsDraconiques.isInnaccessible(it));
EffetsDraconiques.isInnaccessible(it));
return tmrInnaccessibles.map(it => it.system.coord); return tmrInnaccessibles.map(it => it.system.coord);
} }
@ -2363,8 +2362,7 @@ export class RdDActor extends RdDBaseActor {
/* -------------------------------------------- */ /* -------------------------------------------- */
async creerTacheDepuisLivre(item, options = { renderSheet: true }) { async creerTacheDepuisLivre(item, options = { renderSheet: true }) {
const nomTache = "Lire " + item.name; const nomTache = "Lire " + item.name;
const filterTacheLecture = it => it.type == 'tache' && it.name == nomTache; let tachesExistantes = findTache(nomTache);
let tachesExistantes = this.filterItems(filterTacheLecture);
if (tachesExistantes.length == 0) { if (tachesExistantes.length == 0) {
const tache = { const tache = {
name: nomTache, type: 'tache', name: nomTache, type: 'tache',
@ -2380,13 +2378,17 @@ export class RdDActor extends RdDBaseActor {
} }
} }
await this.createEmbeddedDocuments('Item', [tache], options); await this.createEmbeddedDocuments('Item', [tache], options);
tachesExistantes = this.filterItems(filterTacheLecture); tachesExistantes = findTache(nomTache)
} }
return tachesExistantes.length > 0 ? tachesExistantes[0] : undefined; return tachesExistantes.length > 0 ? tachesExistantes[0] : undefined;
function findTache(name) {
return this.filterItems(it => it.name == name, 'tache');
}
} }
blessuresASoigner() { blessuresASoigner() {
// TODO or not TODO: filtrer les blessures poour lesquels on ne peut plus faire de premiers soins? // TODO or not TODO: filtrer les blessures pour lesquelles on ne peut plus faire de premiers soins?
return this.filterItems(it => it.system.gravite > 0 && it.system.gravite <= 6 && !(it.system.premierssoins.done && it.system.soinscomplets.done), 'blessure') return this.filterItems(it => it.system.gravite > 0 && it.system.gravite <= 6 && !(it.system.premierssoins.done && it.system.soinscomplets.done), 'blessure')
} }

View File

@ -119,7 +119,7 @@ export class RdDBaseActor extends Actor {
} }
listItems(type = undefined) { return (type ? this.itemTypes[type] : this.items); } listItems(type = undefined) { return (type ? this.itemTypes[type] : this.items); }
filterItems(filter, type = undefined) { return type ? this.itemTypes[type]?.filter(filter) ?? [] : []; } filterItems(filter, type = undefined) { return (type ? this.itemTypes[type] : this.items)?.filter(filter); }
findItemLike(idOrName, type) { findItemLike(idOrName, type) {
return this.getItem(idOrName, type) return this.getItem(idOrName, type)
?? Misc.findFirstLike(idOrName, this.listItems(type), { description: Misc.typeName('Item', type) }); ?? Misc.findFirstLike(idOrName, this.listItems(type), { description: Misc.typeName('Item', type) });