diff --git a/module/rdd-combat.js b/module/rdd-combat.js
index 01edeea0..d4cd0726 100644
--- a/module/rdd-combat.js
+++ b/module/rdd-combat.js
@@ -107,27 +107,27 @@ export class RdDCombat {
/* -------------------------------------------- */
static _getAttaque(attackerId) {
return game.system.rdd.combatStore.attaques[attackerId];
- }
-
+ }
+
/* -------------------------------------------- */
static _deleteAttaque(attackerId) {
delete game.system.rdd.combatStore.attaques[attackerId];
- }
+ }
/* -------------------------------------------- */
static _storeDefense(defenderRoll) {
game.system.rdd.combatStore.defenses[defenderRoll.passeArme] = duplicate(defenderRoll);
- }
+ }
/* -------------------------------------------- */
static _getDefense(passeArme) {
return game.system.rdd.combatStore.defenses[passeArme];
- }
-
+ }
+
/* -------------------------------------------- */
static _deleteDefense(passeArme) {
delete game.system.rdd.combatStore.defenses[passeArme];
- }
+ }
/* -------------------------------------------- */
static create(attacker, defender, defenderTokenId, target = undefined) {
@@ -135,15 +135,11 @@ export class RdDCombat {
}
/* -------------------------------------------- */
- static createForEvent(event) {
- let attackerId = event.currentTarget.attributes['data-attackerId'].value;
- let attacker = game.actors.get(attackerId);
-
- const dataDefenderTokenId = event.currentTarget.attributes['data-defenderTokenId'];
- if (dataDefenderTokenId) {
- const defenderTokenId = dataDefenderTokenId.value;
- let defenderToken = canvas.tokens.get(defenderTokenId);
- let defender = defenderToken.actor;
+ static createForAttackerAndDefender(attackerId, defenderTokenId) {
+ const attacker = game.actors.get(attackerId);
+ if (defenderTokenId) {
+ const defenderToken = canvas.tokens.get(defenderTokenId);
+ const defender = defenderToken.actor;
return RdDCombat.create(attacker, defender, defenderTokenId);
}
@@ -166,17 +162,19 @@ export class RdDCombat {
}
/* -------------------------------------------- */
- static onMsgDefense(msgData) {
- let defenderToken = canvas.tokens.get(msgData.defenderTokenId);
+ static onMsgDefense(msg) {
+ let defenderToken = canvas.tokens.get(msg.defenderTokenId);
if (defenderToken) {
if (!game.user.isGM && !game.user.character) { // vérification / sanity check
ui.notifications.error("Le joueur " + game.user.name + " n'est connecté à aucun personnage. Impossible de continuer.");
return;
}
- if ((game.user.isGM && !defenderToken.actor.hasPlayerOwner) || (defenderToken.actor.hasPlayerOwner && (game.user.character.id == defenderToken.actor.data._id))) {
- const defenderRoll = msgData.defenderRoll;
- RdDCombat._storeAttaque(msgData.attackerId, defenderRoll.attackerRoll);
+ if ((game.user.isGM && !defenderToken.actor.hasPlayerOwner) || (defenderToken.actor.hasPlayerOwner && (game.user.character._id == defenderToken.actor.data._id))) {
+ const rddCombat = RdDCombat.createForAttackerAndDefender(msg.attackerId, msg.defenderTokenId);
+ const defenderRoll = msg.defenderRoll;
+ RdDCombat._storeAttaque(msg.attackerId, defenderRoll.attackerRoll);
RdDCombat._storeDefense(defenderRoll);
+ rddCombat._chatMessageDefense(msg.paramChatDefense);
}
}
}
@@ -202,8 +200,12 @@ export class RdDCombat {
'#echec-total-attaque',
]) {
html.on("click", button, event => {
+ const rddCombat = RdDCombat.createForAttackerAndDefender(
+ event.currentTarget.attributes['data-attackerId']?.value,
+ event.currentTarget.attributes['data-defenderTokenId']?.value);
+
+ rddCombat.onEvent(button, event);
event.preventDefault();
- RdDCombat.createForEvent(event).onEvent(button, event);
});
}
html.on("click", '#chat-jet-vie', event => {
@@ -308,7 +310,7 @@ export class RdDCombat {
/* -------------------------------------------- */
removeChatMessageActionsPasseArme(passeArme) {
- if (game.settings.get("foundryvtt-reve-de-dragon", "supprimer-dialogues-combat-chat")) {
+ if (game.user.isGM && game.settings.get("foundryvtt-reve-de-dragon", "supprimer-dialogues-combat-chat")) {
ChatUtility.removeMyChatMessageContaining(`
`);
}
}
@@ -413,7 +415,8 @@ export class RdDCombat {
attackerId: this.attackerId,
defenderTokenId: this.defenderTokenId,
isFinesse: isMeleeDiffNegative,
- isRapide: isMeleeDiffNegative && rollData.arme.data.rapide
+ isRapide: isMeleeDiffNegative && rollData.arme.data.rapide,
+ passeArme: rollData.passeArme
})
});
}
@@ -423,9 +426,10 @@ export class RdDCombat {
console.log("RdDCombat.onAttaqueNormale >>>", attackerRoll);
attackerRoll.dmg = RdDBonus.dmg(attackerRoll, this.attacker.getBonusDegat(), this.defender.isEntiteCauchemar());
-
+ let defenderRoll = { attackerRoll: attackerRoll, passeArme: attackerRoll.passeArme, show: {} }
// Save rollData for defender
RdDCombat._storeAttaque(this.attackerId, attackerRoll);
+ RdDCombat._storeDefense(defenderRoll)
attackerRoll.show = {
cible: this.target ? this.defender.data.name : 'la cible',
@@ -438,57 +442,69 @@ export class RdDCombat {
}
if (this.target) {
- await this._sendMessageDefense(attackerRoll);
+ await this._sendMessageDefense(attackerRoll, defenderRoll);
}
}
/* -------------------------------------------- */
- async _sendMessageDefense(attackerRoll, defenderRoll = undefined, essaisPrecedents = undefined) {
+ async _sendMessageDefense(attackerRoll, defenderRoll, essaisPrecedents = undefined) {
console.log("RdDCombat._sendMessageDefense", attackerRoll, defenderRoll, essaisPrecedents, " / ", this.attacker, this.target, this.attackerId, attackerRoll.competence.data.categorie);
this.removeChatMessageActionsPasseArme(attackerRoll.passeArme);
if (essaisPrecedents) {
mergeObject(attackerRoll.essais, essaisPrecedents, { overwrite: true });
}
- const paramDemandeDefense = {
+ const paramChatDefense = {
passeArme: attackerRoll.passeArme,
essais: attackerRoll.essais,
defender: this.defender,
+ attacker: this.attacker,
attackerId: this.attackerId,
defenderTokenId: this.defenderTokenId,
mainsNues: attackerRoll.dmg.mortalite != 'mortel' && this.defender.getCompetence("Corps à corps"),
armes: this._filterArmesParade(this.defender.data.items, attackerRoll.competence, attackerRoll.arme),
diffLibre: attackerRoll.ajustements?.diffLibre?.value ?? 0,
attaqueParticuliere: attackerRoll.particuliere,
- dmg: attackerRoll.dmg
+ attaqueCategorie: attackerRoll.competence.data.categorie,
+ attaqueArme: attackerRoll.arme,
+ dmg: attackerRoll.dmg,
};
- RdDCombat._sendRollMessage(this.attacker, this.defender, this.defenderTokenId,
- defenderRoll ?? { attackerRoll: attackerRoll, passeArme: attackerRoll.passeArme, show: {} },
- essaisPrecedents != undefined);
-
- let chatMessage = {
- alias: this.attacker.name,
- whisper: ChatUtility.getWhisperRecipientsAndGMs(this.defender.name),
- content: await renderTemplate('systems/foundryvtt-reve-de-dragon/templates/chat-demande-defense.html', paramDemandeDefense),
- };
- ChatMessage.create(chatMessage);
+ const selfMessage = essaisPrecedents != undefined;
+ if (!selfMessage && (!game.user.isGM || this.defender.hasPlayerOwner)) {
+ this._socketSendMessageDefense(paramChatDefense, defenderRoll);
+ }
+ else {
+ await this._chatMessageDefense(paramChatDefense);
+ }
}
/* -------------------------------------------- */
- static _sendRollMessage(sender, recipient, defenderTokenId, defenderRoll, selfMessage) {
- // envoyer le message au destinataire
- if (!selfMessage || !game.user.isGM || recipient.hasPlayerOwner) {
- let data = {
- attackerId: sender?.data._id,
- defenderId: recipient?.data._id,
- defenderTokenId: defenderTokenId,
- defenderRoll: duplicate(defenderRoll),
- rollMode: true
- };
- game.socket.emit("system.foundryvtt-reve-de-dragon", { msg: "msg_defense", data: data });
- }
+ async _chatMessageDefense(paramDemandeDefense) {
+ ChatMessage.create({
+ // message privé: du défenseur à lui même (et aux GMs)
+ speaker: ChatMessage.getSpeaker(this.defender, canvas.tokens.get(this.defenderTokenId)),
+ alias: this.attacker.name,
+ whisper: ChatUtility.getWhisperRecipientsAndGMs(this.defender.name),
+ content: await renderTemplate('systems/foundryvtt-reve-de-dragon/templates/chat-demande-defense.html', paramDemandeDefense),
+ });
}
+
+ /* -------------------------------------------- */
+ _socketSendMessageDefense(paramChatDefense, defenderRoll) {
+ // envoyer le message au destinataire
+ game.socket.emit("system.foundryvtt-reve-de-dragon", {
+ msg: "msg_defense", data: {
+ attackerId: this.attacker?.data._id,
+ defenderId: this.defender?.data._id,
+ defenderTokenId: this.defenderTokenId,
+ defenderRoll: duplicate(defenderRoll),
+ paramChatDefense: paramChatDefense,
+ rollMode: true
+ }
+ });
+ }
+
/* -------------------------------------------- */
_filterArmesParade(items, competence) {
items = items.filter(item => (item.type == 'arme' && item.data.equipe) || (item.type == 'competencecreature' && item.data.isparade));
@@ -809,6 +825,10 @@ export class RdDCombat {
console.log("RdDCombat.encaisser >>>", attackerRoll, defenderTokenId);
let defenderRoll = RdDCombat._getDefense(attackerRoll.passeArme);
+ if (!defenderRoll) {
+ ui.notifications.warn("Cette passe d'arme est déjà terminée!")
+ return;
+ }
if (defenderRoll?.rolled && RdDCombat.isEchecTotal(defenderRoll)) {
this._onEchecTotal(defenderRoll);
}
@@ -831,6 +851,7 @@ export class RdDCombat {
});
}
RdDCombat._deleteDefense(attackerRoll.passeArme);
+ this.removeChatMessageActionsPasseArme(attackerRoll.passeArme);
}
/* -------------------------------------------- */
diff --git a/templates/chat-demande-defense.html b/templates/chat-demande-defense.html
index 5ffead54..8b9b1ade 100644
--- a/templates/chat-demande-defense.html
+++ b/templates/chat-demande-defense.html
@@ -5,13 +5,13 @@
{{defender.name}} doit :
{{else}}
{{defender.name}} doit se défendre
- {{~#if (eq surprise 'demi')}} avec une significative {{/if~}}
- {{~#if attaqueParticuliere}} contre une particulière en
+ {{~#if (eq surprise 'demi')}} avec une significative {{/if}} d'une attaque
+ {{~#if attaqueParticuliere}} particulière en
{{~#if (eq attaqueParticuliere 'finesse')}} finesse
{{else if (eq attaqueParticuliere 'force')}} force
- {{else}} rapidité
+ {{else if (eq attaqueParticuliere 'rapidite')}} rapidité
{{/if~}}
- {{/if~}} :
+ {{/if}} de {{attacker.name}} ({{attaqueArme.name}}):
{{/if}}