v11.2.2 - Les tendres moments d'Akarlikarlikar #685

Merged
uberwald merged 15 commits from VincentVk/foundryvtt-reve-de-dragon:v11 into v11 2023-11-24 08:51:06 +01:00
2 changed files with 28 additions and 18 deletions
Showing only changes of commit dfd915f8d1 - Show all commits

View File

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

View File

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