#125 : Deplacement conteneurs complets

This commit is contained in:
sladecraven 2021-01-10 11:35:11 +01:00
parent 0290b182ca
commit 6493d00aab
2 changed files with 28 additions and 11 deletions

View File

@ -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 );
}
}

View File

@ -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,