feat: enemy intent update
This commit is contained in:
parent
0f04af2c6e
commit
aa36f3ea67
|
|
@ -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});
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue