#11 gestion encombrement et malus associé
This commit is contained in:
commit
ea821e352e
@ -15,6 +15,7 @@ import { RdDActorCreatureSheet } from "./actor-creature-sheet.js";
|
||||
import { RdDActorHumanoideSheet } from "./actor-humanoide-sheet.js";
|
||||
import { RdDUtility } from "./rdd-utility.js";
|
||||
import { RdDCalendrier } from "./rdd-calendrier.js";
|
||||
import { RdDResolutionTable } from "./rdd-resolution-table.js";
|
||||
|
||||
/* -------------------------------------------- */
|
||||
/* Foundry VTT Initialization */
|
||||
@ -112,12 +113,12 @@ Hooks.once("init", async function() {
|
||||
|
||||
// Define custom Entity classes
|
||||
CONFIG.Actor.entityClass = RdDActor;
|
||||
CONFIG.RDD = {}
|
||||
CONFIG.RDD.resolutionTable = RdDUtility.buildResolutionTable();
|
||||
CONFIG.RDD.level_category = RdDUtility.getLevelCategory();
|
||||
CONFIG.RDD.carac_array = RdDUtility.getCaracArray();
|
||||
CONFIG.RDD.bonusmalus = RdDUtility.getBonusMalus();
|
||||
game.data.RdDUtility = RdDUtility;
|
||||
CONFIG.RDD = {
|
||||
resolutionTable : RdDResolutionTable.resolutionTable,
|
||||
level_category : RdDUtility.getLevelCategory(),
|
||||
carac_array : RdDUtility.getCaracArray(),
|
||||
bonusmalus : RdDUtility.getBonusMalus()
|
||||
}
|
||||
|
||||
// Register sheet application classes
|
||||
Actors.unregisterSheet("core", ActorSheet);
|
||||
|
99
module/rdd-resolution-table.js
Normal file
99
module/rdd-resolution-table.js
Normal file
@ -0,0 +1,99 @@
|
||||
|
||||
export class RdDResolutionTable {
|
||||
static resolutionTable = this.build()
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static build() {
|
||||
let table = []
|
||||
for (var carac = 0; carac <= 30; carac++) {
|
||||
table[carac] = this._computeRow(carac);
|
||||
}
|
||||
return table;
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static _computeRow(carac) {
|
||||
let dataRow = [
|
||||
this._computeScore(-10, Math.max(Math.floor(carac / 4), 1)),
|
||||
this._computeScore(-9, Math.max(Math.floor(carac / 2), 1))
|
||||
]
|
||||
for (var diff = -8; diff <= 22; diff++) {
|
||||
dataRow[diff + 10] = this._computeScore(diff, Math.max(Math.floor(carac * (diff + 10) / 2), 1));
|
||||
}
|
||||
return dataRow;
|
||||
}
|
||||
|
||||
static _computeScore(diff, score) {
|
||||
return {
|
||||
niveau: diff,
|
||||
score: score,
|
||||
sign: this._reussiteSignificative(score),
|
||||
part: this._reussitePart(score),
|
||||
epart: this._echecParticulier(score),
|
||||
etotal: this._echecTotal(score)
|
||||
}
|
||||
}
|
||||
|
||||
static _reussiteSignificative(score) {
|
||||
return Math.floor(score / 2);
|
||||
}
|
||||
|
||||
static _reussitePart(score) {
|
||||
return Math.ceil(score / 5);
|
||||
}
|
||||
|
||||
static _echecParticulier(score) {
|
||||
return Math.ceil(score / 5) + 80;
|
||||
}
|
||||
|
||||
static _echecTotal(score) {
|
||||
return Math.ceil(score / 10) + 91;
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static buildHTMLTable(caracValue, levelValue, minCarac = 1, maxCarac = 21, minLevel = -10, maxLevel = 11) {
|
||||
return this._buildHTMLTable(caracValue, levelValue, minCarac, maxCarac, minLevel, maxLevel)
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static _buildHTMLTable(caracValue, levelValue, minCarac, maxCarac, minLevel, maxLevel) {
|
||||
minCarac = Math.max(minCarac, 1);
|
||||
maxCarac = Math.min(maxCarac, 30);
|
||||
minLevel = Math.max(minLevel, -10);
|
||||
maxLevel = Math.min(maxLevel, 22);
|
||||
|
||||
var table = $("<table class='table-resolution'/>")
|
||||
.append(this._buildHTMLHeader(this.resolutionTable[0], minLevel, maxLevel));
|
||||
|
||||
for (var carac = minCarac; carac <= maxCarac; carac++) {
|
||||
table.append(this._buildHTMLRow(this.resolutionTable[carac], carac, caracValue, levelValue, minLevel, maxLevel));
|
||||
}
|
||||
return table;
|
||||
}
|
||||
|
||||
static _buildHTMLHeader(dataRow, minLevel, maxLevel) {
|
||||
var tr = $("<tr/>");
|
||||
for (var difficulte = minLevel; difficulte <= maxLevel; difficulte++) {
|
||||
const niveau = dataRow[difficulte + 10].niveau;
|
||||
const txt = (niveau > 0 ? "+" : "") + niveau;
|
||||
tr.append($("<th class='table-resolution-level'/>").text(txt));
|
||||
}
|
||||
return tr;
|
||||
}
|
||||
|
||||
static _buildHTMLRow(dataRow, rowIndex, caracValue, levelValue, minLevel, maxLevel) {
|
||||
var tr = $("<tr/>");
|
||||
for (var difficulte = minLevel; difficulte <= maxLevel; difficulte++) {
|
||||
var td = $("<td/>");
|
||||
let score = dataRow[difficulte + 10].score;
|
||||
if (rowIndex == caracValue && levelValue == difficulte) {
|
||||
td.addClass('table-resolution-target');
|
||||
} else if (difficulte == -8) {
|
||||
td.addClass('table-resolution-carac');
|
||||
}
|
||||
tr.append(td.text(score));
|
||||
}
|
||||
return tr;
|
||||
}
|
||||
|
||||
}
|
@ -1,105 +1,90 @@
|
||||
import { RdDResolutionTable } from "./rdd-resolution-table.js";
|
||||
import { RdDUtility } from "./rdd-utility.js";
|
||||
|
||||
/**
|
||||
* Extend the base Dialog entity by defining a custom window to perform roll.
|
||||
* @extends {Dialog}
|
||||
*/
|
||||
|
||||
export class RdDRollDialog extends Dialog {
|
||||
|
||||
/* -------------------------------------------- */
|
||||
constructor(mode, html, rollData, actor) {
|
||||
let myButtons = { rollButton: {
|
||||
label: "Lancer",
|
||||
callback: html => this.performRollSort(html, false)
|
||||
} };
|
||||
|
||||
let myButtons
|
||||
if (mode == "sort") {
|
||||
myButtons['reserveButton'] = { label: "Mettre en reserve",
|
||||
callback: html => this.performRollSort(html, true)
|
||||
}
|
||||
myButtons = {
|
||||
rollButton: { label: "Lancer le sort", callback: html => this.performRollSort(html, false) },
|
||||
reserveButton: { label: "Mettre en reserve", callback: html => this.performRollSort(html, true) }
|
||||
}
|
||||
}
|
||||
else {
|
||||
myButtons = {
|
||||
rollButton: { label: "Lancer", callback: html => this.actor.performRoll(this.rollData) }
|
||||
};
|
||||
}
|
||||
|
||||
// Common conf
|
||||
let dialogConf = {
|
||||
content: html,
|
||||
buttons: myButtons,
|
||||
default: "rollButton"
|
||||
}
|
||||
let dialogOptions = { classes: [ "rdddialog"] }
|
||||
let dialogConf = { content: html, title: "Test", buttons: myButtons, default: "rollButton" }
|
||||
let dialogOptions = { classes: ["rdddialog"], width: 600, height: 400 }
|
||||
|
||||
// Select proper roll dialog template and stuff
|
||||
if (mode == "competence" ) {
|
||||
dialogConf.title = "Test de compétence",
|
||||
dialogOptions.width = 600;
|
||||
dialogOptions.height = 360;
|
||||
if (mode == "competence") {
|
||||
dialogConf.title = "Test de compétence"
|
||||
dialogConf.height = 400
|
||||
} else if (mode == "arme") {
|
||||
dialogConf.title = "Test de combat/arme",
|
||||
dialogOptions.width = 600;
|
||||
dialogOptions.height = 360;
|
||||
dialogConf.title = "Test de combat/arme"
|
||||
dialogConf.height = 430
|
||||
} else if (mode == "carac") {
|
||||
dialogConf.title = "Test de caractéristique",
|
||||
dialogOptions.width = 600;
|
||||
dialogOptions.height = 320;
|
||||
dialogConf.title = "Test de caractéristique"
|
||||
dialogOptions.height = 350
|
||||
} else if (mode == "sort") {
|
||||
dialogConf.title = "Lancer un sort",
|
||||
dialogOptions.width = 600;
|
||||
dialogOptions.height = 380;
|
||||
dialogConf.title = "Lancer un sort"
|
||||
dialogConf.height = 450
|
||||
}
|
||||
super(dialogConf, dialogOptions);
|
||||
super(dialogConf, dialogOptions)
|
||||
|
||||
this.mode = mode;
|
||||
this.rollData = rollData;
|
||||
this.actor = actor;
|
||||
this.mode = mode
|
||||
this.rollData = rollData
|
||||
this.actor = actor
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
performRollSort (html, isReserve=false) {
|
||||
performRollSort(html, isReserve = false) {
|
||||
this.rollData.isSortReserve = isReserve;
|
||||
this.actor.performRoll( this.rollData );
|
||||
this.actor.performRoll(this.rollData);
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
activateListeners(html) {
|
||||
activateListeners(html) {
|
||||
super.activateListeners(html);
|
||||
|
||||
// Get the rollData stuff
|
||||
var rollData = this.rollData;
|
||||
|
||||
function updateRollResult( rollData ) {
|
||||
if ( rollData.competence )
|
||||
rollData.finalLevel = parseInt(rollData.competence.data.niveau) + parseInt(rollData.bmValue) + parseInt(rollData.etat);
|
||||
else if ( rollData.draconicList )
|
||||
rollData.finalLevel = parseInt(rollData.selectedDraconic.data.niveau) + parseInt(rollData.selectedSort.data.difficulte) + parseInt(rollData.etat);
|
||||
else
|
||||
rollData.finalLevel = parseInt(rollData.bmValue) + parseInt(rollData.etat);
|
||||
function updateRollResult(rollData) {
|
||||
let caracValue = parseInt(rollData.selectedCarac.value)
|
||||
let rollLevel = RdDRollDialog._computeFinalLevel(rollData);
|
||||
|
||||
rollData.finalLevelStr = (rollData.finalLevel >= 0 ) ? "+" + rollData.finalLevel : rollData.finalLevel;
|
||||
$("#roll-param").text( rollData.selectedCarac.value + " / " + rollData.finalLevelStr );
|
||||
rollData.rollTarget = game.data.RdDUtility.getResolutionField( rollData.selectedCarac.value, rollData.finalLevel);
|
||||
rollData.finalLevel = rollLevel;
|
||||
rollData.finalLevelStr = (rollLevel > 0 ? "+" : "") + rollLevel;
|
||||
rollData.rollTarget = RdDUtility.getResolutionField(rollData.selectedCarac.value, rollData.finalLevel);
|
||||
|
||||
let armeTitle = ( rollData.arme ) ? " ("+rollData.arme.name+") " : ""; // If a weapon is there, add it in the title
|
||||
let niveauStr = "";
|
||||
if ( rollData.competence ) {
|
||||
niveauStr = (rollData.competence.data.niveau >= 0) ? "+" + rollData.competence.data.niveau : rollData.competence.data.niveau;
|
||||
$("#compdialogTitle").text( rollData.selectedCarac.label + "/" + rollData.competence.name + armeTitle + " " + niveauStr );
|
||||
} else if ( rollData.draconicList) {
|
||||
$("#compdialogTitle").text( rollData.selectedDraconic.name + " - " + rollData.selectedSort.name );
|
||||
} else {
|
||||
$("#compdialogTitle").text( rollData.selectedCarac.label );
|
||||
}
|
||||
$("#roll-param").text(rollData.selectedCarac.value + " / " + rollData.finalLevelStr);
|
||||
$("#compdialogTitle").text(RdDRollDialog._getTitle(rollData));
|
||||
$(".table-resolution").remove();
|
||||
game.data.RdDUtility.makeHTMLResolutionTable( $("#resolutionTable"), rollData.selectedCarac.value-2, parseInt(rollData.selectedCarac.value) + 2, -10, 11,
|
||||
rollData.selectedCarac.value, rollData.finalLevel );
|
||||
$("#resolutionTable").append(RdDResolutionTable.buildHTMLTable(caracValue, rollLevel, caracValue - 2, caracValue + 2));
|
||||
}
|
||||
|
||||
// Setup everything onload
|
||||
$(function() {
|
||||
$(function () {
|
||||
// Update html, according to data
|
||||
if (rollData.competence) {
|
||||
// Set the default carac from the competence item
|
||||
console.log(rollData.competence.data.defaut_carac, rollData.carac);
|
||||
rollData.selectedCarac = rollData.carac[rollData.competence.data.defaut_carac];
|
||||
$("#carac").val( rollData.competence.data.defaut_carac );
|
||||
$("#carac").val(rollData.competence.data.defaut_carac);
|
||||
}
|
||||
$("#bonusmalus").val( rollData.bmValue );
|
||||
$("#bonusmalus").val(rollData.bmValue);
|
||||
updateRollResult(rollData);
|
||||
});
|
||||
|
||||
@ -127,6 +112,30 @@ export class RdDRollDialog extends Dialog {
|
||||
//console.log("CARAC CLICKED !!!", rollData.selectedCarac, rollData.competence.data.niveau, rollData.bmValue);
|
||||
updateRollResult(rollData);
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
static _computeFinalLevel(rollData) {
|
||||
let etat = rollData.etat === undefined ? 0 : parseInt(rollData.etat);
|
||||
if (rollData.competence) {
|
||||
return etat + parseInt(rollData.competence.data.niveau) + parseInt(rollData.bmValue);
|
||||
}
|
||||
if (rollData.draconicList) {
|
||||
return etat + parseInt(rollData.selectedDraconic.data.niveau) + parseInt(rollData.selectedSort.data.difficulte);
|
||||
}
|
||||
return etat + parseInt(rollData.bmValue);
|
||||
}
|
||||
|
||||
static _getTitle(rollData) {
|
||||
if (rollData.competence) {
|
||||
// If a weapon is there, add it in the title
|
||||
let armeTitle = (rollData.arme) ? " (" + rollData.arme.name + ") " : "";
|
||||
let niveauStr = (rollData.competence.data.niveau > 0 ? "+" : "") + rollData.competence.data.niveau;
|
||||
return rollData.selectedCarac.label + "/" + rollData.competence.name + armeTitle + " " + niveauStr
|
||||
}
|
||||
if (rollData.draconicList) {
|
||||
return rollData.selectedDraconic.name + " - " + rollData.selectedSort.name;
|
||||
}
|
||||
return rollData.selectedCarac.label;
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
/* Common useful functions shared between objects */
|
||||
|
||||
import { RdDActor } from "./actor.js";
|
||||
import { TMRUtility } from "./tmr-utility.js";
|
||||
import { RdDRollTables } from "./rdd-rolltables.js";
|
||||
import { RdDResolutionTable } from "./rdd-resolution-table.js";
|
||||
|
||||
const level_category = {
|
||||
"generale": "-4",
|
||||
@ -48,12 +48,12 @@ const specialResults = [ { "part": 0, "epart": 0, "etotal": 0 }, // 0
|
||||
{ "part": 19, "epart": 99, "etotal": 100 }, // 81-95
|
||||
{ "part": 20, "epart": 100, "etotal": 100 } // 96-00
|
||||
];
|
||||
const levelDown = [ { "level": -11, "score": 1, "part": 0, "epart": 2, "etotal": 90 },
|
||||
{ "level": -12, "score": 1, "part": 0, "epart": 2, "etotal": 70 },
|
||||
{ "level": -13, "score": 1, "part": 0, "epart": 2, "etotal": 50 },
|
||||
{ "level": -14, "score": 1, "part": 0, "epart": 2, "etotal": 30 },
|
||||
{ "level": -15, "score": 1, "part": 0, "epart": 2, "etotal": 10 },
|
||||
{ "level": -16, "score": 1, "part": 0, "epart": 2, "etotal": 2 }
|
||||
const levelDown = [ { "level": -11, "score": 1, "sign": 0, "part": 0, "epart": 2, "etotal": 90 },
|
||||
{ "level": -12, "score": 1, "sign": 0, "part": 0, "epart": 2, "etotal": 70 },
|
||||
{ "level": -13, "score": 1, "sign": 0, "part": 0, "epart": 2, "etotal": 50 },
|
||||
{ "level": -14, "score": 1, "sign": 0, "part": 0, "epart": 2, "etotal": 30 },
|
||||
{ "level": -15, "score": 1, "sign": 0, "part": 0, "epart": 2, "etotal": 10 },
|
||||
{ "level": -16, "score": 1, "sign": 0, "part": 0, "epart": 2, "etotal": 2 }
|
||||
];
|
||||
const fatigueMatrix = [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, // Dummy filler for the array.
|
||||
[2, 3, 3, 2, 3, 3, 2, 3, 3, 2, 3, 3 ],
|
||||
@ -102,7 +102,7 @@ const definitionsEncaissement = {
|
||||
{ minimum: 20, maximum: undefined, endurance: "100", vie: "1", legeres: 1, graves: 0, critiques: 0 },
|
||||
],
|
||||
"cauchemar": [
|
||||
{ minimum: undefined, maximum: 0, gravite: "frayeur", endurance: "0", vie: "0", legeres: 0, graves: 0, critiques: 0 },
|
||||
{ minimum: undefined, maximum: 0, endurance: "0", vie: "0", legeres: 0, graves: 0, critiques: 0 },
|
||||
{ minimum: 1, maximum: 10, endurance: "1d4", vie: "0", legeres: 0, graves: 0, critiques: 0 },
|
||||
{ minimum: 11, maximum: 15, endurance: "1d6", vie: "0", legeres: 0, graves: 0, critiques: 0 },
|
||||
{ minimum: 16, maximum: 19, endurance: "2d6", vie: "0", legeres: 0, graves: 0, critiques: 0 },
|
||||
@ -162,6 +162,7 @@ export class RdDUtility {
|
||||
|
||||
return loadTemplates(templatePaths);
|
||||
}
|
||||
<<<<<<< HEAD
|
||||
|
||||
/************************************************************************************/
|
||||
static buildConteneur( objet, niveau ) {
|
||||
@ -211,6 +212,8 @@ export class RdDUtility {
|
||||
}
|
||||
return tableRes;
|
||||
}
|
||||
=======
|
||||
>>>>>>> fb52e394e7e17fad20a0bdaa2ae9ea00c03a465e
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static getLevelCategory( )
|
||||
@ -226,55 +229,6 @@ export class RdDUtility {
|
||||
return bonusmalus;
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static __buildHTMLResolutionHead( dataRow, minLevel=0, maxLevel=32 ) {
|
||||
let r = dataRow;
|
||||
var row = $("<tr/>");
|
||||
for (var colIndex=minLevel; colIndex <= maxLevel; colIndex++) {
|
||||
let c = dataRow[colIndex];
|
||||
let txt = (c.niveau > 0) ? "+"+c.niveau : c.niveau;
|
||||
row.append($("<th class='table-resolution-level'/>").text(txt) );
|
||||
}
|
||||
return row;
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static __buildHTMLResolutionRow( dataRow, minLevel=0, maxLevel=32, rowIndex, caracValue, levelValue ) {
|
||||
let r = dataRow;
|
||||
var row = $("<tr/>");
|
||||
for (var colIndex=minLevel; colIndex <= maxLevel; colIndex++) {
|
||||
let c = dataRow[colIndex];
|
||||
if (rowIndex == caracValue && levelValue+10 == colIndex) {
|
||||
row.append($("<td class='table-resolution-target'/>").text(c.score));
|
||||
} else {
|
||||
if ( colIndex == 2 )
|
||||
row.append($("<td class='table-resolution-carac'/>").text(c.score));
|
||||
else
|
||||
row.append($("<td/>").text(c.score));
|
||||
}
|
||||
}
|
||||
return row;
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static makeHTMLResolutionTable(container, minCarac = 1, maxCarac = 21, minLevel=-10, maxLevel=22, caracValue, levelValue) {
|
||||
minCarac = (minCarac < 1) ? 1 : minCarac;
|
||||
maxCarac = (maxCarac > 21) ? 21 : maxCarac;
|
||||
let data = CONFIG.RDD.resolutionTable;
|
||||
var table = $("<table/>").addClass('table-resolution');
|
||||
// Build first row of levels
|
||||
minLevel = (minLevel < -10) ? 0 : minLevel+10;
|
||||
maxLevel = (maxLevel > 22) ? 32 : maxLevel+10;
|
||||
let row = this.__buildHTMLResolutionHead( data[0], minLevel, maxLevel );
|
||||
table.append(row);
|
||||
// Then the rest...
|
||||
for (var rowIndex=minCarac; rowIndex <= maxCarac; rowIndex++) {
|
||||
let row = this.__buildHTMLResolutionRow( data[rowIndex], minLevel, maxLevel, rowIndex, caracValue, levelValue );
|
||||
table.append(row);
|
||||
}
|
||||
return container.append(table);
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static isTronc( compName )
|
||||
{
|
||||
@ -291,8 +245,9 @@ export class RdDUtility {
|
||||
static getResolutionField(caracValue, levelValue )
|
||||
{
|
||||
if ( levelValue < -16 ) {
|
||||
return { "score": 0, "part": 0, "epart": 1, "etotal": 1};
|
||||
} if ( levelValue < -10 ) {
|
||||
return { score: 0, sign:0, part: 0, epart: 1, etotal: 1};
|
||||
}
|
||||
if ( levelValue < -10 ) {
|
||||
return levelDown.find(levelData => levelData.level == levelValue);
|
||||
}
|
||||
return CONFIG.RDD.resolutionTable[caracValue][levelValue+10];
|
||||
|
Loading…
Reference in New Issue
Block a user