feat(api): combat snapshots now use CharacterStatsService
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { DataSource, EntityManager, EntityTarget } from 'typeorm';
|
||||
import { CharacterCombatStatsService } from '../characters/character-combat-stats.service';
|
||||
import { CharacterStatsService } from '../characters/character-stats.service';
|
||||
import { Character } from '../characters/entities/character.entity';
|
||||
import { Hunt } from '../hunting/entities/hunt.entity';
|
||||
import { HuntEncounter } from '../hunting/entities/hunt-encounter.entity';
|
||||
@@ -242,6 +242,19 @@ function createState(overrides: Partial<FakeState> = {}): FakeState {
|
||||
};
|
||||
}
|
||||
|
||||
function fakeCharacterStats(): CharacterStatsService {
|
||||
return {
|
||||
calculate: jest.fn(async (character: Character) => ({
|
||||
maxHp: character.baseHp,
|
||||
currentHp: character.currentHp,
|
||||
attack: character.baseAttack,
|
||||
weaponDamage: 8,
|
||||
armor: 6,
|
||||
combatPower: 0,
|
||||
})),
|
||||
} as unknown as CharacterStatsService;
|
||||
}
|
||||
|
||||
function fakeTravelService(
|
||||
status: 'IDLE' | 'TRAVELLING' = 'IDLE',
|
||||
): TravelService {
|
||||
@@ -271,7 +284,7 @@ function createService(
|
||||
const dataSource = new FakeDataSource(state);
|
||||
const travelService = options.travelService ?? fakeTravelService();
|
||||
const combatEngine = new CombatEngineService();
|
||||
const characterCombatStats = new CharacterCombatStatsService();
|
||||
const characterCombatStats = fakeCharacterStats();
|
||||
const service = new CombatService(
|
||||
dataSource as unknown as DataSource,
|
||||
travelService,
|
||||
@@ -785,7 +798,7 @@ describe('CombatService', () => {
|
||||
dataSource as unknown as DataSource,
|
||||
fakeTravelService(),
|
||||
new CombatEngineService(),
|
||||
new CharacterCombatStatsService(),
|
||||
fakeCharacterStats(),
|
||||
rewards,
|
||||
);
|
||||
|
||||
@@ -833,7 +846,7 @@ describe('CombatService', () => {
|
||||
dataSource as unknown as DataSource,
|
||||
fakeTravelService(),
|
||||
new CombatEngineService(),
|
||||
new CharacterCombatStatsService(),
|
||||
fakeCharacterStats(),
|
||||
rewards,
|
||||
);
|
||||
|
||||
@@ -890,7 +903,7 @@ describe('CombatService', () => {
|
||||
dataSource as unknown as DataSource,
|
||||
fakeTravelService(),
|
||||
new CombatEngineService(),
|
||||
new CharacterCombatStatsService(),
|
||||
fakeCharacterStats(),
|
||||
rewards,
|
||||
);
|
||||
|
||||
@@ -927,7 +940,7 @@ describe('CombatService', () => {
|
||||
dataSource as unknown as DataSource,
|
||||
fakeTravelService(),
|
||||
new CombatEngineService(),
|
||||
new CharacterCombatStatsService(),
|
||||
fakeCharacterStats(),
|
||||
fakeRewardService({
|
||||
// Genuinely write XP/silver through the transaction's manager
|
||||
// before failing, so the assertions below prove the rollback
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { DataSource, Repository } from 'typeorm';
|
||||
import { CharacterCombatStatsService } from '../characters/character-combat-stats.service';
|
||||
import { CharacterStatsService } from '../characters/character-stats.service';
|
||||
import { Character } from '../characters/entities/character.entity';
|
||||
import { Hunt } from '../hunting/entities/hunt.entity';
|
||||
import { HuntEncounter } from '../hunting/entities/hunt-encounter.entity';
|
||||
@@ -69,7 +69,7 @@ export class CombatService {
|
||||
private readonly dataSource: DataSource,
|
||||
private readonly travelService: TravelService,
|
||||
private readonly combatEngine: CombatEngineService,
|
||||
private readonly characterCombatStats: CharacterCombatStatsService,
|
||||
private readonly characterStats: CharacterStatsService,
|
||||
private readonly combatRewards: CombatRewardService,
|
||||
) {}
|
||||
|
||||
@@ -126,7 +126,7 @@ export class CombatService {
|
||||
throw invalidHuntEncounter();
|
||||
}
|
||||
|
||||
const playerStats = this.characterCombatStats.getStats(character);
|
||||
const playerStats = await this.characterStats.calculate(character, manager);
|
||||
|
||||
const combat = combats.create({
|
||||
characterId,
|
||||
|
||||
Reference in New Issue
Block a user