/* Common useful functions shared between objects */ 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 }, { "level": -16, "score": 1, "part": 0, "epart": 2, "etotal": 2 }, ]; export class RdDUtility { /* -------------------------------------------- */ 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; } /* -------------------------------------------- */ static __buildHTMLResolutionHead( dataRow ) { let r = dataRow; var row = $("