From aa36f3ea6793a7af07bca669e6557c6991e87d2d Mon Sep 17 00:00:00 2001 From: hypercross Date: Fri, 17 Apr 2026 12:42:29 +0800 Subject: [PATCH] feat: enemy intent update --- .../system/combat/triggers.ts | 48 ++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/src/samples/slay-the-spire-like/system/combat/triggers.ts b/src/samples/slay-the-spire-like/system/combat/triggers.ts index b24900e..0928756 100644 --- a/src/samples/slay-the-spire-like/system/combat/triggers.ts +++ b/src/samples/slay-the-spire-like/system/combat/triggers.ts @@ -25,6 +25,8 @@ type TriggerTypes = { onEffectApplied: { effect: EffectData, entityKey: "player" | string, stacks: number, cardId?: string }, onHpChange: { entityKey: "player" | string, amount: number}, onDamage: { entityKey: "player" | string, amount: number, dealt?: number, prevented?: number}, + onEnemyIntent: { enemyId: string }, + onIntentUpdate: { enemyId: string }, } function createTriggers(){ @@ -131,6 +133,47 @@ function createTriggers(){ }); await triggers.onHpChange.execute(ctx.game,{entityKey: ctx.entityKey, amount: -ctx.amount}); }), + onEnemyIntent: createTrigger("onEnemyIntent", async ctx => { + const enemy = ctx.game.value.enemies.find(e => e.id === ctx.enemyId); + if(!enemy || !enemy.isAlive) return; + + const intent = enemy.intents[enemy.currentIntentId]; + if(!intent) return; + + for(const [target, effect, stacks] of intent.effects){ + if(target === 'team'){ + for(const enemy of getAliveEnemies(ctx.game.value)){ + await triggers.onEffectApplied.execute(ctx.game, { + effect, + entityKey: enemy.id, + stacks, + }); + } + }else { + const entityKey = target === 'self' ? ctx.enemyId : 'player'; + await triggers.onEffectApplied.execute(ctx.game, { + effect, + entityKey, + stacks, + }); + } + } + }), + onIntentUpdate: createTrigger("onIntentUpdate", async ctx => { + await ctx.game.produceAsync(draft => { + const enemy = draft.enemies.find(e => e.id === ctx.enemyId); + if(!enemy) return; + + const intent = enemy.intents[enemy.currentIntentId]; + if(!intent) return; + + const nextIntents = intent.nextIntents; + if(nextIntents.length > 0){ + const nextIndex = ctx.game.rng.nextInt(nextIntents.length); + enemy.currentIntentId = nextIntents[nextIndex]; + } + }); + }), } return triggers; } @@ -157,7 +200,10 @@ export function createStartWith(build: (triggers: Triggers) => void){ for (const enemy of getAliveEnemies(game.value)) { await triggers.onTurnStart.execute(game, {entityKey: enemy.id}); } - // TODO execute enemy intent, then update with new one here + for (const enemy of getAliveEnemies(game.value)) { + await triggers.onEnemyIntent.execute(game, {enemyId: enemy.id}); + await triggers.onIntentUpdate.execute(game, {enemyId: enemy.id}); + } for (const enemy of getAliveEnemies(game.value)) { await triggers.onTurnEnd.execute(game, {entityKey: enemy.id}); }