feat(combat): generalize the web combat action and expose potions/monster intent
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user