diff --git a/module/actor-sheet.js b/module/actor-sheet.js index bb492228..e42c3ce8 100644 --- a/module/actor-sheet.js +++ b/module/actor-sheet.js @@ -56,7 +56,7 @@ export class RdDActorSheet extends ActorSheet { item.data.xpNext = RdDItemCompetence.getCompetenceNextXp(item.data.niveau); item.data.isLevelUp = item.data.xp >= item.data.xpNext; // Flag de niveau à MAJ //this.actor.checkCompetenceXP(item.name); // Petite vérification experience - item.data.showCompetence = !data.data.showCompNiveauBase || (Number(item.data.niveau) != Number(RdDUtility.getLevelCategory(item.data.categorie))); + item.data.showCompetence = !data.data.showCompNiveauBase || (Number(item.data.niveau) != Number(RdDItemCompetence.getLevelCategory(item.data.categorie))); // Ignorer les compétences 'troncs' à ce stade data.data.competenceXPTotal += RdDItemCompetence.computeCompetenceXPCost(item); return item; diff --git a/module/actor.js b/module/actor.js index f732bd7a..92afa55d 100644 --- a/module/actor.js +++ b/module/actor.js @@ -710,7 +710,7 @@ export class RdDActor extends Actor { return; } let caracpath = "data.carac." + caracName + ".xp"; - await this.update({ [caracpath]: caracXP }); + await this.update({ [caracpath]: caracXP ?? 0 }); this.checkCaracXP(caracName); } @@ -736,7 +736,7 @@ export class RdDActor extends Actor { let comp = this.getCompetence(compName); if (comp) { let troncList = RdDItemCompetence.isTronc(compName); - let maxNiveau = compValue; + let nouveauNiveau = compValue ?? RdDItemCompetence.getLevelCategory(comp.data.categorie); if (troncList) { let message = "Vous avez modifié une compétence 'tronc'. Vérifiez que les compétences suivantes évoluent ensemble jusqu'au niveau 0 : "; for (let troncName of troncList) { @@ -747,7 +747,7 @@ export class RdDActor extends Actor { content: message }); } - const update = { _id: comp._id, 'data.niveau': maxNiveau }; + const update = { _id: comp._id, 'data.niveau': nouveauNiveau }; const updated = await this.updateEmbeddedEntity("OwnedItem", update); // Updates one EmbeddedEntity } else { console.log("Competence not found", compName); @@ -758,6 +758,7 @@ export class RdDActor extends Actor { async updateCompetenceXP(compName, compValue) { let comp = this.getCompetence(compName); if (comp) { + compValue = compValue ?? 0; this.checkCompetenceXP(compName, compValue); const update = { _id: comp._id, 'data.xp': compValue }; const updated = await this.updateEmbeddedEntity("OwnedItem", update); // Updates one EmbeddedEntity @@ -771,6 +772,7 @@ export class RdDActor extends Actor { async updateCompetenceXPSort(compName, compValue) { let comp = this.getCompetence(compName); if (comp) { + compValue = compValue ?? 0; const update = { _id: comp._id, 'data.xp_sort': compValue }; const updated = await this.updateEmbeddedEntity("OwnedItem", update); // Updates one EmbeddedEntity } else { @@ -782,6 +784,7 @@ export class RdDActor extends Actor { async updateCompetenceArchetype(compName, compValue) { let comp = this.getCompetence(compName); if (comp) { + compValue = compValue ?? 0; const update = { _id: comp._id, 'data.niveau_archetype': compValue }; const updated = await this.updateEmbeddedEntity("OwnedItem", update); // Updates one EmbeddedEntity } else { diff --git a/module/item-competence.js b/module/item-competence.js index deca47f1..2820001a 100644 --- a/module/item-competence.js +++ b/module/item-competence.js @@ -5,6 +5,18 @@ const competenceTroncs = [["Esquive", "Dague", "Corps à corps"], 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 competence_niveau_max = competence_xp_par_niveau.length - 10; +/* -------------------------------------------- */ +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" } +} + function _buildCumulXP() { let cumulXP = { "-11": 0 }; let cumul = 0; @@ -20,6 +32,16 @@ const competence_xp_cumul = _buildCumulXP(); export class RdDItemCompetence extends Item { + static getCategorieCompetences() { + return categorieCompetences; + } + static getLevelCategory(category) { + return categorieCompetences[category].level; + } + static getLabelCategory(category) { + return categorieCompetences[category].label; + } + /* -------------------------------------------- */ static isCompetenceArme(competence) { switch (competence.data.categorie) { diff --git a/module/item-sheet.js b/module/item-sheet.js index f70e3483..2d1bfdf6 100644 --- a/module/item-sheet.js +++ b/module/item-sheet.js @@ -48,7 +48,7 @@ export class RdDItemSheet extends ItemSheet { /* -------------------------------------------- */ async getData() { let data = super.getData(); - data.categorieCompetences = RdDUtility.getCategorieCompetences(); + data.categorieCompetences = RdDItemCompetence.getCategorieCompetences(); if ( data.item.type == 'tache' || data.item.type == 'livre' || data.item.type == 'meditation' || data.item.type == 'oeuvre') { data.caracList = duplicate(game.system.model.Actor.personnage.carac); data.competences = await RdDUtility.loadCompendiumNames( 'foundryvtt-reve-de-dragon.competences' ); @@ -111,7 +111,7 @@ export class RdDItemSheet extends ItemSheet { async _onClickSelectCategorie(event) { event.preventDefault(); - let level = RdDUtility.getLevelCategory(event.currentTarget.value); + let level = RdDItemCompetence.getLevelCategory(event.currentTarget.value); this.object.data.data.base = level; $("#base").val( level ); } diff --git a/module/rdd-utility.js b/module/rdd-utility.js index 482b829d..d9cfa1e0 100644 --- a/module/rdd-utility.js +++ b/module/rdd-utility.js @@ -1,27 +1,10 @@ /* Common useful functions shared between objects */ -import { RdDRollTables } from "./rdd-rolltables.js"; import { ChatUtility } from "./chat-utility.js"; -import { RdDCombat, RdDCombatManager } 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"; +import { RdDCombat } from "./rdd-combat.js"; import { Misc } from "./misc.js"; import { Grammar } from "./grammar.js"; -/* -------------------------------------------- */ -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" } -} - /* -------------------------------------------- */ const limitesArchetypes = [ { "niveau": 0, "nombreMax": 100, "nombre": 0 }, @@ -403,15 +386,6 @@ export class RdDUtility { } /* -------------------------------------------- */ - static getCategorieCompetences() { - return categorieCompetences; - } - static getLevelCategory(category) { - return categorieCompetences[category].level; - } - static getLabelCategory(category) { - return categorieCompetences[category].label; - } static getCaracArray() { return carac_array; }