2020-12-12 21:58:44 +01:00
|
|
|
|
import { ChatUtility } from "./chat-utility.js";
|
|
|
|
|
import { RdDItemArme } from "./item-arme.js";
|
|
|
|
|
import { RdDItemCompetence } from "./item-competence.js";
|
|
|
|
|
import { Misc } from "./misc.js";
|
2020-12-16 23:02:15 +01:00
|
|
|
|
import { RdDBonus } from "./rdd-bonus.js";
|
2020-12-12 21:58:44 +01:00
|
|
|
|
import { RdDResolutionTable } from "./rdd-resolution-table.js";
|
|
|
|
|
import { RdDRoll } from "./rdd-roll.js";
|
2020-12-17 12:29:54 +01:00
|
|
|
|
import { RdDRollTables } from "./rdd-rolltables.js";
|
2020-12-12 21:58:44 +01:00
|
|
|
|
|
|
|
|
|
export class RdDCombat {
|
|
|
|
|
|
2020-12-16 09:07:00 +01:00
|
|
|
|
/* -------------------------------------------- */
|
2020-12-12 21:58:44 +01:00
|
|
|
|
static isActive() {
|
2020-12-15 23:54:05 +01:00
|
|
|
|
return true;
|
2020-12-12 21:58:44 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
|
static createUsingTarget(attacker) {
|
|
|
|
|
const target = RdDCombat.getTarget();
|
|
|
|
|
if (target == undefined) {
|
2021-01-02 04:28:43 +01:00
|
|
|
|
ui.notifications.warn((game.user.targets && game.user.targets.size > 1)
|
|
|
|
|
? "Vous devez choisir <strong>une seule</strong> cible à attaquer!"
|
|
|
|
|
: "Vous devez choisir une cible à attaquer!");
|
2020-12-12 21:58:44 +01:00
|
|
|
|
}
|
2020-12-18 22:15:17 +01:00
|
|
|
|
const defender = target ? target.actor : undefined;
|
|
|
|
|
const defenderTokenId = target ? target.data._id : undefined;
|
|
|
|
|
return this.create(attacker, defender, defenderTokenId, target)
|
2020-12-12 21:58:44 +01:00
|
|
|
|
}
|
|
|
|
|
|
2020-12-16 09:07:00 +01:00
|
|
|
|
/* -------------------------------------------- */
|
2020-12-12 21:58:44 +01:00
|
|
|
|
static getTarget() {
|
|
|
|
|
if (game.user.targets && game.user.targets.size == 1) {
|
|
|
|
|
for (let target of game.user.targets) {
|
|
|
|
|
return target;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return undefined;
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-16 09:07:00 +01:00
|
|
|
|
/* -------------------------------------------- */
|
2020-12-18 22:15:17 +01:00
|
|
|
|
static create(attacker, defender, defenderTokenId, target = undefined) {
|
|
|
|
|
return new RdDCombat(attacker, defender, defenderTokenId, target)
|
2020-12-12 21:58:44 +01:00
|
|
|
|
}
|
|
|
|
|
|
2020-12-16 09:07:00 +01:00
|
|
|
|
/* -------------------------------------------- */
|
2020-12-12 21:58:44 +01:00
|
|
|
|
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) {
|
2020-12-18 22:15:17 +01:00
|
|
|
|
const defenderTokenId = dataDefenderTokenId.value;
|
|
|
|
|
let defenderToken = canvas.tokens.get(defenderTokenId);
|
2020-12-12 21:58:44 +01:00
|
|
|
|
let defender = defenderToken.actor;
|
|
|
|
|
|
2020-12-18 22:15:17 +01:00
|
|
|
|
return RdDCombat.create(attacker, defender, defenderTokenId);
|
2020-12-12 21:58:44 +01:00
|
|
|
|
}
|
2020-12-18 22:15:17 +01:00
|
|
|
|
return RdDCombat.createUsingTarget(attacker)
|
2020-12-12 21:58:44 +01:00
|
|
|
|
}
|
|
|
|
|
|
2020-12-18 22:15:17 +01:00
|
|
|
|
|
|
|
|
|
static _sendRollMessage(sender, recipient, defenderTokenId, topic, message, rollData) {
|
|
|
|
|
let chatMessage = {
|
|
|
|
|
content: message,
|
|
|
|
|
whisper: ChatUtility.getWhisperRecipients("blindroll", recipient.name),
|
|
|
|
|
};
|
2021-01-01 03:25:48 +01:00
|
|
|
|
|
2020-12-18 22:15:17 +01:00
|
|
|
|
// 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);
|
2021-01-01 03:25:48 +01:00
|
|
|
|
game.socket.emit("system.foundryvtt-reve-de-dragon", { msg: topic, data: data });
|
2020-12-18 22:15:17 +01:00
|
|
|
|
} else {
|
|
|
|
|
chatMessage.whisper = [game.user];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (game.user.isGM) { // Always push the message to the MJ
|
|
|
|
|
ChatMessage.create(chatMessage);
|
|
|
|
|
}
|
2020-12-12 21:58:44 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
|
static registerChatCallbacks(html) {
|
|
|
|
|
for (let button of ['#parer-button', '#esquiver-button', '#particuliere-attaque', '#encaisser-button']) {
|
|
|
|
|
html.on("click", button, event => {
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
RdDCombat.createForEvent(event).onEvent(button, event);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-18 22:15:17 +01:00
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-12 21:58:44 +01:00
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
|
async onEvent(button, event) {
|
|
|
|
|
let rollData = game.system.rdd.rollDataHandler[this.attackerId];
|
2020-12-15 18:15:03 +01:00
|
|
|
|
if (!rollData) {
|
|
|
|
|
ui.notifications.warn("Action automatisée impossible, le jet de l'attaquant a été perdu (suite à un raffraichissement?)")
|
|
|
|
|
return;
|
|
|
|
|
}
|
2020-12-12 21:58:44 +01:00
|
|
|
|
switch (button) {
|
|
|
|
|
case '#particuliere-attaque': return await this.choixParticuliere(rollData, event.currentTarget.attributes['data-mode'].value);
|
2020-12-17 00:23:40 +01:00
|
|
|
|
case '#parer-button': {
|
|
|
|
|
const armeId = event.currentTarget.attributes['data-armeid'];
|
|
|
|
|
return this.parade(rollData, armeId ? armeId.value : undefined);
|
|
|
|
|
}
|
2020-12-12 21:58:44 +01:00
|
|
|
|
case '#esquiver-button': return this.esquive(rollData);
|
|
|
|
|
case '#encaisser-button': return this.encaisser(rollData, event.currentTarget.attributes['data-defenderTokenId'].value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-16 23:02:15 +01:00
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
|
static isEchec(rollData) {
|
|
|
|
|
switch (rollData.surprise) {
|
|
|
|
|
case 'totale': return true;
|
|
|
|
|
}
|
|
|
|
|
return rollData.rolled.isEchec;
|
|
|
|
|
}
|
2020-12-17 12:29:54 +01:00
|
|
|
|
|
2020-12-16 23:02:15 +01:00
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
|
static isEchecTotal(rollData) {
|
2021-01-02 04:28:43 +01:00
|
|
|
|
if (!rollData.attackerRoll && rollData.surprise) {
|
2020-12-16 23:02:15 +01:00
|
|
|
|
return rollData.rolled.isEchec;
|
|
|
|
|
}
|
|
|
|
|
return rollData.rolled.isETotal;
|
|
|
|
|
}
|
2020-12-17 12:29:54 +01:00
|
|
|
|
|
2020-12-16 23:02:15 +01:00
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
|
static isParticuliere(rollData) {
|
2021-01-02 04:28:43 +01:00
|
|
|
|
if (!rollData.attackerRoll && rollData.surprise) {
|
2020-12-16 23:02:15 +01:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return rollData.rolled.isPart;
|
|
|
|
|
}
|
2020-12-17 12:29:54 +01:00
|
|
|
|
|
2020-12-16 23:02:15 +01:00
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
|
static isReussite(rollData) {
|
|
|
|
|
switch (rollData.surprise) {
|
|
|
|
|
case 'totale': return false;
|
|
|
|
|
}
|
|
|
|
|
return rollData.rolled.isSuccess;
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-12 21:58:44 +01:00
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
|
async attaque(competence, arme) {
|
|
|
|
|
if (!await this.accorderEntite('avant-attaque')) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let rollData = this._prepareAttaque(competence, arme);
|
|
|
|
|
console.log("RdDCombat.attaque >>>", rollData);
|
|
|
|
|
|
|
|
|
|
const dialog = await RdDRoll.create(this.attacker, rollData,
|
2020-12-17 12:29:54 +01:00
|
|
|
|
{
|
|
|
|
|
html: 'systems/foundryvtt-reve-de-dragon/templates/dialog-competence.html',
|
|
|
|
|
options: { height: 540 }
|
|
|
|
|
}, {
|
2020-12-12 21:58:44 +01:00
|
|
|
|
name: 'jet-attaque',
|
|
|
|
|
label: 'Attaque: ' + (arme ? arme.name : competence.name),
|
|
|
|
|
callbacks: [
|
|
|
|
|
this.attacker.createCallbackExperience(),
|
2020-12-16 23:02:15 +01:00
|
|
|
|
{ condition: r => (RdDCombat.isReussite(r) && !RdDCombat.isParticuliere(r)), action: r => this._onAttaqueNormale(r) },
|
2020-12-17 01:08:14 +01:00
|
|
|
|
{ condition: RdDCombat.isParticuliere, action: r => this._onAttaqueParticuliere(r) },
|
|
|
|
|
{ condition: RdDCombat.isEchec, action: r => this._onAttaqueEchec(r) },
|
2020-12-16 23:02:15 +01:00
|
|
|
|
{ condition: RdDCombat.isEchecTotal, action: r => this._onAttaqueEchecTotal(r) },
|
2020-12-12 21:58:44 +01:00
|
|
|
|
]
|
2020-12-17 12:29:54 +01:00
|
|
|
|
});
|
2020-12-12 21:58:44 +01:00
|
|
|
|
dialog.render(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
|
_prepareAttaque(competence, arme) {
|
|
|
|
|
let rollData = {
|
|
|
|
|
coupsNonMortels: false,
|
|
|
|
|
competence: competence,
|
2020-12-16 23:02:15 +01:00
|
|
|
|
surprise: this.attacker.getSurprise(),
|
|
|
|
|
surpriseDefenseur: this.defender.getSurprise()
|
2020-12-12 21:58:44 +01:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (this.attacker.isCreature()) {
|
2021-01-01 22:25:32 +01:00
|
|
|
|
RdDItemCompetence.setRollDataCreature(rollData);
|
2020-12-12 21:58:44 +01:00
|
|
|
|
}
|
2020-12-16 23:02:15 +01:00
|
|
|
|
else if (arme) {
|
2020-12-12 21:58:44 +01:00
|
|
|
|
// Usual competence
|
|
|
|
|
rollData.arme = RdDItemArme.armeUneOuDeuxMains(arme, RdDItemCompetence.isArmeUneMain(competence));
|
|
|
|
|
}
|
2020-12-16 23:02:15 +01:00
|
|
|
|
else {
|
|
|
|
|
// sans armes: à mains nues
|
|
|
|
|
rollData.arme = RdDItemArme.mainsNues();
|
|
|
|
|
}
|
2020-12-12 21:58:44 +01:00
|
|
|
|
return rollData;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
|
_onAttaqueParticuliere(rollData) {
|
|
|
|
|
console.log("RdDCombat.onAttaqueParticuliere >>>", rollData);
|
|
|
|
|
// Finesse et Rapidité seulement en mêlée et si la difficulté libre est de -1 minimum
|
2021-01-01 03:25:48 +01:00
|
|
|
|
let message = `
|
|
|
|
|
<h4 class="rdd-roll-part"><strong>Réussite particulière en attaque</strong></h4>
|
|
|
|
|
<br><a class='chat-card-button' id='particuliere-attaque' data-mode='force' data-attackerId='${this.attackerId}'>Attaquer en Force</a>
|
|
|
|
|
`;
|
2020-12-12 21:58:44 +01:00
|
|
|
|
if (rollData.selectedCarac.label == "Mêlée" && rollData.diffLibre < 0) {
|
2021-01-01 03:25:48 +01:00
|
|
|
|
message += `
|
|
|
|
|
<br><a class='chat-card-button' id='particuliere-attaque' data-mode='rapidite' data-attackerId='${this.attackerId}'>Attaquer en Rapidité</a>
|
2021-01-02 04:28:43 +01:00
|
|
|
|
<br><a class='chat-card-button' id='particuliere-attaque' data-mode='finesse' data-attackerId='${this.attackerId}'>Attaquer en Finesse</a>
|
2021-01-01 03:25:48 +01:00
|
|
|
|
`
|
2020-12-12 21:58:44 +01:00
|
|
|
|
}
|
|
|
|
|
game.system.rdd.rollDataHandler[this.attackerId] = rollData;
|
|
|
|
|
// TODO: use a dialog?
|
|
|
|
|
ChatMessage.create({ content: message, whisper: ChatMessage.getWhisperRecipients(this.attacker.name) });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
|
async _onAttaqueNormale(rollData) {
|
|
|
|
|
console.log("RdDCombat.onAttaqueNormale >>>", rollData);
|
2021-01-01 03:25:48 +01:00
|
|
|
|
|
2020-12-16 23:02:15 +01:00
|
|
|
|
rollData.dmg = RdDBonus.dmg(rollData, this.attacker.getBonusDegat(), this.defender.isEntiteCauchemar());
|
2021-01-01 03:25:48 +01:00
|
|
|
|
|
2020-12-12 21:58:44 +01:00
|
|
|
|
// Save rollData for defender
|
|
|
|
|
game.system.rdd.rollDataHandler[this.attackerId] = duplicate(rollData);
|
2021-01-01 03:25:48 +01:00
|
|
|
|
|
|
|
|
|
rollData.show = {
|
2021-01-01 22:25:32 +01:00
|
|
|
|
cible: this.target ? this.defender.data.name : 'la cible',
|
|
|
|
|
isRecul: (rollData.particuliereAttaque == 'force' || rollData.tactique == 'charge')
|
2021-01-01 03:25:48 +01:00
|
|
|
|
}
|
2021-01-02 04:28:43 +01:00
|
|
|
|
await RdDResolutionTable.displayRollData(rollData, this.attacker.name, 'chat-resultat-attaque.html');
|
2021-01-01 03:25:48 +01:00
|
|
|
|
|
2020-12-19 18:02:05 +01:00
|
|
|
|
if (!await this.accorderEntite('avant-defense')) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2021-01-01 03:25:48 +01:00
|
|
|
|
|
2020-12-12 21:58:44 +01:00
|
|
|
|
if (this.target) {
|
2020-12-18 22:15:17 +01:00
|
|
|
|
this._sendMessageDefense(rollData);
|
2020-12-12 21:58:44 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
2020-12-18 22:15:17 +01:00
|
|
|
|
_sendMessageDefense(rollData) {
|
|
|
|
|
console.log("RdDCombat._sendMessageDefense", rollData, " / ", this.attacker, this.target, this.attackerId, rollData.competence.data.categorie);
|
|
|
|
|
|
|
|
|
|
let message = this._buildMessageDefense(rollData);
|
|
|
|
|
// encaisser
|
|
|
|
|
message += this._buildMessageEncaisser(rollData) + "</span>";
|
|
|
|
|
|
|
|
|
|
RdDCombat._sendRollMessage(this.attacker, this.defender, this.defenderTokenId, "msg_defense", message, rollData);
|
|
|
|
|
}
|
2020-12-12 21:58:44 +01:00
|
|
|
|
|
2020-12-26 18:29:03 +01:00
|
|
|
|
/* -------------------------------------------- */
|
2020-12-18 22:15:17 +01:00
|
|
|
|
_buildMessageDefense(rollData) {
|
|
|
|
|
let message = "<strong>" + this.defender.name + "</strong> doit se défendre :<span class='chat-card-button-area'>";
|
2020-12-12 21:58:44 +01:00
|
|
|
|
|
2020-12-16 23:02:15 +01:00
|
|
|
|
if (this.defender.getSurprise() != 'totale') {
|
|
|
|
|
// parades
|
2021-01-02 04:28:43 +01:00
|
|
|
|
for (const arme of this._filterArmesParade(this.defender.data.items, rollData.competence, rollData.arme)) {
|
2020-12-18 22:15:17 +01:00
|
|
|
|
message += "<br><a class='chat-card-button' id='parer-button' data-attackerId='" + this.attackerId + "' data-defenderTokenId='" + this.defenderTokenId + "' data-armeid='" + arme._id + "'>Parer avec " + arme.name + "</a>";
|
2020-12-16 23:02:15 +01:00
|
|
|
|
}
|
2020-12-17 00:23:40 +01:00
|
|
|
|
// corps à corps
|
2021-01-01 22:25:32 +01:00
|
|
|
|
if (rollData.dmg.mortalite != 'mortel' && this.defender.getCompetence("Corps à corps")) {
|
2020-12-18 22:15:17 +01:00
|
|
|
|
message += "<br><a class='chat-card-button' id='parer-button' data-attackerId='" + this.attackerId + "' data-defenderTokenId='" + this.defenderTokenId + "'>Parer à mains nues</a>";
|
2020-12-17 00:23:40 +01:00
|
|
|
|
}
|
2020-12-16 23:02:15 +01:00
|
|
|
|
// esquive
|
2020-12-21 23:34:26 +01:00
|
|
|
|
if (rollData.competence.data.categorie != 'tir') {
|
2020-12-18 22:15:17 +01:00
|
|
|
|
message += "<br><a class='chat-card-button' id='esquiver-button' data-attackerId='" + this.attackerId + "' data-defenderTokenId='" + this.defenderTokenId + "'>Esquiver</a>";
|
2020-12-16 23:02:15 +01:00
|
|
|
|
}
|
2020-12-12 21:58:44 +01:00
|
|
|
|
}
|
2020-12-18 22:15:17 +01:00
|
|
|
|
return message;
|
|
|
|
|
}
|
2020-12-12 21:58:44 +01:00
|
|
|
|
|
2020-12-26 18:29:03 +01:00
|
|
|
|
/* -------------------------------------------- */
|
2020-12-18 22:15:17 +01:00
|
|
|
|
_buildMessageEncaisser(rollData) {
|
|
|
|
|
return "<br><a class='chat-card-button' id='encaisser-button' data-attackerId='" + this.attackerId + "' data-defenderTokenId='" + this.defenderTokenId + "'>Encaisser à " + Misc.toSignedString(rollData.dmg.total) + " !</a>";
|
2020-12-12 21:58:44 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
2021-01-02 04:28:43 +01:00
|
|
|
|
_filterArmesParade(items, competence) {
|
2021-01-03 09:59:30 +01:00
|
|
|
|
let itemsEquipped = items.filter(item => item.data.equipe == true );
|
2021-01-02 04:28:43 +01:00
|
|
|
|
switch (competence.data.categorie) {
|
2020-12-12 21:58:44 +01:00
|
|
|
|
case 'tir':
|
|
|
|
|
case 'lancer':
|
2021-01-03 09:58:07 +01:00
|
|
|
|
return items.filter(item => RdDItemArme.getCategorieParade(itemsEquipped) == 'boucliers')
|
2020-12-12 21:58:44 +01:00
|
|
|
|
default:
|
2021-01-02 04:28:43 +01:00
|
|
|
|
// Le fléau ne peut être paré qu’au bouclier p115
|
|
|
|
|
if (competence.name == "Fléau"){
|
2021-01-03 09:58:07 +01:00
|
|
|
|
return items.filter(item => RdDItemArme.getCategorieParade(itemsEquipped) == 'boucliers')
|
2021-01-02 04:28:43 +01:00
|
|
|
|
}
|
2021-01-03 09:58:07 +01:00
|
|
|
|
return items.filter(item => RdDItemArme.getCategorieParade(itemsEquipped));
|
2020-12-12 21:58:44 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
2020-12-16 09:07:00 +01:00
|
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
2020-12-17 12:29:54 +01:00
|
|
|
|
async _onAttaqueEchecTotal(rollData) {
|
2021-01-02 04:28:43 +01:00
|
|
|
|
// TODO: remplacer par un chat message pour laisser le joueur choisir un appel à la chance _avant_
|
|
|
|
|
// https://gitlab.com/LeRatierBretonnien/foundryvtt-reve-de-dragon/-/issues/85
|
2020-12-12 21:58:44 +01:00
|
|
|
|
console.log("RdDCombat.onEchecTotal >>>", rollData);
|
|
|
|
|
let chatOptions = {
|
2020-12-17 12:29:54 +01:00
|
|
|
|
content: "<strong>Echec total à l'attaque!</strong> "
|
2021-01-01 22:25:32 +01:00
|
|
|
|
+ await RdDRollTables.getMaladresse({ arme: rollData.arme && rollData.arme.data.categorie_parade != 'sans-armes' })
|
2020-12-12 21:58:44 +01:00
|
|
|
|
}
|
|
|
|
|
ChatUtility.chatWithRollMode(chatOptions, this.attacker.name)
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-02 04:28:43 +01:00
|
|
|
|
|
2020-12-16 09:07:00 +01:00
|
|
|
|
/* -------------------------------------------- */
|
2021-01-02 04:28:43 +01:00
|
|
|
|
async _onAttaqueEchec(rollData) {
|
2020-12-12 21:58:44 +01:00
|
|
|
|
console.log("RdDCombat.onAttaqueEchec >>>", rollData);
|
2021-01-02 04:28:43 +01:00
|
|
|
|
await RdDResolutionTable.displayRollData(rollData, this.attacker.name, 'chat-resultat-attaque.html');
|
|
|
|
|
|
2020-12-12 21:58:44 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
|
async choixParticuliere(rollData, choix) {
|
|
|
|
|
console.log("RdDCombat.choixParticuliere >>>", rollData, choix);
|
|
|
|
|
rollData.particuliereAttaque = choix;
|
|
|
|
|
await this._onAttaqueNormale(rollData);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
|
async parade(attackerRoll, armeParadeId) {
|
2021-01-02 04:28:43 +01:00
|
|
|
|
let arme = RdDItemArme.getArmeData(armeParadeId ? this.defender.getOwnedItem(armeParadeId) : null);
|
2020-12-12 21:58:44 +01:00
|
|
|
|
|
|
|
|
|
console.log("RdDCombat.parade >>>", attackerRoll, armeParadeId, arme);
|
|
|
|
|
|
|
|
|
|
let rollData = this._prepareParade(attackerRoll, arme);
|
|
|
|
|
|
|
|
|
|
const dialog = await RdDRoll.create(this.defender, rollData,
|
2020-12-17 12:29:54 +01:00
|
|
|
|
{
|
|
|
|
|
html: 'systems/foundryvtt-reve-de-dragon/templates/dialog-competence.html',
|
|
|
|
|
options: { height: 540 }
|
|
|
|
|
}, {
|
2020-12-12 21:58:44 +01:00
|
|
|
|
name: 'jet-parade',
|
|
|
|
|
label: 'Parade: ' + (arme ? arme.name : rollData.competence.name),
|
|
|
|
|
callbacks: [
|
|
|
|
|
this.defender.createCallbackExperience(),
|
2020-12-16 23:02:15 +01:00
|
|
|
|
{ condition: RdDCombat.isReussite, action: r => this._onParadeNormale(r) },
|
2020-12-17 01:08:14 +01:00
|
|
|
|
{ condition: RdDCombat.isParticuliere, action: r => this._onParadeParticuliere(r) },
|
|
|
|
|
{ condition: RdDCombat.isEchec, action: r => this._onParadeEchec(r) },
|
2020-12-16 23:02:15 +01:00
|
|
|
|
{ condition: RdDCombat.isEchecTotal, action: r => this._onParadeEchecTotal(r) },
|
2020-12-12 21:58:44 +01:00
|
|
|
|
]
|
2020-12-17 12:29:54 +01:00
|
|
|
|
});
|
2020-12-12 21:58:44 +01:00
|
|
|
|
dialog.render(true);
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-17 00:23:40 +01:00
|
|
|
|
_prepareParade(attackerRoll, armeParade) {
|
2020-12-12 21:58:44 +01:00
|
|
|
|
const isCreature = this.defender.isCreature();
|
2021-01-01 22:25:32 +01:00
|
|
|
|
const compName = armeParade.data.competence;
|
2020-12-12 21:58:44 +01:00
|
|
|
|
const armeAttaque = attackerRoll.arme;
|
2020-12-17 12:29:54 +01:00
|
|
|
|
|
2020-12-12 21:58:44 +01:00
|
|
|
|
let rollData = {
|
|
|
|
|
forceValue: this.defender.getForceValue(),
|
|
|
|
|
diffLibre: attackerRoll.diffLibre,
|
|
|
|
|
attackerRoll: attackerRoll,
|
2021-01-02 04:28:43 +01:00
|
|
|
|
competence: this.defender.getCompetence(compName),
|
2020-12-17 00:23:40 +01:00
|
|
|
|
arme: armeParade,
|
2020-12-15 02:20:24 +01:00
|
|
|
|
surprise: this.defender.getSurprise(),
|
2021-01-02 04:28:43 +01:00
|
|
|
|
needParadeSignificative: this.needParadeSignificative(attackerRoll, armeParade),
|
|
|
|
|
diviseur: this._getDiviseurSignificative(attackerRoll, armeParade),
|
|
|
|
|
needResist: this._needArmeResist(armeAttaque, armeParade),
|
|
|
|
|
carac: this.defender.data.data.carac,
|
|
|
|
|
show: {}
|
2020-12-12 21:58:44 +01:00
|
|
|
|
};
|
|
|
|
|
if (isCreature) {
|
2021-01-01 22:25:32 +01:00
|
|
|
|
RdDItemCompetence.setRollDataCreature(rollData);
|
2020-12-12 21:58:44 +01:00
|
|
|
|
}
|
|
|
|
|
return rollData;
|
|
|
|
|
}
|
2020-12-15 02:20:24 +01:00
|
|
|
|
|
2020-12-12 21:58:44 +01:00
|
|
|
|
/* -------------------------------------------- */
|
2021-01-02 04:28:43 +01:00
|
|
|
|
_getDiviseurSignificative(attackerRoll, armeParade = undefined) {
|
|
|
|
|
let facteurSign = this.defender.getDiviseurSignificative();
|
|
|
|
|
if (RdDCombat.isAttaqueFinesse(attackerRoll)) {
|
|
|
|
|
facteurSign *= 2;
|
|
|
|
|
}
|
|
|
|
|
if (this.needParadeSignificative(attackerRoll, armeParade)) {
|
|
|
|
|
facteurSign *= 2;
|
|
|
|
|
}
|
|
|
|
|
return Math.min(4, facteurSign);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static isAttaqueFinesse(attackerRoll) {
|
|
|
|
|
return attackerRoll && attackerRoll.particuliereAttaque == 'finesse';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
needParadeSignificative(attackerRoll, armeParade) {
|
|
|
|
|
return attackerRoll.arme && armeParade &&
|
|
|
|
|
RdDItemArme.needParadeSignificative(attackerRoll.arme, armeParade);
|
2020-12-12 21:58:44 +01:00
|
|
|
|
}
|
2020-12-15 02:20:24 +01:00
|
|
|
|
|
2020-12-12 21:58:44 +01:00
|
|
|
|
/* -------------------------------------------- */
|
2021-01-02 04:28:43 +01:00
|
|
|
|
_needArmeResist(armeAttaque, armeParade) {
|
2021-01-01 22:25:32 +01:00
|
|
|
|
// Epées parant une arme de bois (cf. page 115 ), une résistance est nécessaire
|
|
|
|
|
let attCategory = RdDItemArme.getCategorieParade(armeAttaque);
|
|
|
|
|
let defCategory = RdDItemArme.getCategorieParade(armeParade);
|
2020-12-12 21:58:44 +01:00
|
|
|
|
|
2021-01-01 22:25:32 +01:00
|
|
|
|
return attCategory.match(/epees-/) && defCategory.match(/(haches|lances)/);
|
2020-12-12 21:58:44 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
|
_onParadeParticuliere(rollData) {
|
|
|
|
|
console.log("RdDCombat._onParadeParticuliere >>>", rollData);
|
|
|
|
|
if (!rollData.attackerRoll.isPart) {
|
|
|
|
|
// TODO: attaquant doit jouer résistance et peut être désarmé p132
|
2021-01-02 04:28:43 +01:00
|
|
|
|
ChatUtility.chatWithRollMode({
|
|
|
|
|
content: `L'attaquant doit jouer résistance et peut être désarmé (p132)`
|
|
|
|
|
}, this.defender.name)
|
2020-12-12 21:58:44 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
|
async _onParadeNormale(rollData) {
|
|
|
|
|
console.log("RdDCombat._onParadeNormale >>>", rollData);
|
2020-12-17 12:29:54 +01:00
|
|
|
|
|
2021-01-02 04:28:43 +01:00
|
|
|
|
await this.computeRecul(rollData);
|
2020-12-17 01:08:14 +01:00
|
|
|
|
await this.computeDeteriorationArme(rollData);
|
2021-01-02 04:28:43 +01:00
|
|
|
|
|
|
|
|
|
await RdDResolutionTable.displayRollData(rollData, this.defender.name, 'chat-resultat-parade.html');
|
|
|
|
|
|
2020-12-12 21:58:44 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
2020-12-17 12:29:54 +01:00
|
|
|
|
async _onParadeEchecTotal(rollData) {
|
2021-01-02 04:28:43 +01:00
|
|
|
|
// TODO: remplacer par un chat message pour laisser le joueur choisir un appel à la chance _avant_
|
|
|
|
|
// https://gitlab.com/LeRatierBretonnien/foundryvtt-reve-de-dragon/-/issues/85
|
2020-12-12 21:58:44 +01:00
|
|
|
|
console.log("RdDCombat._onParadeEchecTotal >>>", rollData);
|
|
|
|
|
let chatOptions = {
|
2020-12-17 12:29:54 +01:00
|
|
|
|
content: "<strong>Echec total à la parade!</strong> "
|
2021-01-01 22:25:32 +01:00
|
|
|
|
+ await RdDRollTables.getMaladresse({ arme: rollData.arme && rollData.arme.data.categorie_parade != 'sans-armes' })
|
2020-12-12 21:58:44 +01:00
|
|
|
|
}
|
|
|
|
|
ChatUtility.chatWithRollMode(chatOptions, this.defender.name)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
|
async _onParadeEchec(rollData) {
|
|
|
|
|
console.log("RdDCombat._onParadeEchec >>>", rollData);
|
|
|
|
|
|
2021-01-02 04:28:43 +01:00
|
|
|
|
await this.computeRecul(rollData);
|
2020-12-12 21:58:44 +01:00
|
|
|
|
|
2021-01-02 04:28:43 +01:00
|
|
|
|
await RdDResolutionTable.displayRollData(rollData, this.defender.name, 'chat-resultat-parade.html');
|
2020-12-12 21:58:44 +01:00
|
|
|
|
|
2020-12-18 22:15:17 +01:00
|
|
|
|
this._sendMessageEncaisser(rollData.attackerRoll);
|
2020-12-12 21:58:44 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
|
async esquive(attackerRoll) {
|
|
|
|
|
let esquive = this.defender.getCompetence("esquive");
|
|
|
|
|
if (esquive == undefined) {
|
|
|
|
|
ui.notifications.error(this.defender.name + " n'a pas de compétence 'esquive'");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
console.log("RdDCombat.esquive >>>", attackerRoll, esquive);
|
|
|
|
|
let rollData = this._prepareEsquive(attackerRoll, esquive);
|
|
|
|
|
|
|
|
|
|
const dialog = await RdDRoll.create(this.defender, rollData,
|
|
|
|
|
{ html: 'systems/foundryvtt-reve-de-dragon/templates/dialog-competence.html' }, {
|
|
|
|
|
name: 'jet-esquive',
|
|
|
|
|
label: 'Esquiver',
|
|
|
|
|
callbacks: [
|
|
|
|
|
this.defender.createCallbackExperience(),
|
2020-12-16 23:02:15 +01:00
|
|
|
|
{ condition: RdDCombat.isReussite, action: r => this._onEsquiveNormale(r) },
|
2020-12-17 01:08:14 +01:00
|
|
|
|
{ condition: RdDCombat.isParticuliere, action: r => this._onEsquiveParticuliere(r) },
|
2020-12-16 23:02:15 +01:00
|
|
|
|
{ condition: RdDCombat.isEchec, action: r => this._onEsquiveEchec(r) },
|
2020-12-17 01:08:14 +01:00
|
|
|
|
{ condition: RdDCombat.isEchecTotal, action: r => this._onEsquiveEchecTotal(r) },
|
2020-12-12 21:58:44 +01:00
|
|
|
|
]
|
|
|
|
|
});
|
|
|
|
|
dialog.render(true);
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-26 18:29:03 +01:00
|
|
|
|
/* -------------------------------------------- */
|
2020-12-12 21:58:44 +01:00
|
|
|
|
_prepareEsquive(attackerRoll, competence) {
|
|
|
|
|
let rollData = {
|
|
|
|
|
forceValue: this.defender.getForceValue(),
|
|
|
|
|
diffLibre: attackerRoll.diffLibre,
|
|
|
|
|
attackerRoll: attackerRoll,
|
|
|
|
|
competence: competence,
|
2020-12-15 02:20:24 +01:00
|
|
|
|
surprise: this.defender.getSurprise(),
|
2020-12-16 23:02:15 +01:00
|
|
|
|
surpriseDefenseur: this.defender.getSurprise(),
|
2021-01-02 04:28:43 +01:00
|
|
|
|
diviseur: this._getDiviseurSignificative(attackerRoll),
|
|
|
|
|
carac: this.defender.data.data.carac,
|
|
|
|
|
show: {}
|
2020-12-12 21:58:44 +01:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (this.defender.isCreature()) {
|
2021-01-01 22:25:32 +01:00
|
|
|
|
RdDItemCompetence.setRollDataCreature(rollData);
|
2020-12-12 21:58:44 +01:00
|
|
|
|
}
|
|
|
|
|
return rollData;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
|
_onEsquiveParticuliere(rollData) {
|
|
|
|
|
console.log("RdDCombat._onEsquiveParticuliere >>>", rollData);
|
|
|
|
|
let chatOptions = {
|
2021-01-02 04:28:43 +01:00
|
|
|
|
content: "<strong>Vous pouvez esquiver une deuxième esquive!</strong>"
|
2020-12-12 21:58:44 +01:00
|
|
|
|
}
|
|
|
|
|
ChatUtility.chatWithRollMode(chatOptions, this.defender.name)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
2021-01-02 04:28:43 +01:00
|
|
|
|
async _onEsquiveNormale(rollData) {
|
2020-12-12 21:58:44 +01:00
|
|
|
|
console.log("RdDCombat._onEsquiveNormal >>>", rollData);
|
2021-01-02 04:28:43 +01:00
|
|
|
|
|
|
|
|
|
await RdDResolutionTable.displayRollData(rollData, this.defender.name, 'chat-resultat-esquive.html');
|
2020-12-12 21:58:44 +01:00
|
|
|
|
}
|
2020-12-17 12:29:54 +01:00
|
|
|
|
|
2020-12-12 21:58:44 +01:00
|
|
|
|
/* -------------------------------------------- */
|
2020-12-17 12:29:54 +01:00
|
|
|
|
async _onEsquiveEchecTotal(rollData) {
|
2021-01-02 04:28:43 +01:00
|
|
|
|
// TODO: remplacer par un chat message pour laisser le joueur choisir un appel à la chance _avant_
|
|
|
|
|
// https://gitlab.com/LeRatierBretonnien/foundryvtt-reve-de-dragon/-/issues/85
|
2020-12-12 21:58:44 +01:00
|
|
|
|
console.log("RdDCombat._onEsquiveEchecTotal >>>", rollData);
|
|
|
|
|
let chatOptions = {
|
2020-12-17 12:29:54 +01:00
|
|
|
|
content: "<strong>Echec total à l'esquive'!</strong> "
|
|
|
|
|
+ await RdDRollTables.getMaladresse({ arme: false })
|
2020-12-12 21:58:44 +01:00
|
|
|
|
}
|
|
|
|
|
ChatUtility.chatWithRollMode(chatOptions, this.defender.name)
|
|
|
|
|
}
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
|
async _onEsquiveEchec(rollData) {
|
|
|
|
|
console.log("RdDCombat._onEsquiveEchec >>>", rollData);
|
|
|
|
|
|
2021-01-02 04:28:43 +01:00
|
|
|
|
await this.computeRecul(rollData);
|
2020-12-12 21:58:44 +01:00
|
|
|
|
|
2021-01-02 04:28:43 +01:00
|
|
|
|
await RdDResolutionTable.displayRollData(rollData, this.defender.name, 'chat-resultat-esquive.html');
|
2020-12-12 21:58:44 +01:00
|
|
|
|
|
2020-12-18 22:15:17 +01:00
|
|
|
|
this._sendMessageEncaisser(rollData.attackerRoll);
|
2020-12-12 21:58:44 +01:00
|
|
|
|
}
|
2021-01-01 03:25:48 +01:00
|
|
|
|
|
2020-12-17 00:44:32 +01:00
|
|
|
|
/* -------------------------------------------- */
|
2020-12-17 12:29:54 +01:00
|
|
|
|
async computeDeteriorationArme(rollData) {
|
2020-12-17 00:44:32 +01:00
|
|
|
|
const attackerRoll = rollData.attackerRoll;
|
2021-01-02 04:28:43 +01:00
|
|
|
|
// Est-ce une parade normale?
|
|
|
|
|
if (rollData.arme && attackerRoll && !rollData.rolled.isPart) {
|
|
|
|
|
// Est-ce que l'attaque est une particulière en force ou une charge
|
|
|
|
|
if (rollData.needResist || attackerRoll.particuliereAttaque == 'force' || attackerRoll.tactique == 'charge') {
|
|
|
|
|
|
|
|
|
|
rollData.show = rollData.show || {}
|
|
|
|
|
|
2020-12-17 00:44:32 +01:00
|
|
|
|
const dmg = attackerRoll.dmg.dmgArme + attackerRoll.dmg.dmgActor;
|
|
|
|
|
let resistance = Misc.toInt(rollData.arme.data.resistance);
|
|
|
|
|
let msg = "";
|
|
|
|
|
// Jet de résistance de l'arme de parade (p.132)
|
|
|
|
|
let resistRoll = await RdDResolutionTable.rollData({
|
|
|
|
|
caracValue: resistance,
|
|
|
|
|
finalLevel: - dmg,
|
2020-12-17 12:29:54 +01:00
|
|
|
|
showDice: false
|
|
|
|
|
});
|
2021-01-02 04:28:43 +01:00
|
|
|
|
if (resistRoll.rolled.isSuccess) { // Perte de résistance
|
|
|
|
|
rollData.show.deteriorationArme = 'resiste';
|
2020-12-17 00:44:32 +01:00
|
|
|
|
} else {
|
|
|
|
|
resistance -= dmg;
|
2020-12-17 12:29:54 +01:00
|
|
|
|
if (resistance <= 0) {
|
2020-12-17 00:44:32 +01:00
|
|
|
|
this.defender.deleteEmbeddedEntity("OwnedItem", rollData.arme._id);
|
2021-01-02 04:28:43 +01:00
|
|
|
|
rollData.show.deteriorationArme = 'brise';
|
2020-12-17 00:44:32 +01:00
|
|
|
|
} else {
|
2020-12-17 12:29:54 +01:00
|
|
|
|
this.defender.updateEmbeddedEntity("OwnedItem", { _id: rollData.arme._id, 'data.resistance': resistance });
|
2021-01-02 04:28:43 +01:00
|
|
|
|
rollData.show.deteriorationArme = 'perte';
|
|
|
|
|
rollData.show.perteResistance = dmg;
|
2020-12-17 00:44:32 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
2021-01-02 04:28:43 +01:00
|
|
|
|
// Si l'arme de parade n'est pas un bouclier, jet de désarmement (p.132)
|
|
|
|
|
if (resistance > 0 && !RdDItemArme.getCategorieParade(rollData.arme) == 'boucliers') {
|
2020-12-17 00:44:32 +01:00
|
|
|
|
let desarme = await RdDResolutionTable.rollData({
|
|
|
|
|
caracValue: this.defender.data.data.carac.force.value,
|
|
|
|
|
finalLevel: Misc.toInt(rollData.competence.data.niveau) - dmg,
|
2020-12-17 12:29:54 +01:00
|
|
|
|
showDice: false
|
|
|
|
|
});
|
2021-01-02 04:28:43 +01:00
|
|
|
|
rollData.show.desarme = desarme.rolled.isEchec;
|
|
|
|
|
if (desarme.rolled.isEchec) {
|
|
|
|
|
rollData.show.desarme = true;
|
2020-12-17 00:44:32 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/* -------------------------------------------- */
|
2021-01-02 04:28:43 +01:00
|
|
|
|
async computeRecul(rollData) { // Calcul du recul (p. 132)
|
|
|
|
|
const attaque = rollData.attackerRoll;
|
|
|
|
|
if (this._isAttaqueCauseRecul(attaque)) {
|
2020-12-17 00:44:32 +01:00
|
|
|
|
|
2021-01-02 04:28:43 +01:00
|
|
|
|
let impactRecul = this._computeImpactRecul(attaque);
|
|
|
|
|
const agilite = this.defender.data.data.carac.agilite.value;
|
|
|
|
|
|
|
|
|
|
let rollRecul = await RdDResolutionTable.rollData({ caracValue: 10, finalLevel: impactRecul, showDice: false });
|
|
|
|
|
|
|
|
|
|
if (rollRecul.isSuccess) {
|
|
|
|
|
rollData.show.recul = 'encaisse';
|
|
|
|
|
} else if (rollRecul.isETotal) {
|
|
|
|
|
rollData.show.recul = 'chute';
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
let chute = await RdDResolutionTable.rollData({ caracValue: agilite, finalLevel: impactRecul, showDice: false });
|
|
|
|
|
rollData.show.recul = (chute.isSuccess)
|
|
|
|
|
? 'recul'
|
|
|
|
|
: 'chute';
|
2020-12-17 00:44:32 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-02 04:28:43 +01:00
|
|
|
|
_isAttaqueCauseRecul(attaque) {
|
|
|
|
|
return attaque.particuliereAttaque == 'force' || attaque.tactique == 'charge';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_computeImpactRecul(attaque) {
|
|
|
|
|
return Misc.toInt(this.defender.data.data.carac.taille.value) - (attaque.forceValue + attaque.arme.data.dommagesReels);
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-12 21:58:44 +01:00
|
|
|
|
/* -------------------------------------------- */
|
2021-01-01 03:25:48 +01:00
|
|
|
|
_sendMessageEncaisser(rollData) {
|
2020-12-18 22:15:17 +01:00
|
|
|
|
let message = "<strong>" + this.defender.name + "</strong> doit:" + this._buildMessageEncaisser(rollData);
|
|
|
|
|
RdDCombat._sendRollMessage(this.attacker, this.defender, this.defenderTokenId, "msg_encaisser", message, rollData);
|
2020-12-12 21:58:44 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
|
encaisser(attackerRoll, defenderTokenId) {
|
|
|
|
|
defenderTokenId = defenderTokenId || this.defenderTokenId;
|
|
|
|
|
console.log("RdDCombat.encaisser >>>", attackerRoll, defenderTokenId);
|
|
|
|
|
|
|
|
|
|
if (game.user.isGM) { // Current user is the GM -> direct access
|
|
|
|
|
attackerRoll.attackerId = this.attackerId;
|
|
|
|
|
attackerRoll.defenderTokenId = defenderTokenId;
|
|
|
|
|
this.defender.encaisserDommages(attackerRoll, this.attacker);
|
|
|
|
|
} else { // Emit message for GM
|
|
|
|
|
game.socket.emit("system.foundryvtt-reve-de-dragon", {
|
|
|
|
|
msg: "msg_encaisser",
|
|
|
|
|
data: { attackerId: this.attackerId, defenderTokenId: defenderTokenId }
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
|
/* retourne true si on peut continuer, false si on ne peut pas continuer */
|
|
|
|
|
async accorderEntite(when = 'avant-encaissement') {
|
|
|
|
|
if (when != game.settings.get("foundryvtt-reve-de-dragon", "accorder-entite-cauchemar")
|
|
|
|
|
|| this.defender == undefined
|
|
|
|
|
|| !this.defender.isEntiteCauchemar()
|
|
|
|
|
|| this.defender.isEntiteCauchemarAccordee(this.attacker)) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let rolled = await RdDResolutionTable.roll(this.attacker.getReveActuel(), - Number(this.defender.data.data.carac.niveau.value));
|
|
|
|
|
|
|
|
|
|
let message = {
|
|
|
|
|
content: "Jet de points actuels de rêve à " + rolled.finalLevel + RdDResolutionTable.explain(rolled) + "<br>",
|
|
|
|
|
whisper: ChatMessage.getWhisperRecipients(this.attacker.name)
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (rolled.isSuccess) {
|
|
|
|
|
await this.defender.setEntiteReveAccordee(this.attacker);
|
|
|
|
|
message.content += this.attacker.name + " s'est accordé avec " + this.defender.name;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
message.content += this.attacker.name + " n'est pas accordé avec " + this.defender.name;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ChatMessage.create(message);
|
|
|
|
|
return rolled.isSuccess;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|