v10: pinaillages mineurs #642

Merged
uberwald merged 5 commits from VincentVk/foundryvtt-reve-de-dragon:v10 into v10 2023-04-21 23:08:11 +02:00
5 changed files with 27 additions and 40 deletions
Showing only changes of commit d2d1891838 - Show all commits

View File

@ -98,7 +98,7 @@ export class RdDActor extends RdDBaseActor {
/* -------------------------------------------- */ /* -------------------------------------------- */
async cleanupConteneurs() { 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) .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) } }); .map(c => { return { _id: c._id, 'system.contenu': c.system.contenu.filter(id => this.getItem(id) != undefined) } });
if (updates.length > 0) { 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 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 this.itemTypes['arme'].find(it => it.system.equipe && it.system.competence != "")
return (melee.length > 0)
} }
isEmpoignadeEnCours() { isEmpoignadeEnCours() {
return this.items.find(it => it.type == "empoignade" && it.system.pointsemp > 0) return this.items.find(it => it.type == "empoignade" && it.system.pointsemp > 0)
@ -1101,16 +1100,12 @@ export class RdDActor extends RdDBaseActor {
/* -------------------------------------------- */ /* -------------------------------------------- */
computeIsHautRevant() { computeIsHautRevant() {
if (this.isPersonnage()) { 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" ? "Haut rêvant"
: ""; : "";
} }
} }
hasItemNamed(type, name) {
name = Grammar.toLowerCaseNoAccent(name);
return this.listItems(type).find(it => Grammar.toLowerCaseNoAccent(it.name) == name);
}
/* -------------------------------------------- */ /* -------------------------------------------- */
async computeMalusArmure() { async computeMalusArmure() {
@ -2085,7 +2080,7 @@ export class RdDActor extends RdDBaseActor {
return; return;
} }
// Duplication car les pts de reve sont modifiés dans le sort // 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) { if (sorts.length == 0) {
ui.notifications.info(`Aucun sort disponible en ${TMRUtility.getTMR(coord).label} !`); ui.notifications.info(`Aucun sort disponible en ${TMRUtility.getTMR(coord).label} !`);
return; return;
@ -2365,7 +2360,7 @@ export class RdDActor extends RdDBaseActor {
async getTacheBlessure(blesse, blessure) { async getTacheBlessure(blesse, blessure) {
const gravite = blessure?.system.gravite ?? 0; const gravite = blessure?.system.gravite ?? 0;
if (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 RdDItemBlessure.createTacheSoinBlessure(this, gravite);
await blessure?.updateTacheSoinBlessure(tache); await blessure?.updateTacheSoinBlessure(tache);
return tache return tache
@ -2668,7 +2663,7 @@ export class RdDActor extends RdDBaseActor {
/* -------------------------------------------- */ /* -------------------------------------------- */
_getSignesDraconiques(coord) { _getSignesDraconiques(coord) {
const type = TMRUtility.getTMRType(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() { async resetNombresAstraux() {
let toDelete = this.listItems('nombreastral'); const deletions = this.itemTypes['nombreastral'].map(it => it._id);
const deletions = toDelete.map(it => it._id);
await this.deleteEmbeddedDocuments("Item", deletions); await this.deleteEmbeddedDocuments("Item", deletions);
} }
@ -2900,7 +2894,7 @@ export class RdDActor extends RdDBaseActor {
async supprimerAnciensNombresAstraux() { async supprimerAnciensNombresAstraux() {
const calendrier = game.system.rdd.calendrier; const calendrier = game.system.rdd.calendrier;
if (calendrier) { if (calendrier) {
const toDelete = this.listItems('nombreastral') const toDelete = this.itemTypes['nombreastral']
.filter(it => calendrier.isAfterIndexDate(it.system.jourindex)) .filter(it => calendrier.isAfterIndexDate(it.system.jourindex))
.map(it => it._id); .map(it => it._id);
await this.deleteEmbeddedDocuments("Item", toDelete); await this.deleteEmbeddedDocuments("Item", toDelete);
@ -2958,11 +2952,6 @@ export class RdDActor extends RdDBaseActor {
return entry && entry.length > 0 ? carac[entry[0]] : undefined; 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 countMonteeLaborieuse() { // Return +1 par queue/ombre/souffle Montée Laborieuse présente
let countMonteeLaborieuse = EffetsDraconiques.countMonteeLaborieuse(this); let countMonteeLaborieuse = EffetsDraconiques.countMonteeLaborieuse(this);
@ -3022,8 +3011,8 @@ export class RdDActor extends RdDBaseActor {
mode: mode, mode: mode,
fatigue: RdDUtility.calculFatigueHtml(fatigue, endurance), fatigue: RdDUtility.calculFatigueHtml(fatigue, endurance),
draconic: this.getDraconicList(), draconic: this.getDraconicList(),
sort: this.getSortList(), sort: this.itemTypes['sort'],
signes: this.listItems("signedraconique"), signes: this.itemTypes['signedraconique'],
caracReve: this.system.carac.reve.value, caracReve: this.system.carac.reve.value,
pointsReve: this.getReveActuel(), pointsReve: this.getReveActuel(),
isRapide: isRapide, isRapide: isRapide,

View File

@ -109,7 +109,6 @@ export class RdDBaseActor extends Actor {
isEntite() { return this.type == 'entite'; } isEntite() { return this.type == 'entite'; }
isPersonnage() { return this.type == 'personnage'; } isPersonnage() { return this.type == 'personnage'; }
isVehicule() { return this.type == 'vehicule'; } isVehicule() { return this.type == 'vehicule'; }
getItem(id, type = undefined) { getItem(id, type = undefined) {
const item = this.items.get(id); const item = this.items.get(id);
if (type == undefined || (item?.type == type)) { 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); } 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) { 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) });

View File

@ -17,20 +17,21 @@ export class RdDEmpoignade {
/* -------------------------------------------- */ /* -------------------------------------------- */
static getEmpoignadeById(actor, id) { 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; return emp && duplicate(emp) || undefined;
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
static getEmpoignade(attacker, defender) { 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) { 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) { if (emp) {
// TODO ? central storage ? // TODO ? central storage ?
return duplicate(emp);
} }
return emp && duplicate(emp) || undefined; return undefined;
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
static getMalusTaille(emp, attacker, defender) { static getMalusTaille(emp, attacker, defender) {
@ -270,10 +271,8 @@ export class RdDEmpoignade {
/* -------------------------------------------- */ /* -------------------------------------------- */
static async deleteAllEmpoignades() { static async deleteAllEmpoignades() {
for (let actor of game.actors) { for (let actor of game.actors) {
let empList = actor.items.filter(it => it.type == "empoignade") let empIds = actor.itemTypes["empoignade"].map(it => it.id)
for (let emp of empList) { await actor.deleteEmbeddedDocuments('Item', empIds)
await actor.deleteEmbeddedDocuments('Item', [emp.id])
}
} }
} }

View File

@ -57,7 +57,7 @@ export class AppAstrologie extends Application {
if (this.actor) { if (this.actor) {
return { return {
actor: this.actor, actor: this.actor,
nombres: this._organizeNombresAstraux(this.actor.listItems('nombreastral')), nombres: this._organizeNombresAstraux(this.actor.itemTypes['nombreastral']),
ajustements: CONFIG.RDD.difficultesLibres, ajustements: CONFIG.RDD.difficultesLibres,
etat: this.actor.getEtatGeneral(), etat: this.actor.getEtatGeneral(),
astrologie: this.actor.getCompetence('Astrologie') astrologie: this.actor.getCompetence('Astrologie')