refactor(slay-the-spire-like): update combat targeting and effect logic

Refactor combat targeting types and effect application logic in the
Slay the Spire-like sample.

- Update `getEffectTargets` to use `IntentEffectTarget` and more
  descriptive target keys (e.g., `eachEnemy`, `randomEnemy`).
- Update `promptMainAction` to use `enemy` instead of `single` for
  card target types.
- Refactor `addInstantEffectTriggers` to remove unused effect loading
  and improve enemy/card instantiation logic
This commit is contained in:
2026-04-22 19:35:37 +08:00
parent 38fd46618e
commit a5e2e4888e
7 changed files with 170 additions and 160 deletions
@@ -10,7 +10,7 @@ import {
CardData,
CardEffectTarget,
EffectData,
EffectTarget,
IntentEffectTarget,
} from "@/samples/slay-the-spire-like/system/types";
export function addEffect(
@@ -103,25 +103,25 @@ export function* getAliveEnemies(state: CombatState) {
}
export function* getEffectTargets(
target: CardEffectTarget | EffectTarget,
target: CardEffectTarget | IntentEffectTarget,
game: CombatGameContext,
targetId?: string,
sourceEntityKey: "player" | string = "player",
) {
if (target === "all" || target === "team") {
if (target === "eachEnemy") {
for (const enemy of getAliveEnemies(game.value)) {
yield enemy;
}
} else if (target === "self") {
} else if (target === "user") {
const entity = getCombatEntity(game.value, sourceEntityKey);
if (entity) yield entity;
} else if (target === "player") {
yield game.value.player;
} else if (target === "target") {
} else if (target === "eachTarget") {
if (!targetId) return;
const entity = getCombatEntity(game.value, targetId);
if (entity) yield entity;
} else if (target === "random") {
} else if (target === "randomEnemy") {
const aliveEnemies = [...getAliveEnemies(game.value)];
if (aliveEnemies.length === 0) return;
const index = game.rng.nextInt(aliveEnemies.length);