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) {
|
||||
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(`<div data-passearme="${passeArme}">`);
|
||||
}
|
||||
}
|
||||
@ -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) {
|
||||
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
|
||||
if (!selfMessage || !game.user.isGM || recipient.hasPlayerOwner) {
|
||||
let data = {
|
||||
attackerId: sender?.data._id,
|
||||
defenderId: recipient?.data._id,
|
||||
defenderTokenId: defenderTokenId,
|
||||
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
|
||||
};
|
||||
game.socket.emit("system.foundryvtt-reve-de-dragon", { msg: "msg_defense", data: data });
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
_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);
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
|
@ -5,13 +5,13 @@
|
||||
<span><strong>{{defender.name}}</strong> doit :</span>
|
||||
{{else}}
|
||||
<span><strong>{{defender.name}}</strong> doit se défendre
|
||||
{{~#if (eq surprise 'demi')}} avec une significative {{/if~}}
|
||||
{{~#if attaqueParticuliere}} contre une <strong>particulière en
|
||||
{{~#if (eq surprise 'demi')}} avec une significative {{/if}} d'une attaque
|
||||
{{~#if attaqueParticuliere}} <strong>particulière en
|
||||
{{~#if (eq attaqueParticuliere 'finesse')}} finesse
|
||||
{{else if (eq attaqueParticuliere 'force')}} force
|
||||
{{else}} rapidité
|
||||
{{else if (eq attaqueParticuliere 'rapidite')}} rapidité
|
||||
{{/if~}}</strong>
|
||||
{{/if~}} :
|
||||
{{/if}} de {{attacker.name}} ({{attaqueArme.name}}):
|
||||
</span>
|
||||
{{/if}}
|
||||
<span class='chat-card-button-area'>
|
||||
|
Loading…
Reference in New Issue
Block a user