BattleSessionActionFactory.kt

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

/**
 * battle session action 构造器。
 *
 * 设计意图:
 * - 把 action 族的数据对象创建逻辑从默认命令工厂中拆出;
 * - 让 `choice -> action` 映射可以复用同一套 action 构造入口;
 * - 保持 action 数据结构创建语义集中且独立。
 */
internal class BattleSessionActionFactory {
    fun createMoveAction(
        moveId: String,
        attackerId: String,
        targetId: String,
        priority: Int,
        speed: Int,
        accuracy: Int?,
        evasion: Int?,
        basePower: Int,
        damage: Int,
        attributes: Map<String, Any?>,
    ): BattleSessionMoveAction =
        BattleSessionMoveAction(
            moveId = moveId,
            attackerId = attackerId,
            targetId = targetId,
            priority = priority,
            speed = speed,
            accuracy = accuracy,
            evasion = evasion,
            basePower = basePower,
            damage = damage,
            attributes = attributes,
        )

    fun createItemAction(
        itemId: String,
        actorUnitId: String,
        targetId: String,
        priority: Int,
        speed: Int,
        attributes: Map<String, Any?>,
    ): BattleSessionItemAction =
        BattleSessionItemAction(
            itemId = itemId,
            actorUnitId = actorUnitId,
            targetId = targetId,
            priority = priority,
            speed = speed,
            attributes = attributes,
        )

    fun createCaptureAction(
        playerId: String,
        ballItemId: String,
        sourceUnitId: String,
        targetId: String,
        priority: Int,
        speed: Int,
    ): BattleSessionCaptureAction =
        BattleSessionCaptureAction(
            playerId = playerId,
            ballItemId = ballItemId,
            sourceUnitId = sourceUnitId,
            targetId = targetId,
            priority = priority,
            speed = speed,
        )

    fun createSwitchAction(
        sideId: String,
        outgoingUnitId: String,
        incomingUnitId: String,
        priority: Int,
        speed: Int,
    ): BattleSessionSwitchAction =
        BattleSessionSwitchAction(
            sideId = sideId,
            outgoingUnitId = outgoingUnitId,
            incomingUnitId = incomingUnitId,
            priority = priority,
            speed = speed,
        )

    fun createRunAction(
        sideId: String,
        priority: Int,
        speed: Int,
    ): BattleSessionRunAction =
        BattleSessionRunAction(
            sideId = sideId,
            priority = priority,
            speed = speed,
        )

    fun createWaitAction(
        unitId: String,
        priority: Int,
        speed: Int,
    ): BattleSessionWaitAction =
        BattleSessionWaitAction(
            unitId = unitId,
            priority = priority,
            speed = speed,
        )
}