Ajouts combat #68

- gestion de la feinte (sauf initiative)
- gestion du bonus à l'attaque de la charge
- dégats de corps à corps
- bonus dégâts si surprise, début de gestion de surprise totale
This commit is contained in:
2020-12-16 23:02:15 +01:00
parent c8a2d69e0f
commit f3453a46e7
9 changed files with 287 additions and 318 deletions

View File

@ -1,16 +1,17 @@
import { HtmlUtility } from "./html-utility.js";
import { RdDItemSort } from "./item-sort.js";
import { Misc } from "./misc.js";
import { RdDBonus } from "./rdd-bonus.js";
import { RdDResolutionTable } from "./rdd-resolution-table.js";
/**
* Extend the base Dialog entity to select roll parameters
* @extends {Dialog}
*/
/* -------------------------------------------- */
/* -------------------------------------------- */
export class RdDRoll extends Dialog {
/* -------------------------------------------- */
/* -------------------------------------------- */
static async create(actor, rollData, dialogConfig, ...actions) {
RdDRoll._ensureCorrectActions(actions);
@ -25,7 +26,7 @@ export class RdDRoll extends Dialog {
return new RdDRoll(actor, rollData, html, options, actions);
}
/* -------------------------------------------- */
/* -------------------------------------------- */
static _setDefaultOptions(actor, rollData) {
let defaultRollData = {
@ -38,7 +39,7 @@ export class RdDRoll extends Dialog {
diffLibre: 0,
editLibre: true,
editConditions: true,
forceValue : actor.getForceValue(),
forceValue: actor.getForceValue(),
malusArmureValue: (actor.type == 'personnage ' && actor.data.data.attributs && actor.data.data.attributs.malusarmure) ? actor.data.data.attributs.malusarmure.value : 0,
surencMalusFlag: actor.type == 'personnage ' ? (actor.data.data.compteurs.surenc.value < 0) : false,
surencMalusValue: actor.type == 'personnage ' ? actor.data.data.compteurs.surenc.value : 0,
@ -48,10 +49,10 @@ export class RdDRoll extends Dialog {
encValueForNatation: actor.encombrementTotal ? Math.floor(actor.encombrementTotal) : 0,
ajustementAstrologique: actor.ajustementAstrologique()
}
mergeObject(rollData, defaultRollData, { overwrite: false } );
mergeObject(rollData, defaultRollData, { overwrite: false });
}
/* -------------------------------------------- */
/* -------------------------------------------- */
static _ensureCorrectActions(actions) {
if (actions.length == 0) {
throw 'No action defined';
@ -63,7 +64,7 @@ export class RdDRoll extends Dialog {
});
}
/* -------------------------------------------- */
/* -------------------------------------------- */
constructor(actor, rollData, html, options, actions) {
let conf = {
title: actions[0].label,
@ -81,7 +82,7 @@ export class RdDRoll extends Dialog {
this.rollData = rollData;
}
/* -------------------------------------------- */
/* -------------------------------------------- */
async onAction(action, html) {
await RdDResolutionTable.rollData(this.rollData);
console.log("RdDRoll -=>", this.rollData, this.rollData.rolled);
@ -101,19 +102,26 @@ export class RdDRoll extends Dialog {
this.bringToTop();
var rollData = this.rollData;
var actor = this.actor;
function updateRollResult(rollData) {
let caracValue = parseInt(rollData.selectedCarac.value)
let rollLevel = RdDRoll._computeFinalLevel(rollData);
rollData.dmg = rollData.attackerRoll ? rollData.attackerRoll.dmg : RdDBonus.dmg(rollData, actor.getBonusDegat());
rollData.finalLevel = rollLevel;
rollData.caracValue = caracValue
rollData.caracValue = caracValue;
rollData.diffConditions = RdDBonus.bonusAttaque(rollData.surpriseDefenseur);
rollData.coupsNonMortels = (rollData.attackerRoll ? rollData.attackerRoll.dmg.mortalite : rollData.dmg.mortalite) == 'non-mortel';
let dmgText = Misc.toSignedString(rollData.dmg.total);
if (rollData.coupsNonMortels) {
dmgText = '(' + dmgText + ')';
}
HtmlUtility._showControlWhen(".etat-general", !RdDRoll._isIgnoreEtatGeneral(rollData));
// Sort management
if (rollData.selectedSort) {
rollData.bonus = RdDItemSort.getCaseBonus( rollData.selectedSort, rollData.coord ),
rollData.bonus = RdDItemSort.getCaseBonus(rollData.selectedSort, rollData.coord),
//console.log("Toggle show/hide", rollData.selectedSort);
HtmlUtility._showControlWhen("#div-sort-difficulte", RdDItemSort.isDifficulteVariable(rollData.selectedSort))
HtmlUtility._showControlWhen("#div-sort-ptreve", RdDItemSort.isCoutVariable(rollData.selectedSort))
@ -122,6 +130,9 @@ export class RdDRoll extends Dialog {
// Mise à jour valeurs
$("#roll-param").text(rollData.selectedCarac.value + " / " + Misc.toSignedString(rollData.finalLevel));
$("#compdialogTitle").text(RdDRoll._getTitle(rollData));
$('#coupsNonMortels').prop('checked', rollData.coupsNonMortels);
$("#dmg-arme-actor").text(dmgText);
$("#defenseur-surprise").text(RdDBonus.description(rollData.surpriseDefenseur));
$(".table-resolution").remove();
$("#resolutionTable").append(RdDResolutionTable.buildHTMLTableExtract(caracValue, rollLevel));
$(".span-valeur").remove();
@ -168,7 +179,7 @@ export class RdDRoll extends Dialog {
html.find('#sort').change((event) => {
let sortKey = Misc.toInt(event.currentTarget.value);
this.rollData.selectedSort = rollData.sortList[sortKey]; // Update the selectedCarac
this.rollData.bonus = RdDItemSort.getCaseBonus( rollData.selectedSort, rollData.coord );
this.rollData.bonus = RdDItemSort.getCaseBonus(rollData.selectedSort, rollData.coord);
RdDItemSort.setCoutReveReel(rollData.selectedSort);
//console.log("RdDRollSelectDialog - Sort selection", rollData.selectedSort);
updateRollResult(rollData);
@ -186,10 +197,12 @@ export class RdDRoll extends Dialog {
updateRollResult(rollData);
});
html.find('#coupsNonMortels').change((event) => {
this.rollData.mortalite = event.currentTarget.checked ? "non-mortel" : "mortel";
this.rollData.dmg.mortalite = event.currentTarget.checked ? "non-mortel" : "mortel";
updateRollResult(rollData);
});
html.find('#isCharge').change((event) => {
this.rollData.isCharge = event.currentTarget.checked;
html.find('#tactique-combat').change((event) => {
this.rollData.tactique = event.currentTarget.value;
updateRollResult(rollData);
});
html.find('#surencMalusApply').change((event) => {
this.rollData.surencMalusApply = event.currentTarget.checked;
@ -209,11 +222,38 @@ export class RdDRoll extends Dialog {
static _computeFinalLevel(rollData) {
const etat = RdDRoll._isIgnoreEtatGeneral(rollData) ? 0 : Misc.toInt(rollData.etat);
const diffConditions = Misc.toInt(rollData.diffConditions);
let malusEnc = (rollData.surencMalusApply) ? rollData.surencMalusValue : 0;
let diffLibre = Misc.toInt(rollData.diffLibre);
let malusEncNatation = (rollData.useEncForNatation) ? -rollData.encValueForNatation : 0;
let ajustementChance = rollData.selectedCarac.label.toLowerCase().includes('chance') ? rollData.ajustementAstrologique : 0;
const malusEnc = (rollData.surencMalusApply) ? rollData.surencMalusValue : 0;
const bonusTactique = RdDBonus.bonusAttaque(rollData.tactique);
const malusEncNatation = (rollData.useEncForNatation) ? -rollData.encValueForNatation : 0;
const ajustementChance = rollData.selectedCarac.label.toLowerCase().includes('chance') ? rollData.ajustementAstrologique : 0;
// Gestion malus armure
const malusArmureValue = RdDRoll._computeMalusArmure(rollData);
const diffLibre = RdDRoll._computeDiffLibre(rollData);
const diffCompetence = RdDRoll._computeDiffCompetence(rollData);
return etat + diffCompetence + diffLibre + diffConditions + malusEnc + malusEncNatation + malusArmureValue + ajustementChance + bonusTactique;
}
static _computeDiffCompetence(rollData) {
if (rollData.competence) {
return Misc.toInt(rollData.competence.data.niveau);
}
if (rollData.draconicList) {
return Misc.toInt(rollData.selectedDraconic.data.niveau);
}
return 0;
}
static _computeDiffLibre(rollData) {
let diffLibre = Misc.toInt(rollData.diffLibre);
if (rollData.draconicList && rollData.selectedSort) {
return RdDItemSort.getDifficulte(rollData.selectedSort, diffLibre);
}
return diffLibre;
}
static _computeMalusArmure(rollData) {
let malusArmureValue = 0;
if (rollData.malusArmureValue != 0 && (rollData.selectedCarac.label == "Agilité" || rollData.selectedCarac.label == "Dérobée")) {
$("#addon-message").text("Malus armure appliqué : " + rollData.malusArmureValue);
@ -221,17 +261,7 @@ export class RdDRoll extends Dialog {
} else {
$("#addon-message").text("");
}
let diffCompetence = 0;
if (rollData.competence) {
diffCompetence = Misc.toInt(rollData.competence.data.niveau);
}
else if (rollData.draconicList) {
diffCompetence = Misc.toInt(rollData.selectedDraconic.data.niveau);
diffLibre = RdDItemSort.getDifficulte(rollData.selectedSort, diffLibre);
}
return etat + diffCompetence + diffLibre + diffConditions + malusEnc + malusEncNatation + malusArmureValue + ajustementChance;
return malusArmureValue;
}
/* -------------------------------------------- */