/* Common useful functions shared between objects */ import { TMRUtility } from "./tmr-utility.js"; import { RdDRollTables } from "./rdd-rolltables.js"; import { RdDResolutionTable } from "./rdd-resolution-table.js"; const level_category = { "generale": "-4", "particuliere": "-8", "speciale": "-11", "connaissance": "-11", "draconic": "-11", "melee": "-6", "tir": "-8", "lancer": "-8" } const competenceTroncs = [ ["Esquive", "Dague", "Corps à corps"], ["Epée à 1 main", "Epée à 2 mains", "Hache à 1 main", "Hache à 2 mains", "Lance", "Masse à 1 main", "Masse à 2 mains"] ]; const competence_xp = { "-11" : [ 5, 10, 15, 25, 35, 45, 55, 70, 85, 100, 115, 135, 155, 175 ], "-8" : [ 10, 20, 30, 40, 55, 70, 85, 100, 120, 140,160], "-6" : [ 10, 20, 35, 50, 65, 80, 100, 120, 140], "-4" : [ 15, 30, 45, 60, 80, 100, 120] } // This table starts at 0 -> niveau -10 const competence_xp_par_niveau = [ 5, 5, 5, 10, 10, 10, 10, 15, 15, 15, 15, 20, 20, 20, 20, 30, 30, 40, 40, 60, 60, 100, 100, 100, 100, 100, 100, 100, 100, 100]; 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, "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 ], [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 const fatigueLineSize = [ 3, 6, 7, 8, 9, 10, 11, 12]; const fatigueLineMalus = [ 0, -1, -2, -3, -4, -5, -6, -7 ]; const fatigueMarche = { "aise": { "4":1, "6":2, "8":3, "10":4, "12":6 }, "malaise": { "4":2, "6":3, "8":4, "10":6 }, "difficile": { "4":3, "6":4, "8":6 }, "tresdifficile": { "4":4, "6":6 } } /* Static tables for commands /table */ const table2func = { "queues": {descr: "queues : Tire une queue de Dragon", func: RdDRollTables.getQueue}, "ombre": { descr: "ombre: Tire une Ombre de Dragon", func: RdDRollTables.getOmbre }, "tetehr": {descr: "tetehr: Tire une Tête de Dragon pour Hauts Revants", fund: RdDRollTables.getTeteHR}, "tete" : { descr: "tete: Tire une Tête de Dragon", func: RdDRollTables.getTete}, "souffle": { descr: "souffle: Tire un Souffle de Dragon", func: RdDRollTables.getSouffle}, "tarot" : { descr: "tarot: Tire une carte de Tarot Dracnique", func: RdDRollTables.getTarot} }; const definitionsEncaissement = { "mortel": [ { 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: 1, graves: 0, critiques: 0 }, { minimum: 16, maximum: 19, endurance: "2d6", vie: "2", legeres: 0, graves: 1, critiques: 0 }, { minimum: 20, maximum: undefined, endurance: "100", vie: "4 + @over20", legeres: 0, graves: 0, critiques: 1 }, ], "non-mortel": [ { 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: 1, graves: 0, critiques: 0 }, { minimum: 20, maximum: undefined, endurance: "100", vie: "1", legeres: 1, graves: 0, critiques: 0 }, ], "cauchemar": [ { 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 }, { minimum: 20, maximum: undefined, endurance: "3d6 + @over20", vie: "0", legeres: 0, graves: 0, critiques: 0 }, ] }; /* -------------------------------------------- */ export class RdDUtility { /* -------------------------------------------- */ static async preloadHandlebarsTemplates( ) { const templatePaths = [ //Character Sheets 'systems/foundryvtt-reve-de-dragon/templates/actor-sheet.html', 'systems/foundryvtt-reve-de-dragon/templates/actor-creature-sheet.html', 'systems/foundryvtt-reve-de-dragon/templates/actor-humanoide-sheet.html', //Items 'systems/foundryvtt-reve-de-dragon/templates/item-competence-sheet.html', 'systems/foundryvtt-reve-de-dragon/templates/item-competencecreature-sheet.html', 'systems/foundryvtt-reve-de-dragon/templates/item-arme-sheet.html', 'systems/foundryvtt-reve-de-dragon/templates/item-armure-sheet.html', 'systems/foundryvtt-reve-de-dragon/templates/item-objet-sheet.html', 'systems/foundryvtt-reve-de-dragon/templates/item-conteneur-sheet.html', 'systems/foundryvtt-reve-de-dragon/templates/item-sort-sheet.html', 'systems/foundryvtt-reve-de-dragon/templates/item-herbe-sheet.html', 'systems/foundryvtt-reve-de-dragon/templates/item-ingredient-sheet.html', 'systems/foundryvtt-reve-de-dragon/templates/item-livre-sheet.html', 'systems/foundryvtt-reve-de-dragon/templates/item-tache-sheet.html', 'systems/foundryvtt-reve-de-dragon/templates/item-potion-sheet.html', 'systems/foundryvtt-reve-de-dragon/templates/item-rencontresTMR-sheet.html', 'systems/foundryvtt-reve-de-dragon/templates/item-queue-sheet.html', 'systems/foundryvtt-reve-de-dragon/templates/item-souffle-sheet.html', 'systems/foundryvtt-reve-de-dragon/templates/item-tarot-sheet.html', 'systems/foundryvtt-reve-de-dragon/templates/item-tete-sheet.html', 'systems/foundryvtt-reve-de-dragon/templates/item-ombre-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', 'systems/foundryvtt-reve-de-dragon/templates/enum-aspect-tarot.html', 'systems/foundryvtt-reve-de-dragon/templates/enum-categorie.html', 'systems/foundryvtt-reve-de-dragon/templates/enum-rarete.html', 'systems/foundryvtt-reve-de-dragon/templates/arme-competence.html', 'systems/foundryvtt-reve-de-dragon/templates/sort-draconic.html', 'systems/foundryvtt-reve-de-dragon/templates/sort-tmr.html', // Dialogs 'systems/foundryvtt-reve-de-dragon/templates/dialog-competence.html', 'systems/foundryvtt-reve-de-dragon/templates/dialog-roll-carac.html', 'systems/foundryvtt-reve-de-dragon/templates/dialog-roll-sort.html', 'systems/foundryvtt-reve-de-dragon/templates/dialog-roll-encaisser.html', 'systems/foundryvtt-reve-de-dragon/templates/dialog-tmr.html', // Calendrier 'systems/foundryvtt-reve-de-dragon/templates/calendar_template.html' ]; return loadTemplates(templatePaths); } /* -------------------------------------------- */ static getLevelCategory( ) { return level_category; } static getCaracArray() { return carac_array; } static getBonusMalus() { return bonusmalus; } /* -------------------------------------------- */ static isTronc( compName ) { for (let troncList of competenceTroncs) { for (let troncName of troncList) { if ( troncName == compName) return troncList; } } return false; } /* -------------------------------------------- */ static getResolutionField(caracValue, levelValue ) { if ( levelValue < -16 ) { 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]; } /* -------------------------------------------- */ static computeCompetenceXPCost( competence ) { let minLevel = competence.data.base; if ( minLevel == competence.data.niveau) return 0; if ( competence.data.niveau < -10) return 0; let xp = 0; for (let i=minLevel+1; i<=competence.data.niveau; i++) { xp += competence_xp_par_niveau[i+10]; //console.log(i, i+10, competence_xp_par_niveau[i+10]); } return xp; } /* -------------------------------------------- */ static computeCompetenceTroncXP( competenceList ) { let xp = 0; for (let troncList of competenceTroncs) { let minNiveau = 15; for (let troncName of troncList) { let comp = RdDUtility.findCompetence( competenceList, troncName); minNiveau = (comp.data.niveau < minNiveau) ? comp.data.niveau : minNiveau; } if ( minNiveau > 0 ) minNiveau = 0; // Clamp à 0, pour le tronc commun let minNiveauXP = competence_xp_par_niveau[minNiveau+10]; xp += minNiveauXP; for (let troncName of troncList) { let comp = RdDUtility.findCompetence( competenceList, troncName); xp += competence_xp_par_niveau[comp.data.niveau+10] - minNiveauXP; } } return xp; } /* -------------------------------------------- */ 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; 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 ); if ( data.sante.vie.value > data.sante.vie.max) data.sante.vie.value = data.sante.vie.max; 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; if ( data.sante.endurance.value > endurance) data.sante.endurance.value = endurance; data.sante.fatigue.max = endurance*2; if ( data.sante.fatigue.value > data.sante.fatigue.max ) data.sante.fatigue.value = data.sante.fatigue.max; 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 ! if ( data.carac.taille.value < 10 ) data.attributs.sust.value = 2; else if (data.carac.taille.value < 14 ) data.attributs.sust.value = 3; //Compteurs //data.compteurs.reve.value = data.carac.reve.value; data.reve.reve.max = data.carac.reve.value; //data.compteurs.chance.value = data.carac.chance.value; data.compteurs.chance.max = data.carac.chance.value; } /* -------------------------------------------- */ // Build the nice (?) html table used to manage fatigue. // max should Mbe the endurance max value static makeHTMLfatigueMatrix( value, max ) { max = (max < 16) ? 16 : max; max = (max > 30) ? 30 : max; value = (value > max*2) ? max*2 : value; value = (value < 0) ? 0 : value; let fatigueTab = fatigueMatrix[max]; let table = $("