BattleSessionBeforeTurnStep.kt

package io.github.lishangbu.avalon.game.battle.engine.core.session

/**
 * 回合开始前生命周期步骤。
 *
 * 设计意图:
 * - 把 `on_before_turn` 从 move 结算链中独立出来,作为整个回合在 action 执行前的统一阶段;
 * - 让当前 active 单位身上的 attached effect 可以在真正执行动作前完成一次集中修正;
 * - 保持 turn pipeline 的阶段语义清晰:先校验,再 before-turn,再执行动作,最后 end-turn。
 */
class BattleSessionBeforeTurnStep : BattleSessionTurnStep {
    /**
     * 该步骤位于 turn 校验之后、action 执行之前。
     */
    override val order: Int = 50

    /**
     * 在 battle 尚未结束时,对当前全部 active 单位派发 `on_before_turn`。
     */
    override fun execute(context: BattleSessionTurnContext) {
        context.snapshot =
            if (context.session.currentSnapshot.battle.lifecycle
                    .isEnded()
            ) {
                context.session.currentSnapshot
            } else {
                context.session.processBeforeTurn()
            }
    }
}