DefaultBattleSessionCommandFactory.kt
package io.github.lishangbu.avalon.game.battle.engine.core.session
/**
* 默认 battle session 命令工厂。
*
* 设计意图:
* - 集中承载 choice/action 两个命令族的数据对象创建逻辑。
* - 保证 session 层各个入口对命令对象的创建语义保持一致。
*/
class DefaultBattleSessionCommandFactory : BattleSessionCommandFactory {
private val choiceFactory: BattleSessionChoiceFactory = BattleSessionChoiceFactory()
private val actionFactory: BattleSessionActionFactory = BattleSessionActionFactory()
private val choiceActionMapper: BattleSessionChoiceActionMapper = BattleSessionChoiceActionMapper(actionFactory)
/**
* 创建一个 move choice。
*/
override fun createMoveChoice(
moveId: String,
attackerId: String,
targetId: String,
priority: Int,
speed: Int,
accuracy: Int?,
evasion: Int?,
basePower: Int,
damage: Int,
attributes: Map<String, Any?>,
): MoveChoice =
choiceFactory.createMoveChoice(
moveId = moveId,
attackerId = attackerId,
targetId = targetId,
priority = priority,
speed = speed,
accuracy = accuracy,
evasion = evasion,
basePower = basePower,
damage = damage,
attributes = attributes,
)
/**
* 创建一个 item choice。
*/
override fun createItemChoice(
itemId: String,
actorUnitId: String,
targetId: String,
priority: Int,
speed: Int,
attributes: Map<String, Any?>,
): ItemChoice =
choiceFactory.createItemChoice(
itemId = itemId,
actorUnitId = actorUnitId,
targetId = targetId,
priority = priority,
speed = speed,
attributes = attributes,
)
/**
* 创建一个 capture choice。
*/
override fun createCaptureChoice(
playerId: String,
ballItemId: String,
sourceUnitId: String,
targetId: String,
priority: Int,
speed: Int,
): CaptureChoice =
choiceFactory.createCaptureChoice(
playerId = playerId,
ballItemId = ballItemId,
sourceUnitId = sourceUnitId,
targetId = targetId,
priority = priority,
speed = speed,
)
/**
* 创建一个 switch choice。
*/
override fun createSwitchChoice(
sideId: String,
outgoingUnitId: String,
incomingUnitId: String,
priority: Int,
speed: Int,
): SwitchChoice =
choiceFactory.createSwitchChoice(
sideId = sideId,
outgoingUnitId = outgoingUnitId,
incomingUnitId = incomingUnitId,
priority = priority,
speed = speed,
)
/**
* 创建一个 run choice。
*/
override fun createRunChoice(
sideId: String,
priority: Int,
speed: Int,
): RunChoice =
choiceFactory.createRunChoice(
sideId = sideId,
priority = priority,
speed = speed,
)
/**
* 创建一个 wait choice。
*/
override fun createWaitChoice(
unitId: String,
priority: Int,
speed: Int,
): WaitChoice =
choiceFactory.createWaitChoice(
unitId = unitId,
priority = priority,
speed = speed,
)
/**
* 创建一个 move action。
*/
override 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 =
actionFactory.createMoveAction(
moveId = moveId,
attackerId = attackerId,
targetId = targetId,
priority = priority,
speed = speed,
accuracy = accuracy,
evasion = evasion,
basePower = basePower,
damage = damage,
attributes = attributes,
)
/**
* 创建一个 item action。
*/
override fun createItemAction(
itemId: String,
actorUnitId: String,
targetId: String,
priority: Int,
speed: Int,
attributes: Map<String, Any?>,
): BattleSessionItemAction =
actionFactory.createItemAction(
itemId = itemId,
actorUnitId = actorUnitId,
targetId = targetId,
priority = priority,
speed = speed,
attributes = attributes,
)
/**
* 创建一个 capture action。
*/
override fun createCaptureAction(
playerId: String,
ballItemId: String,
sourceUnitId: String,
targetId: String,
priority: Int,
speed: Int,
): BattleSessionCaptureAction =
actionFactory.createCaptureAction(
playerId = playerId,
ballItemId = ballItemId,
sourceUnitId = sourceUnitId,
targetId = targetId,
priority = priority,
speed = speed,
)
/**
* 创建一个 switch action。
*/
override fun createSwitchAction(
sideId: String,
outgoingUnitId: String,
incomingUnitId: String,
priority: Int,
speed: Int,
): BattleSessionSwitchAction =
actionFactory.createSwitchAction(
sideId = sideId,
outgoingUnitId = outgoingUnitId,
incomingUnitId = incomingUnitId,
priority = priority,
speed = speed,
)
/**
* 创建一个 run action。
*/
override fun createRunAction(
sideId: String,
priority: Int,
speed: Int,
): BattleSessionRunAction =
actionFactory.createRunAction(
sideId = sideId,
priority = priority,
speed = speed,
)
/**
* 创建一个 wait action。
*/
override fun createWaitAction(
unitId: String,
priority: Int,
speed: Int,
): BattleSessionWaitAction =
actionFactory.createWaitAction(
unitId = unitId,
priority = priority,
speed = speed,
)
/**
* 由统一 choice 创建对应的 action。
*/
override fun createAction(choice: BattleSessionChoice): BattleSessionAction = choiceActionMapper.createAction(choice)
}