Fix: prendre un objet d'un token
On peut maintenant prendre un objet à l'acteur d'un token non lié. Avertissement quand on donne un objet à un token
This commit is contained in:
parent
4fe487a0ec
commit
dfd915f8d1
@ -79,13 +79,7 @@ export class RdDBaseActor extends Actor {
|
|||||||
|
|
||||||
static onRemoteActorCall(callData, userId) {
|
static onRemoteActorCall(callData, userId) {
|
||||||
if (userId == game.user.id) {
|
if (userId == game.user.id) {
|
||||||
let actor = game.actors.get(callData?.actorId);
|
const actor = RdDBaseActor.getRealActor(callData?.actorId, callData?.tokenId);
|
||||||
if (callData.tokenId) {
|
|
||||||
let token = canvas.tokens.placeables.find(t => t.id == callData.tokenId)
|
|
||||||
if (token) {
|
|
||||||
actor = token.actor
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (Misc.isOwnerPlayerOrUniqueConnectedGM(actor)) { // Seul le joueur choisi effectue l'appel: le joueur courant si propriétaire de l'actor, ou le MJ sinon
|
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;
|
const args = callData.args;
|
||||||
console.info(`RdDBaseActor.onRemoteActorCall: pour l'Actor ${callData.actorId}, appel de RdDBaseActor.${callData.method}(`, ...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) {
|
static getParentActor(document) {
|
||||||
return document?.parent instanceof Actor ? document.parent : undefined
|
return document?.parent instanceof Actor ? document.parent : undefined
|
||||||
}
|
}
|
||||||
@ -464,14 +468,15 @@ export class RdDBaseActor extends Actor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async processDropItem(params) {
|
async processDropItem(params) {
|
||||||
const targetActorId = this.id;
|
const targetActorId = this.id
|
||||||
const sourceActorId = params.sourceActorId;
|
const sourceActorId = params.sourceActorId
|
||||||
const itemId = params.itemId;
|
const sourceTokenId = params.sourceTokenId
|
||||||
const destId = params.destId;
|
const itemId = params.itemId
|
||||||
const srcId = params.srcId;
|
const destId = params.destId
|
||||||
|
const srcId = params.srcId
|
||||||
if (sourceActorId && sourceActorId != targetActorId) {
|
if (sourceActorId && sourceActorId != targetActorId) {
|
||||||
console.log("Moving objects", sourceActorId, targetActorId, itemId);
|
console.log("Moving objects", sourceActorId, sourceTokenId, targetActorId, itemId);
|
||||||
this.moveItemsBetweenActors(itemId, sourceActorId);
|
this.moveItemsBetweenActors(itemId, sourceActorId, sourceTokenId);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
let result = true;
|
let result = true;
|
||||||
@ -625,10 +630,9 @@ export class RdDBaseActor extends Actor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* -------------------------------------------- */
|
/* -------------------------------------------- */
|
||||||
async moveItemsBetweenActors(itemId, sourceActorId) {
|
async moveItemsBetweenActors(itemId, sourceActorId, sourceTokenId) {
|
||||||
let itemsList = []
|
let sourceActor = RdDBaseActor.getRealActor(sourceActorId, sourceTokenId)
|
||||||
let sourceActor = game.actors.get(sourceActorId);
|
let itemsList = [{ id: itemId, conteneurId: undefined }]
|
||||||
itemsList.push({ id: itemId, conteneurId: undefined }); // Init list
|
|
||||||
sourceActor.buildSubConteneurObjetList(itemId, itemsList); // Get itemId list
|
sourceActor.buildSubConteneurObjetList(itemId, itemsList); // Get itemId list
|
||||||
|
|
||||||
const itemsDataToCreate = itemsList.map(it => sourceActor.getItem(it.id))
|
const itemsDataToCreate = itemsList.map(it => sourceActor.getItem(it.id))
|
||||||
|
@ -43,11 +43,17 @@ export class RdDSheetUtility {
|
|||||||
item = await RdDItem.getCorrespondingItem(item);
|
item = await RdDItem.getCorrespondingItem(item);
|
||||||
}
|
}
|
||||||
if (actor.canReceive(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 {
|
return {
|
||||||
destId: destItemId,
|
destId: destItemId,
|
||||||
targetActorId: actor.id,
|
targetActorId: actor.id,
|
||||||
itemId: item.id,
|
itemId: item.id,
|
||||||
sourceActorId: item.actor?.id,
|
sourceActorId: item.actor?.id,
|
||||||
|
sourceTokenId: item.actor.token?.id,
|
||||||
srcId: objetVersConteneur[item.id],
|
srcId: objetVersConteneur[item.id],
|
||||||
onEnleverConteneur: () => { delete objetVersConteneur[item.id]; },
|
onEnleverConteneur: () => { delete objetVersConteneur[item.id]; },
|
||||||
onAjouterDansConteneur: (itemId, conteneurId) => { objetVersConteneur[itemId] = conteneurId; }
|
onAjouterDansConteneur: (itemId, conteneurId) => { objetVersConteneur[itemId] = conteneurId; }
|
||||||
|
Loading…
Reference in New Issue
Block a user