From 4a6913a2bae774905426430b827a437a9b36a139 Mon Sep 17 00:00:00 2001 From: fabres Date: Thu, 6 Aug 2026 14:23:38 +0200 Subject: [PATCH] =?UTF-8?q?fix:=20XP=20comp=C3=A9tences=20n=C3=A9gatives?= =?UTF-8?q?=20(base=20de=20cat=C3=A9gorie)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Le champ base (INTEGER, min 0) rejetait les bases négatives (-4/-6/-8/-11) : toute compétence voyait sa base forcée à 0, d'où un total d'XP compétences fortement négatif (ex. -5790 sur un personnage neuf). - competence.mjs : base en INTEGER_SIGNED - item-competence.js : _preCreate affecte la base de la catégorie - migrations.js : migration 14.0.3 corrige les compétences existantes - compendiums repackés (bases de catégorie présentes dans les packs) --- module/item-competence.js | 7 +++++++ module/migrations.js | 16 ++++++++++++++++ module/models/competence.mjs | 2 +- 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/module/item-competence.js b/module/item-competence.js index 90a702e6..aa216038 100644 --- a/module/item-competence.js +++ b/module/item-competence.js @@ -55,6 +55,13 @@ export class RdDItemCompetence extends RdDItem { return this.system.niveau == this.system.base && this.system.xp == 0 } + async _preCreate(data, options, user) { + await super._preCreate(data, options, user) + if (this.system.categorie && !Number(data.system?.base)) { + this.updateSource({ 'system.base': RdDItemCompetence.getNiveauBase(this.system.categorie, this.type) }) + } + } + getBaseInit() { const carac = this.getInitCarac() if (carac == undefined) { diff --git a/module/migrations.js b/module/migrations.js index 0cd82b71..3b2b6d53 100644 --- a/module/migrations.js +++ b/module/migrations.js @@ -4,6 +4,7 @@ import { Grammar } from "./grammar.js"; import { Monnaie } from "./item-monnaie.js"; import { ITEM_TYPES, ACTOR_TYPES } from "./constants.js"; import { RdDItem } from "./item.js"; +import { RdDItemCompetence } from "./item-competence.js"; import { RdDTimestamp } from "./time/rdd-timestamp.js"; import { RdDRaretes } from "./item/raretes.js"; import { VOIES_DRACONIC } from "./item-sort.js"; @@ -720,6 +721,20 @@ class _13_0_23_OmbreCategorieFalse extends Migration { } } +class _14_0_3_MigrationCompetenceBase extends Migration { + get code() { return "competence-base-categorie" } + get version() { return "14.0.3" } + + async migrate() { + await this.applyItemsUpdates(items => items + .filter(it => it.type == ITEM_TYPES.competence + && it.system.categorie + && Number(it.system.base) == 0) + .map(it => ({ _id: it.id, 'system.base': RdDItemCompetence.getNiveauBase(it.system.categorie, it.type) })) + ) + } +} + export class Migrations { static getMigrations() { return [ @@ -748,6 +763,7 @@ export class Migrations { new _13_0_21_AjoutAppreciation(), new _13_0_22_PoidsDesMonnaies(), new _13_0_23_OmbreCategorieFalse(), + new _14_0_3_MigrationCompetenceBase(), ]; } diff --git a/module/models/competence.mjs b/module/models/competence.mjs index d8ddcffc..b2f62eea 100644 --- a/module/models/competence.mjs +++ b/module/models/competence.mjs @@ -10,7 +10,7 @@ export default class RdDModelCompetence extends foundry.abstract.TypeDataModel { { niveau: new fields.NumberField({ label: "Niveau", initial: 0, ...INTEGER_SIGNED, min: -11 }), default_diffLibre: new fields.NumberField({ label: "Difficulté libre par défaut", initial: 0, ...INTEGER_SIGNED, min: -10, max: 0 }), - base: new fields.NumberField({ label: "Base", initial: 0, ...INTEGER }), + base: new fields.NumberField({ label: "Base", initial: 0, ...INTEGER_SIGNED }), categorie: new fields.StringField({ label: "Catégorie", initial: "", ...STRING }), xp: new fields.NumberField({ label: "XP", initial: 0, ...INTEGER }), defaut_carac: new fields.StringField({ label: "Caractéristique par défaut", initial: "", ...STRING }),