diff --git a/module/actor/base-actor.js b/module/actor/base-actor.js index fca1564c..0a3e0c03 100644 --- a/module/actor/base-actor.js +++ b/module/actor/base-actor.js @@ -79,13 +79,7 @@ export class RdDBaseActor extends Actor { static onRemoteActorCall(callData, userId) { if (userId == game.user.id) { - let actor = game.actors.get(callData?.actorId); - if (callData.tokenId) { - let token = canvas.tokens.placeables.find(t => t.id == callData.tokenId) - if (token) { - actor = token.actor - } - } + const actor = RdDBaseActor.getRealActor(callData?.actorId, callData?.tokenId); if (Misc.isOwnerPlayerOrUniqueConnectedGM(actor)) { // Seul le joueur choisi effectue l'appel: le joueur courant si propriétaire de l'actor, ou le MJ sinon const args = callData.args; console.info(`RdDBaseActor.onRemoteActorCall: pour l'Actor ${callData.actorId}, appel de RdDBaseActor.${callData.method}(`, ...args, ')'); @@ -94,6 +88,16 @@ export class RdDBaseActor extends Actor { } } + static getRealActor(actorId, tokenId) { + if (tokenId) { + let token = canvas.tokens.get(tokenId) + if (token) { + return token.actor + } + } + return game.actors.get(actorId) + } + static getParentActor(document) { return document?.parent instanceof Actor ? document.parent : undefined } @@ -464,14 +468,15 @@ export class RdDBaseActor extends Actor { } async processDropItem(params) { - const targetActorId = this.id; - const sourceActorId = params.sourceActorId; - const itemId = params.itemId; - const destId = params.destId; - const srcId = params.srcId; + const targetActorId = this.id + const sourceActorId = params.sourceActorId + const sourceTokenId = params.sourceTokenId + const itemId = params.itemId + const destId = params.destId + const srcId = params.srcId if (sourceActorId && sourceActorId != targetActorId) { - console.log("Moving objects", sourceActorId, targetActorId, itemId); - this.moveItemsBetweenActors(itemId, sourceActorId); + console.log("Moving objects", sourceActorId, sourceTokenId, targetActorId, itemId); + this.moveItemsBetweenActors(itemId, sourceActorId, sourceTokenId); return false; } let result = true; @@ -625,10 +630,9 @@ export class RdDBaseActor extends Actor { } /* -------------------------------------------- */ - async moveItemsBetweenActors(itemId, sourceActorId) { - let itemsList = [] - let sourceActor = game.actors.get(sourceActorId); - itemsList.push({ id: itemId, conteneurId: undefined }); // Init list + async moveItemsBetweenActors(itemId, sourceActorId, sourceTokenId) { + let sourceActor = RdDBaseActor.getRealActor(sourceActorId, sourceTokenId) + let itemsList = [{ id: itemId, conteneurId: undefined }] sourceActor.buildSubConteneurObjetList(itemId, itemsList); // Get itemId list const itemsDataToCreate = itemsList.map(it => sourceActor.getItem(it.id)) diff --git a/module/rdd-sheet-utility.js b/module/rdd-sheet-utility.js index 383a231a..a9ad814f 100644 --- a/module/rdd-sheet-utility.js +++ b/module/rdd-sheet-utility.js @@ -43,11 +43,17 @@ export class RdDSheetUtility { item = await RdDItem.getCorrespondingItem(item); } if (actor.canReceive(item)) { + if (!actor.prototypeToken.actorLink && actor.token) { + ui.notifications.warn(`Impossible de donner ${item.name} à ${actor.name}, c'est un acteur temporaire +
La suppression de son token entraînera la perte définitive de ${item.name}.`) + return + } return { destId: destItemId, targetActorId: actor.id, itemId: item.id, sourceActorId: item.actor?.id, + sourceTokenId: item.actor.token?.id, srcId: objetVersConteneur[item.id], onEnleverConteneur: () => { delete objetVersConteneur[item.id]; }, onAjouterDansConteneur: (itemId, conteneurId) => { objetVersConteneur[itemId] = conteneurId; }