2020-12-12 21:58:44 +01:00
|
|
|
|
import { ChatUtility } from "./chat-utility.js";
|
2023-01-19 01:42:42 +01:00
|
|
|
|
import { ENTITE_BLURETTE, HIDE_DICE, SYSTEM_RDD, SYSTEM_SOCKET_ID } from "./constants.js";
|
2022-07-03 15:32:20 +02:00
|
|
|
|
import { Grammar } from "./grammar.js";
|
2020-12-12 21:58:44 +01:00
|
|
|
|
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";
|
2023-06-20 23:43:24 +02:00
|
|
|
|
import { ReglesOptionnelles } from "./settings/regles-optionnelles.js";
|
2022-11-06 21:39:03 +01:00
|
|
|
|
import { STATUSES } from "./settings/status-effects.js";
|
2022-11-23 21:42:39 +01:00
|
|
|
|
import { Targets } from "./targets.js";
|
2023-04-21 18:18:20 +02:00
|
|
|
|
import { RdDEmpoignade } from "./rdd-empoignade.js";
|
2020-12-12 21:58:44 +01:00
|
|
|
|
|
2021-02-27 22:59:10 +01:00
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
|
const premierRoundInit = [
|
2021-06-28 16:08:45 +02:00
|
|
|
|
{ pattern: 'hast', init: 5.90 },
|
|
|
|
|
{ pattern: 'lance', init: 5.85 },
|
|
|
|
|
{ pattern: 'baton', init: 5.80 },
|
|
|
|
|
{ pattern: 'doubledragonne', init: 5.75 },
|
|
|
|
|
{ pattern: 'esparlongue', init: 5.70 },
|
|
|
|
|
{ pattern: 'epeedragonne', init: 5.65 },
|
|
|
|
|
{ pattern: 'epeebatarde', init: 5.60 },
|
|
|
|
|
{ pattern: 'epeecyane', init: 5.55 },
|
|
|
|
|
{ pattern: 'epeesorde', init: 5.50 },
|
|
|
|
|
{ pattern: 'grandehache', init: 5.45 },
|
|
|
|
|
{ pattern: 'bataille', init: 5.40 },
|
|
|
|
|
{ pattern: 'epeegnome', init: 5.35 },
|
|
|
|
|
{ pattern: 'masse', init: 5.30 },
|
|
|
|
|
{ pattern: 'gourdin', init: 5.25 },
|
2022-07-03 15:32:20 +02:00
|
|
|
|
{ pattern: 'fleau', init: 5.20 },
|
2021-06-28 16:08:45 +02:00
|
|
|
|
{ pattern: 'dague', init: 5.15 },
|
|
|
|
|
{ pattern: 'autre', init: 5.10 },
|
2021-02-27 22:59:10 +01:00
|
|
|
|
];
|
|
|
|
|
|
2021-02-09 09:18:52 +01:00
|
|
|
|
/* -------------------------------------------- */
|
2021-02-25 02:13:39 +01:00
|
|
|
|
export class RdDCombatManager extends Combat {
|
|
|
|
|
|
|
|
|
|
static init() {
|
|
|
|
|
/* -------------------------------------------- */
|
2023-02-24 00:38:14 +01:00
|
|
|
|
Hooks.on("getCombatTrackerEntryContext", (html, options) => { RdDCombatManager.pushInitiativeOptions(html, options); });
|
|
|
|
|
Hooks.on("updateCombat", (combat, change, options, userId) => { RdDCombat.onUpdateCombat(combat, change, options, userId) });
|
|
|
|
|
Hooks.on("preDeleteCombat", (combat, html, id) => { combat.onPreDeleteCombat() });
|
2021-02-09 09:18:52 +01:00
|
|
|
|
}
|
2021-02-25 02:13:39 +01:00
|
|
|
|
|
2021-02-17 11:16:27 +01:00
|
|
|
|
/* -------------------------------------------- */
|
2021-06-30 01:01:24 +02:00
|
|
|
|
async nextRound() {
|
|
|
|
|
await this.finDeRound();
|
|
|
|
|
return await super.nextRound();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
|
async onPreDeleteCombat() {
|
2023-02-24 00:38:14 +01:00
|
|
|
|
if (Misc.isUniqueConnectedGM()) {
|
|
|
|
|
await this.finDeRound({ terminer: true });
|
|
|
|
|
ChatUtility.removeChatMessageContaining(`<div data-combatid="${this.id}" data-combatmessage="actor-turn-summary">`)
|
|
|
|
|
game.messages.filter(m => ChatUtility.getMessageData(m, 'attacker-roll') != undefined && ChatUtility.getMessageData(m, 'defender-roll') != undefined)
|
|
|
|
|
.forEach(it => it.delete());
|
2023-04-21 18:18:20 +02:00
|
|
|
|
RdDEmpoignade.deleteAllEmpoignades()
|
2023-02-24 00:38:14 +01:00
|
|
|
|
}
|
2021-06-30 01:01:24 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
|
async finDeRound(options = { terminer: false }) {
|
2023-02-24 00:38:14 +01:00
|
|
|
|
this.turns.forEach(turn => turn.actor.resetItemUse());
|
|
|
|
|
|
2022-09-07 09:01:23 +02:00
|
|
|
|
for (let combatant of this.combatants) {
|
2021-03-14 19:04:35 +01:00
|
|
|
|
if (combatant.actor) {
|
2021-06-30 01:01:24 +02:00
|
|
|
|
await combatant.actor.finDeRound(options);
|
2021-03-14 14:22:25 +01:00
|
|
|
|
}
|
2021-03-14 19:04:35 +01:00
|
|
|
|
else {
|
2021-03-14 14:22:25 +01:00
|
|
|
|
ui.notifications.warn(`Le combatant ${combatant.name} n'est pas associé à un acteur!`)
|
|
|
|
|
}
|
2021-02-17 11:16:27 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
2021-02-09 09:18:52 +01:00
|
|
|
|
|
2021-02-25 02:13:39 +01:00
|
|
|
|
/************************************************************************************/
|
|
|
|
|
async rollInitiative(ids, formula = undefined, messageOptions = {}) {
|
2022-09-07 09:01:23 +02:00
|
|
|
|
console.log(`${game.system.title} | Combat.rollInitiative()`, ids, formula, messageOptions);
|
2022-09-07 18:47:56 +02:00
|
|
|
|
|
2021-02-25 02:13:39 +01:00
|
|
|
|
ids = typeof ids === "string" ? [ids] : ids;
|
|
|
|
|
// calculate initiative
|
|
|
|
|
for (let cId = 0; cId < ids.length; cId++) {
|
2021-12-18 09:45:36 +01:00
|
|
|
|
const combatant = this.combatants.get(ids[cId]);
|
2022-07-03 15:32:20 +02:00
|
|
|
|
let rollFormula = formula ?? RdDCombatManager.formuleInitiative(2, 10, 0, 0);
|
|
|
|
|
if (!formula) {
|
2022-07-14 22:32:57 +02:00
|
|
|
|
if (combatant.actor.type == 'creature' || combatant.actor.type == 'entite') {
|
2023-06-13 01:55:38 +02:00
|
|
|
|
const competence = combatant.actor.items.find(it => RdDItemCompetenceCreature.getCategorieAttaque(it))
|
2022-07-03 15:32:20 +02:00
|
|
|
|
if (competence) {
|
2022-07-14 22:32:57 +02:00
|
|
|
|
rollFormula = RdDCombatManager.formuleInitiative(2, competence.system.carac_value, competence.system.niveau, 0);
|
2021-02-25 02:13:39 +01:00
|
|
|
|
}
|
|
|
|
|
} else {
|
2022-09-07 18:47:56 +02:00
|
|
|
|
const armeCombat = combatant.actor.itemTypes['arme'].find(it => it.system.equipe)
|
2023-04-21 18:18:20 +02:00
|
|
|
|
let compName = "Corps à corps"
|
|
|
|
|
if (armeCombat) {
|
|
|
|
|
if (armeCombat.system.competence != "") {
|
2023-04-21 22:23:40 +02:00
|
|
|
|
compName = armeCombat.system.competence
|
2023-04-21 18:18:20 +02:00
|
|
|
|
}
|
|
|
|
|
if (armeCombat.system.lancer != "") {
|
2023-04-21 22:23:40 +02:00
|
|
|
|
compName = armeCombat.system.lancer
|
2023-04-21 18:18:20 +02:00
|
|
|
|
}
|
|
|
|
|
if (armeCombat.system.tir != "") {
|
2023-04-21 22:23:40 +02:00
|
|
|
|
compName = armeCombat.system.tir
|
2023-04-21 18:18:20 +02:00
|
|
|
|
}
|
2023-04-21 22:23:40 +02:00
|
|
|
|
}
|
2022-07-14 22:32:57 +02:00
|
|
|
|
const competence = RdDItemCompetence.findCompetence(combatant.actor.items, compName);
|
2023-04-21 18:18:20 +02:00
|
|
|
|
if (competence && competence.system.defaut_carac) {
|
2022-07-14 22:32:57 +02:00
|
|
|
|
const carac = combatant.actor.system.carac[competence.system.defaut_carac].value;
|
|
|
|
|
const niveau = competence.system.niveau;
|
2022-09-07 00:09:17 +02:00
|
|
|
|
const bonusEcaille = (armeCombat?.system.magique) ? armeCombat.system.ecaille_efficacite : 0;
|
2022-11-20 16:08:48 +01:00
|
|
|
|
rollFormula = RdDCombatManager.formuleInitiative(2, carac, niveau, bonusEcaille);
|
2023-04-21 18:18:20 +02:00
|
|
|
|
} else {
|
|
|
|
|
ui.notifications.warn(`Votre arme ${armeCombat.name} n'a pas de compétence renseignée`);
|
2021-02-25 02:13:39 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//console.log("Combatat", c);
|
2021-04-16 22:18:36 +02:00
|
|
|
|
const roll = combatant.getInitiativeRoll(rollFormula);
|
2022-11-20 16:08:48 +01:00
|
|
|
|
if (!roll.total) {
|
|
|
|
|
roll.evaluate({ async: false });
|
2021-12-18 09:45:36 +01:00
|
|
|
|
}
|
2023-01-19 01:42:42 +01:00
|
|
|
|
const total = Math.max(roll.total, 0.00);
|
|
|
|
|
console.log("Compute init for", rollFormula, roll, total, combatant);
|
2021-12-18 09:45:36 +01:00
|
|
|
|
let id = combatant._id || combatant.id;
|
2023-01-19 01:42:42 +01:00
|
|
|
|
await this.updateEmbeddedDocuments("Combatant", [{ _id: id, initiative: total }]);
|
2021-02-25 02:13:39 +01:00
|
|
|
|
|
|
|
|
|
// Send a chat message
|
|
|
|
|
let rollMode = messageOptions.rollMode || game.settings.get("core", "rollMode");
|
|
|
|
|
let messageData = mergeObject(
|
|
|
|
|
{
|
|
|
|
|
speaker: {
|
|
|
|
|
scene: canvas.scene._id,
|
2022-11-05 18:06:30 +01:00
|
|
|
|
actor: combatant.actor?._id,
|
2021-04-16 22:18:36 +02:00
|
|
|
|
token: combatant.token._id,
|
|
|
|
|
alias: combatant.token.name,
|
2021-02-25 02:13:39 +01:00
|
|
|
|
sound: CONFIG.sounds.dice,
|
|
|
|
|
},
|
2021-04-16 22:18:36 +02:00
|
|
|
|
flavor: `${combatant.token.name} a fait son jet d'Initiative (${messageOptions.initInfo})
|
2021-02-25 02:13:39 +01:00
|
|
|
|
<br>
|
|
|
|
|
`,
|
|
|
|
|
},
|
|
|
|
|
messageOptions
|
|
|
|
|
);
|
|
|
|
|
roll.toMessage(messageData, { rollMode, create: true });
|
|
|
|
|
|
|
|
|
|
RdDCombatManager.processPremierRoundInit();
|
|
|
|
|
}
|
|
|
|
|
return this;
|
|
|
|
|
};
|
|
|
|
|
|
2022-07-03 15:32:20 +02:00
|
|
|
|
static formuleInitiative(rang, carac, niveau, bonusMalus) {
|
|
|
|
|
return `${rang} +( (${RdDCombatManager.calculInitiative(niveau, carac, bonusMalus)} )/100)`;
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-25 02:13:39 +01:00
|
|
|
|
/* -------------------------------------------- */
|
2023-02-24 00:38:14 +01:00
|
|
|
|
static calculInitiative(niveau, caracValue, bonus = 0) {
|
|
|
|
|
let base = niveau + Math.floor(caracValue / 2) + bonus;
|
2021-02-25 02:13:39 +01:00
|
|
|
|
return "1d6" + (base >= 0 ? "+" : "") + base;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
2022-11-18 03:38:17 +01:00
|
|
|
|
/** Retourne une liste triée d'actions d'armes avec le split arme1 main / arme 2 main / lancer */
|
2022-07-03 15:32:20 +02:00
|
|
|
|
static listActionsArmes(armes, competences, carac) {
|
2022-11-18 03:38:17 +01:00
|
|
|
|
let actions = [];
|
2022-06-12 08:17:59 +02:00
|
|
|
|
for (const arme of armes) {
|
2022-11-18 03:38:17 +01:00
|
|
|
|
if (arme.system.equipe) {
|
2022-11-20 16:08:48 +01:00
|
|
|
|
const dommages = arme.system.dommages.toString();
|
|
|
|
|
const tableauDommages = dommages.includes("/") ? dommages.split("/") : [dommages, dommages];
|
2022-11-18 03:38:17 +01:00
|
|
|
|
if (arme.system.unemain && arme.system.deuxmains && !dommages.includes("/")) {
|
|
|
|
|
ui.notifications.info("Les dommages de l'arme à 1/2 mains " + arme.name + " ne sont pas corrects (ie sous la forme X/Y)");
|
|
|
|
|
}
|
2023-10-23 22:04:45 +02:00
|
|
|
|
if (arme.system.unemain && arme.system.competence) {
|
2022-11-18 03:38:17 +01:00
|
|
|
|
actions.push(RdDCombatManager.$prepareAttaqueArme({
|
|
|
|
|
arme: arme,
|
|
|
|
|
infoMain: "(1 main)",
|
|
|
|
|
dommagesReel: Number(tableauDommages[0]),
|
|
|
|
|
competence: arme.system.competence,
|
|
|
|
|
carac: carac,
|
|
|
|
|
competences: competences
|
|
|
|
|
}));
|
|
|
|
|
}
|
2022-11-18 23:06:27 +01:00
|
|
|
|
if (arme.system.deuxmains && arme.system.competence) {
|
2022-11-18 03:38:17 +01:00
|
|
|
|
actions.push(RdDCombatManager.$prepareAttaqueArme({
|
|
|
|
|
arme: arme,
|
|
|
|
|
infoMain: "(2 mains)",
|
|
|
|
|
dommagesReel: Number(tableauDommages[1]),
|
2023-10-23 22:04:45 +02:00
|
|
|
|
competence: RdDItemArme.competence2Mains(arme),
|
2022-11-18 03:38:17 +01:00
|
|
|
|
carac: carac,
|
|
|
|
|
competences: competences
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
if (arme.system.lancer) {
|
|
|
|
|
actions.push(RdDCombatManager.$prepareAttaqueArme({
|
|
|
|
|
arme: arme,
|
|
|
|
|
infoMain: "(lancer)",
|
|
|
|
|
dommagesReel: Number(tableauDommages[0]),
|
|
|
|
|
competence: arme.system.lancer,
|
|
|
|
|
carac: carac,
|
|
|
|
|
competences: competences
|
|
|
|
|
}));
|
2021-02-25 02:13:39 +01:00
|
|
|
|
}
|
2022-11-18 23:06:27 +01:00
|
|
|
|
if (arme.system.tir) {
|
|
|
|
|
actions.push(RdDCombatManager.$prepareAttaqueArme({
|
|
|
|
|
arme: arme,
|
|
|
|
|
infoMain: "(tir)",
|
|
|
|
|
dommagesReel: Number(tableauDommages[0]),
|
|
|
|
|
competence: arme.system.tir,
|
|
|
|
|
carac: carac,
|
|
|
|
|
competences: competences
|
|
|
|
|
}));
|
|
|
|
|
}
|
2021-02-25 02:13:39 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
2022-11-18 03:38:17 +01:00
|
|
|
|
return actions.sort(Misc.ascending(action => action.name + (action.system.infoMain ?? '')));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static $prepareAttaqueArme(infoAttaque) {
|
|
|
|
|
const comp = infoAttaque.competences.find(c => c.name == infoAttaque.competence);
|
|
|
|
|
const attaque = duplicate(infoAttaque.arme);
|
|
|
|
|
attaque.action = 'attaque';
|
|
|
|
|
attaque.system.competence = infoAttaque.competence;
|
|
|
|
|
attaque.system.dommagesReels = infoAttaque.dommagesReel;
|
|
|
|
|
attaque.system.infoMain = infoAttaque.infoMain;
|
|
|
|
|
attaque.system.niveau = comp.system.niveau;
|
|
|
|
|
attaque.system.initiative = RdDCombatManager.calculInitiative(comp.system.niveau, infoAttaque.carac[comp.system.defaut_carac].value);
|
|
|
|
|
return attaque;
|
2022-07-03 15:32:20 +02:00
|
|
|
|
}
|
|
|
|
|
|
2022-09-20 00:12:25 +02:00
|
|
|
|
static listActionsCreature(competences) {
|
2023-06-13 01:55:38 +02:00
|
|
|
|
return competences.map(it => RdDItemCompetenceCreature.armeCreature(it))
|
|
|
|
|
.filter(it => it != undefined);
|
2022-09-20 00:12:25 +02:00
|
|
|
|
}
|
|
|
|
|
|
2022-07-03 15:32:20 +02:00
|
|
|
|
static listActionsPossessions(actor) {
|
2022-11-20 16:08:48 +01:00
|
|
|
|
return RdDCombatManager._indexActions(actor.getPossessions().map(p => {
|
|
|
|
|
return {
|
|
|
|
|
name: p.name,
|
2023-06-13 01:55:38 +02:00
|
|
|
|
action: 'possession',
|
2022-11-20 16:08:48 +01:00
|
|
|
|
system: {
|
|
|
|
|
competence: p.name,
|
|
|
|
|
possessionid: p.system.possessionid,
|
2022-07-03 15:32:20 +02:00
|
|
|
|
}
|
2022-11-20 16:08:48 +01:00
|
|
|
|
}
|
|
|
|
|
}));
|
2021-02-25 02:13:39 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
2022-07-03 15:32:20 +02:00
|
|
|
|
static listActionsCombat(combatant) {
|
|
|
|
|
const actor = combatant.actor;
|
|
|
|
|
let actions = RdDCombatManager.listActionsPossessions(actor);
|
2022-11-20 16:08:48 +01:00
|
|
|
|
if (actions.length > 0) {
|
2022-07-03 15:32:20 +02:00
|
|
|
|
return actions;
|
2021-03-14 14:22:25 +01:00
|
|
|
|
}
|
2022-12-03 15:33:16 +01:00
|
|
|
|
if (actor.isCreatureEntite()) {
|
2023-06-13 01:55:38 +02:00
|
|
|
|
actions = RdDCombatManager.listActionsCreature(actor.itemTypes['competencecreature']);
|
2022-12-28 23:35:17 +01:00
|
|
|
|
} else if (actor.isPersonnage()) {
|
2021-02-25 02:13:39 +01:00
|
|
|
|
// Recupération des items 'arme'
|
2022-09-20 00:12:25 +02:00
|
|
|
|
const armes = actor.itemTypes['arme'].filter(it => RdDItemArme.isArmeUtilisable(it))
|
2023-04-21 18:18:20 +02:00
|
|
|
|
.concat(RdDItemArme.empoignade())
|
2021-11-20 00:42:04 +01:00
|
|
|
|
.concat(RdDItemArme.mainsNues());
|
2021-02-25 02:13:39 +01:00
|
|
|
|
|
2022-09-20 00:12:25 +02:00
|
|
|
|
const competences = actor.itemTypes['competence'];
|
2023-06-13 01:55:38 +02:00
|
|
|
|
actions = RdDCombatManager.listActionsArmes(armes, competences, actor.system.carac);
|
2021-05-22 02:19:22 +02:00
|
|
|
|
|
2022-09-07 00:09:17 +02:00
|
|
|
|
if (actor.system.attributs.hautrevant.value) {
|
2022-09-07 18:47:56 +02:00
|
|
|
|
actions.push({ name: "Draconic", action: 'haut-reve', system: { initOnly: true, competence: "Draconic" } });
|
2021-04-03 03:04:48 +02:00
|
|
|
|
}
|
2021-02-25 02:13:39 +01:00
|
|
|
|
}
|
|
|
|
|
|
2022-07-03 15:32:20 +02:00
|
|
|
|
return RdDCombatManager._indexActions(actions);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static _indexActions(actions) {
|
2021-02-25 02:13:39 +01:00
|
|
|
|
for (let index = 0; index < actions.length; index++) {
|
|
|
|
|
actions[index].index = index;
|
|
|
|
|
}
|
|
|
|
|
return actions;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
|
static processPremierRoundInit() {
|
|
|
|
|
// Check if we have the whole init !
|
2021-11-26 00:45:21 +01:00
|
|
|
|
if (Misc.isUniqueConnectedGM() && game.combat.current.round == 1) {
|
2022-09-07 09:01:23 +02:00
|
|
|
|
let initMissing = game.combat.combatants.find(it => !it.initiative);
|
2021-02-25 02:13:39 +01:00
|
|
|
|
if (!initMissing) { // Premier round !
|
2022-09-07 09:01:23 +02:00
|
|
|
|
for (let combatant of game.combat.combatants) {
|
2022-07-03 15:32:20 +02:00
|
|
|
|
let action = combatant.initiativeData?.arme;
|
2021-02-25 02:13:39 +01:00
|
|
|
|
//console.log("Parsed !!!", combatant, initDone, game.combat.current, arme);
|
2022-07-03 15:32:20 +02:00
|
|
|
|
if (action && action.type == "arme") {
|
2021-02-25 02:13:39 +01:00
|
|
|
|
for (let initData of premierRoundInit) {
|
2022-09-07 00:09:17 +02:00
|
|
|
|
if (Grammar.toLowerCaseNoAccentNoSpace(action.system.initpremierround).includes(initData.pattern)) {
|
2021-02-25 02:13:39 +01:00
|
|
|
|
let msg = `<h4>L'initiative de ${combatant.actor.name} a été modifiée !</h4>
|
|
|
|
|
<hr>
|
|
|
|
|
<div>
|
2022-07-03 15:32:20 +02:00
|
|
|
|
Etant donné son ${action.name}, son initative pour ce premier round est désormais de ${initData.init}.
|
2021-02-25 02:13:39 +01:00
|
|
|
|
</div>`
|
|
|
|
|
ChatMessage.create({ content: msg });
|
|
|
|
|
game.combat.setInitiative(combatant._id, initData.init);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
|
static incDecInit(combatantId, incDecValue) {
|
2021-12-18 09:45:36 +01:00
|
|
|
|
const combatant = game.combat.combatants.get(combatantId);
|
2021-02-25 02:13:39 +01:00
|
|
|
|
let initValue = combatant.initiative + incDecValue;
|
|
|
|
|
game.combat.setInitiative(combatantId, initValue);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
|
static pushInitiativeOptions(html, options) {
|
|
|
|
|
for (let i = 0; i < options.length; i++) {
|
|
|
|
|
let option = options[i];
|
|
|
|
|
if (option.name == 'COMBAT.CombatantReroll') { // Replace !
|
|
|
|
|
option.name = "Sélectionner l'initiative...";
|
|
|
|
|
option.condition = true;
|
|
|
|
|
option.icon = '<i class="far fa-question-circle"></i>';
|
|
|
|
|
option.callback = target => {
|
|
|
|
|
RdDCombatManager.displayInitiativeMenu(html, target.data('combatant-id'));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
options = [
|
|
|
|
|
{ name: "Incrémenter initiative", condition: true, icon: '<i class="fas fa-plus"></i>', callback: target => { RdDCombatManager.incDecInit(target.data('combatant-id'), +0.01); } },
|
|
|
|
|
{ name: "Décrémenter initiative", condition: true, icon: '<i class="fas fa-minus"></i>', callback: target => { RdDCombatManager.incDecInit(target.data('combatant-id'), -0.01); } }
|
|
|
|
|
].concat(options);
|
|
|
|
|
}
|
|
|
|
|
/* -------------------------------------------- */
|
2022-07-03 15:32:20 +02:00
|
|
|
|
static rollInitiativeAction(combatantId, action) {
|
2021-12-18 09:45:36 +01:00
|
|
|
|
const combatant = game.combat.combatants.get(combatantId);
|
2021-03-14 14:22:25 +01:00
|
|
|
|
if (combatant.actor == undefined) {
|
|
|
|
|
ui.notifications.warn(`Le combatant ${combatant.name} n'est pas associé à un acteur, impossible de déterminer ses actions de combat!`)
|
|
|
|
|
return [];
|
|
|
|
|
}
|
2021-02-25 02:13:39 +01:00
|
|
|
|
|
|
|
|
|
let initInfo = "";
|
|
|
|
|
let initOffset = 0;
|
|
|
|
|
let caracForInit = 0;
|
|
|
|
|
let compNiveau = 0;
|
2021-04-16 22:18:36 +02:00
|
|
|
|
let compData = { name: "Aucune" };
|
2021-03-14 14:22:25 +01:00
|
|
|
|
if (combatant.actor.getSurprise() == "totale") {
|
2021-02-25 02:13:39 +01:00
|
|
|
|
initOffset = -1; // To force 0
|
|
|
|
|
initInfo = "Surprise Totale"
|
2021-03-14 14:22:25 +01:00
|
|
|
|
} else if (combatant.actor.getSurprise() == "demi") {
|
2021-02-25 02:13:39 +01:00
|
|
|
|
initOffset = 0;
|
|
|
|
|
initInfo = "Demi Surprise"
|
2023-06-13 01:55:38 +02:00
|
|
|
|
} else if (action.action == 'possession') {
|
2022-07-03 15:32:20 +02:00
|
|
|
|
initOffset = 10;
|
|
|
|
|
caracForInit = combatant.actor.getReveActuel();
|
|
|
|
|
initInfo = "Possession"
|
2022-07-22 00:36:16 +02:00
|
|
|
|
} else if (action.action == 'autre') {
|
2021-02-25 02:13:39 +01:00
|
|
|
|
initOffset = 2;
|
|
|
|
|
initInfo = "Autre Action"
|
2022-07-03 15:32:20 +02:00
|
|
|
|
} else if (action.action == 'haut-reve') {
|
2021-06-28 16:08:45 +02:00
|
|
|
|
initOffset = 9;
|
2021-02-25 02:13:39 +01:00
|
|
|
|
initInfo = "Draconic"
|
|
|
|
|
} else {
|
2022-09-20 00:09:45 +02:00
|
|
|
|
compData = RdDItemCompetence.findCompetence(combatant.actor.items, action.system.competence);
|
2022-06-12 09:46:58 +02:00
|
|
|
|
compNiveau = compData.system.niveau;
|
2022-09-20 00:12:25 +02:00
|
|
|
|
initInfo = action.name + " / " + action.system.competence;
|
2022-11-20 16:08:48 +01:00
|
|
|
|
|
2022-09-20 00:12:25 +02:00
|
|
|
|
if (combatant.actor.type == 'creature' || combatant.actor.type == 'entite') {
|
|
|
|
|
caracForInit = compData.system.carac_value;
|
|
|
|
|
} else {
|
|
|
|
|
caracForInit = combatant.actor.system.carac[compData.system.defaut_carac].value;
|
2021-02-25 02:13:39 +01:00
|
|
|
|
}
|
2022-09-20 00:12:25 +02:00
|
|
|
|
initOffset = RdDCombatManager._baseInitOffset(compData.system.categorie, action);
|
2021-02-25 02:13:39 +01:00
|
|
|
|
}
|
2022-07-03 15:32:20 +02:00
|
|
|
|
|
2021-03-14 14:22:25 +01:00
|
|
|
|
let malus = combatant.actor.getEtatGeneral(); // Prise en compte état général
|
2021-02-25 02:13:39 +01:00
|
|
|
|
// Cas des créatures et entités vs personnages
|
2022-07-03 15:32:20 +02:00
|
|
|
|
let rollFormula = RdDCombatManager.formuleInitiative(initOffset, caracForInit, compNiveau, malus);
|
2021-02-25 02:13:39 +01:00
|
|
|
|
// Garder la trace de l'arme/compétence utilisée pour l'iniative
|
2022-07-03 15:32:20 +02:00
|
|
|
|
combatant.initiativeData = { arme: action } // pour reclasser l'init au round 0
|
2021-02-25 02:13:39 +01:00
|
|
|
|
game.combat.rollInitiative(combatantId, rollFormula, { initInfo: initInfo });
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-05 20:00:42 +02:00
|
|
|
|
/* -------------------------------------------- */
|
2021-06-28 16:08:45 +02:00
|
|
|
|
static _baseInitOffset(categorie, arme) {
|
|
|
|
|
if (categorie == "tir") { // Offset de principe pour les armes de jet
|
|
|
|
|
return 8;
|
|
|
|
|
}
|
|
|
|
|
if (categorie == "lancer") { // Offset de principe pour les armes de jet
|
|
|
|
|
return 7;
|
|
|
|
|
}
|
2022-09-07 00:09:17 +02:00
|
|
|
|
switch (arme.system.cac) {
|
2022-09-20 00:12:25 +02:00
|
|
|
|
case "empoignade":
|
|
|
|
|
return 3;
|
2022-11-20 16:08:48 +01:00
|
|
|
|
case "pugilat":
|
2022-09-20 00:12:25 +02:00
|
|
|
|
case "naturelle":
|
|
|
|
|
return 4;
|
2021-06-28 16:08:45 +02:00
|
|
|
|
}
|
|
|
|
|
return 5;
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-25 02:13:39 +01:00
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
|
static displayInitiativeMenu(html, combatantId) {
|
2021-02-27 22:59:10 +01:00
|
|
|
|
console.log("Combatant ; ", combatantId);
|
2021-12-18 09:45:36 +01:00
|
|
|
|
const combatant = game.combat.combatants.get(combatantId);
|
2022-11-20 16:08:48 +01:00
|
|
|
|
if (!(combatant?.actor)) {
|
2022-07-03 15:32:20 +02:00
|
|
|
|
ui.notifications.warn(`Le combatant ${combatant.name ?? combatantId} n'est pas associé à un acteur, impossible de déterminer ses actions de combat!`)
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let actions = RdDCombatManager.listActionsCombat(combatant);
|
2021-02-25 02:13:39 +01:00
|
|
|
|
|
|
|
|
|
// Build the relevant submenu
|
2022-07-03 15:32:20 +02:00
|
|
|
|
if (actions) {
|
2021-02-25 02:13:39 +01:00
|
|
|
|
let menuItems = [];
|
2022-07-03 15:32:20 +02:00
|
|
|
|
for (let action of actions) {
|
2021-02-25 02:13:39 +01:00
|
|
|
|
menuItems.push({
|
2022-09-07 00:09:17 +02:00
|
|
|
|
name: action.system.competence,
|
2021-02-25 02:13:39 +01:00
|
|
|
|
icon: "<i class='fas fa-dice-d6'></i>",
|
2022-07-03 15:32:20 +02:00
|
|
|
|
callback: target => { RdDCombatManager.rollInitiativeAction(combatantId, action) }
|
2021-02-25 02:13:39 +01:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
new ContextMenu(html, ".directory-list", menuItems).render();
|
|
|
|
|
}
|
2021-02-09 09:18:52 +01:00
|
|
|
|
}
|
2021-02-25 02:13:39 +01:00
|
|
|
|
|
2021-02-09 09:18:52 +01:00
|
|
|
|
}
|
|
|
|
|
|
2021-02-04 16:35:22 +01:00
|
|
|
|
/* -------------------------------------------- */
|
2020-12-12 21:58:44 +01:00
|
|
|
|
export class RdDCombat {
|
|
|
|
|
|
2021-01-10 00:30:37 +01:00
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
|
static onSocketMessage(sockmsg) {
|
|
|
|
|
switch (sockmsg.msg) {
|
2023-02-24 00:38:14 +01:00
|
|
|
|
case "msg_encaisser": return RdDCombat.onMsgEncaisser(sockmsg.data);
|
|
|
|
|
case "msg_defense": return RdDCombat.onMsgDefense(sockmsg.data);
|
2021-01-10 00:30:37 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
2021-03-29 23:41:08 +02:00
|
|
|
|
static onUpdateCombat(combat, change, options, userId) {
|
2022-09-07 09:01:23 +02:00
|
|
|
|
if (combat.round != 0 && combat.turns && combat.active) {
|
2021-02-09 09:18:52 +01:00
|
|
|
|
RdDCombat.combatNouveauTour(combat);
|
2021-01-10 00:30:37 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
2021-02-09 09:18:52 +01:00
|
|
|
|
static combatNouveauTour(combat) {
|
2021-11-28 18:34:41 +01:00
|
|
|
|
if (Misc.isUniqueConnectedGM()) {
|
2021-06-01 00:08:23 +02:00
|
|
|
|
let turn = combat.turns.find(t => t.token?.id == combat.current.tokenId);
|
|
|
|
|
if (turn?.actor) {
|
|
|
|
|
RdDCombat.displayActorCombatStatus(combat, turn.actor);
|
|
|
|
|
// TODO Playaudio for player??
|
|
|
|
|
}
|
2021-01-10 00:30:37 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
2022-11-23 00:10:06 +01:00
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
|
static rddCombatTarget(target, attacker) {
|
|
|
|
|
const defender = target?.actor;
|
|
|
|
|
const defenderTokenId = target?.id;
|
|
|
|
|
return new RdDCombat(attacker, defender, defenderTokenId, target)
|
2020-12-12 21:58:44 +01:00
|
|
|
|
}
|
|
|
|
|
|
2020-12-16 09:07:00 +01:00
|
|
|
|
/* -------------------------------------------- */
|
2022-11-22 02:12:26 +01:00
|
|
|
|
static rddCombatForAttackerAndDefender(attackerId, defenderTokenId) {
|
2021-01-19 22:31:32 +01:00
|
|
|
|
const attacker = game.actors.get(attackerId);
|
2022-11-22 02:12:26 +01:00
|
|
|
|
let defender = defenderTokenId ? canvas.tokens.get(defenderTokenId)?.actor : undefined;
|
|
|
|
|
let target = undefined
|
|
|
|
|
if (!defenderTokenId || !defender) {
|
2022-11-23 00:10:06 +01:00
|
|
|
|
console.warn(`RdDCombat.rddCombatForAttackerAndDefender: appel avec defenderTokenId ${defenderTokenId} incorrect, ou pas de defender correspondant`);
|
2022-11-23 21:42:39 +01:00
|
|
|
|
target = Targets.getTarget()
|
2022-11-22 02:12:26 +01:00
|
|
|
|
if (!target) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
defenderTokenId = target.id;
|
|
|
|
|
defender = target.actor;
|
|
|
|
|
if (!defenderTokenId || !defender) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2020-12-12 21:58:44 +01:00
|
|
|
|
}
|
2022-11-22 02:12:26 +01:00
|
|
|
|
return new RdDCombat(attacker, defender, defenderTokenId, target)
|
2020-12-12 21:58:44 +01:00
|
|
|
|
}
|
|
|
|
|
|
2021-01-10 00:30:37 +01:00
|
|
|
|
/* -------------------------------------------- */
|
2022-06-12 08:17:59 +02:00
|
|
|
|
static onMsgEncaisser(msg) {
|
|
|
|
|
let defender = canvas.tokens.get(msg.defenderTokenId).actor;
|
2022-01-29 18:49:06 +01:00
|
|
|
|
if (Misc.isOwnerPlayerOrUniqueConnectedGM()) {
|
2022-06-12 08:17:59 +02:00
|
|
|
|
let attackerRoll = msg.attackerRoll;
|
2022-11-05 18:06:30 +01:00
|
|
|
|
let attacker = msg.attackerId ? game.actors.get(msg.attackerId) : undefined;
|
2021-01-15 19:10:50 +01:00
|
|
|
|
|
|
|
|
|
defender.encaisserDommages(attackerRoll, attacker);
|
2022-11-22 02:12:26 +01:00
|
|
|
|
const rddCombat = RdDCombat.rddCombatForAttackerAndDefender(msg.attackerId, msg.defenderTokenId);
|
2022-06-12 08:17:59 +02:00
|
|
|
|
rddCombat?.removeChatMessageActionsPasseArme(attackerRoll.passeArme);
|
2021-01-15 19:10:50 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
2021-01-19 22:31:32 +01:00
|
|
|
|
static onMsgDefense(msg) {
|
|
|
|
|
let defenderToken = canvas.tokens.get(msg.defenderTokenId);
|
2021-11-28 18:34:41 +01:00
|
|
|
|
if (defenderToken && Misc.isUniqueConnectedGM()) {
|
2022-11-22 02:12:26 +01:00
|
|
|
|
const rddCombat = RdDCombat.rddCombatForAttackerAndDefender(msg.attackerId, msg.defenderTokenId);
|
2022-06-12 08:17:59 +02:00
|
|
|
|
rddCombat?.removeChatMessageActionsPasseArme(msg.defenderRoll.passeArme);
|
|
|
|
|
rddCombat?._chatMessageDefense(msg.paramChatDefense, msg.defenderRoll);
|
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 => {
|
2022-11-22 02:12:26 +01:00
|
|
|
|
const rddCombat = RdDCombat.rddCombatForAttackerAndDefender(
|
2021-01-19 22:31:32 +01:00
|
|
|
|
event.currentTarget.attributes['data-attackerId']?.value,
|
|
|
|
|
event.currentTarget.attributes['data-defenderTokenId']?.value);
|
2021-03-18 23:55:59 +01:00
|
|
|
|
if (rddCombat) {
|
|
|
|
|
rddCombat.onEvent(button, event);
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
}
|
2020-12-12 21:58:44 +01:00
|
|
|
|
});
|
|
|
|
|
}
|
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) {
|
2022-10-05 20:00:42 +02:00
|
|
|
|
this.attacker = attacker
|
|
|
|
|
this.defender = defender
|
|
|
|
|
this.target = target
|
|
|
|
|
this.attackerId = this.attacker.id
|
|
|
|
|
this.defenderId = this.defender.id
|
|
|
|
|
this.defenderTokenId = defenderTokenId
|
2020-12-18 22:15:17 +01:00
|
|
|
|
}
|
|
|
|
|
|
2020-12-12 21:58:44 +01:00
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
|
async onEvent(button, event) {
|
2022-01-29 23:33:31 +01:00
|
|
|
|
const chatMessage = ChatUtility.getChatMessage(event);
|
|
|
|
|
const defenderRoll = ChatUtility.getMessageData(chatMessage, 'defender-roll');
|
2022-11-20 16:08:48 +01:00
|
|
|
|
const attackerRoll = defenderRoll?.attackerRoll ?? ChatUtility.getMessageData(chatMessage, 'attacker-roll');
|
2022-01-29 23:33:31 +01:00
|
|
|
|
console.log('RdDCombat', attackerRoll, defenderRoll);
|
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-11-20 02:53:28 +01:00
|
|
|
|
const competence = event.currentTarget.attributes['data-competence']?.value;
|
|
|
|
|
const compId = event.currentTarget.attributes['data-compid']?.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-12-08 23:22:37 +01:00
|
|
|
|
case '#parer-button': return this.parade(attackerRoll, armeParadeId);
|
2021-11-20 02:53:28 +01:00
|
|
|
|
case '#esquiver-button': return this.esquive(attackerRoll, compId, competence);
|
2022-01-29 23:33:31 +01:00
|
|
|
|
case '#encaisser-button': return this.encaisser(attackerRoll, defenderRoll, 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(
|
2022-01-29 23:33:31 +01:00
|
|
|
|
() => this.defenseDestinee(defenderRoll),
|
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
|
|
|
|
/* -------------------------------------------- */
|
2022-01-29 23:33:31 +01:00
|
|
|
|
defenseDestinee(defenderRoll) {
|
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-11-11 02:43:38 +01:00
|
|
|
|
if (game.settings.get(SYSTEM_RDD, "supprimer-dialogues-combat-chat")) {
|
2021-01-20 00:44:19 +01:00
|
|
|
|
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;
|
2021-03-14 19:19:37 +01:00
|
|
|
|
case 'demi': return !rollData.rolled.isSign;
|
2020-12-16 23:02:15 +01:00
|
|
|
|
}
|
|
|
|
|
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) {
|
2021-04-03 23:59:29 +02:00
|
|
|
|
return rollData.rolled.isEchec && rollData.rolled.code != 'notSign';
|
2020-12-16 23:02:15 +01:00
|
|
|
|
}
|
|
|
|
|
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;
|
2021-03-14 19:19:37 +01:00
|
|
|
|
case 'demi': return rollData.rolled.isSign;
|
2020-12-16 23:02:15 +01:00
|
|
|
|
}
|
|
|
|
|
return rollData.rolled.isSuccess;
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-05 20:00:42 +02:00
|
|
|
|
/* -------------------------------------------- */
|
2022-11-20 16:08:48 +01:00
|
|
|
|
async proposerAjustementTirLancer(rollData) {
|
2022-10-07 23:28:41 +02:00
|
|
|
|
if (['tir', 'lancer'].includes(rollData.competence.system.categorie)) {
|
2022-11-20 16:08:48 +01:00
|
|
|
|
if (this.defender.isEntite([ENTITE_BLURETTE])) {
|
|
|
|
|
ChatMessage.create({
|
2022-10-07 23:28:41 +02:00
|
|
|
|
content: `<strong>La cible est une blurette, l'arme à distance sera perdue dans le blurêve`,
|
2022-11-20 16:08:48 +01:00
|
|
|
|
whisper: ChatMessage.getWhisperRecipients("GM")
|
|
|
|
|
})
|
2022-10-07 23:28:41 +02:00
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
const defenderToken = canvas.tokens.get(this.defenderTokenId);
|
|
|
|
|
const dist = this.distance(_token, defenderToken)
|
2022-10-07 23:46:36 +02:00
|
|
|
|
const isVisible = this.isVisible(_token, defenderToken)
|
2022-10-07 23:28:41 +02:00
|
|
|
|
const portee = this._ajustementPortee(dist, rollData.arme)
|
|
|
|
|
const taille = this._ajustementTaille(this.defender)
|
|
|
|
|
const activite = this._ajustementMouvement(this.defender)
|
2022-11-20 16:08:48 +01:00
|
|
|
|
const total = [portee, taille, activite].map(it => it.diff).filter(d => !Number.isNaN(d)).reduce(Misc.sum(), 0)
|
2022-10-07 23:28:41 +02:00
|
|
|
|
ChatMessage.create({
|
|
|
|
|
content: await renderTemplate('systems/foundryvtt-reve-de-dragon/templates/chat-info-distance.html', {
|
|
|
|
|
rollData: rollData,
|
|
|
|
|
attacker: _token,
|
2022-10-07 23:46:36 +02:00
|
|
|
|
isVisible: isVisible,
|
2022-10-07 23:28:41 +02:00
|
|
|
|
defender: defenderToken,
|
|
|
|
|
distance: dist,
|
|
|
|
|
portee: portee,
|
|
|
|
|
taille: taille,
|
|
|
|
|
activite: activite,
|
|
|
|
|
total: total
|
|
|
|
|
}),
|
|
|
|
|
whisper: ChatMessage.getWhisperRecipients("GM")
|
|
|
|
|
})
|
2022-10-06 14:07:47 +02:00
|
|
|
|
}
|
2022-10-05 20:00:42 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-08 11:56:52 +02:00
|
|
|
|
isVisible(token, defenderToken) {
|
|
|
|
|
return canvas.effects.visibility.testVisibility(defenderToken.center, { object: token })
|
2022-10-07 23:46:36 +02:00
|
|
|
|
}
|
2022-11-20 16:08:48 +01:00
|
|
|
|
|
2022-10-08 11:56:52 +02:00
|
|
|
|
distance(token, defenderToken) {
|
|
|
|
|
return Number(canvas.grid.measureDistances([{ ray: new Ray(token.center, defenderToken.center) }], { gridSpaces: false })).toFixed(1);
|
2022-10-07 23:28:41 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_ajustementPortee(dist, arme) {
|
2022-11-20 16:08:48 +01:00
|
|
|
|
if (dist <= arme.system.portee_courte) return { msg: "courte", diff: 0 };
|
|
|
|
|
if (dist <= arme.system.portee_moyenne) return { msg: "moyenne", diff: -3 };
|
|
|
|
|
if (dist <= arme.system.portee_extreme) return { msg: "extrême", diff: -5 };
|
|
|
|
|
return { msg: "inatteignable", diff: -10 };
|
2022-10-07 23:28:41 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_ajustementTaille(actor) {
|
2022-11-20 16:08:48 +01:00
|
|
|
|
if (actor.isVehicule()) return { msg: "véhicule", diff: 0 }
|
2022-10-07 23:28:41 +02:00
|
|
|
|
const taille = actor.getCaracByName('TAILLE')?.value ?? 1;
|
2022-11-20 16:08:48 +01:00
|
|
|
|
if (taille <= 1) return { msg: "souris", diff: -8 };
|
|
|
|
|
if (taille <= 3) return { msg: "chat", diff: -4 };
|
|
|
|
|
if (taille <= 5) return { msg: "chien", diff: -2 };
|
|
|
|
|
if (taille <= 15) return { msg: "humanoïde", diff: 0 };
|
|
|
|
|
if (taille <= 20) return { msg: "ogre", diff: 2 };
|
|
|
|
|
return { msg: "gigantesque", diff: 4 };
|
2022-10-07 23:28:41 +02:00
|
|
|
|
}
|
|
|
|
|
_ajustementMouvement(defender) {
|
2022-11-20 16:08:48 +01:00
|
|
|
|
if (defender.getSurprise(true)) return { msg: "immobile (surprise)", diff: 0 };
|
|
|
|
|
if (game.combat?.combatants.find(it => it.actorId == defender.id)) return { msg: "en mouvement (combat)", diff: -4 };
|
|
|
|
|
return { msg: "à déterminer (0 immobile, -3 actif, -4 en mouvement, -5 en zig-zag)", diff: -3 };
|
2022-10-07 23:28:41 +02:00
|
|
|
|
}
|
|
|
|
|
|
2020-12-12 21:58:44 +01:00
|
|
|
|
/* -------------------------------------------- */
|
2021-06-28 16:08:45 +02:00
|
|
|
|
async attaque(competence, arme) {
|
2022-12-07 14:20:53 +01:00
|
|
|
|
if (!await this.attacker.accorder(this.defender, 'avant-attaque')) {
|
2020-12-12 21:58:44 +01:00
|
|
|
|
return;
|
|
|
|
|
}
|
2023-04-21 18:18:20 +02:00
|
|
|
|
if (arme.system.cac == 'empoignade') {
|
|
|
|
|
RdDEmpoignade.onAttaqueEmpoignade(this.attacker, this.defender)
|
2022-06-12 08:17:59 +02:00
|
|
|
|
return;
|
2021-06-28 16:08:45 +02:00
|
|
|
|
}
|
2023-04-21 22:27:47 +02:00
|
|
|
|
RdDEmpoignade.checkEmpoignadeEnCours(this.attacker)
|
2020-12-12 21:58:44 +01:00
|
|
|
|
|
|
|
|
|
let rollData = this._prepareAttaque(competence, arme);
|
|
|
|
|
console.log("RdDCombat.attaque >>>", rollData);
|
2021-03-12 23:19:34 +01:00
|
|
|
|
if (arme) {
|
|
|
|
|
this.attacker.verifierForceMin(arme);
|
|
|
|
|
}
|
2022-10-07 23:28:41 +02:00
|
|
|
|
await this.proposerAjustementTirLancer(rollData)
|
2020-12-12 21:58:44 +01:00
|
|
|
|
|
|
|
|
|
const dialog = await RdDRoll.create(this.attacker, rollData,
|
2022-11-23 22:41:49 +01:00
|
|
|
|
{ html: 'systems/foundryvtt-reve-de-dragon/templates/dialog-roll-competence.html' },
|
2020-12-17 12:29:54 +01:00
|
|
|
|
{
|
2022-11-23 22:41:49 +01:00
|
|
|
|
name: 'jet-attaque',
|
|
|
|
|
label: 'Attaque: ' + (arme?.name ?? competence.name),
|
|
|
|
|
callbacks: [
|
|
|
|
|
this.attacker.createCallbackExperience(),
|
|
|
|
|
this.attacker.createCallbackAppelAuMoral(),
|
|
|
|
|
{ action: r => this.removeChatMessageActionsPasseArme(r.passeArme) },
|
|
|
|
|
{ condition: r => arme && !RdDCombat.isParticuliere(r), action: r => this.attacker.incDecItemUse(arme._id) },
|
|
|
|
|
{ condition: r => (RdDCombat.isReussite(r) && !RdDCombat.isParticuliere(r)), action: r => this._onAttaqueNormale(r) },
|
|
|
|
|
{ condition: RdDCombat.isParticuliere, action: r => this._onAttaqueParticuliere(r) },
|
|
|
|
|
{ condition: RdDCombat.isEchec, action: r => this._onAttaqueEchec(r) },
|
|
|
|
|
{ condition: RdDCombat.isEchecTotal, action: r => this._onAttaqueEchecTotal(r) },
|
|
|
|
|
]
|
|
|
|
|
});
|
2022-06-12 08:17:59 +02:00
|
|
|
|
dialog.render(true);
|
2020-12-12 21:58:44 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
|
_prepareAttaque(competence, arme) {
|
|
|
|
|
let rollData = {
|
2021-01-07 00:32:22 +01:00
|
|
|
|
passeArme: randomID(16),
|
2022-06-12 12:14:55 +02:00
|
|
|
|
mortalite: arme?.system.mortalite,
|
2023-08-03 00:33:56 +02:00
|
|
|
|
competence: competence,
|
2021-01-13 03:42:13 +01:00
|
|
|
|
surprise: this.attacker.getSurprise(true),
|
|
|
|
|
surpriseDefenseur: this.defender.getSurprise(true),
|
2022-11-23 21:42:39 +01:00
|
|
|
|
targetToken: Targets.extractTokenData(this.target),
|
2021-01-09 19:33:19 +01:00
|
|
|
|
essais: {}
|
2020-12-12 21:58:44 +01:00
|
|
|
|
};
|
2021-06-28 16:08:45 +02:00
|
|
|
|
|
2022-12-03 15:33:16 +01:00
|
|
|
|
if (this.attacker.isCreatureEntite()) {
|
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
|
2022-06-12 12:14:55 +02:00
|
|
|
|
const niveau = competence.system.niveau;
|
2022-06-12 09:46:58 +02:00
|
|
|
|
const init = RdDCombatManager.calculInitiative(niveau, this.attacker.system.carac['melee'].value);
|
2021-06-28 16:08:45 +02:00
|
|
|
|
rollData.arme = RdDItemArme.mainsNues({ niveau: niveau, initiative: init });
|
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) {
|
2022-11-20 16:08:48 +01:00
|
|
|
|
|
2021-03-14 19:06:43 +01:00
|
|
|
|
const isMeleeDiffNegative = (rollData.competence.type == 'competencecreature' || rollData.selectedCarac.label == "Mêlée") && rollData.diffLibre < 0;
|
2021-06-28 16:08:45 +02:00
|
|
|
|
// force toujours, sauf empoignade
|
|
|
|
|
// finesse seulement en mélée, pour l'empoignade, ou si la difficulté libre est de -1 minimum
|
|
|
|
|
// rapidité seulement en mêlée, si l'arme le permet, et si la difficulté libre est de -1 minimum
|
2022-06-12 12:14:55 +02:00
|
|
|
|
const isForce = !rollData.arme.system.empoignade;
|
|
|
|
|
const isFinesse = rollData.arme.system.empoignade || isMeleeDiffNegative;
|
|
|
|
|
const isRapide = !rollData.arme.system.empoignade && isMeleeDiffNegative && rollData.arme.system.rapide;
|
2021-06-28 16:08:45 +02:00
|
|
|
|
// si un seul choix possible, le prendre
|
|
|
|
|
if (isForce && !isFinesse && !isRapide) {
|
|
|
|
|
return await this.choixParticuliere(rollData, "force");
|
|
|
|
|
}
|
|
|
|
|
else if (!isForce && isFinesse && !isRapide) {
|
|
|
|
|
return await this.choixParticuliere(rollData, "finesse");
|
|
|
|
|
}
|
|
|
|
|
else if (!isForce && !isFinesse && isRapide) {
|
|
|
|
|
return await this.choixParticuliere(rollData, "rapidite");
|
|
|
|
|
}
|
2022-11-20 16:08:48 +01:00
|
|
|
|
|
2022-01-29 23:33:31 +01:00
|
|
|
|
const choixParticuliere = await 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,
|
2021-06-28 16:08:45 +02:00
|
|
|
|
isForce: isForce,
|
|
|
|
|
isFinesse: isFinesse,
|
|
|
|
|
isRapide: isRapide,
|
2021-01-19 22:31:32 +01:00
|
|
|
|
passeArme: rollData.passeArme
|
2021-01-07 01:54:38 +01:00
|
|
|
|
})
|
|
|
|
|
});
|
2022-01-29 23:33:31 +01:00
|
|
|
|
ChatUtility.setMessageData(choixParticuliere, 'attacker-roll', rollData);
|
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
|
|
|
|
|
2022-07-22 21:38:15 +02:00
|
|
|
|
attackerRoll.dmg = RdDBonus.dmg(attackerRoll, this.attacker.getBonusDegat(), this.defender.isEntite());
|
2021-01-19 22:31:32 +01:00
|
|
|
|
let defenderRoll = { attackerRoll: attackerRoll, passeArme: attackerRoll.passeArme, show: {} }
|
2021-01-07 01:54:38 +01:00
|
|
|
|
attackerRoll.show = {
|
2022-10-08 15:38:56 +02:00
|
|
|
|
cible: this.target ? this.defender.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
|
|
|
|
|
2022-12-07 14:20:53 +01:00
|
|
|
|
if (!await this.attacker.accorder(this.defender, 'avant-defense')) {
|
2020-12-19 18:02:05 +01:00
|
|
|
|
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-11-20 02:53:28 +01:00
|
|
|
|
|
2021-11-08 14:58:06 +01:00
|
|
|
|
/* -------------------------------------------- */
|
2022-11-20 16:08:48 +01:00
|
|
|
|
isPossession(attackerRoll) {
|
2021-11-08 14:58:06 +01:00
|
|
|
|
return attackerRoll.selectedCarac.label.toLowerCase() == 'possession';
|
|
|
|
|
}
|
2020-12-12 21:58:44 +01:00
|
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
2021-01-19 22:31:32 +01:00
|
|
|
|
async _sendMessageDefense(attackerRoll, defenderRoll, essaisPrecedents = undefined) {
|
2022-06-12 12:14:55 +02:00
|
|
|
|
console.log("RdDCombat._sendMessageDefense", attackerRoll, defenderRoll, essaisPrecedents, " / ", this.attacker, this.target, this.attackerId, attackerRoll.competence.system.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-02-09 09:18:52 +01:00
|
|
|
|
|
|
|
|
|
// # utilisation esquive
|
2022-06-12 09:46:58 +02:00
|
|
|
|
const corpsACorps = this.defender.getCompetence("Corps à corps", { onMessage: it => console.info(it, this.defender) });
|
|
|
|
|
const esquives = duplicate(this.defender.getCompetences("esquive", { onMessage: it => console.info(it, this.defender) }))
|
2022-09-21 14:13:43 +02:00
|
|
|
|
esquives.forEach(e => e.system.nbUsage = e?._id ? this.defender.getItemUse(e._id) : 0);
|
2021-02-09 09:18:52 +01:00
|
|
|
|
|
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-11-20 02:53:28 +01:00
|
|
|
|
isPossession: this.isPossession(attackerRoll),
|
2022-06-12 09:46:58 +02:00
|
|
|
|
defender: this.defender,
|
|
|
|
|
attacker: this.attacker,
|
2021-01-07 00:32:22 +01:00
|
|
|
|
attackerId: this.attackerId,
|
2021-11-20 02:53:28 +01:00
|
|
|
|
esquives: esquives,
|
2021-01-07 00:32:22 +01:00
|
|
|
|
defenderTokenId: this.defenderTokenId,
|
2021-04-20 00:52:06 +02:00
|
|
|
|
mainsNues: attackerRoll.dmg.mortalite != 'mortel' && corpsACorps,
|
2021-02-09 09:18:52 +01:00
|
|
|
|
armes: this._filterArmesParade(this.defender, 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,
|
2022-06-12 12:14:55 +02:00
|
|
|
|
attaqueCategorie: attackerRoll.competence.system.categorie,
|
2021-01-19 22:31:32 +01:00
|
|
|
|
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
|
|
|
|
|
2022-01-29 18:49:06 +01:00
|
|
|
|
if (Misc.isUniqueConnectedGM()) {
|
2022-01-29 23:33:31 +01:00
|
|
|
|
await this._chatMessageDefense(paramChatDefense, defenderRoll);
|
2021-01-19 22:31:32 +01:00
|
|
|
|
}
|
|
|
|
|
else {
|
2022-01-29 18:49:06 +01:00
|
|
|
|
this._socketSendMessageDefense(paramChatDefense, defenderRoll);
|
2021-01-19 22:31:32 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
2021-01-15 19:10:50 +01:00
|
|
|
|
|
2021-01-19 22:31:32 +01:00
|
|
|
|
/* -------------------------------------------- */
|
2022-01-29 23:33:31 +01:00
|
|
|
|
async _chatMessageDefense(paramDemandeDefense, defenderRoll) {
|
|
|
|
|
const choixDefense = await ChatMessage.create({
|
2021-01-19 22:31:32 +01:00
|
|
|
|
// 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
|
|
|
|
});
|
2022-01-29 23:33:31 +01:00
|
|
|
|
// flag pour garder les jets d'attaque/defense
|
|
|
|
|
ChatUtility.setMessageData(choixDefense, 'defender-roll', defenderRoll);
|
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
|
2022-01-29 22:49:34 +01:00
|
|
|
|
game.socket.emit(SYSTEM_SOCKET_ID, {
|
2021-01-19 22:31:32 +01:00
|
|
|
|
msg: "msg_defense", data: {
|
2022-06-12 12:14:55 +02:00
|
|
|
|
attackerId: this.attacker?.id,
|
|
|
|
|
defenderId: this.defender?.id,
|
2021-01-19 22:31:32 +01:00
|
|
|
|
defenderTokenId: this.defenderTokenId,
|
2021-03-29 18:08:18 +02:00
|
|
|
|
defenderRoll: 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-02-09 09:18:52 +01:00
|
|
|
|
_filterArmesParade(defender, competence) {
|
2022-09-07 18:47:56 +02:00
|
|
|
|
let items = defender.items.filter(it => RdDItemArme.isArmeUtilisable(it) || RdDItemCompetenceCreature.isCompetenceParade(it))
|
2023-02-24 00:38:14 +01:00
|
|
|
|
items.forEach(item => item.system.nbUsage = defender.getItemUse(item.id)); // Ajout du # d'utilisation ce round
|
|
|
|
|
|
2022-06-12 12:14:55 +02:00
|
|
|
|
switch (competence.system.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) {
|
2022-01-29 23:33:31 +01:00
|
|
|
|
const choixEchecTotal = await ChatMessage.create({
|
2021-02-25 02:13:39 +01:00
|
|
|
|
whisper: ChatUtility.getWhisperRecipientsAndGMs(this.attacker.name),
|
2021-01-07 01:54:38 +01:00
|
|
|
|
content: await renderTemplate('systems/foundryvtt-reve-de-dragon/templates/chat-demande-attaque-etotal.html', {
|
|
|
|
|
attackerId: this.attackerId,
|
2022-06-12 09:46:58 +02:00
|
|
|
|
attacker: this.attacker,
|
2021-01-07 01:54:38 +01:00
|
|
|
|
defenderTokenId: this.defenderTokenId,
|
|
|
|
|
essais: attackerRoll.essais
|
|
|
|
|
})
|
|
|
|
|
});
|
2022-01-29 23:33:31 +01:00
|
|
|
|
ChatUtility.setMessageData(choixEchecTotal, 'attacker-roll', attackerRoll);
|
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;
|
2022-06-12 12:14:55 +02:00
|
|
|
|
const avecArme = !['', 'sans-armes', 'armes-naturelles'].includes(arme?.system.categorie_parade ?? '');
|
2021-01-07 01:54:38 +01:00
|
|
|
|
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-02-25 02:06:21 +01:00
|
|
|
|
content: `<strong>Maladresse à ${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-03-14 19:04:35 +01:00
|
|
|
|
if (choix != "rapidite") {
|
2022-06-12 12:14:55 +02:00
|
|
|
|
this.attacker.incDecItemUse(rollData.arme.id);
|
2021-03-14 19:04:35 +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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
2021-12-08 23:22:37 +01:00
|
|
|
|
async parade(attackerRoll, armeParadeId) {
|
|
|
|
|
const arme = this.defender.getArmeParade(armeParadeId);
|
2020-12-12 21:58:44 +01:00
|
|
|
|
console.log("RdDCombat.parade >>>", attackerRoll, armeParadeId, arme);
|
2022-09-07 18:47:56 +02:00
|
|
|
|
const competence = arme?.system?.competence;
|
2022-11-20 16:08:48 +01:00
|
|
|
|
if (competence == undefined) {
|
|
|
|
|
console.error("Pas de compétence de parade associée à ", arme?.name, armeParadeId);
|
2021-12-08 23:22:37 +01:00
|
|
|
|
return;
|
|
|
|
|
}
|
2020-12-12 21:58:44 +01:00
|
|
|
|
|
2021-11-20 02:53:28 +01:00
|
|
|
|
let rollData = this._prepareParade(attackerRoll, arme, competence);
|
2020-12-12 21:58:44 +01:00
|
|
|
|
|
|
|
|
|
const dialog = await RdDRoll.create(this.defender, rollData,
|
2022-11-23 22:41:49 +01:00
|
|
|
|
{ html: 'systems/foundryvtt-reve-de-dragon/templates/dialog-roll-competence.html' },
|
2020-12-17 12:29:54 +01:00
|
|
|
|
{
|
2022-11-23 22:41:49 +01:00
|
|
|
|
name: 'jet-parade',
|
|
|
|
|
label: 'Parade: ' + (arme ? arme.name : rollData.competence.name),
|
|
|
|
|
callbacks: [
|
|
|
|
|
this.defender.createCallbackExperience(),
|
|
|
|
|
this.defender.createCallbackAppelAuMoral(),
|
|
|
|
|
{ action: r => this.removeChatMessageActionsPasseArme(r.passeArme) },
|
|
|
|
|
{ condition: r => !RdDCombat.isParticuliere(r), action: r => this.defender.incDecItemUse(armeParadeId) },
|
|
|
|
|
{ condition: RdDCombat.isReussite, action: r => this._onParadeNormale(r) },
|
|
|
|
|
{ condition: RdDCombat.isParticuliere, action: r => this._onParadeParticuliere(r) },
|
|
|
|
|
{ condition: RdDCombat.isEchec, action: r => this._onParadeEchec(r) },
|
|
|
|
|
]
|
|
|
|
|
});
|
2020-12-12 21:58:44 +01:00
|
|
|
|
dialog.render(true);
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-09 09:18:52 +01:00
|
|
|
|
/* -------------------------------------------- */
|
2021-11-20 02:53:28 +01:00
|
|
|
|
_prepareParade(attackerRoll, armeParade, competenceParade) {
|
2021-03-14 19:04:35 +01:00
|
|
|
|
let defenderRoll = {
|
2021-01-07 00:32:22 +01:00
|
|
|
|
passeArme: attackerRoll.passeArme,
|
2020-12-12 21:58:44 +01:00
|
|
|
|
diffLibre: attackerRoll.diffLibre,
|
|
|
|
|
attackerRoll: attackerRoll,
|
2023-08-03 00:33:56 +02:00
|
|
|
|
competence: this.defender.getCompetence(competenceParade),
|
2020-12-17 00:23:40 +01:00
|
|
|
|
arme: armeParade,
|
2021-01-13 03:42:13 +01:00
|
|
|
|
surprise: this.defender.getSurprise(true),
|
2023-06-20 23:43:24 +02:00
|
|
|
|
needParadeSignificative: ReglesOptionnelles.isUsing('categorieParade') && RdDItemArme.needParadeSignificative(attackerRoll.arme, armeParade),
|
2021-11-20 02:53:28 +01:00
|
|
|
|
needResist: RdDItemArme.needArmeResist(attackerRoll.arme, armeParade),
|
2022-06-12 09:46:58 +02:00
|
|
|
|
carac: this.defender.system.carac,
|
2021-01-02 04:28:43 +01:00
|
|
|
|
show: {}
|
2020-12-12 21:58:44 +01:00
|
|
|
|
};
|
2021-01-13 03:42:13 +01:00
|
|
|
|
|
2022-12-03 15:33:16 +01:00
|
|
|
|
if (this.defender.isCreatureEntite()) {
|
2021-03-14 19:04:35 +01:00
|
|
|
|
RdDItemCompetenceCreature.setRollDataCreature(defenderRoll);
|
2020-12-12 21:58:44 +01:00
|
|
|
|
}
|
2021-01-14 00:35:55 +01:00
|
|
|
|
|
2021-03-14 19:04:35 +01:00
|
|
|
|
return defenderRoll;
|
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-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');
|
2022-06-12 08:17:59 +02:00
|
|
|
|
this.removeChatMessageActionsPasseArme(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 });
|
2020-12-12 21:58:44 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
2021-11-20 02:53:28 +01:00
|
|
|
|
async esquive(attackerRoll, compId, compName) {
|
2022-06-12 09:46:58 +02:00
|
|
|
|
const esquive = this.defender.getCompetence(compId) ?? this.defender.getCompetence(compName)
|
2020-12-12 21:58:44 +01:00
|
|
|
|
if (esquive == undefined) {
|
2021-11-20 02:53:28 +01:00
|
|
|
|
ui.notifications.error(this.defender.name + " n'a pas de compétence " + compName);
|
2020-12-12 21:58:44 +01:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
console.log("RdDCombat.esquive >>>", attackerRoll, esquive);
|
|
|
|
|
let rollData = this._prepareEsquive(attackerRoll, esquive);
|
|
|
|
|
|
|
|
|
|
const dialog = await RdDRoll.create(this.defender, rollData,
|
2022-11-23 22:41:49 +01:00
|
|
|
|
{ html: 'systems/foundryvtt-reve-de-dragon/templates/dialog-roll-competence.html' },
|
|
|
|
|
{
|
|
|
|
|
name: 'jet-esquive',
|
|
|
|
|
label: 'Esquiver',
|
|
|
|
|
callbacks: [
|
|
|
|
|
this.defender.createCallbackExperience(),
|
|
|
|
|
this.defender.createCallbackAppelAuMoral(),
|
|
|
|
|
{ condition: r => !RdDCombat.isParticuliere(r), action: r => this.defender.incDecItemUse(esquive._id) },
|
|
|
|
|
{ action: r => this.removeChatMessageActionsPasseArme(r.passeArme) },
|
|
|
|
|
{ condition: RdDCombat.isReussite, action: r => this._onEsquiveNormale(r) },
|
|
|
|
|
{ condition: RdDCombat.isParticuliere, action: r => this._onEsquiveParticuliere(r) },
|
|
|
|
|
{ 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,
|
2023-08-03 00:33:56 +02:00
|
|
|
|
competence: competence,
|
2021-01-13 03:42:13 +01:00
|
|
|
|
surprise: this.defender.getSurprise(true),
|
|
|
|
|
surpriseDefenseur: this.defender.getSurprise(true),
|
2022-06-12 09:46:58 +02:00
|
|
|
|
carac: this.defender.system.carac,
|
2021-01-02 04:28:43 +01:00
|
|
|
|
show: {}
|
2020-12-12 21:58:44 +01:00
|
|
|
|
};
|
|
|
|
|
|
2022-12-03 15:33:16 +01:00
|
|
|
|
if (this.defender.isCreatureEntite()) {
|
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');
|
2022-06-12 08:17:59 +02:00
|
|
|
|
this.removeChatMessageActionsPasseArme(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 })
|
2020-12-12 21:58:44 +01:00
|
|
|
|
}
|
2021-01-01 03:25:48 +01:00
|
|
|
|
|
2020-12-17 00:44:32 +01:00
|
|
|
|
/* -------------------------------------------- */
|
2021-01-28 00:27:44 +01:00
|
|
|
|
async computeDeteriorationArme(defenderRoll) {
|
2023-06-20 23:43:24 +02:00
|
|
|
|
if (!ReglesOptionnelles.isUsing('resistanceArmeParade')) {
|
2021-01-25 08:48:03 +01:00
|
|
|
|
return;
|
|
|
|
|
}
|
2021-01-28 00:27:44 +01:00
|
|
|
|
const attackerRoll = defenderRoll.attackerRoll;
|
2021-01-02 04:28:43 +01:00
|
|
|
|
// Est-ce une parade normale?
|
2021-01-28 00:27:44 +01:00
|
|
|
|
if (defenderRoll.arme && attackerRoll && !defenderRoll.rolled.isPart) {
|
2021-01-02 04:28:43 +01:00
|
|
|
|
// Est-ce que l'attaque est une particulière en force ou une charge
|
2021-01-28 00:27:44 +01:00
|
|
|
|
if (defenderRoll.needResist || this._isForceOuCharge(attackerRoll)) {
|
2021-01-02 04:28:43 +01:00
|
|
|
|
|
2021-01-28 00:27:44 +01:00
|
|
|
|
defenderRoll.show = defenderRoll.show || {}
|
2021-01-02 04:28:43 +01:00
|
|
|
|
|
2020-12-17 00:44:32 +01:00
|
|
|
|
const dmg = attackerRoll.dmg.dmgArme + attackerRoll.dmg.dmgActor;
|
2021-01-29 20:10:43 +01:00
|
|
|
|
let arme = defenderRoll.arme;
|
2022-06-12 12:14:55 +02:00
|
|
|
|
let resistance = Misc.toInt(arme.system.resistance);
|
|
|
|
|
if (arme.system.magique) {
|
2021-01-29 20:10:43 +01:00
|
|
|
|
defenderRoll.show.deteriorationArme = 'resiste'; // Par défaut
|
2022-06-12 12:14:55 +02:00
|
|
|
|
if (arme.system.resistance_magique == undefined) arme.system.resistance_magique = 0; // Quick fix
|
|
|
|
|
if (dmg > arme.system.resistance_magique) { // Jet uniquement si dommages supérieur à résistance magique (cf. 274)
|
2021-01-29 20:10:43 +01:00
|
|
|
|
// Jet de résistance de l'arme de parade (p.132)
|
|
|
|
|
let resistRoll = await RdDResolutionTable.rollData({
|
|
|
|
|
caracValue: resistance,
|
|
|
|
|
finalLevel: - dmg,
|
2021-12-03 22:53:38 +01:00
|
|
|
|
showDice: HIDE_DICE
|
2021-01-29 20:10:43 +01:00
|
|
|
|
});
|
2021-02-25 02:13:39 +01:00
|
|
|
|
if (!resistRoll.rolled.isSuccess) {
|
2022-06-12 12:14:55 +02:00
|
|
|
|
let perteResistance = (dmg - arme.system.resistance_magique)
|
2021-01-29 20:10:43 +01:00
|
|
|
|
resistance -= perteResistance;
|
2021-02-25 02:13:39 +01:00
|
|
|
|
defenderRoll.show.deteriorationArme = resistance <= 0 ? 'brise' : 'perte';
|
2021-01-29 20:10:43 +01:00
|
|
|
|
defenderRoll.show.perteResistance = perteResistance;
|
2022-09-07 18:47:56 +02:00
|
|
|
|
this.defender.updateEmbeddedDocuments('Item', [{ _id: defenderRoll.arme._id, 'system.resistance': resistance }]);
|
2021-01-29 20:10:43 +01:00
|
|
|
|
}
|
2021-02-25 02:13:39 +01:00
|
|
|
|
}
|
2020-12-17 00:44:32 +01:00
|
|
|
|
} else {
|
2021-01-29 20:10:43 +01:00
|
|
|
|
// Jet de résistance de l'arme de parade (p.132)
|
|
|
|
|
let resistRoll = await RdDResolutionTable.rollData({
|
|
|
|
|
caracValue: resistance,
|
|
|
|
|
finalLevel: - dmg,
|
2021-12-03 22:53:38 +01:00
|
|
|
|
showDice: HIDE_DICE
|
2021-01-29 20:10:43 +01:00
|
|
|
|
});
|
|
|
|
|
if (resistRoll.rolled.isSuccess) { // Perte de résistance
|
|
|
|
|
defenderRoll.show.deteriorationArme = 'resiste';
|
|
|
|
|
} else {
|
|
|
|
|
resistance -= dmg;
|
2021-02-25 02:13:39 +01:00
|
|
|
|
defenderRoll.show.deteriorationArme = resistance <= 0 ? 'brise' : 'perte';
|
2021-01-29 20:10:43 +01:00
|
|
|
|
defenderRoll.show.perteResistance = dmg;
|
2022-09-07 18:47:56 +02:00
|
|
|
|
this.defender.updateEmbeddedDocuments('Item', [{ _id: defenderRoll.arme._id, 'system.resistance': resistance }]);
|
2021-01-29 20:10:43 +01:00
|
|
|
|
}
|
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)
|
2023-06-20 23:43:24 +02:00
|
|
|
|
if (ReglesOptionnelles.isUsing('defenseurDesarme') && resistance > 0 && RdDItemArme.getCategorieParade(defenderRoll.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(),
|
2022-06-12 12:14:55 +02:00
|
|
|
|
finalLevel: Misc.toInt(defenderRoll.competence.system.niveau) - dmg,
|
2021-12-03 22:53:38 +01:00
|
|
|
|
showDice: HIDE_DICE
|
2020-12-17 12:29:54 +01:00
|
|
|
|
});
|
2021-01-28 00:27:44 +01:00
|
|
|
|
defenderRoll.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;
|
2023-06-20 23:43:24 +02:00
|
|
|
|
if (ReglesOptionnelles.isUsing('recul') && this._isForceOuCharge(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';
|
2022-09-17 22:36:43 +02:00
|
|
|
|
await this.defender.setEffect(STATUSES.StatusProne, true);
|
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-28 00:27:44 +01:00
|
|
|
|
_isForceOuCharge(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();
|
2022-06-12 12:14:55 +02:00
|
|
|
|
const dommages = attaque.arme.system.dommagesReels ?? attaque.arme.system.dommages;
|
2021-01-23 18:36:30 +01:00
|
|
|
|
return taille - (force + dommages);
|
2021-01-02 04:28:43 +01:00
|
|
|
|
}
|
|
|
|
|
|
2020-12-12 21:58:44 +01:00
|
|
|
|
/* -------------------------------------------- */
|
2022-01-29 23:33:31 +01:00
|
|
|
|
async encaisser(attackerRoll, defenderRoll, 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
|
|
|
|
if (defenderRoll?.rolled && RdDCombat.isEchecTotal(defenderRoll)) {
|
2021-01-07 01:54:38 +01:00
|
|
|
|
this._onEchecTotal(defenderRoll);
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-29 18:49:06 +01:00
|
|
|
|
if (Misc.isOwnerPlayerOrUniqueConnectedGM(this.defender)) {
|
2020-12-12 21:58:44 +01:00
|
|
|
|
attackerRoll.attackerId = this.attackerId;
|
|
|
|
|
attackerRoll.defenderTokenId = defenderTokenId;
|
2021-01-07 00:32:22 +01:00
|
|
|
|
|
|
|
|
|
await this.computeRecul(defenderRoll);
|
2022-10-09 02:19:33 +02:00
|
|
|
|
this.defender.encaisserDommages(attackerRoll, this.attacker, defenderRoll?.show);
|
2021-05-22 02:19:22 +02:00
|
|
|
|
}
|
|
|
|
|
else { // envoi à un GM: les joueurs n'ont pas le droit de modifier les personnages qu'ils ne possèdent pas
|
2022-01-29 22:49:34 +01:00
|
|
|
|
game.socket.emit(SYSTEM_SOCKET_ID, {
|
2020-12-12 21:58:44 +01:00
|
|
|
|
msg: "msg_encaisser",
|
2021-01-15 19:10:50 +01:00
|
|
|
|
data: {
|
|
|
|
|
attackerId: this.attackerId,
|
|
|
|
|
defenderTokenId: defenderTokenId,
|
2021-05-22 14:48:51 +02:00
|
|
|
|
attackerRoll: attackerRoll
|
2021-01-15 19:10:50 +01:00
|
|
|
|
}
|
2020-12-12 21:58:44 +01:00
|
|
|
|
});
|
|
|
|
|
}
|
2021-01-19 22:31:32 +01:00
|
|
|
|
this.removeChatMessageActionsPasseArme(attackerRoll.passeArme);
|
2020-12-12 21:58:44 +01:00
|
|
|
|
}
|
|
|
|
|
|
2021-01-03 15:40:48 +01:00
|
|
|
|
/* -------------------------------------------- */
|
2021-01-10 00:30:37 +01:00
|
|
|
|
static async displayActorCombatStatus(combat, actor) {
|
2022-09-07 18:47:56 +02:00
|
|
|
|
let formData = {
|
2021-01-10 00:30:37 +01:00
|
|
|
|
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(),
|
2022-06-12 12:14:55 +02:00
|
|
|
|
actorId: actor.id,
|
2023-03-20 23:28:25 +01:00
|
|
|
|
isGrave: actor.countBlessures(it => it.isGrave()) > 0,
|
2023-03-14 02:38:21 +01:00
|
|
|
|
isCritique: actor.countBlessures(it => it.isCritique()) > 0
|
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, {
|
2022-09-07 18:47:56 +02:00
|
|
|
|
content: await renderTemplate(`systems/foundryvtt-reve-de-dragon/templates/chat-actor-turn-summary.html`, formData)
|
2021-01-09 19:36:19 +01:00
|
|
|
|
});
|
2021-01-03 15:40:48 +01:00
|
|
|
|
}
|
2021-01-25 08:48:03 +01:00
|
|
|
|
}
|