feat(combat): rejoin the running combat instead of dead-ending
Attacking while a combat is already active returned COMBAT_ALREADY_ACTIVE and left the hunt page showing an error the player could not act on, with no way back into the fight they were already in. Add GET /api/combats/active so the client can resolve that combat, and have the hunt page navigate into it when an attack is rejected for this reason. CombatStore now also exposes the error code so callers can tell this case apart from a genuinely failed attack.
This commit is contained in:
@@ -587,6 +587,58 @@ describe('CombatService', () => {
|
||||
);
|
||||
});
|
||||
|
||||
it('resolves the character ACTIVE combat so the hunt page can rejoin it', async () => {
|
||||
const context = createService();
|
||||
const started = await context.service.startCombat(
|
||||
CHARACTER_ID,
|
||||
ENCOUNTER_ID,
|
||||
);
|
||||
await context.service.performAction(
|
||||
CHARACTER_ID,
|
||||
started.id,
|
||||
CombatAction.ATTACK,
|
||||
);
|
||||
|
||||
const active = await context.service.getActiveCombat(CHARACTER_ID);
|
||||
|
||||
expect(active?.id).toBe(started.id);
|
||||
expect(active?.status).toBe('ACTIVE');
|
||||
expect(active?.round).toBe(2);
|
||||
});
|
||||
|
||||
it('resolves null when the character has no ACTIVE combat', async () => {
|
||||
const { service } = createService();
|
||||
|
||||
await expect(service.getActiveCombat(CHARACTER_ID)).resolves.toBeNull();
|
||||
});
|
||||
|
||||
it('resolves null once the only combat has finished', async () => {
|
||||
const state = createState({ monsters: [monster({ maxHp: 10 })] });
|
||||
const context = createService({ state });
|
||||
const started = await context.service.startCombat(
|
||||
CHARACTER_ID,
|
||||
ENCOUNTER_ID,
|
||||
);
|
||||
await context.service.performAction(
|
||||
CHARACTER_ID,
|
||||
started.id,
|
||||
CombatAction.ATTACK,
|
||||
);
|
||||
|
||||
await expect(
|
||||
context.service.getActiveCombat(CHARACTER_ID),
|
||||
).resolves.toBeNull();
|
||||
});
|
||||
|
||||
it('does not resolve another character ACTIVE combat', async () => {
|
||||
const context = createService();
|
||||
await context.service.startCombat(CHARACTER_ID, ENCOUNTER_ID);
|
||||
|
||||
await expect(
|
||||
context.service.getActiveCombat(OTHER_CHARACTER_ID),
|
||||
).resolves.toBeNull();
|
||||
});
|
||||
|
||||
it('keeps returning LOST after the combat has ended', async () => {
|
||||
const state = createState({
|
||||
characters: [character({ baseHp: 1 })],
|
||||
|
||||
Reference in New Issue
Block a user