2020-05-22 22:37:02 +02:00
|
|
|
/* Common useful functions shared between objects */
|
|
|
|
|
2020-05-24 20:19:57 +02:00
|
|
|
const level_category = {
|
|
|
|
"generale": "-4",
|
|
|
|
"particuliere": "-8",
|
|
|
|
"speciale": "-11",
|
|
|
|
"connaissance": "-11",
|
|
|
|
"draconic": "-11",
|
|
|
|
"melee": "-6",
|
|
|
|
"tir": "-8",
|
|
|
|
"lancer": "-8"
|
|
|
|
}
|
|
|
|
const carac_array = [ "taille", "apparence", "constitution", "force", "agilite", "dexterite", "vue", "ouie", "odoratgout", "volonte", "intellect", "empathie", "reve", "chance", "melee", "tir", "lancer", "derobee"];
|
|
|
|
const bonusmalus = [-10, -9, -8, -7, -6, -5, -4, -3, -2, -1, 0, +1, +2, +3, +4, +5, +6, +7, +8, +9, +10];
|
|
|
|
const specialResults = [ { "part": 0, "epart": 0, "etotal": 0 }, // 0
|
|
|
|
{ "part": 1, "epart": 81, "etotal": 92 }, // 01-05
|
|
|
|
{ "part": 2, "epart": 82, "etotal": 92 }, // 06-10
|
|
|
|
{ "part": 3, "epart": 83, "etotal": 93 }, // 11-15
|
|
|
|
{ "part": 4, "epart": 84, "etotal": 93 }, // 16-20
|
|
|
|
{ "part": 5, "epart": 85, "etotal": 94 }, // 21-25
|
|
|
|
{ "part": 6, "epart": 86, "etotal": 94 }, // 26-30
|
|
|
|
{ "part": 7, "epart": 87, "etotal": 95 }, // 31-35
|
|
|
|
{ "part": 8, "epart": 88, "etotal": 95 }, // 36-40
|
|
|
|
{ "part": 9, "epart": 89, "etotal": 96 }, // 41-45
|
|
|
|
{ "part": 10, "epart": 90, "etotal": 96 }, // 46-50
|
|
|
|
{ "part": 11, "epart": 91, "etotal": 97 }, // 51-55
|
|
|
|
{ "part": 12, "epart": 92, "etotal": 97 }, // 56-60
|
|
|
|
{ "part": 13, "epart": 93, "etotal": 98 }, // 61-65
|
|
|
|
{ "part": 14, "epart": 94, "etotal": 98 }, // 65-70
|
|
|
|
{ "part": 15, "epart": 95, "etotal": 99 }, // 71-75
|
|
|
|
{ "part": 16, "epart": 96, "etotal": 99 }, // 76-80
|
|
|
|
{ "part": 17, "epart": 97, "etotal": 100 }, // 81-85
|
|
|
|
{ "part": 18, "epart": 98, "etotal": 100 }, // 86-90
|
|
|
|
{ "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 },
|
2020-05-27 23:47:49 +02:00
|
|
|
{ "level": -16, "score": 1, "part": 0, "epart": 2, "etotal": 2 }
|
2020-05-24 20:19:57 +02:00
|
|
|
];
|
2020-05-27 23:47:49 +02:00
|
|
|
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 ],
|
|
|
|
[2, 3, 3, 3, 3, 3, 2, 3, 3, 3, 3, 3 ],
|
|
|
|
[3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3 ],
|
|
|
|
[3, 3, 3, 3, 3, 4, 3, 3, 3, 3, 3, 4 ],
|
|
|
|
[3, 3, 4, 3, 3, 4, 3, 3, 4, 3, 3, 4 ],
|
|
|
|
[3, 3, 4, 3, 4, 4, 3, 3, 4, 3, 4, 4 ],
|
|
|
|
[3, 4, 4, 3, 4, 4, 3, 4, 4, 3, 4, 4 ],
|
|
|
|
[3, 4, 4, 4, 4, 4, 3, 4, 4, 4, 4, 4 ],
|
|
|
|
[4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4 ],
|
|
|
|
[4, 4, 4, 4, 4, 5, 4, 4, 4, 4, 4, 5 ],
|
|
|
|
[4, 4, 5, 4, 4, 5, 4, 4, 5, 4, 4, 5 ],
|
|
|
|
[4, 4, 5, 4, 5, 5, 4, 4, 5, 4, 5, 5 ],
|
|
|
|
[4, 5, 5, 4, 5, 5, 4, 5, 5, 4, 5, 5 ],
|
|
|
|
[4, 5, 5, 5, 5, 5, 4, 5, 5, 5, 5, 5 ],
|
|
|
|
[5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5 ] ];
|
|
|
|
const fatigueMalus = [ 0, 0, 0, -1, -1, -1, -2, -3, -4, -5, -6, -7 ]; // Provides the malus for each segment of fatigue
|
2020-05-28 23:36:09 +02:00
|
|
|
const fatigueLineSize = [ 3, 6, 7, 8, 9, 10, 11, 12];
|
|
|
|
const fatigueLineMalus = [ 0, -1, -2, -3, -4, -5, -6, -7 ];
|
2020-05-27 23:47:49 +02:00
|
|
|
const fatigueTemplate = "<table>\
|
|
|
|
<th><tdid=1><td/><td/><td/><td/> <td/> <td/><td/><td/><td/><td/> <td/> <td/><td/><td/><td/><td/></tr>\
|
|
|
|
<th><td/><td/><td/><td/><td/> <td/> <td/><td/><td/><td/><td/> <td/> <td/><td/><td/><td/><td/></tr>\
|
|
|
|
<th><td/><td/><td/><td/><td/></tr>\
|
|
|
|
<th><td/><td/><td/><td/><td/></tr>\
|
|
|
|
<th><td/><td/><td/><td/><td/></tr>\
|
|
|
|
<th><td/><td/><td/><td/><td/></tr>\
|
|
|
|
<th><td/><td/><td/><td/><td/></tr>\
|
|
|
|
<th><td/><td/><td/><td/><td/></tr>\
|
|
|
|
</table>"
|
|
|
|
|
2020-05-22 22:37:02 +02:00
|
|
|
export class RdDUtility {
|
|
|
|
|
2020-05-24 20:19:57 +02:00
|
|
|
/* -------------------------------------------- */
|
|
|
|
static async preloadHandlebarsTemplates( ) {
|
|
|
|
const templatePaths = [
|
|
|
|
//Character Sheets
|
|
|
|
'systems/foundryvtt-reve-de-dragon/templates/actor-sheet.html',
|
|
|
|
//Items
|
|
|
|
'systems/foundryvtt-reve-de-dragon/templates/item-competence-sheet.html',
|
|
|
|
'systems/foundryvtt-reve-de-dragon/templates/competence-categorie.html',
|
|
|
|
'systems/foundryvtt-reve-de-dragon/templates/competence-carac-defaut.html',
|
|
|
|
'systems/foundryvtt-reve-de-dragon/templates/competence-base.html',
|
|
|
|
// Dialogs
|
|
|
|
'systems/foundryvtt-reve-de-dragon/templates/dialog-competence.html'
|
|
|
|
];
|
|
|
|
|
|
|
|
return loadTemplates(templatePaths);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
static buildResolutionTable( ) {
|
|
|
|
let tableRes = []
|
|
|
|
for (var j=0; j<=21; j++) {
|
|
|
|
let subtab = [];
|
|
|
|
for (var i=-10; i<=22; i++) {
|
|
|
|
var m = (i + 10) * 0.5;
|
|
|
|
var v;
|
|
|
|
if (i == -9) {
|
|
|
|
v = Math.floor(j / 2);
|
|
|
|
} else if (i == -10) {
|
|
|
|
v = Math.floor(j / 4);
|
|
|
|
} else {
|
|
|
|
if (j % 2 == 0) {
|
|
|
|
var v = Math.ceil(j * m);
|
|
|
|
} else {
|
|
|
|
var v = Math.floor(j * m);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (v < 1) v = 1;
|
|
|
|
let specResults
|
|
|
|
if ( v > 100 )
|
|
|
|
specResults = { "part": Math.ceil(v / 5), "epart": 1000, "etotal": 1000 };
|
|
|
|
else
|
|
|
|
specResults = specialResults[Math.ceil(v / 5 )];
|
|
|
|
let tabIndex = i+10;
|
|
|
|
subtab[tabIndex] = { "niveau": i, "score": v, "part": specResults.part, "epart": specResults.epart, "etotal": specResults.etotal }
|
|
|
|
}
|
|
|
|
tableRes[j] = subtab;
|
|
|
|
}
|
|
|
|
return tableRes;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
static getLevelCategory( )
|
|
|
|
{
|
|
|
|
return level_category;
|
|
|
|
}
|
|
|
|
static getCaracArray()
|
|
|
|
{
|
|
|
|
return carac_array;
|
|
|
|
}
|
|
|
|
static getBonusMalus()
|
|
|
|
{
|
|
|
|
return bonusmalus;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
2020-05-27 21:09:37 +02:00
|
|
|
static __buildHTMLResolutionHead( dataRow, minLevel=0, maxLevel=32 ) {
|
2020-05-24 20:19:57 +02:00
|
|
|
let r = dataRow;
|
|
|
|
var row = $("<tr/>");
|
2020-05-27 21:09:37 +02:00
|
|
|
for (var colIndex=minLevel; colIndex <= maxLevel; colIndex++) {
|
|
|
|
let c = dataRow[colIndex];
|
2020-05-24 20:19:57 +02:00
|
|
|
let txt = (c.niveau > 0) ? "+"+c.niveau : c.niveau;
|
|
|
|
row.append($("<th class='table-resolution-level'/>").text(txt) );
|
2020-05-27 21:09:37 +02:00
|
|
|
}
|
2020-05-24 20:19:57 +02:00
|
|
|
return row;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
2020-05-27 21:09:37 +02:00
|
|
|
static __buildHTMLResolutionRow( dataRow, minLevel=0, maxLevel=32, rowIndex, caracValue, levelValue ) {
|
2020-05-24 20:19:57 +02:00
|
|
|
let r = dataRow;
|
|
|
|
var row = $("<tr/>");
|
2020-05-27 21:09:37 +02:00
|
|
|
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));
|
|
|
|
}
|
|
|
|
}
|
2020-05-24 20:19:57 +02:00
|
|
|
return row;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
2020-05-27 21:09:37 +02:00
|
|
|
static makeHTMLResolutionTable(container, minCarac = 1, maxCarac = 21, minLevel=-10, maxLevel=22, caracValue, levelValue) {
|
2020-05-24 20:19:57 +02:00
|
|
|
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
|
2020-05-27 21:09:37 +02:00
|
|
|
minLevel = (minLevel < -10) ? 0 : minLevel+10;
|
|
|
|
maxLevel = (maxLevel > 22) ? 32 : maxLevel+10;
|
|
|
|
let row = this.__buildHTMLResolutionHead( data[0], minLevel, maxLevel );
|
2020-05-24 20:19:57 +02:00
|
|
|
table.append(row);
|
|
|
|
// Then the rest...
|
|
|
|
for (var rowIndex=minCarac; rowIndex <= maxCarac; rowIndex++) {
|
2020-05-27 21:09:37 +02:00
|
|
|
let row = this.__buildHTMLResolutionRow( data[rowIndex], minLevel, maxLevel, rowIndex, caracValue, levelValue );
|
2020-05-24 20:19:57 +02:00
|
|
|
table.append(row);
|
|
|
|
}
|
|
|
|
return container.append(table);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
static getResolutionField(caracValue, levelValue )
|
|
|
|
{
|
|
|
|
if ( levelValue < -16 ) {
|
|
|
|
return { "score": 0, "part": 0, "epart": 1, "etotal": 1};
|
|
|
|
} if ( levelValue < -10 ) {
|
|
|
|
return levelDown.find(levelData => levelData.level == levelValue);
|
|
|
|
}
|
|
|
|
return CONFIG.RDD.resolutionTable[caracValue][levelValue+10];
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
static computeCarac( data)
|
|
|
|
{
|
|
|
|
let fmax = parseInt(data.carac.taille.value) + 4;
|
|
|
|
if ( data.carac.force.value > fmax )
|
|
|
|
data.carac.force.value = fmax;
|
|
|
|
|
|
|
|
data.carac.derobee.value = Math.floor(parseInt(((21 - data.carac.taille.value)) + parseInt(data.carac.agilite.value)) / 2);
|
|
|
|
let bonusDomKey = Math.floor( (parseInt(data.carac.force.value) + parseInt(data.carac.taille.value)) / 2);
|
|
|
|
data.attributs.plusdom.value = 2
|
|
|
|
if (bonusDomKey < 8)
|
|
|
|
data.attributs.plusdom.value = -1;
|
|
|
|
else if (bonusDomKey < 12)
|
|
|
|
data.attributs.plusdom.value = 0;
|
|
|
|
else if (bonusDomKey < 14)
|
|
|
|
data.attributs.plusdom.value = 1;
|
2020-05-27 21:57:00 +02:00
|
|
|
|
2020-05-24 20:19:57 +02:00
|
|
|
data.attributs.encombrement.value = (parseInt(data.carac.force.value) + parseInt(data.carac.taille.value)) / 2;
|
|
|
|
data.carac.melee.value = Math.floor( (parseInt(data.carac.force.value) + parseInt(data.carac.agilite.value)) / 2);
|
|
|
|
data.carac.tir.value = Math.floor( (parseInt(data.carac.vue.value) + parseInt(data.carac.dexterite.value)) / 2);
|
|
|
|
data.carac.lancer.value = Math.floor( (parseInt(data.carac.tir.value) + parseInt(data.carac.force.value)) / 2);
|
|
|
|
|
|
|
|
data.sante.vie.max = Math.ceil( parseInt(data.carac.taille.value) + parseInt(data.carac.constitution.value) /2 );
|
2020-05-27 21:57:00 +02:00
|
|
|
data.sante.vie.value = data.sante.vie.max;
|
2020-05-24 20:19:57 +02:00
|
|
|
let endurance = Math.max( parseInt(data.carac.taille.value) + parseInt(data.carac.constitution.value), parseInt(data.sante.vie.max) + parseInt(data.carac.volonte.value) );
|
|
|
|
data.sante.endurance.max = endurance;
|
2020-05-27 21:57:00 +02:00
|
|
|
data.sante.endurance.value = endurance;
|
|
|
|
data.sante.fatigue.max = endurance;
|
|
|
|
data.sante.fatigue.value = endurance;
|
2020-05-24 20:19:57 +02:00
|
|
|
|
|
|
|
data.attributs.sconst.value = 5; // Max !
|
|
|
|
if ( data.carac.constitution.value < 9 )
|
|
|
|
data.attributs.sconst.value = 2;
|
|
|
|
else if (data.carac.constitution.value < 12 )
|
|
|
|
data.attributs.sconst.value = 3;
|
|
|
|
else if (data.carac.constitution.value < 15 )
|
|
|
|
data.attributs.sconst.value = 4;
|
|
|
|
|
|
|
|
data.attributs.sust.value = 4; // Max !
|
2020-05-27 21:57:00 +02:00
|
|
|
if ( data.carac.taille.value < 10 )
|
|
|
|
data.attributs.sust.value = 2;
|
|
|
|
else if (data.carac.taille.value < 14 )
|
|
|
|
data.attributs.sust.value = 3;
|
2020-05-24 20:19:57 +02:00
|
|
|
}
|
|
|
|
|
2020-05-27 23:47:49 +02:00
|
|
|
/* -------------------------------------------- */
|
|
|
|
static makeHTMLfatigueMatrix( value, max )
|
|
|
|
{
|
|
|
|
max = (max < 16) ? 16 : max;
|
|
|
|
max = (max > 30) ? 30 : max;
|
|
|
|
value = (value > max) ? max : value;
|
2020-05-28 23:36:09 +02:00
|
|
|
value = (value < 0) ? 0 : value;
|
|
|
|
|
2020-05-27 23:47:49 +02:00
|
|
|
let fatigueTab = fatigueMatrix[max];
|
|
|
|
let idx = 0; // Current fatigue slot
|
|
|
|
let remFatigue = value;
|
|
|
|
while ( remFatigue >= fatigueTab[idx] ) { // computes the fatigue segment consumed
|
|
|
|
remFatigue = remFatigue - fatigueTab[idx];
|
|
|
|
idx = idx + 1;
|
|
|
|
}
|
|
|
|
// At this point, we have the segment id in idx and the remaing fatigue points for the next segment in remFatigue
|
|
|
|
let table = $("<table/>").addClass('table-fatigue');
|
|
|
|
let segmentIdx = 0;
|
2020-05-28 23:36:09 +02:00
|
|
|
let fatigueCount = 0;
|
2020-05-27 23:47:49 +02:00
|
|
|
for (var line=0; line < fatigueLineSize.length; line++) {
|
|
|
|
let row = $("<tr/>");
|
|
|
|
let segmentsPerLine = fatigueLineSize[line];
|
2020-05-28 23:36:09 +02:00
|
|
|
row.append("<td class='fatigue-malus'>" + fatigueLineMalus[line] + "</td>");
|
2020-05-27 23:47:49 +02:00
|
|
|
while (segmentIdx < segmentsPerLine) {
|
|
|
|
let freeSize = fatigueTab[segmentIdx];
|
|
|
|
for (let col=0; col <5; col++) {
|
2020-05-28 23:36:09 +02:00
|
|
|
if ( col < freeSize ) {
|
|
|
|
if (fatigueCount < value )
|
|
|
|
row.append("<td class='fatigue-used'/>");
|
|
|
|
else
|
|
|
|
row.append("<td class='fatigue-free'/>");
|
|
|
|
fatigueCount++;
|
|
|
|
} else {
|
2020-05-27 23:47:49 +02:00
|
|
|
row.append("<td class='fatigue-none'/>");
|
2020-05-28 23:36:09 +02:00
|
|
|
}
|
2020-05-27 23:47:49 +02:00
|
|
|
}
|
|
|
|
row.append("<td class='fatigue-separator'/>");
|
|
|
|
segmentIdx = segmentIdx + 1;
|
|
|
|
}
|
|
|
|
table.append(row);
|
|
|
|
}
|
2020-05-28 23:36:09 +02:00
|
|
|
//console.log("fatigue", table);
|
2020-05-27 23:47:49 +02:00
|
|
|
return table;
|
|
|
|
}
|
|
|
|
|
2020-05-24 20:19:57 +02:00
|
|
|
/* -------------------------------------------- */
|
|
|
|
|
2020-05-22 22:37:02 +02:00
|
|
|
static findCompetence(compList, compName)
|
|
|
|
{
|
|
|
|
for (const item of compList) {
|
|
|
|
if (item.name == compName) {
|
|
|
|
console.log("Found item !", item);
|
|
|
|
return item;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|