diff --git a/module/actor.js b/module/actor.js index 105a9bef..de93a0ae 100644 --- a/module/actor.js +++ b/module/actor.js @@ -172,6 +172,7 @@ export class RdDActor extends Actor { // Initialize empty items RdDCarac.computeCarac(actorData.data); this.computeIsHautRevant(); + await this.cleanupConteneurs(); await this.computeEncombrementTotalEtMalusArmure(); this.computePrixTotalEquipement(); this.computeEtatGeneral(); @@ -179,6 +180,16 @@ export class RdDActor extends Actor { await this.checkMonnaiePresence(actorData.items); } + /* -------------------------------------------- */ + async cleanupConteneurs() { + let updates = this.listItemsData('conteneur') + .filter(c => c.data.contenu.filter(id => this.getObjet(id) == undefined).length > 0) + .map(c => { return { _id: c._id, 'data.contenu': c.data.contenu.filter(id => this.getObjet(id) != undefined) } }); + if (updates.length > 0) { + await this.updateEmbeddedDocuments("Item", updates) + } + } + /* -------------------------------------------- */ async checkMonnaiePresence(items) { // Ajout opportuniste si les pièces n'existent pas. if (!items) return; // Sanity check during import @@ -4060,7 +4071,7 @@ export class RdDActor extends Actor { notifyGestionTeteSouffleQueue(item, manualMessage = true) { ChatMessage.create({ whisper: ChatUtility.getWhisperRecipientsAndGMs(game.user.name), - content: `${this.name} a reçu un/une ${item.type}: ${item.name}, qui ${manualMessage ? "n'est pas" : "est"} géré automatiquement. ${manualMessage ?? ''}` + content: `${this.name} a reçu un/une ${item.type}: ${item.name}, qui ${manualMessage ? "n'est pas" : "est"} géré(e) automatiquement. ${manualMessage ? manualMessage : ''}` }); } } diff --git a/module/rdd-utility.js b/module/rdd-utility.js index 75cca74b..f3c36f7c 100644 --- a/module/rdd-utility.js +++ b/module/rdd-utility.js @@ -357,7 +357,8 @@ export class RdDUtility { static calculEncContenu(conteneur, objets) { const itemData = Misc.data(conteneur); const contenuDatas = (itemData.data.contenu ?? []).filter(id => id != undefined) - .map(id => Misc.data(objets.find(it => (id == it._id)))); + .map(id => Misc.data(objets.find(it => (id == it._id)))) + .filter(it => it); let enc = Number(itemData.data.encombrement ?? 0) * Number(itemData.data.quantite ?? 1); for (let itemData of contenuDatas){ if (itemData.type == 'conteneur') {