Fix synthetic actors

This commit is contained in:
sladecraven 2020-12-02 00:09:47 +01:00
parent 9c16cf7641
commit 82b0ec1015

View File

@ -617,14 +617,14 @@ export class RdDUtility {
/* -------------------------------------------- */ /* -------------------------------------------- */
static buildDefenseChatCard( attacker, target, rollData ) static buildDefenseChatCard( attacker, target, rollData )
{ {
console.log("Attacker.defense", attacker, target, attacker.data._id, rollData.competence.data.categorie ); console.log("Attacker.defense", attacker, target, target.actor.isToken, attacker.data._id, rollData.competence.data.categorie );
let myTarget = target.actor; let myTarget = target.actor;
let defenseMsg = { title: "Défense en combat", let defenseMsg = { title: "Défense en combat",
content: "<strong>"+myTarget.name+"</strong> doit se défendre : <br><span class='chat-card-button-area'>" + content: "<strong>"+myTarget.name+"</strong> doit se défendre : <br><span class='chat-card-button-area'>" +
"<a class='chat-card-button' id='encaisser-button' data-attackerid='"+attacker.data._id + "' data-defenderid='" + myTarget.data._id + "'>Encaisser !</a></span>", "<a class='chat-card-button' id='encaisser-button' data-attackerid='"+attacker.data._id + "' data-defendertokenid='" + target.data._id + "'>Encaisser !</a></span>",
whisper: ChatMessage.getWhisperRecipients( myTarget.name ), whisper: ChatMessage.getWhisperRecipients( myTarget.name ),
attackerid: attacker.data._id, attackerid: attacker.data._id,
defenderid: myTarget.data._id, defenderTokenId: target.data._id,
rollMode: true rollMode: true
}; };
@ -633,16 +633,16 @@ export class RdDUtility {
for (const arme of myTarget.data.items) { for (const arme of myTarget.data.items) {
if (arme.type == "arme" && this.isArmeMelee(arme.data.competence)) { if (arme.type == "arme" && this.isArmeMelee(arme.data.competence)) {
defenderArmes.push( arme ); defenderArmes.push( arme );
defenseMsg.content += "<br><a class='chat-card-button' id='parer-button' data-attackerid='"+attacker.data._id + "' data-defenderid='" + myTarget.data._id + "' data-armeid='"+arme._id+"'>Parer avec " + arme.name + "</a></span>"; defenseMsg.content += "<br><a class='chat-card-button' id='parer-button' data-attackerid='"+attacker.data._id + "' data-defendertokenid='" + target.data._id + "' data-armeid='"+arme._id+"'>Parer avec " + arme.name + "</a></span>";
} }
} }
defenseMsg.content += "<br><a class='chat-card-button' id='esquiver-button' data-attackerid='"+attacker.data._id + "' data-defenderid='" + myTarget.data._id + "'>Esquiver</a></span>"; defenseMsg.content += "<br><a class='chat-card-button' id='esquiver-button' data-attackerid='"+attacker.data._id + "' data-defendertokenid='" + target.data._id + "'>Esquiver</a></span>";
} }
if ( rollData.competence.data.categorie == "tir" ) { if ( rollData.competence.data.categorie == "tir" ) {
for (const arme of myTarget.data.items) { // Bouclier for parry for (const arme of myTarget.data.items) { // Bouclier for parry
if ( arme.type == "arme" && arme.name.toLowerCase.match("bouclier") ) { if ( arme.type == "arme" && arme.name.toLowerCase.match("bouclier") ) {
defenderArmes.push( arme ); defenderArmes.push( arme );
defenseMsg.content += "<br><a class='chat-card-button' id='parer-button' data-attackerid='"+attacker.data._id + "' data-defenderid='" + myTarget.data._id + "' data-armeid='"+arme._id+"'>Parer avec " + arme.name + "</a></span>"; defenseMsg.content += "<br><a class='chat-card-button' id='parer-button' data-attackerid='"+attacker.data._id + "' data-defendertokenid='" + target.data._id + "' data-armeid='"+arme._id+"'>Parer avec " + arme.name + "</a></span>";
} }
} }
} }
@ -650,10 +650,10 @@ export class RdDUtility {
for (const arme of myTarget.data.items) { // Bouclier for parry Dodge/Esquive for (const arme of myTarget.data.items) { // Bouclier for parry Dodge/Esquive
if ( arme.type == "arme" && arme.name.toLowerCase.match("bouclier") ) { if ( arme.type == "arme" && arme.name.toLowerCase.match("bouclier") ) {
defenderArmes.push( arme ); defenderArmes.push( arme );
defenseMsg.content += "<br><a class='chat-card-button' id='parer-button' data-attackerid='"+attacker.data._id + "' data-defenderid='" + myTarget.data._id + "' data-armeid='"+arme._id+"'>Parer avec " + arme.name + "</a></span>"; defenseMsg.content += "<br><a class='chat-card-button' id='parer-button' data-attackerid='"+attacker.data._id + "' data-defendertokenid='" + target.data._id + "' data-armeid='"+arme._id+"'>Parer avec " + arme.name + "</a></span>";
} }
} }
defenseMsg.content += "<br><a class='chat-card-button' id='esquiver-button' data-attackerid='"+attacker.data._id + "' data-defenderid='" + myTarget.data._id + "'>Esquiver</a></span>"; defenseMsg.content += "<br><a class='chat-card-button' id='esquiver-button' data-attackerid='"+attacker.data._id + "' data-defendertokenid='" + target.data._id + "'>Esquiver</a></span>";
} }
defenseMsg.toSocket = true; // True per default for all players defenseMsg.toSocket = true; // True per default for all players
@ -680,9 +680,9 @@ export class RdDUtility {
/* -------------------------------------------- */ /* -------------------------------------------- */
static _handleMsgDefense(data) { static _handleMsgDefense(data) {
let defenderActor = game.actors.get(data.defenderid); let defenderToken = canvas.tokens.get(data.defenderTokenId);
if (defenderActor) { if (defenderToken) {
if ((game.user.isGM && !defenderActor.hasPlayerOwner) || (defenderActor.hasPlayerOwner && (game.user.character.id == defenderActor.id))) { if ((game.user.isGM && !defenderToken.actor.hasPlayerOwner) || (defenderToken.actor.hasPlayerOwner && (game.user.character.id == defenderToken.actor.data._id))) {
console.log("User is pushing message...", game.user.name); console.log("User is pushing message...", game.user.name);
game.system.rdd.rollDataHandler[data.attackerid] = duplicate(data.rollData); game.system.rdd.rollDataHandler[data.attackerid] = duplicate(data.rollData);
data.whisper = [game.user]; data.whisper = [game.user];
@ -792,8 +792,8 @@ export class RdDUtility {
static _handleMsgEncaisser(data) { static _handleMsgEncaisser(data) {
if (game.user.isGM) { // Seul le GM effectue l'encaissement sur la fiche if (game.user.isGM) { // Seul le GM effectue l'encaissement sur la fiche
let rollData = game.system.rdd.rollDataHandler[data.attackerid]; // Retrieve the rolldata from the store let rollData = game.system.rdd.rollDataHandler[data.attackerid]; // Retrieve the rolldata from the store
let defenderActor = game.actors.get(data.defenderid); let defenderToken = canvas.tokens.get(data.defenderTokenId);
defenderActor.encaisserDommages(rollData); defenderToken.actor.encaisserDommages(rollData);
} }
} }
@ -803,17 +803,17 @@ export class RdDUtility {
html.on("click", '#encaisser-button', event => { html.on("click", '#encaisser-button', event => {
event.preventDefault(); event.preventDefault();
let attackerid = event.currentTarget.attributes['data-attackerid'].value; let attackerid = event.currentTarget.attributes['data-attackerid'].value;
let defenderid = event.currentTarget.attributes['data-defenderid'].value; let defenderTokenId = event.currentTarget.attributes['data-defendertokenid'].value;
if ( game.user.isGM ) { // Current user is the GM -> direct access if ( game.user.isGM ) { // Current user is the GM -> direct access
let rollData = game.system.rdd.rollDataHandler[attackerid]; let rollData = game.system.rdd.rollDataHandler[attackerid];
rollData.attackerid = attackerid; rollData.attackerid = attackerid;
rollData.defenderid = defenderid; rollData.defenderTokenId = defenderTokenId;
let defenderActor = game.actors.get(defenderid ); let defenderToken = canvas.tokens.get( defenderTokenId );
defenderActor.encaisserDommages( rollData ); defenderToken.actor.encaisserDommages( rollData );
} else { // Emit message for GM } else { // Emit message for GM
game.socket.emit("system.foundryvtt-reve-de-dragon", { game.socket.emit("system.foundryvtt-reve-de-dragon", {
msg: "msg_encaisser", msg: "msg_encaisser",
data: { attackerid: attackerid, defenderid: defenderid } data: { attackerid: attackerid, defenderTokenId: defenderTokenId }
} ); } );
} }
}); });
@ -821,19 +821,19 @@ export class RdDUtility {
html.on("click", '#parer-button', event => { html.on("click", '#parer-button', event => {
event.preventDefault(); event.preventDefault();
let attackerid = event.currentTarget.attributes['data-attackerid'].value; let attackerid = event.currentTarget.attributes['data-attackerid'].value;
let defenderActor = game.actors.get(event.currentTarget.attributes['data-defenderid'].value ); let defenderToken = canvas.tokens.get(event.currentTarget.attributes['data-defenderTokenId'].value );
let armeId = event.currentTarget.attributes['data-armeid'].value; let armeId = event.currentTarget.attributes['data-armeid'].value;
let rollData = game.system.rdd.rollDataHandler[attackerid]; let rollData = game.system.rdd.rollDataHandler[attackerid];
defenderActor.parerAttaque( rollData, armeId ); defenderToken.actor.parerAttaque( rollData, armeId );
}); });
html.on("click", '#esquiver-button', event => { html.on("click", '#esquiver-button', event => {
event.preventDefault(); event.preventDefault();
let attackerid = event.currentTarget.attributes['data-attackerid'].value; let attackerid = event.currentTarget.attributes['data-attackerid'].value;
let defenderActor = game.actors.get(event.currentTarget.attributes['data-defenderid'].value ); let defenderToken = canvas.tokens.get(event.currentTarget.attributes['data-defenderTokenId'].value );
let rollData = game.system.rdd.rollDataHandler[attackerid]; let rollData = game.system.rdd.rollDataHandler[attackerid];
//console.log("Esquive !", rollData, defenderActor); //console.log("Esquive !", rollData, defenderActor);
defenderActor.esquiverAttaque( rollData ); defenderToken.actor.esquiverAttaque( rollData );
}); });
html.on("click", '#particuliere-attaque', event => { html.on("click", '#particuliere-attaque', event => {