Merge branch 'appel-chance-combat' into 'v1.2'

#86, #42, Gestion des échecs totaux et appel à la chance en combat

See merge request LeRatierBretonnien/foundryvtt-reve-de-dragon!104
This commit is contained in:
Leratier Bretonnien 2021-01-07 08:21:11 +00:00
commit 12c3d69b53
13 changed files with 487 additions and 311 deletions

View File

@ -1107,68 +1107,6 @@ export class RdDActor extends Actor {
await this.update( { 'data.blessures': bList } ); await this.update( { 'data.blessures': bList } );
} }
/* -------------------------------------------- */
manageBlessures( blessuresData )
{
// Fast exit
if ( this.data.type == 'entite') return; // Une entité n'a pas de blessures
if ( blessuresData.legeres + blessuresData.graves + blessuresData.critiques == 0 ) return;
let workData = duplicate(blessuresData);
let blessures = duplicate(this.data.data.blessures);
// Manage blessures
if ( workData.legeres > 0 ) {
for (let k=0; k<blessures.legeres.liste.length; k++) {
let bless = blessures.legeres.liste[k];
if ( !bless.active ){
bless.active = true;
bless.loc = workData.locName;
workData.legeres--;
}
if (workData.legeres == 0) break;
}
}
if ( workData.legeres > 0 ) {
workData.graves += 1;
blessuresData.graves += 1;
}
if ( workData.graves > 0) {
for (let k=0; k<blessures.graves.liste.length; k++) {
let bless = blessures.graves.liste[k];
if ( !bless.active ) {
bless.active = true;
bless.loc = workData.locName;
workData.graves--;
}
if ( workData.graves == 0) break;
}
}
workData.from3Graves = false;
if ( workData.graves > 0 ) {
workData.critiques = 1;
blessuresData.critiques = 1;
workData.from3Graves = true;
}
if ( workData.critiques > 0 ) {
if ( blessures.critiques.liste[0].active ) {
ChatMessage.create(`<strong>${game.user.name} vient de succomber à une seconde blessure critique ! Que les Dragons gardent son Archétype en paix !</strong>`);
} else {
if ( workData.from3Graves) { // Si la blessure critique provient d'une quatrième grave
this.santeIncDec("endurance", -this.data.data.sante.endurance.value); // Endurance à 0;
this.santeIncDec("vie", -4); // Vie à -4;
}
blessures.critiques.liste[0].active = true;
blessures.critiques.liste[0].loc = workData.locName;
}
}
this.update( { "data.blessures": blessures } );
}
/* -------------------------------------------- */ /* -------------------------------------------- */
async jetDeMoral(situation) { async jetDeMoral(situation) {
let jetMoral = new Roll("1d20").roll(); let jetMoral = new Roll("1d20").roll();
@ -1820,7 +1758,7 @@ export class RdDActor extends Actor {
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
async rollAppelChance( ) async rollAppelChance(onSuccess = () => {}, onEchec = () => {})
{ {
let rollData = { selectedCarac: this.getCaracByName('chance-actuelle'), surprise: '' }; let rollData = { selectedCarac: this.getCaracByName('chance-actuelle'), surprise: '' };
const dialog = await RdDRoll.create(this, rollData, const dialog = await RdDRoll.create(this, rollData,
@ -1830,7 +1768,7 @@ export class RdDActor extends Actor {
label: 'Appel à la chance', label: 'Appel à la chance',
callbacks: [ callbacks: [
this.createCallbackExperience(), this.createCallbackExperience(),
{ action: r => this._appelChanceResult(r) } { action: r => this._appelChanceResult(r, onSuccess, onEchec) },
] ]
} }
); );
@ -1838,11 +1776,15 @@ export class RdDActor extends Actor {
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
async _appelChanceResult(rollData) { async _appelChanceResult(rollData, onSuccess = () => {}, onEchec= ()=>{}) {
await RdDResolutionTable.displayRollData(rollData, this, 'chat-resultat-appelchance.html')
if (rollData.rolled.isSuccess) { if (rollData.rolled.isSuccess) {
await this.chanceActuelleIncDec(-1) await this.chanceActuelleIncDec(-1)
onSuccess();
}
else {
onEchec();
} }
RdDResolutionTable.displayRollData(rollData, this, 'chat-resultat-appelchance.html')
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
@ -1852,6 +1794,21 @@ export class RdDActor extends Actor {
await this.update( {"data.compteurs.chance": chance } ); await this.update( {"data.compteurs.chance": chance } );
} }
/* -------------------------------------------- */
async appelDestinee( onSuccess = () => {}, onEchec= ()=>{}) {
if (this.data.data.compteurs.destinee?.value ?? 0 >0 ) {
ChatMessage.create({content: `<span class="rdd-roll-part">${this.name} a fait appel à la Destinée !</span>` });
let destinee = duplicate(this.data.data.compteurs.destinee);
destinee.value = destinee.value - 1;
await this.update( {"data.compteurs.destinee": destinee } );
onSuccess();
}
else {
onEchec();
}
}
/* -------------------------------------------- */ /* -------------------------------------------- */
ajustementAstrologique() { ajustementAstrologique() {
if (this.isCreature()) { if (this.isCreature()) {
@ -2086,7 +2043,7 @@ export class RdDActor extends Actor {
dmg = 0; // Reset it dmg = 0; // Reset it
if ( update.data.deterioration >= 10) { if ( update.data.deterioration >= 10) {
update.data.deterioration = 0; update.data.deterioration = 0;
let res = /\d+^/.exec(update.data.protection); let res = /\d+/.exec(update.data.protection);
if ( res ) if ( res )
update.data.protection = "1d"+update.data.protection; update.data.protection = "1d"+update.data.protection;
// if ( update.data.protection.toString().length == 1 ) // if ( update.data.protection.toString().length == 1 )
@ -2132,28 +2089,24 @@ export class RdDActor extends Actor {
} }
console.log("encaisserDommages", attackerRoll ) console.log("encaisserDommages", attackerRoll )
const armure = this.computeArmure( attackerRoll );
const rollEncaissement = new Roll("2d10 + @dmg - @armure",{ let encaissement = this.jetEncaissement(attackerRoll);
dmg: attackerRoll.dmg.total,
armure: armure this.ajouterBlessure(encaissement); // Will upate the result table
}).roll();
RdDDice.show(rollEncaissement); await this.santeIncDec("vie", encaissement.vie);
let result = RdDUtility.computeBlessuresSante(rollEncaissement.total, attackerRoll.dmg.mortalite, attackerRoll.dmg.loc); await this.santeIncDec("endurance", encaissement.endurance, (encaissement.critiques > 0));
result.endurance = Math.max(result.endurance, -Number(this.data.data.sante.endurance.value));
await this.santeIncDec("vie", result.vie); const blessureLegere = (encaissement.legeres > 0 ? "une blessure légère" : "");
await this.santeIncDec("endurance", result.endurance, (result.critiques > 0)); const blessureGrave = (encaissement.graves > 0 ? "une blessure grave" : "");
const blessureCritique = (encaissement.critiques > 0 ? "une blessure critique" : "");
this.manageBlessures(result); // Will upate the result table
const blessureLegere = (result.legeres > 0 ? "une blessure légère" : "");
const blessureGrave = (result.graves > 0 ? "une blessure grave" : "");
const blessureCritique = (result.critiques > 0 ? "une blessure critique" : "");
let commonMsg = { let commonMsg = {
title: "Blessures !", title: "Blessures !",
roll: rollEncaissement , roll: encaissement.roll,
content: this.data.name + " a encaissé " + blessureLegere + blessureGrave + blessureCritique content: `${this.data.name} a encaissé ${blessureLegere}${blessureGrave}${blessureCritique} (${encaissement.locName})`
} }
let addonMsg = "<br>Et a perdu : <br>" + result.endurance + " Endurance et " + result.vie + " Points de Vie"; let addonMsg = "<br>Et a perdu : <br>" + encaissement.endurance + " Endurance et " + encaissement.vie + " Points de Vie";
if ( this.hasPlayerOwner ) { if ( this.hasPlayerOwner ) {
commonMsg.content += addonMsg; // Message pour tout le monde commonMsg.content += addonMsg; // Message pour tout le monde
ChatMessage.create( commonMsg ); ChatMessage.create( commonMsg );
@ -2169,6 +2122,92 @@ export class RdDActor extends Actor {
this.sheet.render(false); this.sheet.render(false);
} }
/* -------------------------------------------- */
jetEncaissement(rollData) {
rollData.dmg.loc = rollData.dmg.loc?? RdDUtility.getLocalisation();
const roll = new Roll("2d10 + @dmg - @armure", {
dmg: rollData.dmg.total,
armure: this.computeArmure( rollData )
}).roll();
RdDDice.show(roll, game.settings.get("core", "rollMode"));
let encaissement = RdDUtility.selectEncaissement(roll.total, rollData.dmg.mortalite)
let over20 = Math.max(roll.total - 20, 0);
encaissement.roll = roll;
encaissement.vie = - RdDUtility._evaluatePerte(encaissement.vie, over20);
encaissement.endurance = - RdDUtility._evaluatePerte(encaissement.endurance, over20);
encaissement.loc = rollData.dmg.loc;
encaissement.locName = rollData.dmg.loc.label ?? "Corps";
return encaissement;
}
/* -------------------------------------------- */
ajouterBlessure( encaissement )
{
// Fast exit
if ( this.data.type == 'entite') return; // Une entité n'a pas de blessures
if ( encaissement.legeres + encaissement.graves + encaissement.critiques == 0 ) return;
const endActuelle = Number(this.data.data.sante.endurance.value);
let blessures = duplicate(this.data.data.blessures);
let count = encaissement.legeres;
// Manage blessures
while (count > 0) {
let legere = blessures.legeres.liste.find(it => !it.active);
if (legere) {
this._setBlessure(legere, encaissement);
count--;
}
else {
encaissement.graves += count;
encaissement.legeres -= count;
break;
}
}
count = encaissement.graves;
while (count > 0) {
let grave = blessures.graves.liste.find(it => !it.active);
if (grave) {
this._setBlessure(grave, encaissement);
count--;
}
else{
encaissement.critiques += count;
encaissement.graves -= count;
encaissement.endurance = -endActuelle;
encaissement.vie = -4;
break;
}
}
count = encaissement.critique;
while( count > 0 ) {
let critique = blessures.critiques.liste[0];
if (!critique.active ) {
this._setBlessure(critique, encaissement);
count--;
} else {
// TODO: status effect dead
ChatMessage.create({ content: `<strong>${this.name} vient de succomber à une seconde blessure critique ! Que les Dragons gardent son Archétype en paix !</strong>`});
encaissement.critique -= count;
break;
}
}
encaissement.endurance = Math.max(encaissement.endurance, -endActuelle);
this.update( { "data.blessures": blessures } );
}
/* -------------------------------------------- */
_setBlessure(blessure, encaissement) {
blessure.active = true;
blessure.loc = encaissement.locName;
}
/* -------------------------------------------- */ /* -------------------------------------------- */
/** @override */ /** @override */
getRollData() { getRollData() {

View File

@ -3,6 +3,12 @@
* Class providing helper methods to get the list of users, and * Class providing helper methods to get the list of users, and
*/ */
export class ChatUtility { export class ChatUtility {
static removeMyChatMessageContaining(part) {
const toDelete = game.messages.filter(it => it.user._id == game.user._id)
.filter(it => it.data.content.includes(part));
toDelete.forEach(it => it.delete());
}
/* -------------------------------------------- */ /* -------------------------------------------- */
static chatWithRollMode(chatOptions, name) { static chatWithRollMode(chatOptions, name) {

View File

@ -1,5 +1,4 @@
import { RdDCarac } from "./rdd-carac.js"; import { RdDCarac } from "./rdd-carac.js";
import { RdDUtility } from "./rdd-utility.js";
const conditionsTactiques = [ const conditionsTactiques = [
{ type: '', descr: '', dmg: 0, attaque: 0, parade: 0, esquive: true }, { type: '', descr: '', dmg: 0, attaque: 0, parade: 0, esquive: true },
@ -30,7 +29,7 @@ export class RdDBonus {
/* -------------------------------------------- */ /* -------------------------------------------- */
static dmg(rollData, dmgActor, isCauchemar = false) { static dmg(rollData, dmgActor, isCauchemar = false) {
let dmg = { total: 0, loc: RdDUtility.getLocalisation() }; let dmg = { total: 0 };
if (rollData.arme && rollData.arme.name.toLowerCase() == "esquive") { if (rollData.arme && rollData.arme.name.toLowerCase() == "esquive") {
// Specific case management // Specific case management
ui.notifications.warn("Calcul de bonus dégats sur eswquive"); ui.notifications.warn("Calcul de bonus dégats sur eswquive");
@ -66,13 +65,11 @@ export class RdDBonus {
static _calculMortalite(rollData, isCauchemar) { static _calculMortalite(rollData, isCauchemar) {
if (isCauchemar) { if (isCauchemar) {
return "cauchemar"; return "cauchemar";
}if (rollData.dmg && rollData.dmg.mortalite) {
return rollData.dmg.mortalite;
} }
if (rollData.arme && rollData.arme.data.mortalite) { return isCauchemar ? "cauchemar"
return rollData.arme.data.mortalite; : rollData.dmg?.mortalite
} ?? rollData.arme?.data.mortalite
return "mortel"; ?? "mortel";
} }
/* -------------------------------------------- */ /* -------------------------------------------- */

View File

@ -94,7 +94,17 @@ export class RdDCombat {
/* -------------------------------------------- */ /* -------------------------------------------- */
static registerChatCallbacks(html) { static registerChatCallbacks(html) {
for (let button of ['#parer-button', '#esquiver-button', '#particuliere-attaque', '#encaisser-button']) { for (let button of [
'#parer-button',
'#esquiver-button',
'#particuliere-attaque',
'#encaisser-button',
'#appel-chance-defense',
'#appel-destinee-defense',
'#appel-chance-attaque',
'#appel-destinee-attaque',
'#echec-total-attaque',
]) {
html.on("click", button, event => { html.on("click", button, event => {
event.preventDefault(); event.preventDefault();
RdDCombat.createForEvent(event).onEvent(button, event); RdDCombat.createForEvent(event).onEvent(button, event);
@ -119,19 +129,102 @@ export class RdDCombat {
/* -------------------------------------------- */ /* -------------------------------------------- */
async onEvent(button, event) { async onEvent(button, event) {
let rollData = game.system.rdd.rollDataHandler[this.attackerId]; let attackerRoll = game.system.rdd.rollDataHandler.attaques[this.attackerId];
if (!rollData) { if (!attackerRoll) {
ui.notifications.warn("Action automatisée impossible, le jet de l'attaquant a été perdu (suite à un raffraichissement?)") ui.notifications.warn("Action automatisée impossible, le jet de l'attaquant a été perdu (suite à un raffraichissement?)")
return; return;
} }
const defenderTokenId = event.currentTarget.attributes['data-defenderTokenId'].value;
let defenderRoll = this._getDefense(attackerRoll.passeArme);
const armeParadeId = event.currentTarget.attributes['data-armeid']?.value;
switch (button) { switch (button) {
case '#particuliere-attaque': return await this.choixParticuliere(rollData, event.currentTarget.attributes['data-mode'].value); case '#particuliere-attaque': return await this.choixParticuliere(attackerRoll, event.currentTarget.attributes['data-mode'].value);
case '#parer-button': { case '#parer-button': return this.parade(attackerRoll, armeParadeId);
const armeId = event.currentTarget.attributes['data-armeid']; case '#esquiver-button': return this.esquive(attackerRoll);
return this.parade(rollData, armeId?.value); case '#encaisser-button': return this.encaisser(attackerRoll, defenderTokenId);
case '#echec-total-attaque': return this._onEchecTotal(attackerRoll);
case '#appel-chance-attaque': return this.attacker.rollAppelChance(
() => this.attaqueChanceuse(attackerRoll),
() => this._onEchecTotal(attackerRoll));
case '#appel-chance-defense': return this.defender.rollAppelChance(
() => this.defenseChanceuse(attackerRoll, defenderRoll),
() => this.afficherOptionsDefense(attackerRoll, { defenseChance: true }));
case '#appel-destinee-attaque': return this.attacker.appelDestinee(
() => this.attaqueSignificative(attackerRoll),
() => { });
case '#appel-destinee-defense': return this.defender.appelDestinee(
() => this.defenseDestinee(defenderRoll),
() => { });
} }
case '#esquiver-button': return this.esquive(rollData); }
case '#encaisser-button': return this.encaisser(rollData, event.currentTarget.attributes['data-defenderTokenId'].value);
/* -------------------------------------------- */
_consumeDefense(passeArme) {
let defenderRoll = this._getDefense(passeArme);
game.system.rdd.rollDataHandler.defenses[passeArme] = undefined;
return defenderRoll;
}
/* -------------------------------------------- */
_getDefense(passeArme) {
return game.system.rdd.rollDataHandler.defenses[passeArme];
}
/* -------------------------------------------- */
_storeDefense(defenderRoll) {
game.system.rdd.rollDataHandler.defenses[defenderRoll.passeArme] = defenderRoll;
}
/* -------------------------------------------- */
attaqueChanceuse(attackerRoll) {
ui.notifications.info("L'attaque est rejouée grâce à la chance")
attackerRoll.essais.attaqueChance = true;
this.attaque(attackerRoll, attackerRoll.arme);
}
/* -------------------------------------------- */
attaqueDestinee(attackerRoll) {
ui.notifications.info('Attaque significative grâce à la destinée')
RdDResolutionTable.forceSignificative(attackerRoll.rolled);
this.removeChatMessageActionsPasseArme(attackerRoll.passeArme);
this._onAttaqueNormale(attackerRoll);
}
/* -------------------------------------------- */
defenseChanceuse(attackerRoll, defenderRoll) {
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);
this._sendMessageDefense(attackerRoll);
}
/* -------------------------------------------- */
defenseDestinee(defenderRoll) {
ui.notifications.info('Défense significative grâce à la destinée')
RdDResolutionTable.forceSignificative(defenderRoll.rolled);
this.removeChatMessageActionsPasseArme(defenderRoll.passeArme);
if (defenderRoll.arme) {
this._onParadeNormale(defenderRoll);
}
else {
this._onEsquiveNormale(defenderRoll);
}
}
/* -------------------------------------------- */
afficherOptionsDefense(attackerRoll, essais) {
ui.notifications.info("La chance n'est pas avec vous");
this._sendMessageDefense(attackerRoll, essais);
}
/* -------------------------------------------- */
removeChatMessageActionsPasseArme(passeArme) {
if (game.settings.get("foundryvtt-reve-de-dragon", "supprimer-dialogues-combat-chat")){
ChatUtility.removeMyChatMessageContaining(`<div data-passearme="${passeArme}">`);
} }
} }
@ -185,6 +278,7 @@ export class RdDCombat {
label: 'Attaque: ' + (arme?.name ?? competence.name), label: 'Attaque: ' + (arme?.name ?? competence.name),
callbacks: [ callbacks: [
this.attacker.createCallbackExperience(), this.attacker.createCallbackExperience(),
{ action: r => this.removeChatMessageActionsPasseArme(r.passeArme) },
{ condition: r => (RdDCombat.isReussite(r) && !RdDCombat.isParticuliere(r)), action: r => this._onAttaqueNormale(r) }, { condition: r => (RdDCombat.isReussite(r) && !RdDCombat.isParticuliere(r)), action: r => this._onAttaqueNormale(r) },
{ condition: RdDCombat.isParticuliere, action: r => this._onAttaqueParticuliere(r) }, { condition: RdDCombat.isParticuliere, action: r => this._onAttaqueParticuliere(r) },
{ condition: RdDCombat.isEchec, action: r => this._onAttaqueEchec(r) }, { condition: RdDCombat.isEchec, action: r => this._onAttaqueEchec(r) },
@ -197,10 +291,12 @@ export class RdDCombat {
/* -------------------------------------------- */ /* -------------------------------------------- */
_prepareAttaque(competence, arme) { _prepareAttaque(competence, arme) {
let rollData = { let rollData = {
passeArme: randomID(16),
coupsNonMortels: false, coupsNonMortels: false,
competence: competence, competence: competence,
surprise: this.attacker.getSurprise(), surprise: this.attacker.getSurprise(),
surpriseDefenseur: this.defender.getSurprise() surpriseDefenseur: this.defender.getSurprise(),
essais: { }
}; };
if (this.attacker.isCreature()) { if (this.attacker.isCreature()) {
@ -218,81 +314,67 @@ export class RdDCombat {
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
_onAttaqueParticuliere(rollData) { async _onAttaqueParticuliere(rollData) {
console.log("RdDCombat.onAttaqueParticuliere >>>", rollData); game.system.rdd.rollDataHandler.attaques[this.attackerId] = duplicate(rollData);
// Finesse et Rapidité seulement en mêlée et si la difficulté libre est de -1 minimum // Finesse et Rapidité seulement en mêlée et si la difficulté libre est de -1 minimum
let message = '<h4 class="rdd-roll-part"><strong>Réussite particulière en attaque</strong></h4>'; const isMeleeDiffNegative = rollData.selectedCarac.label == "Mêlée" && rollData.diffLibre < 0;
message += `<br><a class='chat-card-button' id='particuliere-attaque' data-mode='force' data-attackerId='${this.attackerId}'>Attaquer en Force</a>`; ChatMessage.create({
if (rollData.selectedCarac.label == "Mêlée" && rollData.diffLibre < 0) { whisper: ChatMessage.getWhisperRecipients(this.attacker.name),
if (rollData.arme.data.rapide) { content: await renderTemplate('systems/foundryvtt-reve-de-dragon/templates/chat-demande-defense.html', {
message += `<br><a class='chat-card-button' id='particuliere-attaque' data-mode='rapidite' data-attackerId='${this.attackerId}'>Attaquer en Rapidité</a>`; attackerId: this.attackerId,
} defenderTokenId: this.defenderTokenId,
message += `<br><a class='chat-card-button' id='particuliere-attaque' data-mode='finesse' data-attackerId='${this.attackerId}'>Attaquer en Finesse</a>`; isFinesse: isMeleeDiffNegative,
} isRapide: isMeleeDiffNegative && rollData.arme.data.rapide
game.system.rdd.rollDataHandler[this.attackerId] = rollData; })
// TODO: use a dialog? });
ChatMessage.create({ content: message, whisper: ChatMessage.getWhisperRecipients(this.attacker.name) });
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
async _onAttaqueNormale(rollData) { async _onAttaqueNormale(attackerRoll) {
console.log("RdDCombat.onAttaqueNormale >>>", rollData); console.log("RdDCombat.onAttaqueNormale >>>", attackerRoll);
rollData.dmg = RdDBonus.dmg(rollData, this.attacker.getBonusDegat(), this.defender.isEntiteCauchemar()); attackerRoll.dmg = RdDBonus.dmg(attackerRoll, this.attacker.getBonusDegat(), this.defender.isEntiteCauchemar());
// Save rollData for defender // Save rollData for defender
game.system.rdd.rollDataHandler[this.attackerId] = duplicate(rollData); game.system.rdd.rollDataHandler.attaques[this.attackerId] = duplicate(attackerRoll);
rollData.show = { attackerRoll.show = {
cible: this.target ? this.defender.data.name : 'la cible', cible: this.target ? this.defender.data.name : 'la cible',
isRecul: (rollData.particuliere == 'force' || rollData.tactique == 'charge') isRecul: (attackerRoll.particuliere == 'force' || attackerRoll.tactique == 'charge')
} }
await RdDResolutionTable.displayRollData(rollData, this.attacker, 'chat-resultat-attaque.html'); await RdDResolutionTable.displayRollData(attackerRoll, this.attacker, 'chat-resultat-attaque.html');
if (!await this.accorderEntite('avant-defense')) { if (!await this.accorderEntite('avant-defense')) {
return; return;
} }
if (this.target) { if (this.target) {
this._sendMessageDefense(rollData); await this._sendMessageDefense(attackerRoll);
} }
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
_sendMessageDefense(rollData) { async _sendMessageDefense(attackerRoll, essais = {}) {
console.log("RdDCombat._sendMessageDefense", rollData, " / ", this.attacker, this.target, this.attackerId, rollData.competence.data.categorie); console.log("RdDCombat._sendMessageDefense", attackerRoll, essais, " / ", this.attacker, this.target, this.attackerId, attackerRoll.competence.data.categorie);
let message = this._buildMessageDefense(rollData); this.removeChatMessageActionsPasseArme(attackerRoll.passeArme);
// encaisser mergeObject(attackerRoll.essais, essais, {overwrite: true});
message += this._buildMessageEncaisser(rollData) + "</span>"; const paramDemandeDefense = {
passeArme: attackerRoll.passeArme,
essais: attackerRoll.essais,
surprise: this.defender.getSurprise(),
defender: this.defender,
attackerId: this.attackerId,
defenderTokenId: this.defenderTokenId,
mainsNues: attackerRoll.dmg.mortalite != 'mortel' && this.defender.getCompetence("Corps à corps"),
armes: this._filterArmesParade(this.defender.data.items, attackerRoll.competence, attackerRoll.arme),
diffLibre: attackerRoll.ajustements?.diffLibre?.value ?? 0,
dmg: attackerRoll.dmg
};
let message = await renderTemplate('systems/foundryvtt-reve-de-dragon/templates/chat-demande-defense.html', paramDemandeDefense);
RdDCombat._sendRollMessage(this.attacker, this.defender, this.defenderTokenId, "msg_defense", message, rollData); RdDCombat._sendRollMessage(this.attacker, this.defender, this.defenderTokenId, "msg_defense", message, attackerRoll);
}
/* -------------------------------------------- */
_buildMessageDefense(rollData) {
let message = "<strong>" + this.defender.name + "</strong> doit se défendre :<span class='chat-card-button-area'>";
if (this.defender.getSurprise() != 'totale') {
// parades
for (const arme of this._filterArmesParade(this.defender.data.items, rollData.competence, rollData.arme)) {
message += "<br><a class='chat-card-button' id='parer-button' data-attackerId='" + this.attackerId + "' data-defenderTokenId='" + this.defenderTokenId + "' data-armeid='" + arme._id + "'>Parer avec " + arme.name + "</a>";
}
// corps à corps
if (rollData.dmg.mortalite != 'mortel' && this.defender.getCompetence("Corps à corps")) {
message += "<br><a class='chat-card-button' id='parer-button' data-attackerId='" + this.attackerId + "' data-defenderTokenId='" + this.defenderTokenId + "'>Parer à mains nues</a>";
}
// esquive
if (rollData.competence.data.categorie != 'tir') {
message += "<br><a class='chat-card-button' id='esquiver-button' data-attackerId='" + this.attackerId + "' data-defenderTokenId='" + this.defenderTokenId + "'>Esquiver</a>";
}
}
return message;
}
/* -------------------------------------------- */
_buildMessageEncaisser(rollData) {
return "<br><a class='chat-card-button' id='encaisser-button' data-attackerId='" + this.attackerId + "' data-defenderTokenId='" + this.defenderTokenId + "'>Encaisser à " + Misc.toSignedString(rollData.dmg.total) + " !</a>";
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
@ -312,17 +394,33 @@ export class RdDCombat {
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
async _onAttaqueEchecTotal(rollData) { async _onAttaqueEchecTotal(attackerRoll) {
// TODO: remplacer par un chat message pour laisser le joueur choisir un appel à la chance _avant_
// https://gitlab.com/LeRatierBretonnien/foundryvtt-reve-de-dragon/-/issues/85 game.system.rdd.rollDataHandler.attaques[this.attackerId] = duplicate(attackerRoll);
console.log("RdDCombat.onEchecTotal >>>", rollData);
let chatOptions = { // Finesse et Rapidité seulement en mêlée et si la difficulté libre est de -1 minimum
content: "<strong>Echec total à l'attaque!</strong> " ChatMessage.create({
+ await RdDRollTables.getMaladresse({ arme: rollData.arme && rollData.arme.data.categorie_parade != 'sans-armes' }) whisper: ChatMessage.getWhisperRecipients(this.attacker.name),
} content: await renderTemplate('systems/foundryvtt-reve-de-dragon/templates/chat-demande-attaque-etotal.html', {
ChatUtility.chatWithRollMode(chatOptions, this.attacker.name) attackerId: this.attackerId,
attacker: this.attacker,
defenderTokenId: this.defenderTokenId,
essais: attackerRoll.essais
})
});
} }
/* -------------------------------------------- */
async _onEchecTotal(rollData) {
console.log("RdDCombat._onEchecTotal >>>", rollData);
const arme = rollData.arme;
const avecArme = arme?.data.categorie_parade != 'sans-armes';
const action = (rollData.attackerRoll ? (arme ? "la parade" : "l'esquive") : "l'attaque");
ChatUtility.chatWithRollMode({
content: `<strong>Echec total à ${action}!</strong> ` + await RdDRollTables.getMaladresse({ arme: avecArme })
}, this.defender.name)
}
/* -------------------------------------------- */ /* -------------------------------------------- */
async _onAttaqueEchec(rollData) { async _onAttaqueEchec(rollData) {
@ -334,6 +432,7 @@ export class RdDCombat {
/* -------------------------------------------- */ /* -------------------------------------------- */
async choixParticuliere(rollData, choix) { async choixParticuliere(rollData, choix) {
console.log("RdDCombat.choixParticuliere >>>", rollData, choix); console.log("RdDCombat.choixParticuliere >>>", rollData, choix);
// TODO
rollData.particuliere = choix; rollData.particuliere = choix;
await this._onAttaqueNormale(rollData); await this._onAttaqueNormale(rollData);
} }
@ -355,10 +454,10 @@ export class RdDCombat {
label: 'Parade: ' + (arme ? arme.name : rollData.competence.name), label: 'Parade: ' + (arme ? arme.name : rollData.competence.name),
callbacks: [ callbacks: [
this.defender.createCallbackExperience(), this.defender.createCallbackExperience(),
{ action: r => this.removeChatMessageActionsPasseArme(r.passeArme) },
{ condition: RdDCombat.isReussite, action: r => this._onParadeNormale(r) }, { condition: RdDCombat.isReussite, action: r => this._onParadeNormale(r) },
{ condition: RdDCombat.isParticuliere, action: r => this._onParadeParticuliere(r) }, { condition: RdDCombat.isParticuliere, action: r => this._onParadeParticuliere(r) },
{ condition: RdDCombat.isEchec, action: r => this._onParadeEchec(r) }, { condition: RdDCombat.isEchec, action: r => this._onParadeEchec(r) },
{ condition: RdDCombat.isEchecTotal, action: r => this._onParadeEchecTotal(r) },
] ]
}); });
dialog.render(true); dialog.render(true);
@ -370,6 +469,7 @@ export class RdDCombat {
const armeAttaque = attackerRoll.arme; const armeAttaque = attackerRoll.arme;
let rollData = { let rollData = {
passeArme: attackerRoll.passeArme,
forceValue: this.defender.getForceValue(), forceValue: this.defender.getForceValue(),
diffLibre: attackerRoll.diffLibre, diffLibre: attackerRoll.diffLibre,
attackerRoll: attackerRoll, attackerRoll: attackerRoll,
@ -403,7 +503,7 @@ export class RdDCombat {
if (!rollData.attackerRoll.isPart) { if (!rollData.attackerRoll.isPart) {
// TODO: attaquant doit jouer résistance et peut être désarmé p132 // TODO: attaquant doit jouer résistance et peut être désarmé p132
ChatUtility.chatWithRollMode({ ChatUtility.chatWithRollMode({
content: `L'attaquant doit jouer résistance et peut être désarmé (p132)` content: `(à gérer) L'attaquant doit jouer résistance et peut être désarmé (p132)`
}, this.defender.name) }, this.defender.name)
} }
} }
@ -412,34 +512,22 @@ export class RdDCombat {
async _onParadeNormale(rollData) { async _onParadeNormale(rollData) {
console.log("RdDCombat._onParadeNormale >>>", rollData); console.log("RdDCombat._onParadeNormale >>>", rollData);
this._consumeDefense(rollData.passeArme);
await this.computeRecul(rollData); await this.computeRecul(rollData);
await this.computeDeteriorationArme(rollData); await this.computeDeteriorationArme(rollData);
await RdDResolutionTable.displayRollData(rollData, this.defender, 'chat-resultat-parade.html'); await RdDResolutionTable.displayRollData(rollData, this.defender, 'chat-resultat-parade.html');
}
/* -------------------------------------------- */
async _onParadeEchecTotal(rollData) {
// TODO: remplacer par un chat message pour laisser le joueur choisir un appel à la chance _avant_
// https://gitlab.com/LeRatierBretonnien/foundryvtt-reve-de-dragon/-/issues/85
console.log("RdDCombat._onParadeEchecTotal >>>", rollData);
let chatOptions = {
content: "<strong>Echec total à la parade!</strong> "
+ await RdDRollTables.getMaladresse({ arme: rollData.arme && rollData.arme.data.categorie_parade != 'sans-armes' })
}
ChatUtility.chatWithRollMode(chatOptions, this.defender.name)
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
async _onParadeEchec(rollData) { async _onParadeEchec(rollData) {
console.log("RdDCombat._onParadeEchec >>>", rollData); console.log("RdDCombat._onParadeEchec >>>", rollData);
await this.computeRecul(rollData);
await RdDResolutionTable.displayRollData(rollData, this.defender, 'chat-resultat-parade.html'); await RdDResolutionTable.displayRollData(rollData, this.defender, 'chat-resultat-parade.html');
this._sendMessageEncaisser(rollData.attackerRoll); this.removeChatMessageActionsPasseArme(rollData.passeArme);
this._sendMessageDefense(rollData.attackerRoll, { defense: true });
this._storeDefense(rollData);
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
@ -458,10 +546,10 @@ export class RdDCombat {
label: 'Esquiver', label: 'Esquiver',
callbacks: [ callbacks: [
this.defender.createCallbackExperience(), this.defender.createCallbackExperience(),
{ action: r => this.removeChatMessageActionsPasseArme(r.passeArme) },
{ condition: RdDCombat.isReussite, action: r => this._onEsquiveNormale(r) }, { condition: RdDCombat.isReussite, action: r => this._onEsquiveNormale(r) },
{ condition: RdDCombat.isParticuliere, action: r => this._onEsquiveParticuliere(r) }, { condition: RdDCombat.isParticuliere, action: r => this._onEsquiveParticuliere(r) },
{ condition: RdDCombat.isEchec, action: r => this._onEsquiveEchec(r) }, { condition: RdDCombat.isEchec, action: r => this._onEsquiveEchec(r) },
{ condition: RdDCombat.isEchecTotal, action: r => this._onEsquiveEchecTotal(r) },
] ]
}); });
dialog.render(true); dialog.render(true);
@ -470,6 +558,7 @@ export class RdDCombat {
/* -------------------------------------------- */ /* -------------------------------------------- */
_prepareEsquive(attackerRoll, competence) { _prepareEsquive(attackerRoll, competence) {
let rollData = { let rollData = {
passeArme: attackerRoll.passeArme,
forceValue: this.defender.getForceValue(), forceValue: this.defender.getForceValue(),
diffLibre: attackerRoll.diffLibre, diffLibre: attackerRoll.diffLibre,
attackerRoll: attackerRoll, attackerRoll: attackerRoll,
@ -499,30 +588,19 @@ export class RdDCombat {
/* -------------------------------------------- */ /* -------------------------------------------- */
async _onEsquiveNormale(rollData) { async _onEsquiveNormale(rollData) {
console.log("RdDCombat._onEsquiveNormal >>>", rollData); console.log("RdDCombat._onEsquiveNormal >>>", rollData);
this._consumeDefense(rollData.passeArme);
await RdDResolutionTable.displayRollData(rollData, this.defender, 'chat-resultat-esquive.html'); await RdDResolutionTable.displayRollData(rollData, this.defender, 'chat-resultat-esquive.html');
} }
/* -------------------------------------------- */
async _onEsquiveEchecTotal(rollData) {
// TODO: remplacer par un chat message pour laisser le joueur choisir un appel à la chance _avant_
// https://gitlab.com/LeRatierBretonnien/foundryvtt-reve-de-dragon/-/issues/85
console.log("RdDCombat._onEsquiveEchecTotal >>>", rollData);
let chatOptions = {
content: "<strong>Echec total à l'esquive'!</strong> "
+ await RdDRollTables.getMaladresse({ arme: false })
}
ChatUtility.chatWithRollMode(chatOptions, this.defender.name)
}
/* -------------------------------------------- */ /* -------------------------------------------- */
async _onEsquiveEchec(rollData) { async _onEsquiveEchec(rollData) {
console.log("RdDCombat._onEsquiveEchec >>>", rollData); console.log("RdDCombat._onEsquiveEchec >>>", rollData);
await this.computeRecul(rollData);
await RdDResolutionTable.displayRollData(rollData, this.defender, 'chat-resultat-esquive.html'); await RdDResolutionTable.displayRollData(rollData, this.defender, 'chat-resultat-esquive.html');
this._sendMessageEncaisser(rollData.attackerRoll); this.removeChatMessageActionsPasseArme(rollData.passeArme);
this._sendMessageDefense(rollData.attackerRoll, { defense: true })
this._storeDefense(rollData);
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
@ -613,13 +691,21 @@ export class RdDCombat {
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
encaisser(attackerRoll, defenderTokenId) { async encaisser(attackerRoll, defenderTokenId) {
defenderTokenId = defenderTokenId || this.defenderTokenId; defenderTokenId = defenderTokenId || this.defenderTokenId;
console.log("RdDCombat.encaisser >>>", attackerRoll, defenderTokenId); console.log("RdDCombat.encaisser >>>", attackerRoll, defenderTokenId);
let defenderRoll = this._consumeDefense(attackerRoll.passeArme);
if (defenderRoll && RdDCombat.isEchecTotal(defenderRoll)) {
// TODO: echec total!!!
this._onEchecTotal(defenderRoll);
}
if (game.user.isGM) { // Current user is the GM -> direct access if (game.user.isGM) { // Current user is the GM -> direct access
attackerRoll.attackerId = this.attackerId; attackerRoll.attackerId = this.attackerId;
attackerRoll.defenderTokenId = defenderTokenId; attackerRoll.defenderTokenId = defenderTokenId;
await this.computeRecul(defenderRoll);
this.defender.encaisserDommages(attackerRoll, this.attacker); this.defender.encaisserDommages(attackerRoll, this.attacker);
} else { // Emit message for GM } else { // Emit message for GM
game.socket.emit("system.foundryvtt-reve-de-dragon", { game.socket.emit("system.foundryvtt-reve-de-dragon", {

View File

@ -21,6 +21,7 @@ import { RdDResolutionTable } from "./rdd-resolution-table.js";
import { RdDTokenHud } from "./rdd-token-hud.js"; import { RdDTokenHud } from "./rdd-token-hud.js";
import { RdDCommands } from "./rdd-commands.js"; import { RdDCommands } from "./rdd-commands.js";
import { RdDCombat } from "./rdd-combat.js"; import { RdDCombat } from "./rdd-combat.js";
import { ChatUtility } from "./chat-utility.js";
/* -------------------------------------------- */ /* -------------------------------------------- */
/* Foundry VTT Initialization */ /* Foundry VTT Initialization */
@ -104,7 +105,10 @@ Hooks.once("init", async function() {
// Create useful storage space // Create useful storage space
game.system.rdd = { game.system.rdd = {
rollDataHandler: {}, rollDataHandler: {
attaques: {},
defenses: {}
},
TMRUtility: TMRUtility TMRUtility: TMRUtility
} }
@ -157,6 +161,16 @@ Hooks.once("init", async function() {
type: Boolean type: Boolean
}); });
/* -------------------------------------------- */
game.settings.register("foundryvtt-reve-de-dragon", "supprimer-dialogues-combat-chat", {
name: "Supprimer les dialogues de combat",
hint: "Si désactivée, tous les dialogues de combat sont conservés dans la conversation",
scope: "world",
config: true,
default: true,
type: Boolean
});
//game.settings.get("<systemName>","<settingName>") to retrieve it and game.settings.set("<systemName>","<settingName>", <newValue>) //game.settings.get("<systemName>","<settingName>") to retrieve it and game.settings.set("<systemName>","<settingName>", <newValue>)
/* -------------------------------------------- */ /* -------------------------------------------- */
@ -213,9 +227,7 @@ Hooks.once("init", async function() {
/* -------------------------------------------- */ /* -------------------------------------------- */
function messageDeBienvenue(){ function messageDeBienvenue(){
game.messages ChatUtility.removeMyChatMessageContaining('<div id="message-bienvenue-rdd">');
.filter(it => it.user._id == game.user._id && it.data.content.match(/^<div id="message-bienvenue-rdd/))
.forEach(it => it.delete());
ChatMessage.create( { ChatMessage.create( {
user: game.user._id, user: game.user._id,
whisper: [game.user._id], whisper: [game.user._id],

View File

@ -1,5 +1,4 @@
import { ChatUtility } from "./chat-utility.js"; import { ChatUtility } from "./chat-utility.js";
import { RollDataAjustements as RollDataAjustements } from "./rolldata-ajustements.js";
import { Misc } from "./misc.js"; import { Misc } from "./misc.js";
import { RdDDice } from "./rdd-dice.js"; import { RdDDice } from "./rdd-dice.js";
@ -127,7 +126,7 @@ export class RdDResolutionTable {
/* -------------------------------------------- */ /* -------------------------------------------- */
static _updateChancesFactor(chances, diviseur) { static _updateChancesFactor(chances, diviseur) {
if (diviseur && diviseur > 1) { if (diviseur && diviseur > 1) {
let newScore = Math.floor(Number(chances.score) / diviseur); let newScore = Math.floor(chances.score / diviseur);
mergeObject(chances, this._computeCell(null, newScore), { overwrite: true }); mergeObject(chances, this._computeCell(null, newScore), { overwrite: true });
} }
} }
@ -135,10 +134,14 @@ export class RdDResolutionTable {
/* -------------------------------------------- */ /* -------------------------------------------- */
static _updateChancesWithBonus(chances, bonus) { static _updateChancesWithBonus(chances, bonus) {
if (bonus) { if (bonus) {
let newScore = Number(chances.score) + Number(bonus); let newScore = chances.score + bonus;
mergeObject(chances, this._computeCell(null, newScore), { overwrite: true }); mergeObject(chances, this._computeCell(null, newScore), { overwrite: true });
} }
} }
static forceSignificative(chances) {
chances.roll = Math.floor(chances.score /2);
mergeObject(chances, reussites.find(x => x.code == 'sign'), { overwrite: true });
}
/* -------------------------------------------- */ /* -------------------------------------------- */
static async rollChances(chances) { static async rollChances(chances) {
@ -146,7 +149,7 @@ export class RdDResolutionTable {
myRoll.showDice = chances.showDice; myRoll.showDice = chances.showDice;
await RdDDice.show(myRoll); await RdDDice.show(myRoll);
chances.roll = myRoll.total; chances.roll = myRoll.total;
mergeObject(chances, this._computeReussite(chances, chances.roll)); mergeObject(chances, this._computeReussite(chances, chances.roll), { overwrite: true });
return chances; return chances;
} }

View File

@ -1,4 +1,4 @@
import { referenceAjustements, RollDataAjustements } from "./rolldata-ajustements.js"; import { RollDataAjustements } from "./rolldata-ajustements.js";
import { HtmlUtility } from "./html-utility.js"; import { HtmlUtility } from "./html-utility.js";
import { RdDItemCompetence } from "./item-competence.js"; import { RdDItemCompetence } from "./item-competence.js";
import { RdDItemMeditation } from "./item-meditation.js"; import { RdDItemMeditation } from "./item-meditation.js";

View File

@ -2,10 +2,8 @@
import { RdDRollTables } from "./rdd-rolltables.js"; import { RdDRollTables } from "./rdd-rolltables.js";
import { ChatUtility } from "./chat-utility.js"; import { ChatUtility } from "./chat-utility.js";
import { RdDItemCompetence } from "./item-competence.js";
import { RdDCombat } from "./rdd-combat.js"; import { RdDCombat } from "./rdd-combat.js";
import { RdDRollResolutionTable } from "./rdd-roll-resolution-table.js"; import { RdDRollResolutionTable } from "./rdd-roll-resolution-table.js";
import { RdDItem } from "./item.js";
import { RdDItemCompetenceCreature } from "./item-competencecreature.js"; import { RdDItemCompetenceCreature } from "./item-competencecreature.js";
import { RdDItemArme } from "./item-arme.js"; import { RdDItemArme } from "./item-arme.js";
@ -206,6 +204,9 @@ export class RdDUtility {
'systems/foundryvtt-reve-de-dragon/templates/hud-actor-attaque.html', 'systems/foundryvtt-reve-de-dragon/templates/hud-actor-attaque.html',
// messages tchat // messages tchat
'systems/foundryvtt-reve-de-dragon/templates/chat-infojet.html', 'systems/foundryvtt-reve-de-dragon/templates/chat-infojet.html',
'systems/foundryvtt-reve-de-dragon/templates/chat-demande-defense.html',
'systems/foundryvtt-reve-de-dragon/templates/chat-demande-attaque-particuliere.html',
'systems/foundryvtt-reve-de-dragon/templates/chat-demande-attaque-etotal.html',
'systems/foundryvtt-reve-de-dragon/templates/chat-resultat-appelchance.html', 'systems/foundryvtt-reve-de-dragon/templates/chat-resultat-appelchance.html',
'systems/foundryvtt-reve-de-dragon/templates/chat-resultat-attaque.html', 'systems/foundryvtt-reve-de-dragon/templates/chat-resultat-attaque.html',
'systems/foundryvtt-reve-de-dragon/templates/chat-resultat-parade.html', 'systems/foundryvtt-reve-de-dragon/templates/chat-resultat-parade.html',
@ -626,6 +627,7 @@ export class RdDUtility {
/* -------------------------------------------- */ /* -------------------------------------------- */
static getLocalisation( ) static getLocalisation( )
{ {
// TODO: bouger dans une RollTable du compendium et chercher dans les RoolTable puis compendium pour permettre le changement?
let result = new Roll("1d20").roll().total; let result = new Roll("1d20").roll().total;
let txt = "" let txt = ""
if ( result <= 3 ) txt = "Jambe, genou, pied, jarret"; if ( result <= 3 ) txt = "Jambe, genou, pied, jarret";
@ -640,16 +642,6 @@ export class RdDUtility {
return { result: result, label: txt }; return { result: result, label: txt };
} }
/* -------------------------------------------- */
static computeBlessuresSante( degats, mortalite, loc) {
let encaissement = RdDUtility.selectEncaissement(degats, mortalite)
let over20 = Math.max(degats - 20, 0);
encaissement.endurance = - RdDUtility._evaluatePerte(encaissement.endurance, over20);
encaissement.vie = - RdDUtility._evaluatePerte(encaissement.vie, over20);
encaissement.locName = loc ? loc.label : "Corps";
return encaissement;
}
/* -------------------------------------------- */ /* -------------------------------------------- */
static selectEncaissement( degats, mortalite ) { static selectEncaissement( degats, mortalite ) {
const table = definitionsEncaissement[mortalite] === undefined ? definitionsEncaissement["mortel"] : definitionsEncaissement[mortalite]; const table = definitionsEncaissement[mortalite] === undefined ? definitionsEncaissement["mortel"] : definitionsEncaissement[mortalite];
@ -703,60 +695,6 @@ export class RdDUtility {
return competences; return competences;
} }
/* -------------------------------------------- */
static buildDefenseChatCard( attacker, target, rollData )
{
console.log("Attacker.defense", attacker, target, target.actor.isToken, attacker.data._id, rollData.competence.data.categorie );
let myTarget = target.actor;
let defenseMsg = { title: "Défense en combat",
content: "<strong>"+myTarget.name+"</strong> doit se défendre : <br><span class='chat-card-button-area'>" +
"<a class='chat-card-button' id='encaisser-button' data-attackerId='"+attacker.data._id + "' data-defenderTokenId='" + target.data._id + "'>Encaisser !</a></span>",
whisper: ChatMessage.getWhisperRecipients( myTarget.name ),
attackerId: attacker.data._id,
defenderTokenId: target.data._id,
rollMode: true
};
if ( rollData.competence.data.categorie == 'melee' || rollData.competence.data.categorie == 'competencecreature') { // Melee attack or creature
let defenderArmes = [];
for (const arme of myTarget.data.items) {
if (arme.type == "arme" && RdDItemCompetence.isCompetenceMelee(arme.data.competence)) {
defenderArmes.push( arme );
defenseMsg.content += "<br><a class='chat-card-button' id='parer-button' data-attackerId='"+attacker.data._id + "' data-defenderTokenId='" + target.data._id + "' data-armeid='"+arme._id+"'>Parer avec " + arme.name + "</a></span>";
}
if (arme.type == "competencecreature" && arme.data.isparade) {
defenderArmes.push( arme );
defenseMsg.content += "<br><a class='chat-card-button' id='parer-button' data-attackerId='"+attacker.data._id + "' data-defenderTokenId='" + target.data._id + "' data-armeid='"+arme._id+"'>Parer avec " + arme.name + "</a></span>";
}
}
defenseMsg.content += "<br><a class='chat-card-button' id='esquiver-button' data-attackerId='"+attacker.data._id + "' data-defenderTokenId='" + target.data._id + "'>Esquiver</a></span>";
}
if ( rollData.competence.data.categorie == "tir" ) {
for (const arme of myTarget.data.items) { // Bouclier for parry
if ( arme.type == "arme" && arme.name.toLowerCase.match("bouclier") ) {
defenderArmes.push( arme );
defenseMsg.content += "<br><a class='chat-card-button' id='parer-button' data-attackerId='"+attacker.data._id + "' data-defenderTokenId='" + target.data._id + "' data-armeid='"+arme._id+"'>Parer avec " + arme.name + "</a></span>";
}
}
}
if ( rollData.competence.data.categorie == "lancer" ) {
for (const arme of myTarget.data.items) { // Bouclier for parry Dodge/Esquive
if ( arme.type == "arme" && arme.name.toLowerCase.match("bouclier") ) {
defenderArmes.push( arme );
defenseMsg.content += "<br><a class='chat-card-button' id='parer-button' data-attackerId='"+attacker.data._id + "' data-defenderTokenId='" + target.data._id + "' data-armeid='"+arme._id+"'>Parer avec " + arme.name + "</a></span>";
}
}
defenseMsg.content += "<br><a class='chat-card-button' id='esquiver-button' data-attackerId='"+attacker.data._id + "' data-defenderTokenId='" + target.data._id + "'>Esquiver</a></span>";
}
defenseMsg.toSocket = true; // True per default for all players
if (game.user.isGM) { // In GM case, only if target is a player
defenseMsg.toSocket = myTarget.hasPlayerOwner;
}
return defenseMsg;
}
/* -------------------------------------------- */ /* -------------------------------------------- */
static async responseNombreAstral( data ) { static async responseNombreAstral( data ) {
let actor = game.actors.get( data.id); let actor = game.actors.get( data.id);
@ -793,7 +731,7 @@ export class RdDUtility {
} }
if ((game.user.isGM && !defenderToken.actor.hasPlayerOwner) || (defenderToken.actor.hasPlayerOwner && (game.user.character.id == defenderToken.actor.data._id))) { if ((game.user.isGM && !defenderToken.actor.hasPlayerOwner) || (defenderToken.actor.hasPlayerOwner && (game.user.character.id == defenderToken.actor.data._id))) {
//console.log("User is pushing message...", game.user.name); //console.log("User is pushing message...", game.user.name);
game.system.rdd.rollDataHandler[data.attackerId] = duplicate(data.rollData); game.system.rdd.rollDataHandler.attaques[data.attackerId] = duplicate(data.rollData);
data.whisper = [game.user]; data.whisper = [game.user];
data.blind = true; data.blind = true;
data.rollMode = "blindroll"; data.rollMode = "blindroll";
@ -895,9 +833,12 @@ export class RdDUtility {
/* -------------------------------------------- */ /* -------------------------------------------- */
static _handleMsgEncaisser(data) { static _handleMsgEncaisser(data) {
if (game.user.isGM) { // Seul le GM effectue l'encaissement sur la fiche if (game.user.isGM) { // Seul le GM effectue l'encaissement sur la fiche
let attackerRoll = game.system.rdd.rollDataHandler[data.attackerId]; // Retrieve the rolldata from the store let attackerRoll = game.system.rdd.rollDataHandler.attaques[data.attackerId]; // Retrieve the rolldata from the store
let defenderToken = canvas.tokens.get(data.defenderTokenId); game.system.rdd.rollDataHandler.attaques[data.attackerId] = undefined;
defenderToken.actor.encaisserDommages(attackerRoll); game.system.rdd.rollDataHandler.defenses[attackerRoll.passeArme] = undefined;
let defender = canvas.tokens.get(data.defenderTokenId).actor;
defender.encaisserDommages(attackerRoll);
} }
} }

View File

@ -125,16 +125,6 @@ export class RollDataAjustements {
} }
} }
// /* -------------------------------------------- */
// static calculListe(ajustements, rollData, actor) {
// let list = [];
// for (var key in referenceAjustements) {
// if (referenceAjustements[key].isUsed(rollData, actor)) {
// list.push(Ajustements._apply(referenceAjustements[key], rollData, actor));
// }
// }
// return list;
// }
/* -------------------------------------------- */ /* -------------------------------------------- */
static sum(ajustements) { static sum(ajustements) {

View File

@ -0,0 +1,22 @@
<div data-passearme="{{passeArme}}">
<h4 class="rdd-roll-part"><strong>Echec total en attaque</strong></h4>
<br>
{{#if (eq attacker.data.type 'personnage')}}
{{#unless essais.attaqueChance}}
<a class='chat-card-button' id='appel-chance-attaque' data-attackerId='{{attackerId}}'
data-defenderTokenId='{{defenderTokenId}}'>Faire appel à la chance</a>
</a>
<br>
{{/unless}}
{{#if (gt attacker.data.data.compteurs.destinee.value 0)}}
<a class='chat-card-button' id='appel-destinee-attaque' data-attackerId='{{attackerId}}'
data-defenderTokenId='{{defenderTokenId}}'>Utiliser la destinée</a>
</a>
<br>
{{/if}}
{{/if}}
<a class='chat-card-button' id='echec-total-attaque' data-attackerId='{{attackerId}}'
data-defenderTokenId='{{defenderTokenId}}'>
Tirer l'échec total !
</a>
</div>

View File

@ -0,0 +1,19 @@
<div data-passearme="{{passeArme}}">
<h4 class="rdd-roll-part"><strong>Réussite particulière en attaque</strong></h4>
<br>
<a class="chat-card-button" id="particuliere-attaque" data-mode="force" data-attackerId="{{attackerId}}">
Attaquer en Force
</a>
{{#if isRapide}}
<br>
<a class="chat-card-button" id="particuliere-attaque" data-mode="rapidite" data-attackerId="{{attackerId}}">
Attaquer en Rapidité
</a>
{{/if}}
{{#if isFinesse}}
<br>
<a class="chat-card-button" id="particuliere-attaque" data-mode="finesse" data-attackerId="{{attackerId}}">
Attaquer en Finesse
</a>
{{/if}}
</div>

View File

@ -0,0 +1,62 @@
<div data-passearme="{{passeArme}}">
{{#if (eq surprise 'totale')}}
<span><strong>{{defender.name}}</strong> est totalement surpris</span>
{{else if essais.defense}}
<span><strong>{{defender.name}}</strong> doit</span>
{{else}}
<span><strong>{{defender.name}}</strong> doit se défendre
{{#if (eq surprise 'demi')}} avec une significative {{/if}} :
</span>
{{/if}}
<span class='chat-card-button-area'>
<br>
{{#unless (eq surprise 'totale')}}
{{#if essais.defense}}
<br>
{{#unless essais.defenseChance}}
{{#if (eq defender.data.type 'personnage')}}
<a class='chat-card-button' id='appel-chance-defense' data-attackerId='{{attackerId}}'
data-defenderTokenId='{{defenderTokenId}}'>Faire appel à la chance</a>
</a>
<br>
{{/if}}
{{/unless}}
{{#if (eq defender.data.type 'personnage')}}
{{#if (gt defender.data.data.compteurs.destinee.value 0)}}
<a class='chat-card-button' id='appel-destinee-defense' data-attackerId='{{attackerId}}'
data-defenderTokenId='{{defenderTokenId}}'>Utiliser la destinée</a>
</a>
<br>
{{/if}}
{{/if}}
{{else}}
{{#each armes as |arme key|}}
<a class='chat-card-button' id='parer-button' data-attackerId='{{../attackerId}}' data-defenderTokenId='{{../defenderTokenId}}' data-armeid='{{arme._id }}'>
Parer avec {{arme.name}} à {{../diffLibre }}
</a>
<br>
{{/each}}
{{#if mainsNues}}
<a class='chat-card-button' id='parer-button' data-attackerId='{{attackerId}}' data-defenderTokenId='{{defenderTokenId}}'>
Parer à mains nues à {{diffLibre}}
</a>
<br>
{{/if}}
{{#if (ne attaqueCategorie 'tir')}}
<a class='chat-card-button' id='esquiver-button' data-attackerId='{{attackerId}}' data-defenderTokenId='{{defenderTokenId}}'>
Esquiver à {{diffLibre}}
</a>
<br>
{{/if}}
{{/if}}
{{/unless}}
<a class='chat-card-button' id='encaisser-button' data-attackerId='{{attackerId}}'
data-defenderTokenId='{{defenderTokenId}}'>
Encaisser à {{#if (eq dmg.mortalite 'non-mortel')~}}
({{numberFormat dmg.total decimals=0 sign=true}})
{{~else~}}
{{numberFormat dmg.total decimals=0 sign=true}}
{{~/if}} !
</a>
</span>
</div>

View File

@ -24,7 +24,6 @@
<span class="rdd-roll-etotal">{{numberFormat dmg.total decimals=0 sign=true}}</span> (entités de cauchemar) <span class="rdd-roll-etotal">{{numberFormat dmg.total decimals=0 sign=true}}</span> (entités de cauchemar)
{{~/if}}. {{~/if}}.
{{#if show.isRecul}}Si votre adversaire n'esquive pas, il devra résister à l'impact ou reculer sous le choc!{{/if}} {{#if show.isRecul}}Si votre adversaire n'esquive pas, il devra résister à l'impact ou reculer sous le choc!{{/if}}
Le coup vise: {{dmg.loc.label}}.
</span> </span>
</div> </div>
{{#if (eq particuliere 'rapidite')}} {{#if (eq particuliere 'rapidite')}}