diff --git a/module/rdd-combat.js b/module/rdd-combat.js
index 6a6a46d1..1abff7a6 100644
--- a/module/rdd-combat.js
+++ b/module/rdd-combat.js
@@ -20,7 +20,9 @@ export class RdDCombat {
if (target == undefined) {
ui.notifications.warn("Vous devez choisir une seule cible à attaquer!");
}
- return this.create(attacker, target ? target.actor : undefined, target)
+ const defender = target ? target.actor : undefined;
+ const defenderTokenId = target ? target.data._id : undefined;
+ return this.create(attacker, defender, defenderTokenId, target)
}
/* -------------------------------------------- */
@@ -34,8 +36,8 @@ export class RdDCombat {
}
/* -------------------------------------------- */
- static create(attacker, defender, target = undefined) {
- return new RdDCombat(attacker, defender, target)
+ static create(attacker, defender, defenderTokenId, target = undefined) {
+ return new RdDCombat(attacker, defender, defenderTokenId, target)
}
/* -------------------------------------------- */
@@ -45,22 +47,40 @@ export class RdDCombat {
const dataDefenderTokenId = event.currentTarget.attributes['data-defenderTokenId'];
if (dataDefenderTokenId) {
- let defenderToken = canvas.tokens.get(dataDefenderTokenId.value);
+ const defenderTokenId = dataDefenderTokenId.value;
+ let defenderToken = canvas.tokens.get(defenderTokenId);
let defender = defenderToken.actor;
- return this.create(attacker, defender);
+ return RdDCombat.create(attacker, defender, defenderTokenId);
}
- return this.createUsingTarget(attacker)
+ return RdDCombat.createUsingTarget(attacker)
}
- /* -------------------------------------------- */
- constructor(attacker, defender, target) {
- this.attacker = attacker;
- this.defender = defender;
- this.target = target;
- this.attackerId = this.attacker.data._id;
- this.defenderId = this.defender.data._id;
- this.defenderTokenId = target ? target.data._id : undefined;
+
+ static _sendRollMessage(sender, recipient, defenderTokenId, topic, message, rollData) {
+ let chatMessage = {
+ content: message,
+ whisper: ChatUtility.getWhisperRecipients("blindroll", recipient.name),
+ };
+
+ // envoyer le message au destinataire
+ if (!game.user.isGM || recipient.hasPlayerOwner) {
+ let data = {
+ attackerId: sender ? sender.data._id : undefined,
+ defenderId: recipient ? recipient.data._id : undefined,
+ defenderTokenId: defenderTokenId,
+ rollData: duplicate(rollData),
+ rollMode: true
+ };
+ mergeObject(data, chatMessage);
+ game.socket.emit("system.foundryvtt-reve-de-dragon", { msg: topic, data: data});
+ } else {
+ chatMessage.whisper = [game.user];
+ }
+
+ if (game.user.isGM) { // Always push the message to the MJ
+ ChatMessage.create(chatMessage);
+ }
}
/* -------------------------------------------- */
@@ -73,6 +93,16 @@ export class RdDCombat {
}
}
+ /* -------------------------------------------- */
+ constructor(attacker, defender, defenderTokenId, target) {
+ this.attacker = attacker;
+ this.defender = defender;
+ this.target = target;
+ this.attackerId = this.attacker.data._id;
+ this.defenderId = this.defender.data._id;
+ this.defenderTokenId = defenderTokenId;
+ }
+
/* -------------------------------------------- */
async onEvent(button, event) {
let rollData = game.system.rdd.rollDataHandler[this.attackerId];
@@ -91,7 +121,6 @@ export class RdDCombat {
}
}
-
/* -------------------------------------------- */
static isEchec(rollData) {
switch (rollData.surprise) {
@@ -240,55 +269,43 @@ export class RdDCombat {
ChatUtility.chatWithRollMode(chatOptions, this.attacker.name)
if (this.target) {
- this._messageDefenseur(rollData);
+ this._sendMessageDefense(rollData);
}
}
/* -------------------------------------------- */
- _messageDefenseur(rollData) {
- console.log("RdDCombat._messageDefenseur", rollData, " / ", this.attacker, this.target, this.target.actor.isToken, this.attacker.data._id, rollData.competence.data.categorie);
+ _sendMessageDefense(rollData) {
+ console.log("RdDCombat._sendMessageDefense", rollData, " / ", this.attacker, this.target, this.attackerId, rollData.competence.data.categorie);
- let content = "" + this.defender.name + " doit se défendre :";
+ let message = this._buildMessageDefense(rollData);
+ // encaisser
+ message += this._buildMessageEncaisser(rollData) + "";
+
+ RdDCombat._sendRollMessage(this.attacker, this.defender, this.defenderTokenId, "msg_defense", message, rollData);
+ }
+
+ _buildMessageDefense(rollData) {
+ let message = "" + this.defender.name + " doit se défendre :";
if (this.defender.getSurprise() != 'totale') {
// parades
for (const arme of this._filterArmesParade(this.defender.data.items, rollData.competence.data.categorie)) {
- content += "
Parer avec " + arme.name + "";
+ message += "
Parer avec " + arme.name + "";
}
// corps à corps
if (rollData.dmg.mortalite != 'mortel') {
- content += "
Parer à mains nues";
+ message += "
Parer à mains nues";
}
// esquive
if (rollData.competence.data.categorie == 'melee' || rollData.competence.data.categorie == "lancer" || rollData.competence.data.categorie == 'competencecreature') {
- content += "
Esquiver";
+ message += "
Esquiver";
}
}
+ return message;
+ }
- // encaisser
- content += "
Encaisser à " + Misc.toSignedString(rollData.dmg.total) + " !";
- content += ""
-
- let defense = {
- title: "Défense en combat",
- content: content,
- whisper: ChatUtility.getWhisperRecipients("blindroll", this.defender.name),
- attackerId: this.attackerId,
- defenderTokenId: this.defenderTokenId,
- rollMode: true,
- rollData: duplicate(rollData)
- };
-
- // envoyer le message de defense
- if (!game.user.isGM || this.defender.hasPlayerOwner) {
- game.socket.emit("system.foundryvtt-reve-de-dragon", { msg: "msg_defense", data: defense });
- } else {
- defense.whisper = [game.user];
- }
-
- if (game.user.isGM) { // Always push the message to the MJ
- ChatMessage.create(defense);
- }
+ _buildMessageEncaisser(rollData) {
+ return "
Encaisser à " + Misc.toSignedString(rollData.dmg.total) + " !";
}
/* -------------------------------------------- */
@@ -296,7 +313,7 @@ export class RdDCombat {
switch (categorie) {
case 'tir':
case 'lancer':
- return items.filter(item =>
+ return items.filter(item =>
item.type == 'arme' &&
item.data.competence.toLowerCase().match("bouclier"));
default:
@@ -479,7 +496,8 @@ export class RdDCombat {
await this.computeRecul(rollData, true);
// TODO: gestion message pour chance/encaissement
- this.encaisser(rollData.attackerRoll);
+ this._sendMessageEncaisser(rollData.attackerRoll);
+
}
/* -------------------------------------------- */
@@ -575,10 +593,10 @@ export class RdDCombat {
ChatUtility.chatWithRollMode(chatOptions, this.defender.name)
await this.computeRecul(rollData, true);
- this.encaisser(rollData.attackerRoll);
+ this._sendMessageEncaisser(rollData.attackerRoll);
}
-
-
+
+
/* -------------------------------------------- */
async computeDeteriorationArme(rollData) {
const attackerRoll = rollData.attackerRoll;
@@ -661,11 +679,10 @@ export class RdDCombat {
}
}
-
/* -------------------------------------------- */
- encaisser(attackerRoll) {
- // TODO: gestion message pour chance/encaissement
- this.encaisser(attackerRoll, this.defenderTokenId);
+ _sendMessageEncaisser(rollData){
+ let message = "" + this.defender.name + " doit:" + this._buildMessageEncaisser(rollData);
+ RdDCombat._sendRollMessage(this.attacker, this.defender, this.defenderTokenId, "msg_encaisser", message, rollData);
}
/* -------------------------------------------- */