AddVolatileActionExecutor.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.AddVolatileActionNode
import io.github.lishangbu.avalon.game.battle.engine.core.event.EventContext
import io.github.lishangbu.avalon.game.battle.engine.core.mutation.AddVolatileMutation
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.type.ActionTypeId
import io.github.lishangbu.avalon.game.battle.engine.core.type.StandardActionTypeIds
/**
* `add_volatile` 动作执行器。
*/
class AddVolatileActionExecutor : ActionExecutor {
override val type: ActionTypeId = StandardActionTypeIds.ADD_VOLATILE
override fun execute(
action: ActionNode,
context: EventContext,
): ActionResult {
require(action is AddVolatileActionNode) { "Action must be AddVolatileActionNode." }
val resolvedDuration =
AttachedEffectDurationResolver.resolve(
explicitDuration = action.duration,
effectId = action.value,
context = context,
)
return ActionResult(
mutations =
listOf(
AddVolatileMutation(
target = action.target,
volatileEffectId = action.value,
duration = resolvedDuration,
sourceId = context.source?.id ?: context.self?.id,
),
),
)
}
}