2020-12-12 21:58:44 +01:00
|
|
|
import { ChatUtility } from "./chat-utility.js";
|
|
|
|
import { RdDItemArme } from "./item-arme.js";
|
|
|
|
import { RdDItemCompetence } from "./item-competence.js";
|
|
|
|
import { Misc } from "./misc.js";
|
2020-12-16 23:02:15 +01:00
|
|
|
import { RdDBonus } from "./rdd-bonus.js";
|
2020-12-12 21:58:44 +01:00
|
|
|
import { RdDResolutionTable } from "./rdd-resolution-table.js";
|
|
|
|
import { RdDRoll } from "./rdd-roll.js";
|
2020-12-17 12:29:54 +01:00
|
|
|
import { RdDRollTables } from "./rdd-rolltables.js";
|
2020-12-12 21:58:44 +01:00
|
|
|
|
|
|
|
export class RdDCombat {
|
|
|
|
|
2020-12-16 09:07:00 +01:00
|
|
|
/* -------------------------------------------- */
|
2020-12-12 21:58:44 +01:00
|
|
|
static isActive() {
|
2020-12-15 23:54:05 +01:00
|
|
|
return true;
|
2020-12-12 21:58:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
static createUsingTarget(attacker) {
|
|
|
|
const target = RdDCombat.getTarget();
|
|
|
|
if (target == undefined) {
|
2020-12-15 02:20:24 +01:00
|
|
|
ui.notifications.warn("Vous devez choisir une seule cible à attaquer!");
|
2020-12-12 21:58:44 +01:00
|
|
|
}
|
|
|
|
return this.create(attacker, target ? target.actor : undefined, target)
|
|
|
|
}
|
|
|
|
|
2020-12-16 09:07:00 +01:00
|
|
|
/* -------------------------------------------- */
|
2020-12-12 21:58:44 +01:00
|
|
|
static getTarget() {
|
|
|
|
if (game.user.targets && game.user.targets.size == 1) {
|
|
|
|
for (let target of game.user.targets) {
|
|
|
|
return target;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
|
2020-12-16 09:07:00 +01:00
|
|
|
/* -------------------------------------------- */
|
2020-12-12 21:58:44 +01:00
|
|
|
static create(attacker, defender, target = undefined) {
|
|
|
|
return new RdDCombat(attacker, defender, target)
|
|
|
|
}
|
|
|
|
|
2020-12-16 09:07:00 +01:00
|
|
|
/* -------------------------------------------- */
|
2020-12-12 21:58:44 +01:00
|
|
|
static createForEvent(event) {
|
|
|
|
let attackerId = event.currentTarget.attributes['data-attackerId'].value;
|
|
|
|
let attacker = game.actors.get(attackerId);
|
|
|
|
|
|
|
|
const dataDefenderTokenId = event.currentTarget.attributes['data-defenderTokenId'];
|
|
|
|
if (dataDefenderTokenId) {
|
|
|
|
let defenderToken = canvas.tokens.get(dataDefenderTokenId.value);
|
|
|
|
let defender = defenderToken.actor;
|
|
|
|
|
|
|
|
return this.create(attacker, defender);
|
|
|
|
}
|
|
|
|
return this.createUsingTarget(attacker)
|
|
|
|
}
|
|
|
|
|
2020-12-16 09:07:00 +01:00
|
|
|
/* -------------------------------------------- */
|
2020-12-12 21:58:44 +01:00
|
|
|
constructor(attacker, defender, target) {
|
|
|
|
this.attacker = attacker;
|
|
|
|
this.defender = defender;
|
|
|
|
this.target = target;
|
|
|
|
this.attackerId = this.attacker.data._id;
|
|
|
|
this.defenderId = this.defender.data._id;
|
|
|
|
this.defenderTokenId = target ? target.data._id : undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
static registerChatCallbacks(html) {
|
|
|
|
for (let button of ['#parer-button', '#esquiver-button', '#particuliere-attaque', '#encaisser-button']) {
|
|
|
|
html.on("click", button, event => {
|
|
|
|
event.preventDefault();
|
|
|
|
RdDCombat.createForEvent(event).onEvent(button, event);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
async onEvent(button, event) {
|
|
|
|
let rollData = game.system.rdd.rollDataHandler[this.attackerId];
|
2020-12-15 18:15:03 +01:00
|
|
|
if (!rollData) {
|
|
|
|
ui.notifications.warn("Action automatisée impossible, le jet de l'attaquant a été perdu (suite à un raffraichissement?)")
|
|
|
|
return;
|
|
|
|
}
|
2020-12-12 21:58:44 +01:00
|
|
|
switch (button) {
|
|
|
|
case '#particuliere-attaque': return await this.choixParticuliere(rollData, event.currentTarget.attributes['data-mode'].value);
|
2020-12-17 00:23:40 +01:00
|
|
|
case '#parer-button': {
|
|
|
|
const armeId = event.currentTarget.attributes['data-armeid'];
|
|
|
|
return this.parade(rollData, armeId ? armeId.value : undefined);
|
|
|
|
}
|
2020-12-12 21:58:44 +01:00
|
|
|
case '#esquiver-button': return this.esquive(rollData);
|
|
|
|
case '#encaisser-button': return this.encaisser(rollData, event.currentTarget.attributes['data-defenderTokenId'].value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-16 23:02:15 +01:00
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
static isEchec(rollData) {
|
|
|
|
switch (rollData.surprise) {
|
|
|
|
case 'demi': return !rollData.rolled.isSign;
|
|
|
|
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) {
|
|
|
|
if (rollData.arme && rollData.surprise == 'demi') {
|
|
|
|
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) {
|
|
|
|
if (rollData.arme && rollData.surprise) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return rollData.rolled.isPart;
|
|
|
|
}
|
2020-12-17 12:29:54 +01:00
|
|
|
|
2020-12-16 23:02:15 +01:00
|
|
|
/* -------------------------------------------- */
|
|
|
|
static isReussite(rollData) {
|
|
|
|
switch (rollData.surprise) {
|
|
|
|
case 'demi': return rollData.rolled.isSign;
|
|
|
|
case 'totale': return false;
|
|
|
|
}
|
|
|
|
return rollData.rolled.isSuccess;
|
|
|
|
}
|
|
|
|
|
2020-12-12 21:58:44 +01:00
|
|
|
/* -------------------------------------------- */
|
|
|
|
async attaque(competence, arme) {
|
|
|
|
if (!await this.accorderEntite('avant-attaque')) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let rollData = this._prepareAttaque(competence, arme);
|
|
|
|
console.log("RdDCombat.attaque >>>", rollData);
|
|
|
|
|
|
|
|
const dialog = await RdDRoll.create(this.attacker, rollData,
|
2020-12-17 12:29:54 +01:00
|
|
|
{
|
|
|
|
html: 'systems/foundryvtt-reve-de-dragon/templates/dialog-competence.html',
|
|
|
|
options: { height: 540 }
|
|
|
|
}, {
|
2020-12-12 21:58:44 +01:00
|
|
|
name: 'jet-attaque',
|
|
|
|
label: 'Attaque: ' + (arme ? arme.name : competence.name),
|
|
|
|
callbacks: [
|
|
|
|
this.attacker.createCallbackExperience(),
|
2020-12-16 23:02:15 +01:00
|
|
|
{ condition: r => (RdDCombat.isReussite(r) && !RdDCombat.isParticuliere(r)), action: r => this._onAttaqueNormale(r) },
|
2020-12-17 01:08:14 +01:00
|
|
|
{ condition: RdDCombat.isParticuliere, action: r => this._onAttaqueParticuliere(r) },
|
|
|
|
{ condition: RdDCombat.isEchec, action: r => this._onAttaqueEchec(r) },
|
2020-12-16 23:02:15 +01:00
|
|
|
{ condition: RdDCombat.isEchecTotal, action: r => this._onAttaqueEchecTotal(r) },
|
2020-12-12 21:58:44 +01:00
|
|
|
]
|
2020-12-17 12:29:54 +01:00
|
|
|
});
|
2020-12-12 21:58:44 +01:00
|
|
|
dialog.render(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
_prepareAttaque(competence, arme) {
|
|
|
|
let rollData = {
|
|
|
|
coupsNonMortels: false,
|
|
|
|
competence: competence,
|
2020-12-16 23:02:15 +01:00
|
|
|
surprise: this.attacker.getSurprise(),
|
|
|
|
surpriseDefenseur: this.defender.getSurprise()
|
2020-12-12 21:58:44 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
if (this.attacker.isCreature()) {
|
2020-12-15 02:20:24 +01:00
|
|
|
this._modifieRollDataCreature(rollData, competence);
|
2020-12-12 21:58:44 +01:00
|
|
|
}
|
2020-12-16 23:02:15 +01:00
|
|
|
else if (arme) {
|
2020-12-12 21:58:44 +01:00
|
|
|
// Usual competence
|
|
|
|
rollData.arme = RdDItemArme.armeUneOuDeuxMains(arme, RdDItemCompetence.isArmeUneMain(competence));
|
|
|
|
}
|
2020-12-16 23:02:15 +01:00
|
|
|
else {
|
|
|
|
// sans armes: à mains nues
|
|
|
|
rollData.arme = RdDItemArme.mainsNues();
|
|
|
|
}
|
2020-12-12 21:58:44 +01:00
|
|
|
return rollData;
|
|
|
|
}
|
|
|
|
|
2020-12-15 02:20:24 +01:00
|
|
|
_modifieRollDataCreature(rollData, competence) {
|
2020-12-12 21:58:44 +01:00
|
|
|
competence = duplicate(competence);
|
|
|
|
competence.data.defaut_carac = "carac_creature";
|
|
|
|
competence.data.categorie = "creature";
|
2020-12-15 02:20:24 +01:00
|
|
|
|
2020-12-12 21:58:44 +01:00
|
|
|
rollData.competence = competence;
|
|
|
|
rollData.carac = { "carac_creature": { label: competence.name, value: competence.data.carac_value } };
|
|
|
|
rollData.arme = {
|
|
|
|
name: competence.name, data: {
|
|
|
|
dommages: competence.data.dommages,
|
|
|
|
dommagesReels: competence.data.dommages
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
_onAttaqueParticuliere(rollData) {
|
|
|
|
console.log("RdDCombat.onAttaqueParticuliere >>>", rollData);
|
|
|
|
let message = "<strong>Réussite particulière en attaque</strong>";
|
|
|
|
message += "<br><a class='chat-card-button' id='particuliere-attaque' data-mode='force' data-attackerId='" + this.attackerId + "'>Attaquer en Force</a>";
|
|
|
|
// Finesse et Rapidité seulement en mêlée et si la difficulté libre est de -1 minimum
|
|
|
|
if (rollData.selectedCarac.label == "Mêlée" && rollData.diffLibre < 0) {
|
|
|
|
message += "<br><a class='chat-card-button' id='particuliere-attaque' data-mode='rapidite' data-attackerId='" + this.attackerId + "'>Attaquer en Rapidité</a>";
|
|
|
|
message += "<br><a class='chat-card-button' id='particuliere-attaque' data-mode='finesse' data-attackerId='" + this.attackerId + "'>Attaquer en Finesse</a>";
|
|
|
|
}
|
|
|
|
game.system.rdd.rollDataHandler[this.attackerId] = rollData;
|
|
|
|
// TODO: use a dialog?
|
|
|
|
ChatMessage.create({ content: message, whisper: ChatMessage.getWhisperRecipients(this.attacker.name) });
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
async _onAttaqueNormale(rollData) {
|
|
|
|
console.log("RdDCombat.onAttaqueNormale >>>", rollData);
|
|
|
|
if (!await this.accorderEntite('avant-defense')) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let explications = "";
|
|
|
|
|
2020-12-16 23:02:15 +01:00
|
|
|
rollData.dmg = RdDBonus.dmg(rollData, this.attacker.getBonusDegat(), this.defender.isEntiteCauchemar());
|
2020-12-17 12:29:54 +01:00
|
|
|
|
2020-12-12 21:58:44 +01:00
|
|
|
if (this.target) {
|
|
|
|
explications += "<br><strong>Cible</strong> : " + this.defender.data.name;
|
|
|
|
}
|
2020-12-16 23:02:15 +01:00
|
|
|
explications += "<br>Encaissement à " + Misc.toSignedString(rollData.dmg.total) + " (" + rollData.dmg.loc.label + ")";
|
2020-12-17 12:29:54 +01:00
|
|
|
|
2020-12-12 21:58:44 +01:00
|
|
|
// Save rollData for defender
|
|
|
|
game.system.rdd.rollDataHandler[this.attackerId] = duplicate(rollData);
|
2020-12-17 12:29:54 +01:00
|
|
|
|
2020-12-17 01:08:14 +01:00
|
|
|
// Message spécial pour la rapidité, qui reste difficile à gérer automatiquement
|
|
|
|
if (rollData.particuliereAttaque == 'rapidite') {
|
|
|
|
explications += "<br>Vous avez attaqué en Rapidité. Vous pourrez faire une deuxième attaque, ou utiliser votre arme pour vous défendre.";
|
|
|
|
}
|
2020-12-12 21:58:44 +01:00
|
|
|
|
|
|
|
// Final chat message
|
|
|
|
let chatOptions = {
|
|
|
|
content: "<strong>Test : " + rollData.selectedCarac.label + " / " + rollData.competence.name + "</strong>"
|
2020-12-17 12:29:54 +01:00
|
|
|
+ "<br>Difficultés <strong>libre : " + rollData.diffLibre + "</strong> / conditions : " + Misc.toSignedString(rollData.diffConditions) + " / état : " + rollData.etat
|
|
|
|
+ RdDResolutionTable.explain(rollData.rolled)
|
|
|
|
+ explications
|
2020-12-12 21:58:44 +01:00
|
|
|
}
|
|
|
|
ChatUtility.chatWithRollMode(chatOptions, this.attacker.name)
|
2020-12-17 12:29:54 +01:00
|
|
|
|
2020-12-12 21:58:44 +01:00
|
|
|
if (this.target) {
|
|
|
|
this._messageDefenseur(rollData);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
_messageDefenseur(rollData) {
|
|
|
|
console.log("RdDCombat._messageDefenseur", rollData, " / ", this.attacker, this.target, this.target.actor.isToken, this.attacker.data._id, rollData.competence.data.categorie);
|
|
|
|
|
2020-12-15 02:20:24 +01:00
|
|
|
let content = "<strong>" + this.defender.name + "</strong> doit se défendre :<span class='chat-card-button-area'>";
|
2020-12-12 21:58:44 +01:00
|
|
|
|
2020-12-16 23:02:15 +01:00
|
|
|
if (this.defender.getSurprise() != 'totale') {
|
|
|
|
// parades
|
|
|
|
for (const arme of this._filterArmesParade(this.defender.data.items, rollData.competence.data.categorie)) {
|
|
|
|
content += "<br><a class='chat-card-button' id='parer-button' data-attackerId='" + this.attackerId + "' data-defenderTokenId='" + this.defenderTokenId + "' data-armeid='" + arme._id + "'>Parer avec " + arme.name + "</a>";
|
|
|
|
}
|
2020-12-17 00:23:40 +01:00
|
|
|
// corps à corps
|
|
|
|
if (rollData.dmg.mortalite != 'mortel') {
|
|
|
|
content += "<br><a class='chat-card-button' id='parer-button' data-attackerId='" + this.attackerId + "' data-defenderTokenId='" + this.defenderTokenId + "'>Parer à mains nues</a>";
|
|
|
|
}
|
2020-12-16 23:02:15 +01:00
|
|
|
// esquive
|
|
|
|
if (rollData.competence.data.categorie == 'melee' || rollData.competence.data.categorie == "lancer" || rollData.competence.data.categorie == 'competencecreature') {
|
|
|
|
content += "<br><a class='chat-card-button' id='esquiver-button' data-attackerId='" + this.attackerId + "' data-defenderTokenId='" + this.defenderTokenId + "'>Esquiver</a>";
|
|
|
|
}
|
2020-12-12 21:58:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// encaisser
|
2020-12-15 02:20:24 +01:00
|
|
|
content += "<br><a class='chat-card-button' id='encaisser-button' data-attackerId='" + this.attackerId + "' data-defenderTokenId='" + this.defenderTokenId + "'>Encaisser à " + Misc.toSignedString(rollData.dmg.total) + " !</a>";
|
2020-12-12 21:58:44 +01:00
|
|
|
content += "</span>"
|
|
|
|
|
|
|
|
let defense = {
|
|
|
|
title: "Défense en combat",
|
|
|
|
content: content,
|
2020-12-17 18:31:37 +01:00
|
|
|
whisper: ChatUtility.getWhisperRecipients("blindroll", this.defender.name),
|
2020-12-12 21:58:44 +01:00
|
|
|
attackerId: this.attackerId,
|
|
|
|
defenderTokenId: this.defenderTokenId,
|
|
|
|
rollMode: true,
|
|
|
|
rollData: duplicate(rollData)
|
|
|
|
};
|
|
|
|
|
|
|
|
// envoyer le message de defense
|
|
|
|
if (!game.user.isGM || this.defender.hasPlayerOwner) {
|
|
|
|
game.socket.emit("system.foundryvtt-reve-de-dragon", { msg: "msg_defense", data: defense });
|
|
|
|
} else {
|
|
|
|
defense.whisper = [game.user];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (game.user.isGM) { // Always push the message to the MJ
|
|
|
|
ChatMessage.create(defense);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
2020-12-16 00:42:52 +01:00
|
|
|
_filterArmesParade(items, categorie) {
|
2020-12-12 21:58:44 +01:00
|
|
|
switch (categorie) {
|
|
|
|
case 'tir':
|
|
|
|
case 'lancer':
|
2020-12-16 00:42:52 +01:00
|
|
|
return items.filter(item => item.data.competence.toLowerCase().match("bouclier"));
|
2020-12-12 21:58:44 +01:00
|
|
|
default:
|
2020-12-16 00:42:52 +01:00
|
|
|
return items.filter(item => {
|
|
|
|
if (item.type == 'competencecreature') {
|
|
|
|
return item.data.isparade;
|
|
|
|
}
|
|
|
|
if (item.type == 'arme') {
|
|
|
|
const comp = this.defender.getCompetence(item.data.competence);
|
|
|
|
return comp && comp.data.categorie == 'melee';
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
});
|
2020-12-12 21:58:44 +01:00
|
|
|
}
|
|
|
|
}
|
2020-12-16 09:07:00 +01:00
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
2020-12-17 12:29:54 +01:00
|
|
|
async _onAttaqueEchecTotal(rollData) {
|
2020-12-12 21:58:44 +01:00
|
|
|
console.log("RdDCombat.onEchecTotal >>>", rollData);
|
|
|
|
let chatOptions = {
|
2020-12-17 12:29:54 +01:00
|
|
|
content: "<strong>Echec total à l'attaque!</strong> "
|
|
|
|
+ await RdDRollTables.getMaladresse({ arme: rollData.arme && !rollData.arme.data.sansArme })
|
2020-12-12 21:58:44 +01:00
|
|
|
}
|
|
|
|
ChatUtility.chatWithRollMode(chatOptions, this.attacker.name)
|
|
|
|
}
|
|
|
|
|
2020-12-16 09:07:00 +01:00
|
|
|
/* -------------------------------------------- */
|
2020-12-12 21:58:44 +01:00
|
|
|
_onAttaqueEchec(rollData) {
|
|
|
|
console.log("RdDCombat.onAttaqueEchec >>>", rollData);
|
|
|
|
let chatOptions = {
|
|
|
|
content: "<strong>Test : " + rollData.selectedCarac.label + " / " + rollData.competence.name + "</strong>"
|
|
|
|
+ "<br>Difficultés <strong>libre : " + rollData.diffLibre + "</strong> / conditions : " + Misc.toSignedString(rollData.diffConditions) + " / état : " + rollData.etat
|
2020-12-15 02:20:24 +01:00
|
|
|
+ RdDResolutionTable.explain(rollData.rolled)
|
|
|
|
+ (this.target ? "<br><strong>Cible</strong> : " + this.defender.data.name : "")
|
2020-12-12 21:58:44 +01:00
|
|
|
}
|
|
|
|
ChatUtility.chatWithRollMode(chatOptions, this.attacker.name)
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
async choixParticuliere(rollData, choix) {
|
|
|
|
console.log("RdDCombat.choixParticuliere >>>", rollData, choix);
|
|
|
|
rollData.particuliereAttaque = choix;
|
|
|
|
await this._onAttaqueNormale(rollData);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
async parade(attackerRoll, armeParadeId) {
|
2020-12-17 00:23:40 +01:00
|
|
|
|
|
|
|
let arme = this._findArmeParade(armeParadeId);
|
2020-12-12 21:58:44 +01:00
|
|
|
|
|
|
|
console.log("RdDCombat.parade >>>", attackerRoll, armeParadeId, arme);
|
|
|
|
|
|
|
|
let rollData = this._prepareParade(attackerRoll, arme);
|
|
|
|
|
|
|
|
const dialog = await RdDRoll.create(this.defender, rollData,
|
2020-12-17 12:29:54 +01:00
|
|
|
{
|
|
|
|
html: 'systems/foundryvtt-reve-de-dragon/templates/dialog-competence.html',
|
|
|
|
options: { height: 540 }
|
|
|
|
}, {
|
2020-12-12 21:58:44 +01:00
|
|
|
name: 'jet-parade',
|
|
|
|
label: 'Parade: ' + (arme ? arme.name : rollData.competence.name),
|
|
|
|
callbacks: [
|
|
|
|
this.defender.createCallbackExperience(),
|
2020-12-16 23:02:15 +01:00
|
|
|
{ condition: RdDCombat.isReussite, action: r => this._onParadeNormale(r) },
|
2020-12-17 01:08:14 +01:00
|
|
|
{ condition: RdDCombat.isParticuliere, action: r => this._onParadeParticuliere(r) },
|
|
|
|
{ condition: RdDCombat.isEchec, action: r => this._onParadeEchec(r) },
|
2020-12-16 23:02:15 +01:00
|
|
|
{ condition: RdDCombat.isEchecTotal, action: r => this._onParadeEchecTotal(r) },
|
2020-12-12 21:58:44 +01:00
|
|
|
]
|
2020-12-17 12:29:54 +01:00
|
|
|
});
|
2020-12-12 21:58:44 +01:00
|
|
|
dialog.render(true);
|
|
|
|
}
|
|
|
|
|
2020-12-17 00:23:40 +01:00
|
|
|
_findArmeParade(armeParadeId) {
|
|
|
|
if (armeParadeId) {
|
|
|
|
const armeItem = this.defender.getOwnedItem(armeParadeId);
|
|
|
|
return armeItem.data;
|
|
|
|
|
|
|
|
}
|
2020-12-17 12:29:54 +01:00
|
|
|
return RdDItemArme.mainsNues()
|
2020-12-17 00:23:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
_prepareParade(attackerRoll, armeParade) {
|
2020-12-12 21:58:44 +01:00
|
|
|
const isCreature = this.defender.isCreature();
|
2020-12-17 00:23:40 +01:00
|
|
|
const compName = isCreature ? armeParade.name : armeParade.data.competence;
|
2020-12-12 21:58:44 +01:00
|
|
|
const competence = this.defender.getCompetence(compName);
|
|
|
|
const armeAttaque = attackerRoll.arme;
|
2020-12-17 12:29:54 +01:00
|
|
|
|
2020-12-12 21:58:44 +01:00
|
|
|
if (compName != competence.name) {
|
|
|
|
// TODO: toujours utiliser competence.name ...
|
|
|
|
ui.notifications.warn("Différence entre compétence " + competence.name + " et compétence de l'arme " + compName);
|
|
|
|
}
|
|
|
|
|
|
|
|
let rollData = {
|
|
|
|
forceValue: this.defender.getForceValue(),
|
|
|
|
diffLibre: attackerRoll.diffLibre,
|
|
|
|
attackerRoll: attackerRoll,
|
|
|
|
competence: competence,
|
2020-12-17 00:23:40 +01:00
|
|
|
arme: armeParade,
|
2020-12-15 02:20:24 +01:00
|
|
|
surprise: this.defender.getSurprise(),
|
2020-12-16 23:02:15 +01:00
|
|
|
surpriseDefenseur: this.defender.getSurprise(),
|
2020-12-12 21:58:44 +01:00
|
|
|
needSignificative: this._needSignificative(attackerRoll) || RdDItemArme.needParadeSignificative(armeAttaque, armeParade),
|
|
|
|
needResist: this._needResist(armeAttaque, armeParade),
|
|
|
|
carac: this.defender.data.data.carac
|
|
|
|
};
|
|
|
|
if (isCreature) {
|
2020-12-15 02:20:24 +01:00
|
|
|
this._modifieRollDataCreature(rollData, competence);
|
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
|
|
|
/* -------------------------------------------- */
|
|
|
|
_needSignificative(attackerRoll) {
|
|
|
|
return attackerRoll.particuliereAttaque == 'finesse';
|
|
|
|
}
|
2020-12-15 02:20:24 +01:00
|
|
|
|
2020-12-12 21:58:44 +01:00
|
|
|
/* -------------------------------------------- */
|
|
|
|
_needResist(armeAttaque, armeParade) {
|
|
|
|
// Manage weapon categories when parrying (cf. page 115 )
|
|
|
|
let attCategory = RdDItemArme.getCategorieArme(armeAttaque);
|
|
|
|
let defCategory = RdDItemArme.getCategorieArme(armeParade);
|
|
|
|
|
|
|
|
return (attCategory.match("epee") && (defCategory == "hache" || defCategory == "lance"));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
_onParadeParticuliere(rollData) {
|
|
|
|
console.log("RdDCombat._onParadeParticuliere >>>", rollData);
|
|
|
|
if (!rollData.attackerRoll.isPart) {
|
|
|
|
// TODO: attaquant doit jouer résistance et peut être désarmé p132
|
|
|
|
}
|
|
|
|
let chatOptions = {
|
|
|
|
content: "<strong>Vous pouvez utiliser votre arme pour une deuxième parade!</strong>"
|
|
|
|
}
|
|
|
|
ChatUtility.chatWithRollMode(chatOptions, this.defender.name)
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
async _onParadeNormale(rollData) {
|
|
|
|
console.log("RdDCombat._onParadeNormale >>>", rollData);
|
2020-12-17 12:29:54 +01:00
|
|
|
|
2020-12-12 21:58:44 +01:00
|
|
|
let chatOptions = {
|
|
|
|
content: "<strong>Test : " + rollData.selectedCarac.label + " / " + rollData.competence.name + "</strong>"
|
2020-12-17 12:29:54 +01:00
|
|
|
+ "<br>Difficultés <strong>libre : " + rollData.diffLibre + "</strong> / conditions : " + Misc.toSignedString(rollData.diffConditions) + " / état : " + rollData.etat
|
|
|
|
+ RdDResolutionTable.explain(rollData.rolled)
|
|
|
|
+ "<br><strong>Attaque parée!</strong>"
|
2020-12-12 21:58:44 +01:00
|
|
|
}
|
|
|
|
ChatUtility.chatWithRollMode(chatOptions, this.defender.name)
|
2020-12-17 01:08:14 +01:00
|
|
|
await this.computeRecul(rollData, false);
|
|
|
|
await this.computeDeteriorationArme(rollData);
|
2020-12-12 21:58:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
2020-12-17 12:29:54 +01:00
|
|
|
async _onParadeEchecTotal(rollData) {
|
2020-12-12 21:58:44 +01:00
|
|
|
console.log("RdDCombat._onParadeEchecTotal >>>", rollData);
|
|
|
|
let chatOptions = {
|
2020-12-17 12:29:54 +01:00
|
|
|
content: "<strong>Echec total à la parade!</strong> "
|
|
|
|
+ await RdDRollTables.getMaladresse({ arme: rollData.arme && !rollData.arme.data.sansArme })
|
2020-12-12 21:58:44 +01:00
|
|
|
}
|
|
|
|
ChatUtility.chatWithRollMode(chatOptions, this.defender.name)
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
async _onParadeEchec(rollData) {
|
|
|
|
console.log("RdDCombat._onParadeEchec >>>", rollData);
|
|
|
|
|
2020-12-15 02:20:24 +01:00
|
|
|
let explications = "<br><strong>Parade échouée, encaissement !</strong> ";
|
2020-12-16 23:02:15 +01:00
|
|
|
explications += RdDBonus.description(rollData.surprise);
|
2020-12-12 21:58:44 +01:00
|
|
|
if (rollData.needSignificative) {
|
|
|
|
explications += " Significative nécessaire!";
|
|
|
|
}
|
|
|
|
|
|
|
|
let chatOptions = {
|
|
|
|
content: "<strong>Test : " + rollData.selectedCarac.label + " / " + rollData.competence.name + "</strong>"
|
|
|
|
+ "<br>Difficultés <strong>libre : " + rollData.diffLibre + "</strong> / conditions : " + Misc.toSignedString(rollData.diffConditions) + " / état : " + rollData.etat
|
|
|
|
+ RdDResolutionTable.explain(rollData.rolled)
|
|
|
|
+ explications
|
|
|
|
}
|
|
|
|
|
|
|
|
ChatUtility.chatWithRollMode(chatOptions, this.defender.name)
|
|
|
|
|
2020-12-17 00:44:32 +01:00
|
|
|
await this.computeRecul(rollData, true);
|
2020-12-12 21:58:44 +01:00
|
|
|
// TODO: gestion message pour chance/encaissement
|
|
|
|
this.encaisser(rollData.attackerRoll);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
async esquive(attackerRoll) {
|
|
|
|
let esquive = this.defender.getCompetence("esquive");
|
|
|
|
if (esquive == undefined) {
|
|
|
|
ui.notifications.error(this.defender.name + " n'a pas de compétence 'esquive'");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
console.log("RdDCombat.esquive >>>", attackerRoll, esquive);
|
|
|
|
let rollData = this._prepareEsquive(attackerRoll, esquive);
|
|
|
|
|
|
|
|
const dialog = await RdDRoll.create(this.defender, rollData,
|
|
|
|
{ html: 'systems/foundryvtt-reve-de-dragon/templates/dialog-competence.html' }, {
|
|
|
|
name: 'jet-esquive',
|
|
|
|
label: 'Esquiver',
|
|
|
|
callbacks: [
|
|
|
|
this.defender.createCallbackExperience(),
|
2020-12-16 23:02:15 +01:00
|
|
|
{ condition: RdDCombat.isReussite, action: r => this._onEsquiveNormale(r) },
|
2020-12-17 01:08:14 +01:00
|
|
|
{ condition: RdDCombat.isParticuliere, action: r => this._onEsquiveParticuliere(r) },
|
2020-12-16 23:02:15 +01:00
|
|
|
{ condition: RdDCombat.isEchec, action: r => this._onEsquiveEchec(r) },
|
2020-12-17 01:08:14 +01:00
|
|
|
{ condition: RdDCombat.isEchecTotal, action: r => this._onEsquiveEchecTotal(r) },
|
2020-12-12 21:58:44 +01:00
|
|
|
]
|
|
|
|
});
|
|
|
|
dialog.render(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
_prepareEsquive(attackerRoll, competence) {
|
|
|
|
let rollData = {
|
|
|
|
forceValue: this.defender.getForceValue(),
|
|
|
|
diffLibre: attackerRoll.diffLibre,
|
|
|
|
attackerRoll: attackerRoll,
|
|
|
|
competence: competence,
|
2020-12-15 02:20:24 +01:00
|
|
|
surprise: this.defender.getSurprise(),
|
2020-12-16 23:02:15 +01:00
|
|
|
surpriseDefenseur: this.defender.getSurprise(),
|
2020-12-12 21:58:44 +01:00
|
|
|
needSignificative: this._needSignificative(attackerRoll),
|
|
|
|
carac: this.defender.data.data.carac
|
|
|
|
};
|
|
|
|
|
|
|
|
if (this.defender.isCreature()) {
|
2020-12-15 02:20:24 +01:00
|
|
|
this._modifieRollDataCreature(rollData, competence);
|
2020-12-12 21:58:44 +01:00
|
|
|
}
|
|
|
|
return rollData;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
_onEsquiveParticuliere(rollData) {
|
|
|
|
console.log("RdDCombat._onEsquiveParticuliere >>>", rollData);
|
|
|
|
let chatOptions = {
|
|
|
|
content: "<strong>Vous pouvez esquiver une deuxième attaque!</strong>"
|
|
|
|
}
|
|
|
|
ChatUtility.chatWithRollMode(chatOptions, this.defender.name)
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
_onEsquiveNormale(rollData) {
|
|
|
|
console.log("RdDCombat._onEsquiveNormal >>>", rollData);
|
|
|
|
let chatOptions = {
|
|
|
|
content: "<strong>Test : " + rollData.selectedCarac.label + " / " + rollData.competence.name + "</strong>"
|
|
|
|
+ "<br>Difficultés <strong>libre : " + rollData.diffLibre + "</strong> / conditions : " + Misc.toSignedString(rollData.diffConditions) + " / état : " + rollData.etat
|
|
|
|
+ RdDResolutionTable.explain(rollData.rolled)
|
|
|
|
+ "<br><strong>Attaque esquivée!</strong>"
|
|
|
|
}
|
|
|
|
ChatUtility.chatWithRollMode(chatOptions, this.defender.name)
|
|
|
|
}
|
2020-12-17 12:29:54 +01:00
|
|
|
|
2020-12-12 21:58:44 +01:00
|
|
|
/* -------------------------------------------- */
|
2020-12-17 12:29:54 +01:00
|
|
|
async _onEsquiveEchecTotal(rollData) {
|
2020-12-12 21:58:44 +01:00
|
|
|
console.log("RdDCombat._onEsquiveEchecTotal >>>", rollData);
|
|
|
|
let chatOptions = {
|
2020-12-17 12:29:54 +01:00
|
|
|
content: "<strong>Echec total à l'esquive'!</strong> "
|
|
|
|
+ await RdDRollTables.getMaladresse({ arme: false })
|
2020-12-12 21:58:44 +01:00
|
|
|
}
|
|
|
|
ChatUtility.chatWithRollMode(chatOptions, this.defender.name)
|
|
|
|
}
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
async _onEsquiveEchec(rollData) {
|
|
|
|
console.log("RdDCombat._onEsquiveEchec >>>", rollData);
|
|
|
|
|
2020-12-15 02:20:24 +01:00
|
|
|
let explications = "<br><strong>Esquive échouée, encaissement !</strong> ";
|
2020-12-16 23:02:15 +01:00
|
|
|
explications += RdDBonus.description(rollData.surprise);
|
2020-12-12 21:58:44 +01:00
|
|
|
if (rollData.needSignificative) {
|
|
|
|
explications += " Significative nécessaire!";
|
|
|
|
}
|
|
|
|
|
|
|
|
let chatOptions = {
|
|
|
|
content: "<strong>Test : " + rollData.selectedCarac.label + " / " + rollData.competence.name + "</strong>"
|
|
|
|
+ "<br>Difficultés <strong>libre : " + rollData.diffLibre + "</strong> / conditions : " + Misc.toSignedString(rollData.diffConditions) + " / état : " + rollData.etat
|
|
|
|
+ RdDResolutionTable.explain(rollData.rolled)
|
|
|
|
+ explications
|
|
|
|
}
|
|
|
|
|
|
|
|
ChatUtility.chatWithRollMode(chatOptions, this.defender.name)
|
|
|
|
|
2020-12-17 00:44:32 +01:00
|
|
|
await this.computeRecul(rollData, true);
|
2020-12-12 21:58:44 +01:00
|
|
|
this.encaisser(rollData.attackerRoll);
|
|
|
|
}
|
2020-12-15 02:20:24 +01:00
|
|
|
|
2020-12-17 12:29:54 +01:00
|
|
|
|
2020-12-17 00:44:32 +01:00
|
|
|
/* -------------------------------------------- */
|
2020-12-17 12:29:54 +01:00
|
|
|
async computeDeteriorationArme(rollData) {
|
2020-12-17 00:44:32 +01:00
|
|
|
const attackerRoll = rollData.attackerRoll;
|
|
|
|
if (rollData.arme && attackerRoll) { // C'est une parade
|
|
|
|
// Est-ce que l'attaque est une particulière, en force ou charge et que l'attaque n'en est pas une ?
|
2020-12-17 12:29:54 +01:00
|
|
|
if ((rollData.needResist || attackerRoll.particuliereAttaque == 'force' || attackerRoll.tactique == 'charge')
|
|
|
|
&& !rollData.rolled.isPart) {
|
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
|
|
|
|
});
|
2020-12-17 00:44:32 +01:00
|
|
|
if (resistRoll.isSuccess) { // Perte de résistance
|
|
|
|
msg = "Votre " + rollData.arme.name + " tient le choc de la parade. "
|
|
|
|
} 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);
|
|
|
|
msg = "Sous la violence de la parade, votre " + rollData.arme.name + " s'est brisée sous le coup!";
|
|
|
|
} else {
|
2020-12-17 12:29:54 +01:00
|
|
|
this.defender.updateEmbeddedEntity("OwnedItem", { _id: rollData.arme._id, 'data.resistance': resistance });
|
2020-12-17 00:44:32 +01:00
|
|
|
msg = "En parant, vous endommagez votre " + rollData.arme.name + ", qui perd " + dmg + " de résistance. ";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Jet de désarmement
|
2020-12-17 12:29:54 +01:00
|
|
|
if (resistance > 0 && !rollData.arme.name.toLowerCase().includes('bouclier')) { // Si l'arme de parade n'est pas un bouclier, jet de désarmement (p.132)
|
2020-12-17 00:44:32 +01:00
|
|
|
let desarme = await RdDResolutionTable.rollData({
|
|
|
|
caracValue: this.defender.data.data.carac.force.value,
|
|
|
|
finalLevel: Misc.toInt(rollData.competence.data.niveau) - dmg,
|
2020-12-17 12:29:54 +01:00
|
|
|
showDice: false
|
|
|
|
});
|
|
|
|
if (desarme.isEchec) {
|
2020-12-17 00:44:32 +01:00
|
|
|
msg += "Vous ne parvenez pas à garder votre arme en main, elle tombe au sol à vos pieds";
|
|
|
|
}
|
|
|
|
}
|
2020-12-17 12:29:54 +01:00
|
|
|
ChatMessage.create({
|
|
|
|
content: msg,
|
|
|
|
user: game.user._id,
|
|
|
|
whisper: [game.user._id, ChatMessage.getWhisperRecipients("GM")]
|
|
|
|
});
|
2020-12-17 00:44:32 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* -------------------------------------------- */
|
2020-12-17 12:29:54 +01:00
|
|
|
async computeRecul(rollData, encaisser = undefined) { // Calcul du recul (p. 132)
|
|
|
|
if (rollData.arme || encaisser) {
|
|
|
|
if ((rollData.attackerRoll.particuliereAttaque && rollData.attackerRoll.particuliereAttaque == 'force') || rollData.attackerRoll.tactique == 'charge') {
|
|
|
|
let reculNiveau = Misc.toInt(this.defender.data.data.carac.taille.value) - (rollData.attackerRoll.forceValue + rollData.attackerRoll.arme.data.dommagesReels);
|
2020-12-17 00:44:32 +01:00
|
|
|
let recul = await RdDResolutionTable.rollData({
|
|
|
|
caracValue: 10,
|
|
|
|
finalLevel: reculNiveau,
|
2020-12-17 12:29:54 +01:00
|
|
|
showDice: false
|
|
|
|
});
|
2020-12-17 00:44:32 +01:00
|
|
|
|
|
|
|
let msg = "";
|
|
|
|
if (recul.isSuccess) {
|
|
|
|
msg = " Vous ne reculez pas malgré la force du coup.";
|
|
|
|
} else {
|
|
|
|
let chute = await RdDResolutionTable.rollData({
|
|
|
|
caracValue: this.defender.data.data.carac.agilite.value,
|
|
|
|
finalLevel: reculNiveau,
|
2020-12-17 12:29:54 +01:00
|
|
|
showDice: false
|
|
|
|
});
|
|
|
|
if (!chute.isSuccess || recul.isETotal) {
|
2020-12-17 00:44:32 +01:00
|
|
|
msg = "Sous la violence du coup, vous reculez et chutez au sol ! Vous ne pouvez plus attaquer ce round.";
|
|
|
|
} else {
|
|
|
|
msg = "La violence du choc vous fait reculer de quelques mètres ! Vous ne pouvez plus attaquer ce round.";
|
|
|
|
}
|
2020-12-17 12:29:54 +01:00
|
|
|
}
|
|
|
|
ChatMessage.create({
|
|
|
|
content: msg,
|
|
|
|
user: game.user._id,
|
|
|
|
whisper: [game.user._id, ChatMessage.getWhisperRecipients("GM")]
|
|
|
|
});
|
2020-12-17 00:44:32 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-12-12 21:58:44 +01:00
|
|
|
/* -------------------------------------------- */
|
|
|
|
encaisser(attackerRoll) {
|
|
|
|
// TODO: gestion message pour chance/encaissement
|
|
|
|
this.encaisser(attackerRoll, this.defenderTokenId);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
encaisser(attackerRoll, defenderTokenId) {
|
|
|
|
defenderTokenId = defenderTokenId || this.defenderTokenId;
|
|
|
|
console.log("RdDCombat.encaisser >>>", attackerRoll, defenderTokenId);
|
|
|
|
|
|
|
|
if (game.user.isGM) { // Current user is the GM -> direct access
|
|
|
|
attackerRoll.attackerId = this.attackerId;
|
|
|
|
attackerRoll.defenderTokenId = defenderTokenId;
|
|
|
|
this.defender.encaisserDommages(attackerRoll, this.attacker);
|
|
|
|
} else { // Emit message for GM
|
|
|
|
game.socket.emit("system.foundryvtt-reve-de-dragon", {
|
|
|
|
msg: "msg_encaisser",
|
|
|
|
data: { attackerId: this.attackerId, defenderTokenId: defenderTokenId }
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
/* retourne true si on peut continuer, false si on ne peut pas continuer */
|
|
|
|
async accorderEntite(when = 'avant-encaissement') {
|
|
|
|
if (when != game.settings.get("foundryvtt-reve-de-dragon", "accorder-entite-cauchemar")
|
|
|
|
|| this.defender == undefined
|
|
|
|
|| !this.defender.isEntiteCauchemar()
|
|
|
|
|| this.defender.isEntiteCauchemarAccordee(this.attacker)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
let rolled = await RdDResolutionTable.roll(this.attacker.getReveActuel(), - Number(this.defender.data.data.carac.niveau.value));
|
|
|
|
|
|
|
|
let message = {
|
|
|
|
content: "Jet de points actuels de rêve à " + rolled.finalLevel + RdDResolutionTable.explain(rolled) + "<br>",
|
|
|
|
whisper: ChatMessage.getWhisperRecipients(this.attacker.name)
|
|
|
|
};
|
|
|
|
|
|
|
|
if (rolled.isSuccess) {
|
|
|
|
await this.defender.setEntiteReveAccordee(this.attacker);
|
|
|
|
message.content += this.attacker.name + " s'est accordé avec " + this.defender.name;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
message.content += this.attacker.name + " n'est pas accordé avec " + this.defender.name;
|
|
|
|
}
|
|
|
|
|
|
|
|
ChatMessage.create(message);
|
|
|
|
return rolled.isSuccess;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|