From 6493d00aabbf6d7d84f1883f23c9ae3b41133046 Mon Sep 17 00:00:00 2001 From: sladecraven Date: Sun, 10 Jan 2021 11:35:11 +0100 Subject: [PATCH] #125 : Deplacement conteneurs complets --- module/actor.js | 37 +++++++++++++++++++++++++++---------- system.json | 2 +- 2 files changed, 28 insertions(+), 11 deletions(-) diff --git a/module/actor.js b/module/actor.js index c8deb06f..a5d2272b 100644 --- a/module/actor.js +++ b/module/actor.js @@ -671,7 +671,7 @@ export class RdDActor extends Actor { } // Et gérer le nouvel objet let nouvelObjet = this.items.find(objet => (itemId == objet._id)); - if (currentEnc + nouvelObjet.data.data.encombrement > Number(conteneur.data.data.capacite)) { + if (nouvelObjet && currentEnc + nouvelObjet.data.data.encombrement > Number(conteneur.data.data.capacite)) { ui.notifications.warn("Capacité d'encombrement insuffisante dans le conteneur !"); return false; } @@ -689,19 +689,19 @@ export class RdDActor extends Actor { this.buildSubConteneurObjetList( subId, deleteList ); } if ( subObj) // Robust... - deleteList.push( subId ); + deleteList.push( {id: subId, conteneurId: conteneurId } ); } } - deleteList.push(conteneurId); } /* -------------------------------------------- */ async deleteAllConteneur(itemId) { let list = []; + list.push( {id: itemId, conteneurId: undefined }); // Init list this.buildSubConteneurObjetList(itemId, list); //console.log("List to delete", list); - for (let id of list) { - await this.deleteOwnedItem(id); + for (let item of list) { + await this.deleteOwnedItem(item.id); } } @@ -755,13 +755,30 @@ export class RdDActor extends Actor { async moveItemsBetweenActors( itemId, sourceActorId ) { let itemsList = [] let sourceActor = game.actors.get( sourceActorId ); + itemsList.push( {id: itemId, conteneurId: undefined }); // Init list sourceActor.buildSubConteneurObjetList( itemId, itemsList ); // Get itemId list - for (let srcItemId of itemsList) { - let copyItem = sourceActor.data.items.find( item => item._id == srcItemId ); - await this.createOwnedItem( duplicate(copyItem) ); + + + let conteneurMap = {}; + for (let item of itemsList) { + let copyItem = sourceActor.data.items.find( subItem => subItem._id == item.id ); + let newItem = await this.createOwnedItem( duplicate(copyItem) ); + console.log('New object', newItem); + if (copyItem.type == 'conteneur') { + conteneurMap[copyItem._id] = newItem._id; + } + // gestion conteneur/contenu + if ( item.conteneurId) { // l'Objet était dans un conteneur + let newConteneurId = conteneurMap[item.conteneurId]; + let newConteneur = this.data.items.find( subItem => subItem._id == newConteneurId ); + console.log('New conteneur filling!', newConteneur); + let contenu = duplicate(newConteneur.data.contenu); + contenu.push( newItem._id ); + await this.updateOwnedItem( {_id: newConteneurId, 'data.contenu': contenu }); + } } - for( let srcItemId of itemsList) { - await sourceActor.deleteOwnedItem( srcItemId ); + for( let item of itemsList) { + await sourceActor.deleteOwnedItem( item.id ); } } diff --git a/system.json b/system.json index c6b0955c..f422ea47 100644 --- a/system.json +++ b/system.json @@ -2,7 +2,7 @@ "name": "foundryvtt-reve-de-dragon", "title": "Rêve de Dragon", "description": "Rêve de Dragon RPG for FoundryVTT", - "version": "1.2.9", + "version": "1.2.10", "minimumCoreVersion": "0.7.5", "compatibleCoreVersion": "0.7.8", "templateVersion": 80,