InvertBoostRelayActionExecutor.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.InvertBoostRelayActionNode
import io.github.lishangbu.avalon.game.battle.engine.core.event.EventContext
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.BattleBoostContextSupport
import io.github.lishangbu.avalon.game.battle.engine.core.type.ActionTypeId
import io.github.lishangbu.avalon.game.battle.engine.core.type.StandardActionTypeIds

/**
 * `invert_boost_relay` 动作执行器。
 *
 * 说明:
 * - 只处理当前 relay 为 boost map 的场景;
 * - 如果 relay 不是 `Map<String, Number>`,则保持原 relay 不变;
 * - 结果会走统一 boost 负载规范化,避免长短写别名在改写后继续并存。
 */
class InvertBoostRelayActionExecutor : ActionExecutor {
    override val type: ActionTypeId = StandardActionTypeIds.INVERT_BOOST_RELAY

    override fun execute(
        action: ActionNode,
        context: EventContext,
    ): ActionResult {
        require(action is InvertBoostRelayActionNode) { "Action must be InvertBoostRelayActionNode." }
        val normalizedBoosts = BattleBoostContextSupport.normalizeBoostMap(context.relay) ?: return ActionResult(relay = context.relay)
        val inverted = normalizedBoosts.mapValues { (_, delta) -> -delta }
        return ActionResult(
            relay = BattleBoostContextSupport.normalizeBoostMap(inverted),
        )
    }
}