Fix messages passe d'arme
- l'attaquant ne peut plus lancer les dés du défenseur (sauf GM) - ajout du nom de l'attaquant au message de défense - nettoyage des messages de la passe d'arme uniqument par le GM pour éviter suppression par le joueur
This commit is contained in:
parent
68152e6bb2
commit
c23065119e
@ -135,15 +135,11 @@ export class RdDCombat {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* -------------------------------------------- */
|
/* -------------------------------------------- */
|
||||||
static createForEvent(event) {
|
static createForAttackerAndDefender(attackerId, defenderTokenId) {
|
||||||
let attackerId = event.currentTarget.attributes['data-attackerId'].value;
|
const attacker = game.actors.get(attackerId);
|
||||||
let attacker = game.actors.get(attackerId);
|
if (defenderTokenId) {
|
||||||
|
const defenderToken = canvas.tokens.get(defenderTokenId);
|
||||||
const dataDefenderTokenId = event.currentTarget.attributes['data-defenderTokenId'];
|
const defender = defenderToken.actor;
|
||||||
if (dataDefenderTokenId) {
|
|
||||||
const defenderTokenId = dataDefenderTokenId.value;
|
|
||||||
let defenderToken = canvas.tokens.get(defenderTokenId);
|
|
||||||
let defender = defenderToken.actor;
|
|
||||||
|
|
||||||
return RdDCombat.create(attacker, defender, defenderTokenId);
|
return RdDCombat.create(attacker, defender, defenderTokenId);
|
||||||
}
|
}
|
||||||
@ -166,17 +162,19 @@ export class RdDCombat {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* -------------------------------------------- */
|
/* -------------------------------------------- */
|
||||||
static onMsgDefense(msgData) {
|
static onMsgDefense(msg) {
|
||||||
let defenderToken = canvas.tokens.get(msgData.defenderTokenId);
|
let defenderToken = canvas.tokens.get(msg.defenderTokenId);
|
||||||
if (defenderToken) {
|
if (defenderToken) {
|
||||||
if (!game.user.isGM && !game.user.character) { // vérification / sanity check
|
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.");
|
ui.notifications.error("Le joueur " + game.user.name + " n'est connecté à aucun personnage. Impossible de continuer.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if ((game.user.isGM && !defenderToken.actor.hasPlayerOwner) || (defenderToken.actor.hasPlayerOwner && (game.user.character.id == defenderToken.actor.data._id))) {
|
if ((game.user.isGM && !defenderToken.actor.hasPlayerOwner) || (defenderToken.actor.hasPlayerOwner && (game.user.character._id == defenderToken.actor.data._id))) {
|
||||||
const defenderRoll = msgData.defenderRoll;
|
const rddCombat = RdDCombat.createForAttackerAndDefender(msg.attackerId, msg.defenderTokenId);
|
||||||
RdDCombat._storeAttaque(msgData.attackerId, defenderRoll.attackerRoll);
|
const defenderRoll = msg.defenderRoll;
|
||||||
|
RdDCombat._storeAttaque(msg.attackerId, defenderRoll.attackerRoll);
|
||||||
RdDCombat._storeDefense(defenderRoll);
|
RdDCombat._storeDefense(defenderRoll);
|
||||||
|
rddCombat._chatMessageDefense(msg.paramChatDefense);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -202,8 +200,12 @@ export class RdDCombat {
|
|||||||
'#echec-total-attaque',
|
'#echec-total-attaque',
|
||||||
]) {
|
]) {
|
||||||
html.on("click", button, event => {
|
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();
|
event.preventDefault();
|
||||||
RdDCombat.createForEvent(event).onEvent(button, event);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
html.on("click", '#chat-jet-vie', event => {
|
html.on("click", '#chat-jet-vie', event => {
|
||||||
@ -308,7 +310,7 @@ export class RdDCombat {
|
|||||||
|
|
||||||
/* -------------------------------------------- */
|
/* -------------------------------------------- */
|
||||||
removeChatMessageActionsPasseArme(passeArme) {
|
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(`<div data-passearme="${passeArme}">`);
|
ChatUtility.removeMyChatMessageContaining(`<div data-passearme="${passeArme}">`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -413,7 +415,8 @@ export class RdDCombat {
|
|||||||
attackerId: this.attackerId,
|
attackerId: this.attackerId,
|
||||||
defenderTokenId: this.defenderTokenId,
|
defenderTokenId: this.defenderTokenId,
|
||||||
isFinesse: isMeleeDiffNegative,
|
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);
|
console.log("RdDCombat.onAttaqueNormale >>>", attackerRoll);
|
||||||
|
|
||||||
attackerRoll.dmg = RdDBonus.dmg(attackerRoll, this.attacker.getBonusDegat(), this.defender.isEntiteCauchemar());
|
attackerRoll.dmg = RdDBonus.dmg(attackerRoll, this.attacker.getBonusDegat(), this.defender.isEntiteCauchemar());
|
||||||
|
let defenderRoll = { attackerRoll: attackerRoll, passeArme: attackerRoll.passeArme, show: {} }
|
||||||
// Save rollData for defender
|
// Save rollData for defender
|
||||||
RdDCombat._storeAttaque(this.attackerId, attackerRoll);
|
RdDCombat._storeAttaque(this.attackerId, attackerRoll);
|
||||||
|
RdDCombat._storeDefense(defenderRoll)
|
||||||
|
|
||||||
attackerRoll.show = {
|
attackerRoll.show = {
|
||||||
cible: this.target ? this.defender.data.name : 'la cible',
|
cible: this.target ? this.defender.data.name : 'la cible',
|
||||||
@ -438,57 +442,69 @@ export class RdDCombat {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (this.target) {
|
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);
|
console.log("RdDCombat._sendMessageDefense", attackerRoll, defenderRoll, essaisPrecedents, " / ", this.attacker, this.target, this.attackerId, attackerRoll.competence.data.categorie);
|
||||||
|
|
||||||
this.removeChatMessageActionsPasseArme(attackerRoll.passeArme);
|
this.removeChatMessageActionsPasseArme(attackerRoll.passeArme);
|
||||||
if (essaisPrecedents) {
|
if (essaisPrecedents) {
|
||||||
mergeObject(attackerRoll.essais, essaisPrecedents, { overwrite: true });
|
mergeObject(attackerRoll.essais, essaisPrecedents, { overwrite: true });
|
||||||
}
|
}
|
||||||
const paramDemandeDefense = {
|
const paramChatDefense = {
|
||||||
passeArme: attackerRoll.passeArme,
|
passeArme: attackerRoll.passeArme,
|
||||||
essais: attackerRoll.essais,
|
essais: attackerRoll.essais,
|
||||||
defender: this.defender,
|
defender: this.defender,
|
||||||
|
attacker: this.attacker,
|
||||||
attackerId: this.attackerId,
|
attackerId: this.attackerId,
|
||||||
defenderTokenId: this.defenderTokenId,
|
defenderTokenId: this.defenderTokenId,
|
||||||
mainsNues: attackerRoll.dmg.mortalite != 'mortel' && this.defender.getCompetence("Corps à corps"),
|
mainsNues: attackerRoll.dmg.mortalite != 'mortel' && this.defender.getCompetence("Corps à corps"),
|
||||||
armes: this._filterArmesParade(this.defender.data.items, attackerRoll.competence, attackerRoll.arme),
|
armes: this._filterArmesParade(this.defender.data.items, attackerRoll.competence, attackerRoll.arme),
|
||||||
diffLibre: attackerRoll.ajustements?.diffLibre?.value ?? 0,
|
diffLibre: attackerRoll.ajustements?.diffLibre?.value ?? 0,
|
||||||
attaqueParticuliere: attackerRoll.particuliere,
|
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,
|
const selfMessage = essaisPrecedents != undefined;
|
||||||
defenderRoll ?? { attackerRoll: attackerRoll, passeArme: attackerRoll.passeArme, show: {} },
|
if (!selfMessage && (!game.user.isGM || this.defender.hasPlayerOwner)) {
|
||||||
essaisPrecedents != undefined);
|
this._socketSendMessageDefense(paramChatDefense, defenderRoll);
|
||||||
|
}
|
||||||
let chatMessage = {
|
else {
|
||||||
alias: this.attacker.name,
|
await this._chatMessageDefense(paramChatDefense);
|
||||||
whisper: ChatUtility.getWhisperRecipientsAndGMs(this.defender.name),
|
}
|
||||||
content: await renderTemplate('systems/foundryvtt-reve-de-dragon/templates/chat-demande-defense.html', paramDemandeDefense),
|
|
||||||
};
|
|
||||||
ChatMessage.create(chatMessage);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -------------------------------------------- */
|
/* -------------------------------------------- */
|
||||||
static _sendRollMessage(sender, recipient, defenderTokenId, defenderRoll, selfMessage) {
|
async _chatMessageDefense(paramDemandeDefense) {
|
||||||
// envoyer le message au destinataire
|
ChatMessage.create({
|
||||||
if (!selfMessage || !game.user.isGM || recipient.hasPlayerOwner) {
|
// message privé: du défenseur à lui même (et aux GMs)
|
||||||
let data = {
|
speaker: ChatMessage.getSpeaker(this.defender, canvas.tokens.get(this.defenderTokenId)),
|
||||||
attackerId: sender?.data._id,
|
alias: this.attacker.name,
|
||||||
defenderId: recipient?.data._id,
|
whisper: ChatUtility.getWhisperRecipientsAndGMs(this.defender.name),
|
||||||
defenderTokenId: defenderTokenId,
|
content: await renderTemplate('systems/foundryvtt-reve-de-dragon/templates/chat-demande-defense.html', paramDemandeDefense),
|
||||||
defenderRoll: duplicate(defenderRoll),
|
});
|
||||||
rollMode: true
|
|
||||||
};
|
|
||||||
game.socket.emit("system.foundryvtt-reve-de-dragon", { msg: "msg_defense", data: data });
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* -------------------------------------------- */
|
||||||
|
_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) {
|
_filterArmesParade(items, competence) {
|
||||||
items = items.filter(item => (item.type == 'arme' && item.data.equipe) || (item.type == 'competencecreature' && item.data.isparade));
|
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);
|
console.log("RdDCombat.encaisser >>>", attackerRoll, defenderTokenId);
|
||||||
|
|
||||||
let defenderRoll = RdDCombat._getDefense(attackerRoll.passeArme);
|
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)) {
|
if (defenderRoll?.rolled && RdDCombat.isEchecTotal(defenderRoll)) {
|
||||||
this._onEchecTotal(defenderRoll);
|
this._onEchecTotal(defenderRoll);
|
||||||
}
|
}
|
||||||
@ -831,6 +851,7 @@ export class RdDCombat {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
RdDCombat._deleteDefense(attackerRoll.passeArme);
|
RdDCombat._deleteDefense(attackerRoll.passeArme);
|
||||||
|
this.removeChatMessageActionsPasseArme(attackerRoll.passeArme);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -------------------------------------------- */
|
/* -------------------------------------------- */
|
||||||
|
@ -5,13 +5,13 @@
|
|||||||
<span><strong>{{defender.name}}</strong> doit :</span>
|
<span><strong>{{defender.name}}</strong> doit :</span>
|
||||||
{{else}}
|
{{else}}
|
||||||
<span><strong>{{defender.name}}</strong> doit se défendre
|
<span><strong>{{defender.name}}</strong> doit se défendre
|
||||||
{{~#if (eq surprise 'demi')}} avec une significative {{/if~}}
|
{{~#if (eq surprise 'demi')}} avec une significative {{/if}} d'une attaque
|
||||||
{{~#if attaqueParticuliere}} contre une <strong>particulière en
|
{{~#if attaqueParticuliere}} <strong>particulière en
|
||||||
{{~#if (eq attaqueParticuliere 'finesse')}} finesse
|
{{~#if (eq attaqueParticuliere 'finesse')}} finesse
|
||||||
{{else if (eq attaqueParticuliere 'force')}} force
|
{{else if (eq attaqueParticuliere 'force')}} force
|
||||||
{{else}} rapidité
|
{{else if (eq attaqueParticuliere 'rapidite')}} rapidité
|
||||||
{{/if~}}</strong>
|
{{/if~}}</strong>
|
||||||
{{/if~}} :
|
{{/if}} de {{attacker.name}} ({{attaqueArme.name}}):
|
||||||
</span>
|
</span>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
<span class='chat-card-button-area'>
|
<span class='chat-card-button-area'>
|
||||||
|
Loading…
Reference in New Issue
Block a user