cleanup itemTypes
Utilisation de itemTypes plutôt que de méthode listItems ou de filtrer les items par type. Potentiellement, itemTypes peut être précalculé par Foundry C'est aussi un peu plus lisibles (conditions du filter moins longues, et le filtrage par type est mis en avant en premier)
This commit is contained in:
parent
5580b6d59c
commit
d2d1891838
@ -98,7 +98,7 @@ export class RdDActor extends RdDBaseActor {
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async cleanupConteneurs() {
|
||||
let updates = this.listItems('conteneur')
|
||||
let updates = this.itemTypes['conteneur']
|
||||
.filter(c => c.system.contenu.filter(id => this.getItem(id) == undefined).length > 0)
|
||||
.map(c => { return { _id: c._id, 'system.contenu': c.system.contenu.filter(id => this.getItem(id) != undefined) } });
|
||||
if (updates.length > 0) {
|
||||
@ -333,8 +333,7 @@ export class RdDActor extends RdDBaseActor {
|
||||
|
||||
/* -------------------------------------------- */
|
||||
hasArmeeMeleeEquipee() { // Return true si l'acteur possède au moins 1 arme de mêlée équipée
|
||||
let melee = this.items.filter(it => it.type == "arme" && it.system.equipe && it.system.competence != "")
|
||||
return (melee.length > 0)
|
||||
return this.itemTypes['arme'].find(it => it.system.equipe && it.system.competence != "")
|
||||
}
|
||||
isEmpoignadeEnCours() {
|
||||
return this.items.find(it => it.type == "empoignade" && it.system.pointsemp > 0)
|
||||
@ -1101,16 +1100,12 @@ export class RdDActor extends RdDBaseActor {
|
||||
/* -------------------------------------------- */
|
||||
computeIsHautRevant() {
|
||||
if (this.isPersonnage()) {
|
||||
this.system.attributs.hautrevant.value = this.hasItemNamed('tete', 'don de haut-reve')
|
||||
this.system.attributs.hautrevant.value = this.itemTypes['tete'].find(it => Grammar.equalsInsensitive(it.name, 'don de haut-reve'))
|
||||
? "Haut rêvant"
|
||||
: "";
|
||||
}
|
||||
}
|
||||
|
||||
hasItemNamed(type, name) {
|
||||
name = Grammar.toLowerCaseNoAccent(name);
|
||||
return this.listItems(type).find(it => Grammar.toLowerCaseNoAccent(it.name) == name);
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async computeMalusArmure() {
|
||||
@ -1672,9 +1667,9 @@ export class RdDActor extends RdDBaseActor {
|
||||
await this.rollTache(tache.id);
|
||||
}
|
||||
}
|
||||
async actionHerbe(item, onActionItem = async () => {}) {
|
||||
async actionHerbe(item, onActionItem = async () => { }) {
|
||||
if (item.isHerbeAPotion()) {
|
||||
return DialogFabriquerPotion.create(this, item, onActionItem);
|
||||
return DialogFabriquerPotion.create(this, item, onActionItem);
|
||||
}
|
||||
return;
|
||||
}
|
||||
@ -2085,7 +2080,7 @@ export class RdDActor extends RdDBaseActor {
|
||||
return;
|
||||
}
|
||||
// Duplication car les pts de reve sont modifiés dans le sort
|
||||
let sorts = duplicate(this.$filterSortList(this.getSortList(), coord));
|
||||
let sorts = duplicate(this.$filterSortList(this.itemTypes['sort'], coord));
|
||||
if (sorts.length == 0) {
|
||||
ui.notifications.info(`Aucun sort disponible en ${TMRUtility.getTMR(coord).label} !`);
|
||||
return;
|
||||
@ -2365,7 +2360,7 @@ export class RdDActor extends RdDBaseActor {
|
||||
async getTacheBlessure(blesse, blessure) {
|
||||
const gravite = blessure?.system.gravite ?? 0;
|
||||
if (gravite > 0) {
|
||||
const tache = this.listItems('tache').find(it => it.system.itemId == blessure.id)
|
||||
const tache = this.itemTypes['tache'].find(it => it.system.itemId == blessure.id)
|
||||
?? await RdDItemBlessure.createTacheSoinBlessure(this, gravite);
|
||||
await blessure?.updateTacheSoinBlessure(tache);
|
||||
return tache
|
||||
@ -2668,7 +2663,7 @@ export class RdDActor extends RdDBaseActor {
|
||||
/* -------------------------------------------- */
|
||||
_getSignesDraconiques(coord) {
|
||||
const type = TMRUtility.getTMRType(coord);
|
||||
return this.listItems("signedraconique").filter(it => it.system.typesTMR.includes(type));
|
||||
return this.itemTypes["signedraconique"].filter(it => it.system.typesTMR.includes(type));
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
@ -2875,8 +2870,7 @@ export class RdDActor extends RdDBaseActor {
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async resetNombresAstraux() {
|
||||
let toDelete = this.listItems('nombreastral');
|
||||
const deletions = toDelete.map(it => it._id);
|
||||
const deletions = this.itemTypes['nombreastral'].map(it => it._id);
|
||||
await this.deleteEmbeddedDocuments("Item", deletions);
|
||||
}
|
||||
|
||||
@ -2900,7 +2894,7 @@ export class RdDActor extends RdDBaseActor {
|
||||
async supprimerAnciensNombresAstraux() {
|
||||
const calendrier = game.system.rdd.calendrier;
|
||||
if (calendrier) {
|
||||
const toDelete = this.listItems('nombreastral')
|
||||
const toDelete = this.itemTypes['nombreastral']
|
||||
.filter(it => calendrier.isAfterIndexDate(it.system.jourindex))
|
||||
.map(it => it._id);
|
||||
await this.deleteEmbeddedDocuments("Item", toDelete);
|
||||
@ -2958,11 +2952,6 @@ export class RdDActor extends RdDBaseActor {
|
||||
return entry && entry.length > 0 ? carac[entry[0]] : undefined;
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
getSortList() {
|
||||
return this.listItems("sort");
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
countMonteeLaborieuse() { // Return +1 par queue/ombre/souffle Montée Laborieuse présente
|
||||
let countMonteeLaborieuse = EffetsDraconiques.countMonteeLaborieuse(this);
|
||||
@ -3022,8 +3011,8 @@ export class RdDActor extends RdDBaseActor {
|
||||
mode: mode,
|
||||
fatigue: RdDUtility.calculFatigueHtml(fatigue, endurance),
|
||||
draconic: this.getDraconicList(),
|
||||
sort: this.getSortList(),
|
||||
signes: this.listItems("signedraconique"),
|
||||
sort: this.itemTypes['sort'],
|
||||
signes: this.itemTypes['signedraconique'],
|
||||
caracReve: this.system.carac.reve.value,
|
||||
pointsReve: this.getReveActuel(),
|
||||
isRapide: isRapide,
|
||||
|
@ -32,7 +32,7 @@ export class RdDBaseActor extends Actor {
|
||||
case "msg_refresh_nombre_astral":
|
||||
Hooks.callAll(APP_ASTROLOGIE_REFRESH);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static remoteActorCall(callData, userId = undefined) {
|
||||
@ -109,7 +109,6 @@ export class RdDBaseActor extends Actor {
|
||||
isEntite() { return this.type == 'entite'; }
|
||||
isPersonnage() { return this.type == 'personnage'; }
|
||||
isVehicule() { return this.type == 'vehicule'; }
|
||||
|
||||
getItem(id, type = undefined) {
|
||||
const item = this.items.get(id);
|
||||
if (type == undefined || (item?.type == type)) {
|
||||
@ -119,7 +118,7 @@ export class RdDBaseActor extends Actor {
|
||||
}
|
||||
|
||||
listItems(type = undefined) { return (type ? this.itemTypes[type] : this.items); }
|
||||
filterItems(filter, type = undefined) { return this.listItems(type)?.filter(filter) ?? []; }
|
||||
filterItems(filter, type = undefined) { return type ? this.itemTypes[type]?.filter(filter) ?? [] : []; }
|
||||
findItemLike(idOrName, type) {
|
||||
return this.getItem(idOrName, type)
|
||||
?? Misc.findFirstLike(idOrName, this.listItems(type), { description: Misc.typeName('Item', type) });
|
||||
|
@ -96,15 +96,15 @@ export class RdDCombatManager extends Combat {
|
||||
let compName = "Corps à corps"
|
||||
if (armeCombat) {
|
||||
if (armeCombat.system.competence != "") {
|
||||
compName = armeCombat.system.competence
|
||||
compName = armeCombat.system.competence
|
||||
}
|
||||
if (armeCombat.system.lancer != "") {
|
||||
compName = armeCombat.system.lancer
|
||||
compName = armeCombat.system.lancer
|
||||
}
|
||||
if (armeCombat.system.tir != "") {
|
||||
compName = armeCombat.system.tir
|
||||
compName = armeCombat.system.tir
|
||||
}
|
||||
}
|
||||
}
|
||||
const competence = RdDItemCompetence.findCompetence(combatant.actor.items, compName);
|
||||
if (competence && competence.system.defaut_carac) {
|
||||
const carac = combatant.actor.system.carac[competence.system.defaut_carac].value;
|
||||
|
@ -17,20 +17,21 @@ export class RdDEmpoignade {
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static getEmpoignadeById(actor, id) {
|
||||
let emp = actor.items.find(emp => emp.type == 'empoignade' && emp.system.empoignadeid == id)
|
||||
let emp = actor.itemTypes['empoignade'].find(it => it.system.empoignadeid == id)
|
||||
return emp && duplicate(emp) || undefined;
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static getEmpoignade(attacker, defender) {
|
||||
let emp = attacker.items.find(emp => emp.type == 'empoignade' && emp.system.empoigneurid == attacker.id && emp.system.empoigneid == defender.id)
|
||||
let emp = attacker.itemTypes['empoignade'].find(it => it.system.empoigneurid == attacker.id && it.system.empoigneid == defender.id)
|
||||
if (!emp) {
|
||||
emp = attacker.items.find(emp => emp.type == 'empoignade' && emp.system.empoigneurid == defender.id && emp.system.empoigneid == attacker.id)
|
||||
emp = attacker.itemTypes['empoignade'].find(it => it.system.empoigneurid == defender.id && it.system.empoigneid == attacker.id)
|
||||
}
|
||||
if (emp) {
|
||||
// TODO ? central storage ?
|
||||
return duplicate(emp);
|
||||
}
|
||||
return emp && duplicate(emp) || undefined;
|
||||
return undefined;
|
||||
}
|
||||
/* -------------------------------------------- */
|
||||
static getMalusTaille(emp, attacker, defender) {
|
||||
@ -270,13 +271,11 @@ export class RdDEmpoignade {
|
||||
/* -------------------------------------------- */
|
||||
static async deleteAllEmpoignades() {
|
||||
for (let actor of game.actors) {
|
||||
let empList = actor.items.filter(it => it.type == "empoignade")
|
||||
for (let emp of empList) {
|
||||
await actor.deleteEmbeddedDocuments('Item', [emp.id])
|
||||
}
|
||||
let empIds = actor.itemTypes["empoignade"].map(it => it.id)
|
||||
await actor.deleteEmbeddedDocuments('Item', empIds)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static async deleteLinkedEmpoignade(actorId, empoignade) {
|
||||
let actorDeleteId = (actorId == empoignade.system.empoigneurid) ? empoignade.system.empoigneid : empoignade.system.empoigneurid
|
||||
|
@ -57,7 +57,7 @@ export class AppAstrologie extends Application {
|
||||
if (this.actor) {
|
||||
return {
|
||||
actor: this.actor,
|
||||
nombres: this._organizeNombresAstraux(this.actor.listItems('nombreastral')),
|
||||
nombres: this._organizeNombresAstraux(this.actor.itemTypes['nombreastral']),
|
||||
ajustements: CONFIG.RDD.difficultesLibres,
|
||||
etat: this.actor.getEtatGeneral(),
|
||||
astrologie: this.actor.getCompetence('Astrologie')
|
||||
|
Loading…
Reference in New Issue
Block a user