fix: level-up formula uses current level, add xpToNextLevel to API
All checks were successful
CI/CD — Build & Deploy / Build & Deploy (push) Successful in 33s

XP threshold was computed on level+1 (target), making early levels too
steep (283 XP for level 2 instead of 100). Now uses current level:
level 1→2 = 100 XP, level 2→3 = 283 XP, level 10→11 = 3162 XP.

Added xpToNextLevel field to character and combat responses so the
frontend can display accurate progress bars.
This commit is contained in:
2026-03-24 16:02:51 +01:00
parent 6df11f2860
commit 214045c7ce
3 changed files with 18 additions and 6 deletions

View File

@@ -11,6 +11,7 @@ import { LevelThreshold } from './entities/level-threshold.entity';
import { CreateCharacterDto } from './dto/create-character.dto';
import { DistributeStatsDto } from './dto/distribute-stats.dto';
import { User } from '../user/user.entity';
import { xpRequiredForLevel } from '../combat/combat.engine';
const STAT_POOL = 10; // 5 stats × 1 base + 5 points à distribuer
const ENDURANCE_REGEN_MINUTES = 6; // 1 pt d'endurance toutes les 6 min = 10 pts/heure
@@ -35,7 +36,7 @@ export class CharacterService {
return Math.min(character.enduranceSaved + recharge, character.enduranceMax);
}
async create(dto: CreateCharacterDto, user: User): Promise<Character & { enduranceCurrent: number }> {
async create(dto: CreateCharacterDto, user: User) {
const totalStats =
dto.force + dto.agilite + dto.intelligence + dto.chance + dto.vitalite;
@@ -66,10 +67,14 @@ export class CharacterService {
});
const saved = await this.characterRepository.save(character);
return { ...saved, enduranceCurrent: this.calculateEndurance(saved) };
return {
...saved,
enduranceCurrent: this.calculateEndurance(saved),
xpToNextLevel: xpRequiredForLevel(saved.level),
};
}
async findByUser(user: User): Promise<Character & { enduranceCurrent: number }> {
async findByUser(user: User) {
const character = await this.characterRepository.findOne({
where: { userId: user.id },
});
@@ -78,7 +83,11 @@ export class CharacterService {
throw new NotFoundException('Aucun personnage trouvé pour ce joueur');
}
return { ...character, enduranceCurrent: this.calculateEndurance(character) };
return {
...character,
enduranceCurrent: this.calculateEndurance(character),
xpToNextLevel: xpRequiredForLevel(character.level),
};
}
async getEndurance(