Ajout arme morsure au chafouin

retravail sur les competences;

- standardiser les noms de fichiers de templates
- méthodes classify pour construire une multimap par type
- méthodes pour charger les entrées du compendium
- méthodes spécifiques au compétences déplacées
This commit is contained in:
Vincent Vandemeulebrouck
2021-01-08 22:23:50 +01:00
parent 4dbab303f3
commit a338bb144e
25 changed files with 543 additions and 595 deletions

View File

@ -6,46 +6,26 @@ import { RdDCombat } from "./rdd-combat.js";
import { RdDRollResolutionTable } from "./rdd-roll-resolution-table.js";
import { RdDItemCompetenceCreature } from "./item-competencecreature.js";
import { RdDItemArme } from "./item-arme.js";
import { RdDItemCompetence } from "./item-competence.js";
/* -------------------------------------------- */
const level_category = {
"generale": "-4",
"particuliere": "-8",
"specialisee": "-11",
"connaissance": "-11",
"draconic": "-11",
"melee": "-6",
"tir": "-8",
"lancer": "-8"
}
/* -------------------------------------------- */
const label_category = {
"generale": "Générales",
"particuliere": "Particulières",
"specialisee": "Spécialisées",
"connaissance": "Connaissances",
"draconic": "Draconics",
"melee": "Mêlée",
"tir": "Tir",
"lancer": "Lancer"
}
/* -------------------------------------------- */
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]
const categorieCompetences = {
"generale": { level: "-4", label: "Générales" },
"particuliere": { level: "-8", label: "Particulières" },
"specialisee": { level: "-11", label: "Spécialisées" },
"connaissance": { level: "-11", label: "Connaissances" },
"draconic": { level: "-11", label: "Draconics" },
"melee": { level: "-6", label: "Mêlée" },
"tir": { level: "-8", label: "Tir" },
"lancer": { level: "-8", label: "Lancer" }
}
/* -------------------------------------------- */
// 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 difficultesLibres = [0, -1, -2, -3, -4, -5, -6, -7, -8, -9, -10];
const ajustementsConditions = [-10, -9, -8, -7, -6, -5, -4, -3, -2, -1, 0, +1, +2, +3, +4, +5, +6, +7, +8, +9, +10];
const ajustementsEncaissement = [-10, -9, -8, -7, -6, -5, -4, -3, -2, -1, 0, +1, +2, +3, +4, +5, +6, +7, +8, +9, +10, +11, +12, +13, +14, +15, +16, +17, +18, +19, +20, +21, +22, +23, +24, +25];
const carac_array = ["taille", "apparence", "constitution", "force", "agilite", "dexterite", "vue", "ouie", "odoratgout", "volonte", "intellect", "empathie", "reve", "chance", "melee", "tir", "lancer", "derobee"];
const difficultesLibres = [0, -1, -2, -3, -4, -5, -6, -7, -8, -9, -10];
const ajustementsConditions = [-10, -9, -8, -7, -6, -5, -4, -3, -2, -1, 0, +1, +2, +3, +4, +5, +6, +7, +8, +9, +10];
const ajustementsEncaissement = [-10, -9, -8, -7, -6, -5, -4, -3, -2, -1, 0, +1, +2, +3, +4, +5, +6, +7, +8, +9, +10, +11, +12, +13, +14, +15, +16, +17, +18, +19, +20, +21, +22, +23, +24, +25];
const carac_xp_par_valeur = [6, 6, 7, 7, 8, 8, 9, 9, 10, 20, 30, 40, 50, 60, 70];
const XP_CARAC_OFFSET = 7;
@ -54,12 +34,12 @@ function _buildAllSegmentsFatigue(max) {
const cycle = [5, 2, 4, 1, 3, 0];
let fatigue = [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]];
for (let i = 0; i <= max; i++) {
const ligneFatigue= duplicate(fatigue[i]);
const ligneFatigue = duplicate(fatigue[i]);
const caseIncrementee = cycle[i % 6];
ligneFatigue[caseIncrementee]++;
ligneFatigue[caseIncrementee + 6]++;
ligneFatigue.fatigueMax = 2 * (i + 1);
fatigue[i + 1] = ligneFatigue ;
fatigue[i + 1] = ligneFatigue;
}
return fatigue;
@ -68,10 +48,9 @@ function _buildAllSegmentsFatigue(max) {
/* -------------------------------------------- */
function _cumulSegmentsFatigue(matrix) {
let cumulMatrix = [];
for (let line of matrix)
{
for (let line of matrix) {
let cumul = duplicate(line);
for (let i = 1; i < 12; i++) {
cumul[i] += cumul[i - 1];
}
@ -84,33 +63,37 @@ function _cumulSegmentsFatigue(matrix) {
const fatigueMatrix = _buildAllSegmentsFatigue(60);
const cumulFatigueMatrix = _cumulSegmentsFatigue(fatigueMatrix);
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 } }
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 = { "rdd": { descr: "rdd: Ouvre la table de résolution", func: RdDRollResolutionTable.open },
"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} };
/* Static tables for commands /table */
const table2func = {
"rdd": { descr: "rdd: Ouvre la table de résolution", func: RdDRollResolutionTable.open },
"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 definitionsBlessures = [
{ type: "legere", facteur: 2 },
{ type: "grave", facteur : 4 },
{ type: "critique", facteur : 6 }
{ type: "grave", facteur: 4 },
{ type: "critique", facteur: 6 }
]
/* -------------------------------------------- */
const nomEthylisme = [ "Emeché", "Gris", "Pinté", "Pas frais", "Ivre", "Bu", "Complètement fait", "Ivre mort"];
const nomEthylisme = ["Emeché", "Gris", "Pinté", "Pas frais", "Ivre", "Bu", "Complètement fait", "Ivre mort"];
/* -------------------------------------------- */
const definitionsEncaissement = {
@ -138,9 +121,9 @@ const definitionsEncaissement = {
};
/* -------------------------------------------- */
export class RdDUtility {
export class RdDUtility {
/* -------------------------------------------- */
static async preloadHandlebarsTemplates( ) {
static async preloadHandlebarsTemplates() {
const templatePaths = [
//Character Sheets
'systems/foundryvtt-reve-de-dragon/templates/actor-sheet.html',
@ -168,14 +151,14 @@ export class RdDUtility {
'systems/foundryvtt-reve-de-dragon/templates/item-ombre-sheet.html',
'systems/foundryvtt-reve-de-dragon/templates/item-monnaie-sheet.html',
'systems/foundryvtt-reve-de-dragon/templates/item-meditation-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-categorie_parade.html',
'systems/foundryvtt-reve-de-dragon/templates/enum-categorie-competence.html',
'systems/foundryvtt-reve-de-dragon/templates/enum-categorie-ingredient.html',
'systems/foundryvtt-reve-de-dragon/templates/enum-categorie-parade.html',
'systems/foundryvtt-reve-de-dragon/templates/enum-competence.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',
'systems/foundryvtt-reve-de-dragon/templates/niveau-ethylisme.html',
@ -225,7 +208,7 @@ export class RdDUtility {
return loadTemplates(templatePaths);
}
/* -------------------------------------------- */
/* -------------------------------------------- */
static checkNull(items) {
if (items && items.length) {
return items;
@ -234,46 +217,46 @@ export class RdDUtility {
}
/* -------------------------------------------- */
static getNomEthylisme( niveauEthylisme ) {
static getNomEthylisme(niveauEthylisme) {
let index = -niveauEthylisme;
return index <0 ? 'Aucun' : nomEthylisme[index];
return index < 0 ? 'Aucun' : nomEthylisme[index];
}
/* -------------------------------------------- */
static initAfficheContenu( actorId ) { // persistent handling of conteneur show/hide
if ( !this.afficheContenu )
static initAfficheContenu(actorId) { // persistent handling of conteneur show/hide
if (!this.afficheContenu)
this.afficheContenu = {};
}
/* -------------------------------------------- */
static toggleAfficheContenu( conteneurId) {
static toggleAfficheContenu(conteneurId) {
this.afficheContenu[conteneurId] = !this.afficheContenu[conteneurId];
}
/* -------------------------------------------- */
static getAfficheContenu( conteneurId) {
static getAfficheContenu(conteneurId) {
return this.afficheContenu[conteneurId];
}
/* -------------------------------------------- */
static filterItemsPerTypeForSheet( data ) {
data.data.materiel = this.checkNull(data.itemsByType['objet']);
data.data.conteneurs = this.checkNull(data.itemsByType['conteneur']);
data.data.armes = this.checkNull(data.itemsByType['arme']);
data.data.armures = this.checkNull(data.itemsByType['armure']);
data.data.livres = this.checkNull(data.itemsByType['livre']);
data.data.potions = this.checkNull(data.itemsByType['potion']);
static filterItemsPerTypeForSheet(data) {
data.data.materiel = this.checkNull(data.itemsByType['objet']);
data.data.conteneurs = this.checkNull(data.itemsByType['conteneur']);
data.data.armes = this.checkNull(data.itemsByType['arme']);
data.data.armures = this.checkNull(data.itemsByType['armure']);
data.data.livres = this.checkNull(data.itemsByType['livre']);
data.data.potions = this.checkNull(data.itemsByType['potion']);
data.data.ingredients = this.checkNull(data.itemsByType['ingredient']);
data.data.munitions = this.checkNull(data.itemsByType['munition']);
data.data.herbes = this.checkNull(data.itemsByType['herbe']);
data.data.sorts = this.checkNull(data.itemsByType['sort']);
data.data.queues = this.checkNull(data.itemsByType['queue']);
data.data.souffles = this.checkNull(data.itemsByType['souffle']);
data.data.ombres = this.checkNull(data.itemsByType['ombre']);
data.data.tetes = this.checkNull(data.itemsByType['tete']);
data.data.taches = this.checkNull(data.itemsByType['tache']);
data.data.monnaie = this.checkNull(data.itemsByType['monnaie']);
data.data.munitions = this.checkNull(data.itemsByType['munition']);
data.data.herbes = this.checkNull(data.itemsByType['herbe']);
data.data.sorts = this.checkNull(data.itemsByType['sort']);
data.data.queues = this.checkNull(data.itemsByType['queue']);
data.data.souffles = this.checkNull(data.itemsByType['souffle']);
data.data.ombres = this.checkNull(data.itemsByType['ombre']);
data.data.tetes = this.checkNull(data.itemsByType['tete']);
data.data.taches = this.checkNull(data.itemsByType['tache']);
data.data.monnaie = this.checkNull(data.itemsByType['monnaie']);
data.data.meditations = this.checkNull(data.itemsByType['meditation']);
data.data.recettesAlchimiques = this.checkNull(data.itemsByType['recettealchimique']);
data.data.objets = data.data.conteneurs.concat(data.data.materiel).concat(data.data.armes).concat(data.data.armures).concat(data.data.munitions).concat(data.data.livres).concat(data.data.potions).concat(data.data.herbes).concat(data.data.ingredients);
data.data.objets = data.data.conteneurs.concat(data.data.materiel).concat(data.data.armes).concat(data.data.armures).concat(data.data.munitions).concat(data.data.livres).concat(data.data.potions).concat(data.data.herbes).concat(data.data.ingredients);
}
/* -------------------------------------------- */
@ -302,19 +285,19 @@ export class RdDUtility {
//conteneur.data.encTotal = ; Deja calculé
if (conteneur.data.contenu) {
for (let id of conteneur.data.contenu) {
let objet = data.data.objets.find( objet => (id == objet._id) );
let objet = data.data.objets.find(objet => (id == objet._id));
if (objet) {
if (!objet.data.encombrement) objet.data.encombrement = 0; // Auto-fix
objet.estContenu = true; // Permet de filtrer ce qifui est porté dans le template
actorSheet.objetVersConteneur[id] = conteneur._id;
conteneur.data.encTotal += Number(objet.data.encombrement) * Number(((objet.data.quantite)?objet.data.quantite:1));
conteneur.subItems.push( objet );
conteneur.data.encTotal += Number(objet.data.encombrement) * Number(((objet.data.quantite) ? objet.data.quantite : 1));
conteneur.subItems.push(objet);
}
}
}
}
// Construit la liste des conteneurs de niveau 1 (c'est à dire non contenu eux-même dans un conteneur)
let newConteneurs = data.data.conteneurs.filter(function(conteneur, index, arr) { return !conteneur.estContenu } );
let newConteneurs = data.data.conteneurs.filter(function (conteneur, index, arr) { return !conteneur.estContenu });
data.data.conteneurs = newConteneurs;
//console.log(newConteneurs);
}
@ -323,20 +306,20 @@ export class RdDUtility {
/** Construit la structure récursive des conteneurs, avec imbrication potentielle
*
*/
static buildConteneur( objet, niveau ) {
static buildConteneur(objet, niveau) {
if (!niveau) niveau = 1;
objet.niveau = niveau;
//console.log("OBJ:", objet);
let str = Handlebars.partials['systems/foundryvtt-reve-de-dragon/templates/actor-inventaire-conteneur.html']( { item: objet} );
let str = Handlebars.partials['systems/foundryvtt-reve-de-dragon/templates/actor-inventaire-conteneur.html']({ item: objet });
if (objet.type == 'conteneur') {
//console.log("ITEM DISPLAYED", this.getAfficheContenu(objet._id) );
if ( this.getAfficheContenu(objet._id) ) {
str = str + "<ul class='item-list alterne-list item-display-show list-item-margin"+niveau+"'>";
if (this.getAfficheContenu(objet._id)) {
str = str + "<ul class='item-list alterne-list item-display-show list-item-margin" + niveau + "'>";
} else {
str = str + "<ul class='item-list alterne-list item-display-hide list-item-margin"+niveau+"'>";
str = str + "<ul class='item-list alterne-list item-display-hide list-item-margin" + niveau + "'>";
}
for (let subItem of objet.subItems) {
str = str + this.buildConteneur(subItem, niveau+1);
str = str + this.buildConteneur(subItem, niveau + 1);
}
str = str + "</ul>";
}
@ -344,146 +327,51 @@ export class RdDUtility {
}
/* -------------------------------------------- */
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 getCategorieCompetences() {
return categorieCompetences;
}
/* -------------------------------------------- */
static getLevelCategory( )
{
return level_category;
static getLevelCategory(category) {
return categorieCompetences[category].level;
}
static getLabelCategory( )
{
return label_category;
static getLabelCategory(category) {
return categorieCompetences[category].label;
}
static getCaracArray()
{
static getCaracArray() {
return carac_array;
}
static getDifficultesLibres()
{
static getDifficultesLibres() {
return difficultesLibres;
}
static getAjustementsConditions()
{
static getAjustementsConditions() {
return ajustementsConditions;
}
static getAjustementsEncaissement()
{
static getAjustementsEncaissement() {
return ajustementsEncaissement;
}
static getDefinitionsBlessures() {
return definitionsBlessures;
}
/* -------------------------------------------- */
static isTronc( compName )
{
for (let troncList of competenceTroncs) {
for (let troncName of troncList) {
if ( troncName == compName)
return troncList;
}
}
return false;
}
/* -------------------------------------------- */
static getCaracNextXp( value ) {
static getCaracNextXp(value) {
return carac_xp_par_valeur[value - XP_CARAC_OFFSET];
}
/* -------------------------------------------- */
static getCompetenceNextXp( niveau ) {
return competence_xp_par_niveau[niveau+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]);
}
if (competence.data.categorie == 'draconic') {
xp+= competence.data.xp_sort;
}
return xp;
}
/* -------------------------------------------- */
static computeCompetenceTroncXP( competenceList )
{
let xp = 0;
for (let troncList of competenceTroncs) {
let minNiveau = 0;
for (let troncName of troncList) {
let comp = RdDUtility.findCompetence( competenceList, troncName);
if (comp) {
minNiveau = Math.min(comp.data.niveau, minNiveau);
}
}
minNiveau = Math.max(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);
if (comp){
xp += competence_xp_par_niveau[comp.data.niveau+10] - minNiveauXP;
}
}
}
return xp;
}
/* -------------------------------------------- */
/** Retourne une liste triée d'armes avec le split arme1 main / arme 2 main */
static _finalizeArmeList( armes, competenceList, carac ) {
static _finalizeArmeList(armes, competences, carac) {
// Gestion des armes 1/2 mains
let armesEquipe = [];
for (const arme of armes) {
for (const arme of armes) {
if (arme.data.equipe) {
armesEquipe.push( arme );
let comp = competenceList.find(c => c.name == arme.data.competence);
armesEquipe.push(arme);
let comp = competences.find(c => c.name == arme.data.competence);
arme.data.initiative = RdDUtility.calculInitiative(arme.data.niveau, carac[comp.data.defaut_carac].value);
// Dupliquer les armes pouvant être à 1 main et 2 mains en patchant la compétence
if (arme.data.unemain && !arme.data.deuxmains ) {
if (arme.data.unemain && !arme.data.deuxmains) {
arme.data.mainInfo = "(1m)";
} else if ( !arme.data.unemain && arme.data.deuxmains ) {
} else if (!arme.data.unemain && arme.data.deuxmains) {
arme.data.mainInfo = "(2m)";
} else if (arme.data.unemain && arme.data.deuxmains) {
arme.data.mainInfo = "(1m)";
@ -491,72 +379,71 @@ export class RdDUtility {
arme2main.data.mainInfo = "(2m)";
arme2main.data.dommages = arme2main.data.dommages.split("/")[1]; // Existence temporaire uniquement dans la liste des armes, donc OK
arme2main.data.competence = arme2main.data.competence.replace(" 1 main", " 2 mains"); // Replace !
let comp = competenceList.find(c => c.name == arme2main.data.competence);
let comp = competences.find(c => c.name == arme2main.data.competence);
arme2main.data.niveau = comp.data.niveau;
arme2main.data.initiative = RdDUtility.calculInitiative(arme2main.data.niveau, carac[comp.data.defaut_carac].value);
armesEquipe.push(arme2main);
}
}
}
return armesEquipe.sort((a, b) => {
return armesEquipe.sort((a, b) => {
const nameA = a.name + (a.data.mainInfo ?? '');
const nameB = b.name + (b.data.mainInfo ?? '');
if ( nameA > nameB) return 1;
if ( nameA < nameB) return -1;
if (nameA > nameB) return 1;
if (nameA < nameB) return -1;
return 0;
} );
});
}
/* -------------------------------------------- */
static calculInitiative(niveau, caracValue) {
let base = niveau + Math.floor(caracValue/2);
let base = niveau + Math.floor(caracValue / 2);
return "1d6" + (base >= 0 ? "+" : "") + base;
}
/* -------------------------------------------- */
static computeCarac( data)
{
static computeCarac(data) {
data.carac.force.value = Math.min(data.carac.force.value, parseInt(data.carac.taille.value) + 4);
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);
let bonusDomKey = Math.floor((parseInt(data.carac.force.value) + parseInt(data.carac.taille.value)) / 2);
// TODO: gérer table des bonus dommages (et autres) des créatures
data.attributs.plusdom.value = 2
if (bonusDomKey < 8)
if (bonusDomKey < 8)
data.attributs.plusdom.value = -1;
else if (bonusDomKey < 12)
else if (bonusDomKey < 12)
data.attributs.plusdom.value = 0;
else if (bonusDomKey < 14)
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 );
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);
data.sante.vie.value = Math.min(data.sante.vie.value, data.sante.vie.max)
data.sante.endurance.max = 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 = 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.value = Math.min(data.sante.endurance.value, data.sante.endurance.max);
data.sante.fatigue.max = data.sante.endurance.max*2;
data.sante.fatigue.max = data.sante.endurance.max * 2;
data.sante.fatigue.value = Math.min(data.sante.fatigue.value, data.sante.fatigue.max);
data.attributs.sconst.value = 5; // Max !
if ( data.carac.constitution.value < 9 )
if (data.carac.constitution.value < 9)
data.attributs.sconst.value = 2;
else if (data.carac.constitution.value < 12 )
else if (data.carac.constitution.value < 12)
data.attributs.sconst.value = 3;
else if (data.carac.constitution.value < 15 )
data.attributs.sconst.value = 4;
else if (data.carac.constitution.value < 15)
data.attributs.sconst.value = 4;
data.attributs.sust.value = 4; // Max !
if ( data.carac.taille.value < 10 )
if (data.carac.taille.value < 10)
data.attributs.sust.value = 2;
else if (data.carac.taille.value < 14 )
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;
@ -572,12 +459,11 @@ export class RdDUtility {
}
/* -------------------------------------------- */
static calculMalusFatigue(fatigue, maxEnd)
{
static calculMalusFatigue(fatigue, maxEnd) {
maxEnd = Math.max(maxEnd, 1);
maxEnd = Math.min(maxEnd, cumulFatigueMatrix.length);
let segments = cumulFatigueMatrix[maxEnd];
for (let i=0; i<12; i++) {
for (let i = 0; i < 12; i++) {
if (fatigue <= segments[i]) {
return fatigueMalus[i]
}
@ -587,7 +473,7 @@ export class RdDUtility {
/* -------------------------------------------- */
// Build the nice (?) html table used to manage fatigue.
// max should be the endurance max value
static makeHTMLfatigueMatrix( fatigue, maxEndurance) {
static makeHTMLfatigueMatrix(fatigue, maxEndurance) {
let segments = this.getSegmentsFatigue(maxEndurance);
return this.makeHTMLfatigueMatrixForSegment(fatigue, segments);
}
@ -627,25 +513,24 @@ export class RdDUtility {
}
/* -------------------------------------------- */
static getLocalisation( )
{
static getLocalisation() {
// TODO: bouger dans une RollTable du compendium et chercher dans les RoolTable puis compendium pour permettre le changement?
let result = new Roll("1d20").roll().total;
let txt = ""
if ( result <= 3 ) txt = "Jambe, genou, pied, jarret";
else if ( result <= 7 ) txt = "Hanche, cuisse, fesse";
else if ( result <= 9 ) txt = "Ventre, reins";
else if ( result <= 12 ) txt = "Poitrine, dos";
else if ( result <= 14 ) txt = "Avant-bras, main, coude";
else if ( result <= 18 ) txt = "Epaule, bras, omoplate";
else if ( result == 19) txt = "Tête";
else if ( result == 20) txt = "Tête (visage)";
if (result <= 3) txt = "Jambe, genou, pied, jarret";
else if (result <= 7) txt = "Hanche, cuisse, fesse";
else if (result <= 9) txt = "Ventre, reins";
else if (result <= 12) txt = "Poitrine, dos";
else if (result <= 14) txt = "Avant-bras, main, coude";
else if (result <= 18) txt = "Epaule, bras, omoplate";
else if (result == 19) txt = "Tête";
else if (result == 20) txt = "Tête (visage)";
return { result: result, label: txt };
}
/* -------------------------------------------- */
static selectEncaissement( degats, mortalite ) {
static selectEncaissement(degats, mortalite) {
const table = definitionsEncaissement[mortalite] === undefined ? definitionsEncaissement["mortel"] : definitionsEncaissement[mortalite];
for (let encaissement of table) {
if ((encaissement.minimum === undefined || encaissement.minimum <= degats)
@ -659,67 +544,74 @@ export class RdDUtility {
/* -------------------------------------------- */
static _evaluatePerte(formula, over20) {
console.log("_evaluatePerte", formula, over20 )
let perte = new Roll(formula, { over20:over20})
console.log("_evaluatePerte", formula, over20)
let perte = new Roll(formula, { over20: over20 })
perte.evaluate()
return perte.total
}
/* -------------------------------------------- */
static currentFatigueMalus( value, max)
{
static currentFatigueMalus(value, max) {
max = Math.max(1, Math.min(max, 60));
value = Math.min(max*2, Math.max(0, value));
value = Math.min(max * 2, Math.max(0, value));
let fatigueTab = fatigueMatrix[max];
let fatigueRem = value;
for (let idx=0; idx<fatigueTab.length; idx++) {
for (let idx = 0; idx < fatigueTab.length; idx++) {
fatigueRem -= fatigueTab[idx];
if ( fatigueRem <= 0) {
if (fatigueRem <= 0) {
return fatigueMalus[idx];
}
}
return -7; // This is the max !
}
/* -------------------------------------------- */
static findCompetence(compList, compName)
{
compName = compName.toLowerCase();
return compList.find(item => item.name.toLowerCase() == compName && (item.type =="competence" || item.type == "competencecreature"))
}
/* -------------------------------------------- */
static async getCompetenceList( compendium ) {
static async loadCompendiumNames(compendium) {
const pack = game.packs.get(compendium);
let competences;
await pack.getIndex().then(index => competences = index);
return competences;
}
static async loadCompendium(compendium, filter = item => true) {
let compendiumItems = await RdDUtility.loadCompendiumNames(compendium);
const pack = game.packs.get(compendium);
let list = [];
for (let compendiumItem of compendiumItems) {
await pack.getEntity(compendiumItem._id).then(it => {
const item = it.data;
if (filter(item)) {
list.push(item);
}
});
};
return list;
}
/* -------------------------------------------- */
static async responseNombreAstral( data ) {
let actor = game.actors.get( data.id);
static async responseNombreAstral(data) {
let actor = game.actors.get(data.id);
actor.ajouteNombreAstral(data);
}
/* -------------------------------------------- */
static performSocketMesssage( sockmsg )
{
static performSocketMesssage(sockmsg) {
console.log(">>>>> MSG RECV", sockmsg);
switch(sockmsg.msg) {
case "msg_encaisser":
switch (sockmsg.msg) {
case "msg_encaisser":
return RdDUtility._handleMsgEncaisser(sockmsg.data);
case "msg_defense" :
case "msg_defense":
return RdDUtility._handleMsgDefense(sockmsg.data);
case "msg_gm_chat_message":
return ChatUtility.handleGMChatMessage(sockmsg.data);
case "msg_sync_time":
return game.system.rdd.calendrier.syncPlayerTime( sockmsg.data );
case "msg_sync_time":
return game.system.rdd.calendrier.syncPlayerTime(sockmsg.data);
case "msg_request_nombre_astral":
return game.system.rdd.calendrier.requestNombreAstral( sockmsg.data );
return game.system.rdd.calendrier.requestNombreAstral(sockmsg.data);
case "msg_response_nombre_astral":
return RdDUtility.responseNombreAstral( sockmsg.data );
return RdDUtility.responseNombreAstral(sockmsg.data);
}
}
@ -727,7 +619,7 @@ export class RdDUtility {
static _handleMsgDefense(data) {
let defenderToken = canvas.tokens.get(data.defenderTokenId);
if (defenderToken) {
if ( !game.user.isGM && game.user.character == undefined) { // vérification / sanity check
if (!game.user.isGM && game.user.character == undefined) { // vérification / sanity check
ui.notifications.error("Le joueur " + game.user.name + " n'est connecté à aucun personnage. Impossible de continuer.");
return;
}
@ -743,58 +635,58 @@ export class RdDUtility {
}
/* -------------------------------------------- */
static rollInitiativeCompetence( combatantId, arme ) {
static rollInitiativeCompetence(combatantId, arme) {
const combatant = game.combat.getCombatant(combatantId);
const actor = combatant.actor;
const actor = combatant.actor;
if ( arme.name == "Autre action") {
game.combat.rollInitiative(combatantId, "1d6" );
} else if ( arme.name == "Draconic") {
game.combat.rollInitiative(combatantId, "1d6+200" );
if (arme.name == "Autre action") {
game.combat.rollInitiative(combatantId, "1d6");
} else if (arme.name == "Draconic") {
game.combat.rollInitiative(combatantId, "1d6+200");
} else {
let initOffset = 0;
let caracForInit = 0;
let competence = RdDUtility.findCompetence( combatant.actor.data.items, arme.data.competence);
let competence = RdDItemCompetence.findCompetence(combatant.actor.data.items, arme.data.competence);
if ( actor.data.type == 'creature' || actor.data.type == 'entite') {
if (actor.data.type == 'creature' || actor.data.type == 'entite') {
caracForInit = competence.data.carac_value;
} else {
caracForInit = actor.data.data.carac[competence.data.defaut_carac].value;
if (competence.data.categorie == "lancer" ) { // Offset de principe pour les armes de jet
initOffset = 40;
}
if (competence.data.categorie == "tir" ) { // Offset de principe pour les armes de jet
initOffset = 80;
}
caracForInit = actor.data.data.carac[competence.data.defaut_carac].value;
if (competence.data.categorie == "lancer") { // Offset de principe pour les armes de jet
initOffset = 40;
}
if (competence.data.categorie == "tir") { // Offset de principe pour les armes de jet
initOffset = 80;
}
}
initOffset -= actor.getEtatGeneral(); // Prise en compte état général
// Cas des créatures et entités vs personnages
let rollFormula = RdDUtility.calculInitiative(competence.data.niveau, caracForInit) + "+" + initOffset;
game.combat.rollInitiative(combatantId, rollFormula );
// Cas des créatures et entités vs personnages
let rollFormula = RdDUtility.calculInitiative(competence.data.niveau, caracForInit) + "+" + initOffset;
game.combat.rollInitiative(combatantId, rollFormula);
}
}
/* -------------------------------------------- */
static buildListeActionsCombat( combatant ) {
static buildListeActionsCombat(combatant) {
const actor = combatant.actor; // Easy access
let items = actor.data.items;
let actions = []
if ( actor.isCreature()) {
actions = actions.concat(items.filter(it => it.type =='competencecreature' && it.data.iscombat)
if (actor.isCreature()) {
actions = actions.concat(items.filter(it => it.type == 'competencecreature' && it.data.iscombat)
.map(competence => RdDItemCompetenceCreature.toArme(competence)));
} else {
// Recupération des items 'arme'
let armes = items.filter(it => it.type =='arme')
let armes = items.filter(it => it.type == 'arme')
.map(arme => duplicate(arme)) /* pas de changements aux armes d'origine */
.concat(RdDItemArme.mainsNues());
let competences = items.filter(it => it.type == 'competence');
actions = actions.concat(this._finalizeArmeList( armes, competences, actor.data.data.carac ));
actions.push( { name: "Draconic", data: { initOnly: true, competence: "Draconic" } } );
let competences = items.filter(it => it.type == 'competence');
actions = actions.concat(this._finalizeArmeList(armes, competences, actor.data.data.carac));
actions.push({ name: "Draconic", data: { initOnly: true, competence: "Draconic" } });
}
actions.push( { name: "Autre action", data: { initOnly: true, competence: "Autre action" } } );
actions.push({ name: "Autre action", data: { initOnly: true, competence: "Autre action" } });
for (let index = 0; index < actions.length; index++) {
actions[index].index = index;
}
@ -802,34 +694,35 @@ export class RdDUtility {
}
/* -------------------------------------------- */
static displayInitiativeMenu( html, combatantId) {
static displayInitiativeMenu(html, combatantId) {
const combatant = game.combat.getCombatant(combatantId);
let armesList = this.buildListeActionsCombat( combatant );
let armesList = this.buildListeActionsCombat(combatant);
// Build the relevant submenu
if ( armesList ) {
if (armesList) {
let menuItems = [];
for ( let arme of armesList ) {
menuItems.push( {
name: arme.data.competence,
for (let arme of armesList) {
menuItems.push({
name: arme.data.competence,
icon: "<i class='fas fa-dice-d6'></i>",
callback: target => { RdDUtility.rollInitiativeCompetence( combatantId, arme ) } } );
callback: target => { RdDUtility.rollInitiativeCompetence(combatantId, arme) }
});
}
new ContextMenu(html, ".directory-list", menuItems ).render();
new ContextMenu(html, ".directory-list", menuItems).render();
}
}
/* -------------------------------------------- */
static pushInitiativeOptions( html, options ) {
static pushInitiativeOptions(html, options) {
options.push(
{
name: "Sélectionner l'initiative...",
condition: true,
icon: '<i class="far fa-question-circle"></i>',
callback: target => {
RdDUtility.displayInitiativeMenu( html, target.data('combatant-id') );
callback: target => {
RdDUtility.displayInitiativeMenu(html, target.data('combatant-id'));
}
});
});
}
/* -------------------------------------------- */
@ -845,52 +738,52 @@ export class RdDUtility {
}
/* -------------------------------------------- */
static async chatListeners( html )
{
static async chatListeners(html) {
RdDCombat.registerChatCallbacks(html);
// Gestion spécifique message passeurs
html.on("click", '.tmr-passeur-coord a', event => {
let coord = event.currentTarget.attributes['data-tmr-coord'].value;
let coord = event.currentTarget.attributes['data-tmr-coord'].value;
let actorId = event.currentTarget.attributes['data-actor-id'].value;
let actor = game.actors.get( actorId );
let actor = game.actors.get(actorId);
actor.tmrApp.forceDemiRevePosition(coord);
});
// Gestion spécifique des sorts en réserve multiples (ie têtes)
html.on("click", '#sort-reserve', event => {
let coord = event.currentTarget.attributes['data-tmr-coord'].value;
let sortId = event.currentTarget.attributes['data-sort-id'].value;
let coord = event.currentTarget.attributes['data-tmr-coord'].value;
let sortId = event.currentTarget.attributes['data-sort-id'].value;
let actorId = event.currentTarget.attributes['data-actor-id'].value;
let actor = game.actors.get( actorId );
let actor = game.actors.get(actorId);
actor.tmrApp.lancerSortEnReserve(coord, sortId);
});
});
// Gestion du bouton payer
html.on("click", '#payer-button', event => {
let sumdenier = event.currentTarget.attributes['data-somme-denier'].value;
let jsondata = event.currentTarget.attributes['data-jsondata']
let objData
if ( jsondata ) {
if (jsondata) {
objData = JSON.parse(jsondata.value)
}
if (game.user.character ) {
if (game.user.character) {
game.user.character.payerDenier(sumdenier, objData);
} else {
let msgPayer = "Vous devez avoir un acteur relié pour effectuer le paiement";
ChatMessage.create( { content: msgPayer, whisper: [game.user] } );
ChatMessage.create({ content: msgPayer, whisper: [game.user] });
}
});
}
/* -------------------------------------------- */
static createMonnaie( name, valeur_deniers, img = "", enc = 0.01) {
let piece = { name: name, type: 'monnaie', img: img, _id: randomID(16),
data: {
quantite: 0,
valeur_deniers: valeur_deniers,
encombrement: enc,
description: ""
}
}
static createMonnaie(name, valeur_deniers, img = "", enc = 0.01) {
let piece = {
name: name, type: 'monnaie', img: img, _id: randomID(16),
data: {
quantite: 0,
valeur_deniers: valeur_deniers,
encombrement: enc,
description: ""
}
}
return piece;
}
@ -899,9 +792,9 @@ export class RdDUtility {
som1 = (som1) ? som1.toLowerCase() : "0d";
som2 = (som2) ? som2.toLowerCase() : "0d";
let regExp = /(\d+)(\w+)/g;
let p1 = regExp.exec( som1);
let p1 = regExp.exec(som1);
regExp = /(\d+)(\w+)/g;
let p2 = regExp.exec( som2);
let p2 = regExp.exec(som2);
let sumd = 0;
let sums = 0;
if (p1[2] == 'd') sumd += Number(p1[1]);
@ -909,10 +802,10 @@ export class RdDUtility {
if (p2[2] == 'd') sumd += Number(p2[1]);
if (p2[2] == 's') sums += Number(p2[1]);
let sumtotald = sumd + (sums*100);
let msgPayer = "La somme de "+sums+" Sols et "+sumd+" Deniers est à payer, cliquer sur le lien ci-dessous si besoin.<br>";
msgPayer += "<a id='payer-button' class='chat-card-button' data-somme-denier='"+sumtotald+"'>Payer</a>"
ChatMessage.create( { content: msgPayer } );
let sumtotald = sumd + (sums * 100);
let msgPayer = "La somme de " + sums + " Sols et " + sumd + " Deniers est à payer, cliquer sur le lien ci-dessous si besoin.<br>";
msgPayer += "<a id='payer-button' class='chat-card-button' data-somme-denier='" + sumtotald + "'>Payer</a>"
ChatMessage.create({ content: msgPayer });
}
/* -------------------------------------------- */