feat(api): CharacterStatsService reports effective (regenerated) HP
- Update CharacterStatsService constructor to accept CharacterVitalsService - Compute currentHp via CharacterVitalsService.effectiveHp() instead of raw pass-through - Add hpRegenPerSecond and hpRegenSince fields to EffectiveCharacterStats return type - Update spec with new test cases for regeneration calculation and field pass-through - Equipment and combat tests now fail as expected (separate tasks will fix constructor calls) Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -2,6 +2,8 @@ import { Injectable } from '@nestjs/common';
|
||||
import { DataSource } from 'typeorm';
|
||||
import { CharacterEquipment } from '../equipment/entities/character-equipment.entity';
|
||||
import { EquipmentSlot } from '../items/equipment-slot.enum';
|
||||
import { HP_REGEN_PER_SECOND } from './character-vitals.constants';
|
||||
import { CharacterVitalsService } from './character-vitals.service';
|
||||
import { Character } from './entities/character.entity';
|
||||
|
||||
export interface EffectiveCharacterStats {
|
||||
@@ -11,6 +13,8 @@ export interface EffectiveCharacterStats {
|
||||
weaponDamage: number;
|
||||
armor: number;
|
||||
combatPower: number;
|
||||
hpRegenPerSecond: number;
|
||||
hpRegenSince: Date | null;
|
||||
}
|
||||
|
||||
type RepositoryScope = Pick<DataSource, 'getRepository'>;
|
||||
@@ -21,7 +25,10 @@ type RepositoryScope = Pick<DataSource, 'getRepository'>;
|
||||
*/
|
||||
@Injectable()
|
||||
export class CharacterStatsService {
|
||||
constructor(private readonly dataSource: DataSource) {}
|
||||
constructor(
|
||||
private readonly dataSource: DataSource,
|
||||
private readonly characterVitals: CharacterVitalsService,
|
||||
) {}
|
||||
|
||||
async calculate(
|
||||
character: Character,
|
||||
@@ -54,11 +61,13 @@ export class CharacterStatsService {
|
||||
|
||||
return {
|
||||
maxHp,
|
||||
currentHp: character.currentHp,
|
||||
currentHp: this.characterVitals.effectiveHp(character, maxHp),
|
||||
attack,
|
||||
weaponDamage,
|
||||
armor,
|
||||
combatPower: maxHp / 10 + attack * 2 + weaponDamage * 2 + armor * 1.5,
|
||||
hpRegenPerSecond: HP_REGEN_PER_SECOND,
|
||||
hpRegenSince: character.hpRegenSince,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user