StealBoostsActionExecutor.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.StealBoostsActionNode
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
/**
* `steal_boosts` 动作执行器。
*/
class StealBoostsActionExecutor : ActionExecutor {
override val type: ActionTypeId = StandardActionTypeIds.STEAL_BOOSTS
override fun execute(
action: ActionNode,
context: EventContext,
): ActionResult {
require(action is StealBoostsActionNode) { "Action must be StealBoostsActionNode." }
val sourceUnit = EventContextTargetResolver.resolveSingleUnit(action.from, context) ?: return ActionResult()
val targetUnit = EventContextTargetResolver.resolveSingleUnit(action.target, context) ?: return ActionResult()
val transferResult =
BattleStoredBoostSupport.steal(
source = sourceUnit.boosts,
target = targetUnit.boosts,
selection = action.selection,
stats = action.stats,
)
return ActionResult(
mutations =
listOf(
SetBoostsMutation(action.from, transferResult.sourceBoosts),
SetBoostsMutation(action.target, transferResult.targetBoosts),
),
)
}
}