feat(combat): generalize the web combat action and expose potions/monster intent

This commit is contained in:
Bastian Wagner
2026-08-20 22:01:28 +02:00
parent c7b9601eb4
commit b8d00278b8
5 changed files with 29 additions and 13 deletions

View File

@@ -1,7 +1,7 @@
import { HttpErrorResponse } from '@angular/common/http';
import { Injectable, signal } from '@angular/core';
import { firstValueFrom } from 'rxjs';
import { Combat } from '../../core/api/game-api.models';
import { Combat, CombatAction } from '../../core/api/game-api.models';
import { GameApiService } from '../../core/api/game-api.service';
const GENERIC_ERROR_MESSAGE = 'Der Kampf konnte nicht geladen werden.';
@@ -16,6 +16,7 @@ const COMBAT_ERROR_MESSAGES: Readonly<Record<string, string>> = {
COMBAT_ALREADY_ACTIVE: 'Du befindest dich bereits in einem Kampf.',
COMBAT_NOT_FOUND: 'Dieser Kampf wurde nicht gefunden.',
COMBAT_ALREADY_FINISHED: 'Dieser Kampf ist bereits beendet.',
COMBAT_NO_POTIONS_REMAINING: 'Du hast keine Tränke mehr.',
};
@Injectable({ providedIn: 'root' })
@@ -83,7 +84,7 @@ export class CombatStore {
}
}
async attack(): Promise<void> {
async performAction(action: CombatAction): Promise<void> {
const combat = this.combatState();
if (!combat || this.actionPendingState()) {
return;
@@ -93,7 +94,7 @@ export class CombatStore {
this.clearError();
try {
const updated = await firstValueFrom(this.api.performCombatAction(combat.id, 'ATTACK'));
const updated = await firstValueFrom(this.api.performCombatAction(combat.id, action));
this.combatState.set(updated);
} catch (error) {
this.setError(error);