InvertStoredBoostsActionExecutor.kt

package io.github.lishangbu.avalon.game.battle.engine.core.runtime.action

import io.github.lishangbu.avalon.game.battle.engine.core.dsl.ActionNode
import io.github.lishangbu.avalon.game.battle.engine.core.dsl.action.InvertStoredBoostsActionNode
import io.github.lishangbu.avalon.game.battle.engine.core.event.EventContext
import io.github.lishangbu.avalon.game.battle.engine.core.mutation.SetBoostsMutation
import io.github.lishangbu.avalon.game.battle.engine.core.runtime.ActionExecutor
import io.github.lishangbu.avalon.game.battle.engine.core.runtime.ActionResult
import io.github.lishangbu.avalon.game.battle.engine.core.runtime.support.BattleStoredBoostSupport
import io.github.lishangbu.avalon.game.battle.engine.core.runtime.support.EventContextTargetResolver
import io.github.lishangbu.avalon.game.battle.engine.core.type.ActionTypeId
import io.github.lishangbu.avalon.game.battle.engine.core.type.StandardActionTypeIds

/**
 * `invert_stored_boosts` 动作执行器。
 */
class InvertStoredBoostsActionExecutor : ActionExecutor {
    override val type: ActionTypeId = StandardActionTypeIds.INVERT_STORED_BOOSTS

    override fun execute(
        action: ActionNode,
        context: EventContext,
    ): ActionResult {
        require(action is InvertStoredBoostsActionNode) { "Action must be InvertStoredBoostsActionNode." }
        val targetUnit = EventContextTargetResolver.resolveSingleUnit(action.target, context) ?: return ActionResult()
        return ActionResult(
            mutations =
                listOf(
                    SetBoostsMutation(
                        action.target,
                        BattleStoredBoostSupport.invert(targetUnit.boosts, action.stats),
                    ),
                ),
        )
    }
}