Fix: cas de xp/niveau vide

Après avoir enlevé l'xp par erreur, elle est gardée vide, mieux vaut
la mettre à 0 pour pouvoir l'augmenter par la suite
This commit is contained in:
Vincent Vandemeulebrouck 2021-03-15 00:07:53 +01:00
parent 57ec6403bb
commit 1de15d0b32
5 changed files with 32 additions and 33 deletions

View File

@ -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;

View File

@ -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 {

View File

@ -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) {

View File

@ -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 );
}

View File

@ -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;
}