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";
|
2021-01-13 23:47:12 +01:00
|
|
|
|
import { RdDItemCompetenceCreature } from "./item-competencecreature.js";
|
2020-12-12 21:58:44 +01:00
|
|
|
|
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 {
|
|
|
|
|
|
2021-01-10 00:30:37 +01:00
|
|
|
|
static init() {
|
2021-01-25 08:48:03 +01:00
|
|
|
|
RdDCombatSettings.onInit();
|
2021-01-10 00:30:37 +01:00
|
|
|
|
this.initStorePasseArmes();
|
|
|
|
|
Hooks.on("updateCombat", (combat, data) => { RdDCombat.onUpdateCombat(combat, data) });
|
|
|
|
|
Hooks.on("preDeleteCombat", (combat, options) => { RdDCombat.onPreDeleteCombat(combat, options); });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
|
static initStorePasseArmes() {
|
|
|
|
|
game.system.rdd.combatStore = {
|
|
|
|
|
attaques: {},
|
|
|
|
|
defenses: {}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
|
static onSocketMessage(sockmsg) {
|
|
|
|
|
switch (sockmsg.msg) {
|
|
|
|
|
case "msg_encaisser":
|
2021-01-15 19:10:50 +01:00
|
|
|
|
return RdDCombat.onMsgEncaisser(sockmsg.data);
|
2021-01-10 00:30:37 +01:00
|
|
|
|
case "msg_defense":
|
2021-01-15 19:10:50 +01:00
|
|
|
|
return RdDCombat.onMsgDefense(sockmsg.data);
|
2021-01-10 00:30:37 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
|
static onUpdateCombat(combat, data) {
|
|
|
|
|
if (combat.data.round != 0 && combat.turns && combat.data.active) {
|
|
|
|
|
RdDCombat.combatNouveauRound(combat);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
|
static onPreDeleteCombat(combat, options) {
|
|
|
|
|
if (game.user.isGM) {
|
2021-01-20 00:44:19 +01:00
|
|
|
|
ChatUtility.removeChatMessageContaining(`<div data-combatid="${combat.id}" data-combatmessage="actor-turn-summary">`)
|
2021-01-10 00:30:37 +01:00
|
|
|
|
/*
|
|
|
|
|
* TODO: support de plusieurs combats parallèles
|
|
|
|
|
* il faudrait avoir un id de combat en plus de celui de passe d'armes
|
|
|
|
|
*/
|
|
|
|
|
for (const key in game.system.rdd.combatStore.attaques) {
|
|
|
|
|
const attackerRoll = game.system.rdd.combatStore.attaques[key];
|
2021-01-20 00:44:19 +01:00
|
|
|
|
ChatUtility.removeChatMessageContaining(`<div data-passearme="${attackerRoll.passeArme}">`);
|
2021-01-10 00:30:37 +01:00
|
|
|
|
}
|
|
|
|
|
for (const key in game.system.rdd.combatStore.defenses) {
|
|
|
|
|
const defenderRoll = game.system.rdd.combatStore.defenses[key];
|
2021-01-20 00:44:19 +01:00
|
|
|
|
ChatUtility.removeChatMessageContaining(`<div data-passearme="${defenderRoll.passeArme}">`);
|
2021-01-10 00:30:37 +01:00
|
|
|
|
}
|
|
|
|
|
RdDCombat.initStorePasseArmes();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
|
static combatNouveauRound(combat) {
|
|
|
|
|
let turn = combat.turns.find(t => t.tokenId == combat.current.tokenId);
|
|
|
|
|
if (game.user.isGM) {
|
|
|
|
|
// seul le GM notifie le status
|
|
|
|
|
this.displayActorCombatStatus(combat, turn.actor);
|
|
|
|
|
// TODO Playaudio for player??
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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-05 18:43:13 +01:00
|
|
|
|
ui.notifications.warn((game.user.targets?.size ?? 0) > 1
|
2021-01-02 04:28:43 +01:00
|
|
|
|
? "Vous devez choisir <strong>une seule</strong> cible à attaquer!"
|
|
|
|
|
: "Vous devez choisir une cible à attaquer!");
|
2020-12-12 21:58:44 +01:00
|
|
|
|
}
|
2021-01-04 14:10:21 +01:00
|
|
|
|
const defender = target?.actor;
|
|
|
|
|
const defenderTokenId = target?.data._id;
|
2020-12-18 22:15:17 +01:00
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-15 19:10:50 +01:00
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
|
static _storeAttaque(attackerId, attackerRoll) {
|
|
|
|
|
game.system.rdd.combatStore.attaques[attackerId] = duplicate(attackerRoll);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
|
static _getAttaque(attackerId) {
|
|
|
|
|
return game.system.rdd.combatStore.attaques[attackerId];
|
2021-01-19 22:31:32 +01:00
|
|
|
|
}
|
|
|
|
|
|
2021-01-15 19:10:50 +01:00
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
|
static _deleteAttaque(attackerId) {
|
|
|
|
|
delete game.system.rdd.combatStore.attaques[attackerId];
|
2021-01-19 22:31:32 +01:00
|
|
|
|
}
|
2021-01-15 19:10:50 +01:00
|
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
|
static _storeDefense(defenderRoll) {
|
|
|
|
|
game.system.rdd.combatStore.defenses[defenderRoll.passeArme] = duplicate(defenderRoll);
|
2021-01-19 22:31:32 +01:00
|
|
|
|
}
|
2021-01-15 19:10:50 +01:00
|
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
|
static _getDefense(passeArme) {
|
|
|
|
|
return game.system.rdd.combatStore.defenses[passeArme];
|
2021-01-19 22:31:32 +01:00
|
|
|
|
}
|
|
|
|
|
|
2021-01-15 19:10:50 +01:00
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
|
static _deleteDefense(passeArme) {
|
2021-01-19 19:58:19 +01:00
|
|
|
|
delete game.system.rdd.combatStore.defenses[passeArme];
|
2021-01-19 22:31:32 +01:00
|
|
|
|
}
|
2021-01-15 19:10:50 +01:00
|
|
|
|
|
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
|
|
|
|
/* -------------------------------------------- */
|
2021-01-19 22:31:32 +01:00
|
|
|
|
static createForAttackerAndDefender(attackerId, defenderTokenId) {
|
|
|
|
|
const attacker = game.actors.get(attackerId);
|
|
|
|
|
if (defenderTokenId) {
|
|
|
|
|
const defenderToken = canvas.tokens.get(defenderTokenId);
|
|
|
|
|
const defender = defenderToken.actor;
|
2020-12-12 21:58:44 +01:00
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
2021-01-10 00:30:37 +01:00
|
|
|
|
/* -------------------------------------------- */
|
2021-01-15 19:10:50 +01:00
|
|
|
|
static onMsgEncaisser(data) {
|
|
|
|
|
let attackerRoll = RdDCombat._getAttaque(data.attackerId); // Retrieve the rolldata from the store
|
|
|
|
|
|
|
|
|
|
if (game.user.id === data.gmId) { // Seul le GM effectue l'encaissement sur la fiche
|
|
|
|
|
let attacker = data.attackerId ? game.actors.get(data.attackerId) : null;
|
|
|
|
|
let defender = canvas.tokens.get(data.defenderTokenId).actor;
|
|
|
|
|
|
|
|
|
|
defender.encaisserDommages(attackerRoll, attacker);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RdDCombat._deleteDefense(attackerRoll.passeArme);
|
|
|
|
|
RdDCombat._deleteAttaque(data.attackerId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
2021-01-19 22:31:32 +01:00
|
|
|
|
static onMsgDefense(msg) {
|
|
|
|
|
let defenderToken = canvas.tokens.get(msg.defenderTokenId);
|
2021-01-10 00:30:37 +01:00
|
|
|
|
if (defenderToken) {
|
2021-01-15 19:10:50 +01:00
|
|
|
|
if (!game.user.isGM && !game.user.character) { // vérification / sanity check
|
2021-01-10 00:30:37 +01:00
|
|
|
|
ui.notifications.error("Le joueur " + game.user.name + " n'est connecté à aucun personnage. Impossible de continuer.");
|
|
|
|
|
return;
|
|
|
|
|
}
|
2021-01-19 22:31:32 +01:00
|
|
|
|
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);
|
2021-01-15 19:10:50 +01:00
|
|
|
|
RdDCombat._storeDefense(defenderRoll);
|
2021-01-20 00:44:19 +01:00
|
|
|
|
rddCombat.removeChatMessageActionsPasseArme(defenderRoll.passeArme);
|
2021-01-19 22:31:32 +01:00
|
|
|
|
rddCombat._chatMessageDefense(msg.paramChatDefense);
|
2021-01-10 00:30:37 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-03 15:40:48 +01:00
|
|
|
|
/* -------------------------------------------- */
|
2021-01-05 18:43:13 +01:00
|
|
|
|
static _callJetDeVie(event) {
|
2021-01-03 15:40:48 +01:00
|
|
|
|
let actorId = event.currentTarget.attributes['data-actorId'].value;
|
|
|
|
|
let actor = game.actors.get(actorId);
|
|
|
|
|
actor.jetVie();
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-12 21:58:44 +01:00
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
|
static registerChatCallbacks(html) {
|
2021-01-07 00:32:22 +01:00
|
|
|
|
for (let button of [
|
|
|
|
|
'#parer-button',
|
|
|
|
|
'#esquiver-button',
|
|
|
|
|
'#particuliere-attaque',
|
|
|
|
|
'#encaisser-button',
|
|
|
|
|
'#appel-chance-defense',
|
|
|
|
|
'#appel-destinee-defense',
|
2021-01-07 01:54:38 +01:00
|
|
|
|
'#appel-chance-attaque',
|
|
|
|
|
'#appel-destinee-attaque',
|
|
|
|
|
'#echec-total-attaque',
|
2021-01-07 00:32:22 +01:00
|
|
|
|
]) {
|
2020-12-12 21:58:44 +01:00
|
|
|
|
html.on("click", button, event => {
|
2021-01-19 22:31:32 +01:00
|
|
|
|
const rddCombat = RdDCombat.createForAttackerAndDefender(
|
|
|
|
|
event.currentTarget.attributes['data-attackerId']?.value,
|
|
|
|
|
event.currentTarget.attributes['data-defenderTokenId']?.value);
|
|
|
|
|
|
|
|
|
|
rddCombat.onEvent(button, event);
|
2020-12-12 21:58:44 +01:00
|
|
|
|
event.preventDefault();
|
|
|
|
|
});
|
|
|
|
|
}
|
2021-01-03 15:40:48 +01:00
|
|
|
|
html.on("click", '#chat-jet-vie', event => {
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
RdDCombat._callJetDeVie(event);
|
2021-01-05 18:43:13 +01:00
|
|
|
|
});
|
2021-01-03 15:40:48 +01:00
|
|
|
|
|
2020-12-12 21:58:44 +01:00
|
|
|
|
}
|
|
|
|
|
|
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) {
|
2021-01-15 19:10:50 +01:00
|
|
|
|
const attackerRoll = RdDCombat._getAttaque(this.attackerId);
|
2021-01-07 00:32:22 +01:00
|
|
|
|
if (!attackerRoll) {
|
2020-12-15 18:15:03 +01:00
|
|
|
|
ui.notifications.warn("Action automatisée impossible, le jet de l'attaquant a été perdu (suite à un raffraichissement?)")
|
|
|
|
|
return;
|
|
|
|
|
}
|
2021-01-15 19:10:50 +01:00
|
|
|
|
const defenderRoll = game.system.rdd.combatStore.defenses[attackerRoll.passeArme];
|
2021-01-13 03:11:03 +01:00
|
|
|
|
const defenderTokenId = event.currentTarget.attributes['data-defenderTokenId']?.value;
|
2021-01-07 00:32:22 +01:00
|
|
|
|
|
2021-01-07 01:54:38 +01:00
|
|
|
|
const armeParadeId = event.currentTarget.attributes['data-armeid']?.value;
|
2021-01-07 00:32:22 +01:00
|
|
|
|
|
2020-12-12 21:58:44 +01:00
|
|
|
|
switch (button) {
|
2021-01-07 00:32:22 +01:00
|
|
|
|
case '#particuliere-attaque': return await this.choixParticuliere(attackerRoll, event.currentTarget.attributes['data-mode'].value);
|
2021-01-07 01:54:38 +01:00
|
|
|
|
case '#parer-button': return this.parade(attackerRoll, armeParadeId);
|
2021-01-07 00:32:22 +01:00
|
|
|
|
case '#esquiver-button': return this.esquive(attackerRoll);
|
|
|
|
|
case '#encaisser-button': return this.encaisser(attackerRoll, defenderTokenId);
|
2021-01-07 01:54:38 +01:00
|
|
|
|
case '#echec-total-attaque': return this._onEchecTotal(attackerRoll);
|
2021-01-07 00:32:22 +01:00
|
|
|
|
|
2021-01-07 01:54:38 +01:00
|
|
|
|
case '#appel-chance-attaque': return this.attacker.rollAppelChance(
|
|
|
|
|
() => this.attaqueChanceuse(attackerRoll),
|
|
|
|
|
() => this._onEchecTotal(attackerRoll));
|
2021-01-07 00:32:22 +01:00
|
|
|
|
case '#appel-chance-defense': return this.defender.rollAppelChance(
|
2021-01-15 19:10:50 +01:00
|
|
|
|
() => this.defenseChanceuse(attackerRoll, defenderRoll),
|
|
|
|
|
() => this.afficherOptionsDefense(attackerRoll, defenderRoll, { defenseChance: true }));
|
2021-01-07 01:54:38 +01:00
|
|
|
|
case '#appel-destinee-attaque': return this.attacker.appelDestinee(
|
2021-01-09 19:33:19 +01:00
|
|
|
|
() => this.attaqueSignificative(attackerRoll),
|
2021-01-07 01:54:38 +01:00
|
|
|
|
() => { });
|
|
|
|
|
case '#appel-destinee-defense': return this.defender.appelDestinee(
|
2021-01-08 22:55:00 +01:00
|
|
|
|
() => this.defenseDestinee(attackerRoll),
|
2021-01-07 01:54:38 +01:00
|
|
|
|
() => { });
|
2021-01-07 00:32:22 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-07 01:54:38 +01:00
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
|
attaqueChanceuse(attackerRoll) {
|
|
|
|
|
ui.notifications.info("L'attaque est rejouée grâce à la chance")
|
|
|
|
|
attackerRoll.essais.attaqueChance = true;
|
|
|
|
|
this.attaque(attackerRoll, attackerRoll.arme);
|
|
|
|
|
}
|
2021-01-07 00:32:22 +01:00
|
|
|
|
|
2021-01-07 01:54:38 +01:00
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
|
attaqueDestinee(attackerRoll) {
|
|
|
|
|
ui.notifications.info('Attaque significative grâce à la destinée')
|
2021-01-23 18:36:30 +01:00
|
|
|
|
RdDResolutionTable.significativeRequise(attackerRoll.rolled);
|
2021-01-07 01:54:38 +01:00
|
|
|
|
this.removeChatMessageActionsPasseArme(attackerRoll.passeArme);
|
|
|
|
|
this._onAttaqueNormale(attackerRoll);
|
2021-01-07 00:32:22 +01:00
|
|
|
|
}
|
|
|
|
|
|
2021-01-07 01:54:38 +01:00
|
|
|
|
/* -------------------------------------------- */
|
2021-01-15 19:10:50 +01:00
|
|
|
|
defenseChanceuse(attackerRoll, defenderRoll) {
|
2021-01-07 01:54:38 +01:00
|
|
|
|
ui.notifications.info("La défense est rejouée grâce à la chance")
|
|
|
|
|
attackerRoll.essais.defenseChance = true;
|
|
|
|
|
attackerRoll.essais.defense = false;
|
|
|
|
|
this.removeChatMessageActionsPasseArme(attackerRoll.passeArme);
|
2021-01-15 19:10:50 +01:00
|
|
|
|
this._sendMessageDefense(attackerRoll, defenderRoll, attackerRoll.essais);
|
2021-01-07 00:32:22 +01:00
|
|
|
|
}
|
|
|
|
|
|
2021-01-07 01:54:38 +01:00
|
|
|
|
/* -------------------------------------------- */
|
2021-01-08 22:55:00 +01:00
|
|
|
|
defenseDestinee(attackerRoll) {
|
2021-01-15 19:10:50 +01:00
|
|
|
|
let defenderRoll = RdDCombat._getDefense(attackerRoll.passeArme);
|
2021-01-08 22:55:00 +01:00
|
|
|
|
if (defenderRoll) {
|
|
|
|
|
ui.notifications.info('Défense significative grâce à la destinée')
|
2021-01-23 18:36:30 +01:00
|
|
|
|
RdDResolutionTable.significativeRequise(defenderRoll.rolled);
|
2021-01-08 22:55:00 +01:00
|
|
|
|
this.removeChatMessageActionsPasseArme(defenderRoll.passeArme);
|
|
|
|
|
if (defenderRoll.arme) {
|
|
|
|
|
this._onParadeNormale(defenderRoll);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
this._onEsquiveNormale(defenderRoll);
|
|
|
|
|
}
|
2021-01-07 00:32:22 +01:00
|
|
|
|
}
|
2021-01-07 01:54:38 +01:00
|
|
|
|
else {
|
2021-01-08 22:55:00 +01:00
|
|
|
|
ui.notifications.warn("Appel à la destinée impossible, la passe d'armes est déjà terminée!")
|
2020-12-12 21:58:44 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-07 01:54:38 +01:00
|
|
|
|
/* -------------------------------------------- */
|
2021-01-15 19:10:50 +01:00
|
|
|
|
afficherOptionsDefense(attackerRoll, defenderRoll, essais) {
|
2021-01-07 01:54:38 +01:00
|
|
|
|
ui.notifications.info("La chance n'est pas avec vous");
|
2021-01-15 19:10:50 +01:00
|
|
|
|
this._sendMessageDefense(attackerRoll, defenderRoll, essais);
|
2021-01-07 01:54:38 +01:00
|
|
|
|
}
|
|
|
|
|
|
2021-01-07 00:32:22 +01:00
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
|
removeChatMessageActionsPasseArme(passeArme) {
|
2021-01-20 00:44:19 +01:00
|
|
|
|
if (game.settings.get("foundryvtt-reve-de-dragon", "supprimer-dialogues-combat-chat")) {
|
|
|
|
|
ChatUtility.removeChatMessageContaining(`<div data-passearme="${passeArme}">`);
|
2021-01-07 01:54:38 +01:00
|
|
|
|
}
|
2021-01-07 00:32:22 +01:00
|
|
|
|
}
|
|
|
|
|
|
2020-12-16 23:02:15 +01:00
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
|
static isEchec(rollData) {
|
2021-01-13 03:11:03 +01:00
|
|
|
|
switch (rollData.ajustements.surprise.used) {
|
2020-12-16 23:02:15 +01:00
|
|
|
|
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-13 03:11:03 +01:00
|
|
|
|
if (!rollData.attackerRoll && rollData.ajustements.surprise.used) {
|
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-13 03:11:03 +01:00
|
|
|
|
if (!rollData.attackerRoll && rollData.ajustements.surprise.used) {
|
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) {
|
2021-01-13 03:11:03 +01:00
|
|
|
|
switch (rollData.ajustements.surprise.used) {
|
2020-12-16 23:02:15 +01:00
|
|
|
|
case 'totale': return false;
|
|
|
|
|
}
|
|
|
|
|
return rollData.rolled.isSuccess;
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-12 21:58:44 +01:00
|
|
|
|
/* -------------------------------------------- */
|
2021-01-14 00:35:55 +01:00
|
|
|
|
async attaque(competence, arme = undefined) {
|
2020-12-12 21:58:44 +01:00
|
|
|
|
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',
|
2021-01-04 14:10:21 +01:00
|
|
|
|
label: 'Attaque: ' + (arme?.name ?? competence.name),
|
2020-12-12 21:58:44 +01:00
|
|
|
|
callbacks: [
|
|
|
|
|
this.attacker.createCallbackExperience(),
|
2021-01-07 00:32:22 +01:00
|
|
|
|
{ action: r => this.removeChatMessageActionsPasseArme(r.passeArme) },
|
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 = {
|
2021-01-07 00:32:22 +01:00
|
|
|
|
passeArme: randomID(16),
|
2020-12-12 21:58:44 +01:00
|
|
|
|
coupsNonMortels: false,
|
|
|
|
|
competence: competence,
|
2021-01-13 03:42:13 +01:00
|
|
|
|
surprise: this.attacker.getSurprise(true),
|
|
|
|
|
surpriseDefenseur: this.defender.getSurprise(true),
|
2021-01-09 19:33:19 +01:00
|
|
|
|
essais: {}
|
2020-12-12 21:58:44 +01:00
|
|
|
|
};
|
2021-01-13 03:42:13 +01:00
|
|
|
|
rollData.diviseurSignificative = this._getDiviseurSignificative(rollData);
|
2020-12-12 21:58:44 +01:00
|
|
|
|
|
|
|
|
|
if (this.attacker.isCreature()) {
|
2021-01-13 23:47:12 +01:00
|
|
|
|
RdDItemCompetenceCreature.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
|
2021-01-05 18:43:13 +01:00
|
|
|
|
rollData.arme = RdDItemArme.mainsNues({ niveau: competence.data.niveau });
|
2020-12-16 23:02:15 +01:00
|
|
|
|
}
|
2020-12-12 21:58:44 +01:00
|
|
|
|
return rollData;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
2021-01-07 01:54:38 +01:00
|
|
|
|
async _onAttaqueParticuliere(rollData) {
|
2021-01-15 19:10:50 +01:00
|
|
|
|
RdDCombat._storeAttaque(this.attackerId, rollData);
|
2021-01-07 01:54:38 +01:00
|
|
|
|
|
|
|
|
|
// Finesse et Rapidité seulement en mêlée et si la difficulté libre est de -1 minimum
|
|
|
|
|
const isMeleeDiffNegative = rollData.selectedCarac.label == "Mêlée" && rollData.diffLibre < 0;
|
|
|
|
|
ChatMessage.create({
|
2021-01-15 19:10:50 +01:00
|
|
|
|
alias: this.attacker.name,
|
|
|
|
|
whisper: ChatUtility.getWhisperRecipientsAndGMs(this.attacker.name),
|
2021-01-13 03:11:03 +01:00
|
|
|
|
content: await renderTemplate('systems/foundryvtt-reve-de-dragon/templates/chat-demande-attaque-particuliere.html', {
|
2021-01-15 19:10:50 +01:00
|
|
|
|
alias: this.attacker.name,
|
2021-01-07 01:54:38 +01:00
|
|
|
|
attackerId: this.attackerId,
|
|
|
|
|
defenderTokenId: this.defenderTokenId,
|
|
|
|
|
isFinesse: isMeleeDiffNegative,
|
2021-01-19 22:31:32 +01:00
|
|
|
|
isRapide: isMeleeDiffNegative && rollData.arme.data.rapide,
|
|
|
|
|
passeArme: rollData.passeArme
|
2021-01-07 01:54:38 +01:00
|
|
|
|
})
|
|
|
|
|
});
|
2020-12-12 21:58:44 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
2021-01-07 01:54:38 +01:00
|
|
|
|
async _onAttaqueNormale(attackerRoll) {
|
|
|
|
|
console.log("RdDCombat.onAttaqueNormale >>>", attackerRoll);
|
2021-01-01 03:25:48 +01:00
|
|
|
|
|
2021-01-07 01:54:38 +01:00
|
|
|
|
attackerRoll.dmg = RdDBonus.dmg(attackerRoll, this.attacker.getBonusDegat(), this.defender.isEntiteCauchemar());
|
2021-01-19 22:31:32 +01:00
|
|
|
|
let defenderRoll = { attackerRoll: attackerRoll, passeArme: attackerRoll.passeArme, show: {} }
|
2020-12-12 21:58:44 +01:00
|
|
|
|
// Save rollData for defender
|
2021-01-15 19:10:50 +01:00
|
|
|
|
RdDCombat._storeAttaque(this.attackerId, attackerRoll);
|
2021-01-19 22:31:32 +01:00
|
|
|
|
RdDCombat._storeDefense(defenderRoll)
|
2021-01-01 03:25:48 +01:00
|
|
|
|
|
2021-01-07 01:54:38 +01:00
|
|
|
|
attackerRoll.show = {
|
2021-01-01 22:25:32 +01:00
|
|
|
|
cible: this.target ? this.defender.data.name : 'la cible',
|
2021-01-07 01:54:38 +01:00
|
|
|
|
isRecul: (attackerRoll.particuliere == 'force' || attackerRoll.tactique == 'charge')
|
2021-01-01 03:25:48 +01:00
|
|
|
|
}
|
2021-01-07 01:54:38 +01:00
|
|
|
|
await RdDResolutionTable.displayRollData(attackerRoll, this.attacker, '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) {
|
2021-01-19 22:31:32 +01:00
|
|
|
|
await this._sendMessageDefense(attackerRoll, defenderRoll);
|
2020-12-12 21:58:44 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
2021-01-19 22:31:32 +01:00
|
|
|
|
async _sendMessageDefense(attackerRoll, defenderRoll, essaisPrecedents = undefined) {
|
2021-01-15 19:10:50 +01:00
|
|
|
|
console.log("RdDCombat._sendMessageDefense", attackerRoll, defenderRoll, essaisPrecedents, " / ", this.attacker, this.target, this.attackerId, attackerRoll.competence.data.categorie);
|
2020-12-18 22:15:17 +01:00
|
|
|
|
|
2021-01-07 00:32:22 +01:00
|
|
|
|
this.removeChatMessageActionsPasseArme(attackerRoll.passeArme);
|
2021-01-15 19:10:50 +01:00
|
|
|
|
if (essaisPrecedents) {
|
|
|
|
|
mergeObject(attackerRoll.essais, essaisPrecedents, { overwrite: true });
|
|
|
|
|
}
|
2021-01-19 22:31:32 +01:00
|
|
|
|
const paramChatDefense = {
|
2021-01-07 00:32:22 +01:00
|
|
|
|
passeArme: attackerRoll.passeArme,
|
2021-01-07 01:54:38 +01:00
|
|
|
|
essais: attackerRoll.essais,
|
2021-01-07 00:32:22 +01:00
|
|
|
|
defender: this.defender,
|
2021-01-19 22:31:32 +01:00
|
|
|
|
attacker: this.attacker,
|
2021-01-07 00:32:22 +01:00
|
|
|
|
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),
|
2021-01-07 01:54:38 +01:00
|
|
|
|
diffLibre: attackerRoll.ajustements?.diffLibre?.value ?? 0,
|
2021-01-15 19:09:44 +01:00
|
|
|
|
attaqueParticuliere: attackerRoll.particuliere,
|
2021-01-19 22:31:32 +01:00
|
|
|
|
attaqueCategorie: attackerRoll.competence.data.categorie,
|
|
|
|
|
attaqueArme: attackerRoll.arme,
|
2021-01-20 09:19:16 +01:00
|
|
|
|
surprise: this.defender.getSurprise(true),
|
2021-01-19 22:31:32 +01:00
|
|
|
|
dmg: attackerRoll.dmg,
|
2021-01-07 01:54:38 +01:00
|
|
|
|
};
|
2020-12-12 21:58:44 +01:00
|
|
|
|
|
2021-01-19 22:31:32 +01:00
|
|
|
|
const selfMessage = essaisPrecedents != undefined;
|
|
|
|
|
if (!selfMessage && (!game.user.isGM || this.defender.hasPlayerOwner)) {
|
|
|
|
|
this._socketSendMessageDefense(paramChatDefense, defenderRoll);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
await this._chatMessageDefense(paramChatDefense);
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-01-15 19:10:50 +01:00
|
|
|
|
|
2021-01-19 22:31:32 +01:00
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
|
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)),
|
2021-01-15 19:10:50 +01:00
|
|
|
|
alias: this.attacker.name,
|
|
|
|
|
whisper: ChatUtility.getWhisperRecipientsAndGMs(this.defender.name),
|
|
|
|
|
content: await renderTemplate('systems/foundryvtt-reve-de-dragon/templates/chat-demande-defense.html', paramDemandeDefense),
|
2021-01-19 22:31:32 +01:00
|
|
|
|
});
|
2020-12-18 22:15:17 +01:00
|
|
|
|
}
|
2020-12-12 21:58:44 +01:00
|
|
|
|
|
2021-01-15 19:10:50 +01:00
|
|
|
|
/* -------------------------------------------- */
|
2021-01-19 22:31:32 +01:00
|
|
|
|
_socketSendMessageDefense(paramChatDefense, defenderRoll) {
|
2021-01-15 19:10:50 +01:00
|
|
|
|
// envoyer le message au destinataire
|
2021-01-19 22:31:32 +01:00
|
|
|
|
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,
|
2021-01-15 19:10:50 +01:00
|
|
|
|
defenderRoll: duplicate(defenderRoll),
|
2021-01-19 22:31:32 +01:00
|
|
|
|
paramChatDefense: paramChatDefense,
|
2021-01-15 19:10:50 +01:00
|
|
|
|
rollMode: true
|
2021-01-19 22:31:32 +01:00
|
|
|
|
}
|
|
|
|
|
});
|
2021-01-15 19:10:50 +01:00
|
|
|
|
}
|
2021-01-19 22:31:32 +01:00
|
|
|
|
|
2020-12-12 21:58:44 +01:00
|
|
|
|
/* -------------------------------------------- */
|
2021-01-02 04:28:43 +01:00
|
|
|
|
_filterArmesParade(items, competence) {
|
2021-01-04 00:17:22 +01:00
|
|
|
|
items = items.filter(item => (item.type == 'arme' && item.data.equipe) || (item.type == 'competencecreature' && item.data.isparade));
|
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 16:56:25 +01:00
|
|
|
|
return items.filter(item => RdDItemArme.getCategorieParade(item) == '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
|
2021-01-05 18:43:13 +01:00
|
|
|
|
if (competence.name == "Fléau") {
|
2021-01-03 16:56:25 +01:00
|
|
|
|
return items.filter(item => RdDItemArme.getCategorieParade(item) == 'boucliers')
|
2021-01-02 04:28:43 +01:00
|
|
|
|
}
|
2021-01-03 16:56:25 +01:00
|
|
|
|
return items.filter(item => RdDItemArme.getCategorieParade(item));
|
2020-12-12 21:58:44 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
2020-12-16 09:07:00 +01:00
|
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
2021-01-07 01:54:38 +01:00
|
|
|
|
async _onAttaqueEchecTotal(attackerRoll) {
|
|
|
|
|
|
2021-01-15 19:10:50 +01:00
|
|
|
|
RdDCombat._storeAttaque(this.attackerId, attackerRoll);
|
2021-01-07 01:54:38 +01:00
|
|
|
|
|
|
|
|
|
// Finesse et Rapidité seulement en mêlée et si la difficulté libre est de -1 minimum
|
|
|
|
|
ChatMessage.create({
|
|
|
|
|
whisper: ChatMessage.getWhisperRecipients(this.attacker.name),
|
|
|
|
|
content: await renderTemplate('systems/foundryvtt-reve-de-dragon/templates/chat-demande-attaque-etotal.html', {
|
|
|
|
|
attackerId: this.attackerId,
|
|
|
|
|
attacker: this.attacker,
|
|
|
|
|
defenderTokenId: this.defenderTokenId,
|
|
|
|
|
essais: attackerRoll.essais
|
|
|
|
|
})
|
|
|
|
|
});
|
2020-12-12 21:58:44 +01:00
|
|
|
|
}
|
|
|
|
|
|
2021-01-07 01:54:38 +01:00
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
|
async _onEchecTotal(rollData) {
|
|
|
|
|
console.log("RdDCombat._onEchecTotal >>>", rollData);
|
|
|
|
|
|
|
|
|
|
const arme = rollData.arme;
|
|
|
|
|
const avecArme = arme?.data.categorie_parade != 'sans-armes';
|
|
|
|
|
const action = (rollData.attackerRoll ? (arme ? "la parade" : "l'esquive") : "l'attaque");
|
2021-01-09 19:36:19 +01:00
|
|
|
|
ChatUtility.createChatWithRollMode(this.defender.name, {
|
2021-01-07 01:54:38 +01:00
|
|
|
|
content: `<strong>Echec total à ${action}!</strong> ` + await RdDRollTables.getMaladresse({ arme: avecArme })
|
2021-01-09 19:36:19 +01:00
|
|
|
|
});
|
2021-01-07 01:54:38 +01:00
|
|
|
|
}
|
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-05 18:43:13 +01:00
|
|
|
|
await RdDResolutionTable.displayRollData(rollData, this.attacker, 'chat-resultat-attaque.html');
|
|
|
|
|
|
2020-12-12 21:58:44 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
|
async choixParticuliere(rollData, choix) {
|
|
|
|
|
console.log("RdDCombat.choixParticuliere >>>", rollData, choix);
|
2021-01-24 19:52:02 +01:00
|
|
|
|
|
2021-01-20 00:44:19 +01:00
|
|
|
|
this.removeChatMessageActionsPasseArme(rollData.passeArme);
|
2021-01-03 16:58:11 +01:00
|
|
|
|
rollData.particuliere = choix;
|
2020-12-12 21:58:44 +01:00
|
|
|
|
await this._onAttaqueNormale(rollData);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
|
async parade(attackerRoll, armeParadeId) {
|
2021-01-14 00:35:55 +01:00
|
|
|
|
let arme = this.defender.getArmeParade(armeParadeId);
|
2021-01-15 19:10:50 +01:00
|
|
|
|
|
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(),
|
2021-01-07 00:32:22 +01:00
|
|
|
|
{ action: r => this.removeChatMessageActionsPasseArme(r.passeArme) },
|
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-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) {
|
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;
|
2021-01-14 00:35:55 +01:00
|
|
|
|
|
2020-12-12 21:58:44 +01:00
|
|
|
|
let rollData = {
|
2021-01-07 00:32:22 +01:00
|
|
|
|
passeArme: attackerRoll.passeArme,
|
2020-12-12 21:58:44 +01:00
|
|
|
|
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,
|
2021-01-13 03:42:13 +01:00
|
|
|
|
surprise: this.defender.getSurprise(true),
|
2021-01-25 08:48:03 +01:00
|
|
|
|
needParadeSignificative: RdDCombatSettings.isUsingCategorieParade() && RdDItemArme.needParadeSignificative(armeAttaque, armeParade),
|
2021-01-05 18:43:13 +01:00
|
|
|
|
needResist: RdDItemArme.needArmeResist(armeAttaque, armeParade),
|
2021-01-02 04:28:43 +01:00
|
|
|
|
carac: this.defender.data.data.carac,
|
|
|
|
|
show: {}
|
2020-12-12 21:58:44 +01:00
|
|
|
|
};
|
2021-01-13 03:42:13 +01:00
|
|
|
|
rollData.diviseurSignificative = this._getDiviseurSignificative(rollData);
|
|
|
|
|
|
|
|
|
|
if (this.defender.isCreature()) {
|
2021-01-13 23:47:12 +01:00
|
|
|
|
RdDItemCompetenceCreature.setRollDataCreature(rollData);
|
2020-12-12 21:58:44 +01:00
|
|
|
|
}
|
2021-01-14 00:35:55 +01:00
|
|
|
|
|
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-09 19:33:19 +01:00
|
|
|
|
_getDiviseurSignificative(defenderRoll) {
|
2021-01-13 03:42:13 +01:00
|
|
|
|
let facteurSign = 1;
|
2021-01-14 00:35:55 +01:00
|
|
|
|
if (defenderRoll.surprise == 'demi') {
|
2021-01-13 03:42:13 +01:00
|
|
|
|
facteurSign *= 2;
|
2021-01-14 00:35:55 +01:00
|
|
|
|
}
|
2021-01-13 03:42:13 +01:00
|
|
|
|
if (defenderRoll.needParadeSignificative) {
|
|
|
|
|
facteurSign *= 2;
|
|
|
|
|
}
|
2021-01-09 19:33:19 +01:00
|
|
|
|
if (RdDBonus.isDefenseAttaqueFinesse(defenderRoll)) {
|
2021-01-02 04:28:43 +01:00
|
|
|
|
facteurSign *= 2;
|
|
|
|
|
}
|
2021-01-25 08:48:03 +01:00
|
|
|
|
if (!RdDCombatSettings.isUsingTripleSignificative()) {
|
|
|
|
|
facteurSign = Math.min(facteurSign, 4);
|
|
|
|
|
}
|
2021-01-05 18:43:13 +01:00
|
|
|
|
return facteurSign;
|
2020-12-12 21:58:44 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
2021-01-09 19:33:19 +01:00
|
|
|
|
_onParadeParticuliere(defenderRoll) {
|
|
|
|
|
console.log("RdDCombat._onParadeParticuliere >>>", defenderRoll);
|
|
|
|
|
if (!defenderRoll.attackerRoll.isPart) {
|
2020-12-12 21:58:44 +01:00
|
|
|
|
// TODO: attaquant doit jouer résistance et peut être désarmé p132
|
2021-01-09 19:36:19 +01:00
|
|
|
|
ChatUtility.createChatWithRollMode(this.defender.name, {
|
2021-01-07 00:32:22 +01:00
|
|
|
|
content: `(à gérer) L'attaquant doit jouer résistance et peut être désarmé (p132)`
|
2021-01-09 19:36:19 +01:00
|
|
|
|
});
|
2020-12-12 21:58:44 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
2021-01-09 19:33:19 +01:00
|
|
|
|
async _onParadeNormale(defenderRoll) {
|
|
|
|
|
console.log("RdDCombat._onParadeNormale >>>", defenderRoll);
|
2020-12-17 12:29:54 +01:00
|
|
|
|
|
2021-01-09 19:33:19 +01:00
|
|
|
|
await this.computeRecul(defenderRoll);
|
|
|
|
|
await this.computeDeteriorationArme(defenderRoll);
|
|
|
|
|
await RdDResolutionTable.displayRollData(defenderRoll, this.defender, 'chat-resultat-parade.html');
|
2021-01-15 19:10:50 +01:00
|
|
|
|
|
|
|
|
|
RdDCombat._deleteDefense(defenderRoll.passeArme);
|
2020-12-12 21:58:44 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
2021-01-09 19:33:19 +01:00
|
|
|
|
async _onParadeEchec(defenderRoll) {
|
|
|
|
|
console.log("RdDCombat._onParadeEchec >>>", defenderRoll);
|
2020-12-12 21:58:44 +01:00
|
|
|
|
|
2021-01-09 19:33:19 +01:00
|
|
|
|
await RdDResolutionTable.displayRollData(defenderRoll, this.defender, 'chat-resultat-parade.html');
|
2020-12-12 21:58:44 +01:00
|
|
|
|
|
2021-01-09 19:33:19 +01:00
|
|
|
|
this.removeChatMessageActionsPasseArme(defenderRoll.passeArme);
|
2021-01-15 19:10:50 +01:00
|
|
|
|
this._sendMessageDefense(defenderRoll.attackerRoll, defenderRoll, { defense: true });
|
2021-01-19 19:58:19 +01:00
|
|
|
|
RdDCombat._storeDefense(defenderRoll);
|
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(),
|
2021-01-07 00:32:22 +01:00
|
|
|
|
{ action: r => this.removeChatMessageActionsPasseArme(r.passeArme) },
|
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-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 = {
|
2021-01-07 00:32:22 +01:00
|
|
|
|
passeArme: attackerRoll.passeArme,
|
2020-12-12 21:58:44 +01:00
|
|
|
|
diffLibre: attackerRoll.diffLibre,
|
|
|
|
|
attackerRoll: attackerRoll,
|
|
|
|
|
competence: competence,
|
2021-01-13 03:42:13 +01:00
|
|
|
|
surprise: this.defender.getSurprise(true),
|
|
|
|
|
surpriseDefenseur: this.defender.getSurprise(true),
|
2021-01-02 04:28:43 +01:00
|
|
|
|
carac: this.defender.data.data.carac,
|
|
|
|
|
show: {}
|
2020-12-12 21:58:44 +01:00
|
|
|
|
};
|
2021-01-13 03:42:13 +01:00
|
|
|
|
rollData.diviseurSignificative = this._getDiviseurSignificative(rollData);
|
2020-12-12 21:58:44 +01:00
|
|
|
|
|
|
|
|
|
if (this.defender.isCreature()) {
|
2021-01-13 23:47:12 +01:00
|
|
|
|
RdDItemCompetenceCreature.setRollDataCreature(rollData);
|
2020-12-12 21:58:44 +01:00
|
|
|
|
}
|
|
|
|
|
return rollData;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
|
_onEsquiveParticuliere(rollData) {
|
|
|
|
|
console.log("RdDCombat._onEsquiveParticuliere >>>", rollData);
|
2021-01-09 19:36:19 +01:00
|
|
|
|
ChatUtility.createChatWithRollMode(this.defender.name, {
|
2021-01-20 00:44:40 +01:00
|
|
|
|
content: "<strong>Vous pouvez esquiver une deuxième fois!</strong>"
|
2021-01-09 19:36:19 +01:00
|
|
|
|
});
|
2020-12-12 21:58:44 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
2021-01-13 03:42:13 +01:00
|
|
|
|
async _onEsquiveNormale(defenderRoll) {
|
|
|
|
|
console.log("RdDCombat._onEsquiveNormal >>>", defenderRoll);
|
|
|
|
|
await RdDResolutionTable.displayRollData(defenderRoll, this.defender, 'chat-resultat-esquive.html');
|
2021-01-15 19:10:50 +01:00
|
|
|
|
RdDCombat._deleteDefense(defenderRoll.passeArme);
|
2020-12-12 21:58:44 +01:00
|
|
|
|
}
|
2020-12-17 12:29:54 +01:00
|
|
|
|
|
2020-12-12 21:58:44 +01:00
|
|
|
|
/* -------------------------------------------- */
|
2021-01-13 03:42:13 +01:00
|
|
|
|
async _onEsquiveEchec(defenderRoll) {
|
|
|
|
|
console.log("RdDCombat._onEsquiveEchec >>>", defenderRoll);
|
2020-12-12 21:58:44 +01:00
|
|
|
|
|
2021-01-13 03:42:13 +01:00
|
|
|
|
await RdDResolutionTable.displayRollData(defenderRoll, this.defender, 'chat-resultat-esquive.html');
|
2020-12-12 21:58:44 +01:00
|
|
|
|
|
2021-01-13 03:42:13 +01:00
|
|
|
|
this.removeChatMessageActionsPasseArme(defenderRoll.passeArme);
|
2021-01-15 19:10:50 +01:00
|
|
|
|
this._sendMessageDefense(defenderRoll.attackerRoll, defenderRoll, { defense: true })
|
2021-01-19 19:58:19 +01:00
|
|
|
|
RdDCombat._storeDefense(defenderRoll);
|
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) {
|
2021-01-25 08:48:03 +01:00
|
|
|
|
if (!RdDCombatSettings.isUsingResistanceArmeParade()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
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
|
2021-01-03 16:58:11 +01:00
|
|
|
|
if (rollData.needResist || attackerRoll.particuliere == 'force' || attackerRoll.tactique == 'charge') {
|
2021-01-02 04:28:43 +01:00
|
|
|
|
|
|
|
|
|
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)
|
2021-01-25 08:48:03 +01:00
|
|
|
|
if (RdDCombatSettings.isUsingDefenseurDesarme() && resistance > 0 && RdDItemArme.getCategorieParade(rollData.arme) != 'boucliers') {
|
2020-12-17 00:44:32 +01:00
|
|
|
|
let desarme = await RdDResolutionTable.rollData({
|
2021-01-23 18:36:30 +01:00
|
|
|
|
caracValue: this.defender.getForce(),
|
2020-12-17 00:44:32 +01:00
|
|
|
|
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;
|
2020-12-17 00:44:32 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-01-24 19:52:02 +01:00
|
|
|
|
|
2020-12-17 00:44:32 +01:00
|
|
|
|
/* -------------------------------------------- */
|
2021-01-09 19:33:19 +01:00
|
|
|
|
async computeRecul(defenderRoll) { // Calcul du recul (p. 132)
|
|
|
|
|
const attackerRoll = defenderRoll.attackerRoll;
|
2021-01-25 08:48:03 +01:00
|
|
|
|
if (RdDCombatSettings.isUsingRecul() && this._isAttaqueCauseRecul(attackerRoll)) {
|
2021-01-23 18:36:30 +01:00
|
|
|
|
const impact = this._computeImpactRecul(attackerRoll);
|
|
|
|
|
const rollRecul = await RdDResolutionTable.rollData({ caracValue: 10, finalLevel: impact });
|
|
|
|
|
if (rollRecul.rolled.isSuccess) {
|
2021-01-09 19:33:19 +01:00
|
|
|
|
defenderRoll.show.recul = 'encaisse';
|
2021-01-24 19:52:02 +01:00
|
|
|
|
} else if (rollRecul.rolled.isETotal || this._isReculCauseChute(impact)) {
|
2021-01-09 19:33:19 +01:00
|
|
|
|
defenderRoll.show.recul = 'chute';
|
2021-01-24 19:52:02 +01:00
|
|
|
|
await this.defender.addStatusEffectById('prone');
|
2021-01-02 04:28:43 +01:00
|
|
|
|
}
|
|
|
|
|
else {
|
2021-01-24 19:52:02 +01:00
|
|
|
|
defenderRoll.show.recul = 'recul';
|
2020-12-17 00:44:32 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-24 19:52:02 +01:00
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
|
async _isReculCauseChute(impact) {
|
|
|
|
|
const agilite = this.defender.getAgilite();
|
|
|
|
|
const chute = await RdDResolutionTable.rollData({ caracValue: agilite, finalLevel: impact });
|
|
|
|
|
return chute.rolled.isEchec;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
2021-01-02 04:28:43 +01:00
|
|
|
|
_isAttaqueCauseRecul(attaque) {
|
2021-01-03 16:58:11 +01:00
|
|
|
|
return attaque.particuliere == 'force' || attaque.tactique == 'charge';
|
2021-01-02 04:28:43 +01:00
|
|
|
|
}
|
|
|
|
|
|
2021-01-24 19:52:02 +01:00
|
|
|
|
/* -------------------------------------------- */
|
2021-01-02 04:28:43 +01:00
|
|
|
|
_computeImpactRecul(attaque) {
|
2021-01-23 18:36:30 +01:00
|
|
|
|
const taille = this.defender.getTaille();
|
|
|
|
|
const force = this.attacker.getForce();
|
|
|
|
|
const dommages = attaque.arme.data.dommagesReels;
|
|
|
|
|
return taille - (force + dommages);
|
2021-01-02 04:28:43 +01:00
|
|
|
|
}
|
|
|
|
|
|
2020-12-12 21:58:44 +01:00
|
|
|
|
/* -------------------------------------------- */
|
2021-01-07 00:32:22 +01:00
|
|
|
|
async encaisser(attackerRoll, defenderTokenId) {
|
2020-12-12 21:58:44 +01:00
|
|
|
|
defenderTokenId = defenderTokenId || this.defenderTokenId;
|
|
|
|
|
console.log("RdDCombat.encaisser >>>", attackerRoll, defenderTokenId);
|
|
|
|
|
|
2021-01-15 19:10:50 +01:00
|
|
|
|
let defenderRoll = RdDCombat._getDefense(attackerRoll.passeArme);
|
2021-01-19 22:31:32 +01:00
|
|
|
|
if (!defenderRoll) {
|
|
|
|
|
ui.notifications.warn("Cette passe d'arme est déjà terminée!")
|
|
|
|
|
return;
|
|
|
|
|
}
|
2021-01-15 19:10:50 +01:00
|
|
|
|
if (defenderRoll?.rolled && RdDCombat.isEchecTotal(defenderRoll)) {
|
2021-01-07 01:54:38 +01:00
|
|
|
|
this._onEchecTotal(defenderRoll);
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-12 21:58:44 +01:00
|
|
|
|
if (game.user.isGM) { // Current user is the GM -> direct access
|
|
|
|
|
attackerRoll.attackerId = this.attackerId;
|
|
|
|
|
attackerRoll.defenderTokenId = defenderTokenId;
|
2021-01-07 00:32:22 +01:00
|
|
|
|
|
|
|
|
|
await this.computeRecul(defenderRoll);
|
2021-01-23 18:36:30 +01:00
|
|
|
|
this.defender.encaisserDommages(attackerRoll, this.attacker, defenderRoll);
|
2021-01-15 19:10:50 +01:00
|
|
|
|
} else { // envoi à un GM: les joueurs n'ont pas le droit de modifier les personnages qu'ils ne possèdent pas
|
2020-12-12 21:58:44 +01:00
|
|
|
|
game.socket.emit("system.foundryvtt-reve-de-dragon", {
|
|
|
|
|
msg: "msg_encaisser",
|
2021-01-15 19:10:50 +01:00
|
|
|
|
data: {
|
|
|
|
|
attackerId: this.attackerId,
|
|
|
|
|
defenderTokenId: defenderTokenId,
|
|
|
|
|
attackerRoll: attackerRoll,
|
|
|
|
|
gmId: game.users.entities.find(u => u.isGM)?.id,
|
|
|
|
|
}
|
2020-12-12 21:58:44 +01:00
|
|
|
|
});
|
|
|
|
|
}
|
2021-01-15 19:10:50 +01:00
|
|
|
|
RdDCombat._deleteDefense(attackerRoll.passeArme);
|
2021-01-19 22:31:32 +01:00
|
|
|
|
this.removeChatMessageActionsPasseArme(attackerRoll.passeArme);
|
2020-12-12 21:58:44 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
|
/* 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;
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-03 15:40:48 +01:00
|
|
|
|
/* -------------------------------------------- */
|
2021-01-10 00:30:37 +01:00
|
|
|
|
static async displayActorCombatStatus(combat, actor) {
|
|
|
|
|
let data = {
|
|
|
|
|
combatId: combat._id,
|
2021-01-05 18:43:13 +01:00
|
|
|
|
alias: actor.name,
|
2021-01-03 15:40:48 +01:00
|
|
|
|
etatGeneral: actor.getEtatGeneral(),
|
2021-01-05 18:43:13 +01:00
|
|
|
|
isSonne: actor.getSonne(),
|
2021-01-03 15:40:48 +01:00
|
|
|
|
blessuresStatus: actor.computeResumeBlessure(),
|
|
|
|
|
SConst: actor.getSConst(),
|
|
|
|
|
actorId: actor.data._id,
|
|
|
|
|
isGrave: false,
|
|
|
|
|
isCritique: false
|
|
|
|
|
}
|
2021-01-05 18:43:13 +01:00
|
|
|
|
if (actor.countBlessuresByName("critiques") > 0) { // Pour éviter le cumul grave + critique
|
2021-01-10 00:30:37 +01:00
|
|
|
|
data.isCritique = true;
|
2021-01-05 18:43:13 +01:00
|
|
|
|
} else if (actor.countBlessuresByName("graves") > 0) {
|
2021-01-10 00:30:37 +01:00
|
|
|
|
data.isGrave = true;
|
2021-01-03 15:40:48 +01:00
|
|
|
|
}
|
2021-01-10 00:30:37 +01:00
|
|
|
|
|
2021-01-09 19:36:19 +01:00
|
|
|
|
ChatUtility.createChatWithRollMode(actor.name, {
|
2021-01-10 00:30:37 +01:00
|
|
|
|
content: await renderTemplate(`systems/foundryvtt-reve-de-dragon/templates/chat-actor-turn-summary.html`, data)
|
2021-01-09 19:36:19 +01:00
|
|
|
|
});
|
2021-01-03 15:40:48 +01:00
|
|
|
|
}
|
2021-01-25 08:48:03 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export class RdDCombatSettings extends FormApplication {
|
|
|
|
|
static onInit() {
|
|
|
|
|
game.settings.register("foundryvtt-reve-de-dragon", "rdd-combat-recul", { name: "rdd-combat-recul", scope: "world", config: false, default: true, type: Boolean });
|
|
|
|
|
game.settings.register("foundryvtt-reve-de-dragon", "rdd-combat-resistanceArmeParade", { name: "rdd-combat-resistanceArmeParade", scope: "world", config: false, default: true, type: Boolean });
|
|
|
|
|
game.settings.register("foundryvtt-reve-de-dragon", "rdd-combat-deteriorationArmure", { name: "rdd-combat-deteriorationArmure", scope: "world", config: false, default: true, type: Boolean });
|
|
|
|
|
game.settings.register("foundryvtt-reve-de-dragon", "rdd-combat-defenseurDesarme", { name: "rdd-combat-defenseurDesarme", scope: "world", config: false, default: true, type: Boolean });
|
|
|
|
|
game.settings.register("foundryvtt-reve-de-dragon", "rdd-combat-categorieParade", { name: "rdd-combat-categorieParade", scope: "world", config: false, default: true, type: Boolean });
|
|
|
|
|
game.settings.register("foundryvtt-reve-de-dragon", "rdd-combat-tripleSignificative", { name: "rdd-combat-tripleSignificative", scope: "world", config: false, default: true, type: Boolean });
|
|
|
|
|
|
|
|
|
|
game.settings.registerMenu("foundryvtt-reve-de-dragon", "rdd-combat-options", {
|
|
|
|
|
name: "Choisir les options de combat",
|
|
|
|
|
label: "Choix des options de combat",
|
|
|
|
|
hint: "Ouvre la fenêtre de sélection des options de combats pour désactiver certaines règles",
|
|
|
|
|
icon: "fas fa-bars",
|
|
|
|
|
type: RdDCombatSettings,
|
|
|
|
|
restricted: true
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
constructor(...args) {
|
|
|
|
|
super(...args);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static get defaultOptions() {
|
|
|
|
|
const options = super.defaultOptions;
|
|
|
|
|
mergeObject(options, {
|
|
|
|
|
id: "combat-settings",
|
|
|
|
|
template: "systems/foundryvtt-reve-de-dragon/templates/combat-settings.html",
|
|
|
|
|
height: 600,
|
|
|
|
|
width: 350,
|
|
|
|
|
minimizable: false,
|
|
|
|
|
closeOnSubmit: true,
|
|
|
|
|
title: "Options de combat"
|
|
|
|
|
});
|
|
|
|
|
return options;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getData() {
|
|
|
|
|
let data = super.getData();
|
|
|
|
|
data.recul = RdDCombatSettings.isUsingRecul();
|
|
|
|
|
data.resistanceArmeParade = RdDCombatSettings.isUsingResistanceArmeParade();
|
|
|
|
|
data.deteriorationArmure = RdDCombatSettings.isUsingDeteriorationArmure();
|
|
|
|
|
data.defenseurDesarme = RdDCombatSettings.isUsingDefenseurDesarme();
|
|
|
|
|
data.categorieParade = RdDCombatSettings.isUsingCategorieParade();
|
|
|
|
|
data.tripleSignificative = RdDCombatSettings.isUsingTripleSignificative();
|
|
|
|
|
return data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static isUsingRecul() {
|
|
|
|
|
return game.settings.get("foundryvtt-reve-de-dragon", "rdd-combat-recul");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static isUsingResistanceArmeParade() {
|
|
|
|
|
return game.settings.get("foundryvtt-reve-de-dragon", "rdd-combat-resistanceArmeParade");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static isUsingDeteriorationArmure() {
|
|
|
|
|
return game.settings.get("foundryvtt-reve-de-dragon", "rdd-combat-deteriorationArmure");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static isUsingDefenseurDesarme() {
|
|
|
|
|
return game.settings.get("foundryvtt-reve-de-dragon", "rdd-combat-defenseurDesarme");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static isUsingCategorieParade() {
|
|
|
|
|
return game.settings.get("foundryvtt-reve-de-dragon", "rdd-combat-categorieParade");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static isUsingTripleSignificative() {
|
|
|
|
|
return game.settings.get("foundryvtt-reve-de-dragon", "rdd-combat-tripleSignificative");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
activateListeners(html) {
|
|
|
|
|
html.find(".select-option").click((event) => {
|
|
|
|
|
if (event.currentTarget.attributes.name) {
|
|
|
|
|
let id = event.currentTarget.attributes.name.value;
|
|
|
|
|
let isChecked = event.currentTarget.checked;
|
|
|
|
|
game.settings.set("foundryvtt-reve-de-dragon", id, isChecked);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async _updateObject(event, formData) {
|
|
|
|
|
this.close();
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-01-03 15:40:48 +01:00
|
|
|
|
|