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