From dda8f4cfe9df4abfcd4aa0568363bc69d54ad8ef Mon Sep 17 00:00:00 2001 From: hypercross Date: Mon, 20 Apr 2026 00:00:38 +0800 Subject: [PATCH] style: reformat card-events.ts with 2-space indentation --- .../data/desert/triggers/card-events.ts | 219 +++++++++--------- 1 file changed, 114 insertions(+), 105 deletions(-) diff --git a/src/samples/slay-the-spire-like/data/desert/triggers/card-events.ts b/src/samples/slay-the-spire-like/data/desert/triggers/card-events.ts index a6d0ec3..a979c65 100644 --- a/src/samples/slay-the-spire-like/data/desert/triggers/card-events.ts +++ b/src/samples/slay-the-spire-like/data/desert/triggers/card-events.ts @@ -6,116 +6,125 @@ import { EffectData } from "@/samples/slay-the-spire-like/system/types"; import getEffects from "../effect.csv"; export function addCardEventTriggers(triggers: Triggers) { - const effects = getEffects(); + const effects = getEffects(); - function findEffect(id: string): EffectData { - const found = effects.find(e => e.id === id); - if (found) return found; - return { id, name: id, description: "", lifecycle: "instant" } as EffectData; - } + function findEffect(id: string): EffectData { + const found = effects.find((e) => e.id === id); + if (found) return found; + return { + id, + name: id, + description: "", + lifecycle: "instant", + } as EffectData; + } - // storm: give static card to player when storm enemy attacks - triggers.onEnemyIntent.use(async (ctx, next) => { - await next(); + // storm: give static card to player when storm enemy attacks + triggers.onEnemyIntent.use(async (ctx, next) => { + await next(); - const enemy = getCombatEntity(ctx.game.value, ctx.enemyId); - if (!enemy || !enemy.isAlive) return; - - const storm = enemy.effects.storm?.stacks ?? 0; - if (storm > 0) { - for (let i = 0; i < storm; i++) { - await triggers.onEffectApplied.execute(ctx.game, { - effect: findEffect("static"), - entityKey: "player", - stacks: 1, - sourceEntityKey: ctx.enemyId, - }); - } - } - }); - - // crossbow: replay other crossbows on same target - triggers.onEffectApplied.use(async (ctx, next) => { - await next(); - - if (ctx.effect.id !== "crossbow" || !ctx.cardId || !ctx.targetId) return; - - const { cards, regions } = ctx.game.value.player.deck; - const handIds = [...regions.hand.childIds]; - for (const id of handIds) { - const card = cards[id]; - if (card && card.itemId === "crossbow" && id !== ctx.cardId) { - await triggers.onCardPlayed.execute(ctx.game, { - cardId: id, - targetId: ctx.targetId, - sourceEntityKey: "player", - }); - } - } - }); - - // burnForEnergy: consume adjacent item, gain energy when its card is played - triggers.onCardPlayed.use(async (ctx, next) => { - await next(); - - const card = ctx.game.value.player.deck.cards[ctx.cardId]; - if (!card) return; - const playedItemId = card.itemId; - - const adjacent = getAdjacentItems(ctx.game.value.inventory, playedItemId); - for (const [adjItemId] of adjacent) { - const adjEffects = ctx.game.value.player.itemEffects[adjItemId]; - if (!adjEffects) continue; - const burn = adjEffects.burnForEnergy; - if (!burn || burn.stacks <= 0) continue; - - await ctx.game.produceAsync(draft => { - const item = draft.inventory.items.get(adjItemId); - if (item) { - draft.inventory.items.delete(adjItemId); - } - draft.player.energy += burn.stacks; - delete draft.player.itemEffects[adjItemId]; - }); - break; - } - }); - - // sandwormKing: heal 10 hp when player discards fatigue - triggers.onCardDiscarded.use(async (ctx, next) => { - await next(); - - const card = ctx.game.value.player.deck.cards[ctx.cardId]; - if (!card || card.cardData.id !== "fatigue") return; - - const sandwormKing = ctx.game.value.enemies.find( - e => e.enemy.id === "沙虫王" && e.isAlive - ); - if (!sandwormKing) return; - - await ctx.game.produceAsync(draft => { - const king = draft.enemies.find(e => e.id === sandwormKing.id); - if (king) { - king.hp = Math.min(king.hp + 10, king.maxHp); - } - }); - }); - - // vulture: give vultureEye when vulture deals damage - triggers.onDamage.use(async (ctx, next) => { - await next(); - - const dealt = ctx.amount - (ctx.prevented ?? 0); - if (dealt <= 0 || !ctx.sourceEntityKey) return; - - const attacker = getCombatEntity(ctx.game.value, ctx.sourceEntityKey); - if (!attacker || !("enemy" in attacker) || attacker.enemy.id !== "秃鹫") return; + const enemy = getCombatEntity(ctx.game.value, ctx.enemyId); + if (!enemy || !enemy.isAlive) return; + const storm = enemy.effects.storm?.stacks ?? 0; + if (storm > 0) { + for (let i = 0; i < storm; i++) { await triggers.onEffectApplied.execute(ctx.game, { - effect: findEffect("vultureEye"), - entityKey: "player", - stacks: 1, - sourceEntityKey: ctx.sourceEntityKey, + effect: findEffect("static"), + entityKey: "player", + stacks: 1, + sourceEntityKey: ctx.enemyId, }); + } + } + }); + + // crossbow: replay other crossbows on same target + triggers.onEffectApplied.use(async (ctx, next) => { + await next(); + + if (ctx.effect.id !== "crossbow" || !ctx.cardId || !ctx.targetId) return; + + const { cards, regions } = ctx.game.value.player.deck; + const handIds = [...regions.hand.childIds]; + for (const id of handIds) { + const card = cards[id]; + if (card && card.itemId === "crossbow" && id !== ctx.cardId) { + await triggers.onCardPlayed.execute(ctx.game, { + cardId: id, + targetId: ctx.targetId, + sourceEntityKey: "player", + }); + } + } + }); + + // burnForEnergy: consume adjacent item, gain energy when its card is played + triggers.onCardPlayed.use(async (ctx, next) => { + await next(); + + const card = ctx.game.value.player.deck.cards[ctx.cardId]; + if (!card) return; + const playedItemId = card.itemId; + + const adjacent = getAdjacentItems( + ctx.game.value.inventory, + playedItemId, + ); + for (const [adjItemId] of adjacent) { + const adjEffects = ctx.game.value.player.itemEffects[adjItemId]; + if (!adjEffects) continue; + const burn = adjEffects.burnForEnergy; + if (!burn || burn.stacks <= 0) continue; + + await ctx.game.produceAsync((draft) => { + const item = draft.inventory.items.get(adjItemId); + if (item) { + draft.inventory.items.delete(adjItemId); + } + draft.player.energy += burn.stacks; + delete draft.player.itemEffects[adjItemId]; + }); + break; + } + }); + + // sandwormKing: heal 10 hp when player discards fatigue + triggers.onCardDiscarded.use(async (ctx, next) => { + await next(); + + const card = ctx.game.value.player.deck.cards[ctx.cardId]; + if (!card || card.cardData.id !== "fatigue") return; + + const sandwormKing = ctx.game.value.enemies.find( + (e) => e.enemy.id === "沙虫王" && e.isAlive, + ); + if (!sandwormKing) return; + + await ctx.game.produceAsync((draft) => { + const king = draft.enemies.find((e) => e.id === sandwormKing.id); + if (king) { + king.hp = Math.min(king.hp + 10, king.maxHp); + } }); + }); + + // vulture: give vultureEye when vulture deals damage + triggers.onDamage.use(async (ctx, next) => { + await next(); + + const dealt = ctx.amount - (ctx.prevented ?? 0); + if (dealt <= 0 || !ctx.sourceEntityKey) return; + + const attacker = getCombatEntity(ctx.game.value, ctx.sourceEntityKey); + if (!attacker || !("enemy" in attacker) || attacker.enemy.id !== "秃鹫") + return; + + await triggers.onEffectApplied.execute(ctx.game, { + effect: findEffect("vultureEye"), + entityKey: "player", + stacks: 1, + sourceEntityKey: ctx.sourceEntityKey, + }); + }); }