Documentation ¶
Index ¶
- type TurnBased
- func (slf *TurnBased[CampID, EntityID, Camp, Entity]) AddCamp(camp Camp, entity Entity, entities ...Entity)
- func (slf *TurnBased[CampID, EntityID, Camp, Entity]) Close()
- func (slf TurnBased) OnTurnBasedEntityActionFinishEvent(controller TurnBasedControllerInfo[CampID, EntityID, Camp, Entity])
- func (slf TurnBased) OnTurnBasedEntityActionSubmitEvent(controller TurnBasedControllerInfo[CampID, EntityID, Camp, Entity])
- func (slf TurnBased) OnTurnBasedEntityActionTimeoutEvent(controller TurnBasedControllerInfo[CampID, EntityID, Camp, Entity])
- func (slf TurnBased) OnTurnBasedEntitySwitchEvent(controller TurnBasedControllerAction[CampID, EntityID, Camp, Entity])
- func (slf TurnBased) OnTurnBasedRoundChangeEvent(controller TurnBasedControllerInfo[CampID, EntityID, Camp, Entity])
- func (slf TurnBased) RegTurnBasedEntityActionFinishEvent(...)
- func (slf TurnBased) RegTurnBasedEntityActionSubmitEvent(...)
- func (slf TurnBased) RegTurnBasedEntityActionTimeoutEvent(...)
- func (slf TurnBased) RegTurnBasedEntitySwitchEvent(handler TurnBasedEntitySwitchEventHandler[CampID, EntityID, Camp, Entity])
- func (slf TurnBased) RegTurnBasedRoundChangeEvent(handler TurnBasedRoundChangeEventHandler[CampID, EntityID, Camp, Entity])
- func (slf *TurnBased[CampID, EntityID, Camp, Entity]) Run()
- func (slf *TurnBased[CampID, EntityID, Camp, Entity]) SetActionTimeout(actionTimeoutHandler func(Camp, Entity) time.Duration)
- type TurnBasedController
- func (slf *TurnBasedController[CampID, EntityID, Camp, Entity]) Finish()
- func (slf *TurnBasedController[CampID, EntityID, Camp, Entity]) GetActionEndTime() time.Time
- func (slf *TurnBasedController[CampID, EntityID, Camp, Entity]) GetActionStartTime() time.Time
- func (slf *TurnBasedController[CampID, EntityID, Camp, Entity]) GetActionTimeoutDuration() time.Duration
- func (slf *TurnBasedController[CampID, EntityID, Camp, Entity]) GetCamp() Camp
- func (slf *TurnBasedController[CampID, EntityID, Camp, Entity]) GetEntity() Entity
- func (slf *TurnBasedController[CampID, EntityID, Camp, Entity]) GetRound() int
- func (slf *TurnBasedController[CampID, EntityID, Camp, Entity]) Refresh(duration time.Duration) time.Time
- func (slf *TurnBasedController[CampID, EntityID, Camp, Entity]) Stop()
- type TurnBasedControllerAction
- type TurnBasedControllerInfo
- type TurnBasedEntityActionFinishEventHandler
- type TurnBasedEntityActionSubmitEventHandler
- type TurnBasedEntityActionTimeoutEventHandler
- type TurnBasedEntitySwitchEventHandler
- type TurnBasedRoundChangeEventHandler
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type TurnBased ¶ added in v0.2.7
type TurnBased[CampID, EntityID comparable, Camp generic.IdR[CampID], Entity generic.IdR[EntityID]] struct { // contains filtered or unexported fields }
TurnBased 回合制
func NewTurnBased ¶ added in v0.2.7
func NewTurnBased[CampID, EntityID comparable, Camp generic.IdR[CampID], Entity generic.IdR[EntityID]](calcNextTurnDuration func(Camp, Entity) time.Duration) *TurnBased[CampID, EntityID, Camp, Entity]
NewTurnBased 创建一个新的回合制
- calcNextTurnDuration 将返回下一次行动时间间隔,适用于按照速度计算下一次行动时间间隔的情况。当返回 0 时,将使用默认的行动超时时间
func (*TurnBased[CampID, EntityID, Camp, Entity]) AddCamp ¶ added in v0.2.7
func (slf *TurnBased[CampID, EntityID, Camp, Entity]) AddCamp(camp Camp, entity Entity, entities ...Entity)
AddCamp 添加阵营
func (*TurnBased[CampID, EntityID, Camp, Entity]) Close ¶ added in v0.2.7
func (slf *TurnBased[CampID, EntityID, Camp, Entity]) Close()
Close 关闭回合制
func (TurnBased) OnTurnBasedEntityActionFinishEvent ¶ added in v0.2.7
func (slf TurnBased) OnTurnBasedEntityActionFinishEvent(controller TurnBasedControllerInfo[CampID, EntityID, Camp, Entity])
OnTurnBasedEntityActionFinishEvent 触发回合制实体行动结束事件
func (TurnBased) OnTurnBasedEntityActionSubmitEvent ¶ added in v0.2.7
func (slf TurnBased) OnTurnBasedEntityActionSubmitEvent(controller TurnBasedControllerInfo[CampID, EntityID, Camp, Entity])
OnTurnBasedEntityActionSubmitEvent 触发回合制实体行动提交事件
func (TurnBased) OnTurnBasedEntityActionTimeoutEvent ¶ added in v0.2.7
func (slf TurnBased) OnTurnBasedEntityActionTimeoutEvent(controller TurnBasedControllerInfo[CampID, EntityID, Camp, Entity])
OnTurnBasedEntityActionTimeoutEvent 触发回合制实体行动超时事件
func (TurnBased) OnTurnBasedEntitySwitchEvent ¶ added in v0.2.7
func (slf TurnBased) OnTurnBasedEntitySwitchEvent(controller TurnBasedControllerAction[CampID, EntityID, Camp, Entity])
OnTurnBasedEntitySwitchEvent 触发回合制实体切换事件
func (TurnBased) OnTurnBasedRoundChangeEvent ¶ added in v0.2.7
func (slf TurnBased) OnTurnBasedRoundChangeEvent(controller TurnBasedControllerInfo[CampID, EntityID, Camp, Entity])
OnTurnBasedRoundChangeEvent 触发回合制回合变更事件
func (TurnBased) RegTurnBasedEntityActionFinishEvent ¶ added in v0.2.7
func (slf TurnBased) RegTurnBasedEntityActionFinishEvent(handler TurnBasedEntityActionFinishEventHandler[CampID, EntityID, Camp, Entity])
RegTurnBasedEntityActionFinishEvent 注册回合制实体行动结束事件处理函数,该处理函数将在实体行动结束时触发
func (TurnBased) RegTurnBasedEntityActionSubmitEvent ¶ added in v0.2.7
func (slf TurnBased) RegTurnBasedEntityActionSubmitEvent(handler TurnBasedEntityActionSubmitEventHandler[CampID, EntityID, Camp, Entity])
RegTurnBasedEntityActionSubmitEvent 注册回合制实体行动提交事件处理函数,该处理函数将在实体行动提交时触发
- 该事件将在实体以任意方式结束行动时触发,包括正常结束、超时结束等
- 该事件会在原本的行动结束事件之后触发
func (TurnBased) RegTurnBasedEntityActionTimeoutEvent ¶ added in v0.2.7
func (slf TurnBased) RegTurnBasedEntityActionTimeoutEvent(handler TurnBasedEntityActionTimeoutEventHandler[CampID, EntityID, Camp, Entity])
RegTurnBasedEntityActionTimeoutEvent 注册回合制实体行动超时事件处理函数,该处理函数将在实体行动超时时触发
func (TurnBased) RegTurnBasedEntitySwitchEvent ¶ added in v0.2.7
func (slf TurnBased) RegTurnBasedEntitySwitchEvent(handler TurnBasedEntitySwitchEventHandler[CampID, EntityID, Camp, Entity])
RegTurnBasedEntitySwitchEvent 注册回合制实体切换事件处理函数,该处理函数将在切换到实体切换为操作时机时触发
- 刚函数通常仅用于告知当前操作实体已经完成切换,适合做一些前置校验,但不应该在该函数中执行长时间阻塞操作
- 操作计时将在该函数执行完毕后开始
场景:
- 回合开始,如果该实体被标记为已死亡,则跳过该实体
func (TurnBased) RegTurnBasedRoundChangeEvent ¶ added in v0.2.7
func (slf TurnBased) RegTurnBasedRoundChangeEvent(handler TurnBasedRoundChangeEventHandler[CampID, EntityID, Camp, Entity])
RegTurnBasedRoundChangeEvent 注册回合制回合变更事件处理函数,该处理函数将在回合变更时触发
func (*TurnBased[CampID, EntityID, Camp, Entity]) Run ¶ added in v0.2.7
func (slf *TurnBased[CampID, EntityID, Camp, Entity]) Run()
Run 运行
func (*TurnBased[CampID, EntityID, Camp, Entity]) SetActionTimeout ¶ added in v0.2.7
func (slf *TurnBased[CampID, EntityID, Camp, Entity]) SetActionTimeout(actionTimeoutHandler func(Camp, Entity) time.Duration)
SetActionTimeout 设置行动超时时间处理函数
- 默认情况下行动超时时间函数将始终返回 0
type TurnBasedController ¶ added in v0.2.7
type TurnBasedController[CampID, EntityID comparable, Camp generic.IdR[CampID], Entity generic.IdR[EntityID]] struct { // contains filtered or unexported fields }
TurnBasedController 回合制控制器
func (*TurnBasedController[CampID, EntityID, Camp, Entity]) Finish ¶ added in v0.2.7
func (slf *TurnBasedController[CampID, EntityID, Camp, Entity]) Finish()
Finish 结束当前操作,将立即切换到下一个操作实体
func (*TurnBasedController[CampID, EntityID, Camp, Entity]) GetActionEndTime ¶ added in v0.2.7
func (slf *TurnBasedController[CampID, EntityID, Camp, Entity]) GetActionEndTime() time.Time
GetActionEndTime 获取当前行动结束时间
func (*TurnBasedController[CampID, EntityID, Camp, Entity]) GetActionStartTime ¶ added in v0.2.7
func (slf *TurnBasedController[CampID, EntityID, Camp, Entity]) GetActionStartTime() time.Time
GetActionStartTime 获取当前行动开始时间
func (*TurnBasedController[CampID, EntityID, Camp, Entity]) GetActionTimeoutDuration ¶ added in v0.2.7
func (slf *TurnBasedController[CampID, EntityID, Camp, Entity]) GetActionTimeoutDuration() time.Duration
GetActionTimeoutDuration 获取当前行动超时时长
func (*TurnBasedController[CampID, EntityID, Camp, Entity]) GetCamp ¶ added in v0.2.7
func (slf *TurnBasedController[CampID, EntityID, Camp, Entity]) GetCamp() Camp
GetCamp 获取当前操作阵营
func (*TurnBasedController[CampID, EntityID, Camp, Entity]) GetEntity ¶ added in v0.2.7
func (slf *TurnBasedController[CampID, EntityID, Camp, Entity]) GetEntity() Entity
GetEntity 获取当前操作实体
func (*TurnBasedController[CampID, EntityID, Camp, Entity]) GetRound ¶ added in v0.2.7
func (slf *TurnBasedController[CampID, EntityID, Camp, Entity]) GetRound() int
GetRound 获取当前回合数
func (*TurnBasedController[CampID, EntityID, Camp, Entity]) Refresh ¶ added in v0.2.7
func (slf *TurnBasedController[CampID, EntityID, Camp, Entity]) Refresh(duration time.Duration) time.Time
Refresh 刷新当前操作实体的行动超时时间
- 当不在行动阶段时,将返回 time.Time 零值
func (*TurnBasedController[CampID, EntityID, Camp, Entity]) Stop ¶ added in v0.2.7
func (slf *TurnBasedController[CampID, EntityID, Camp, Entity]) Stop()
Stop 在当前回合执行完毕后停止回合进程
type TurnBasedControllerAction ¶ added in v0.2.7
type TurnBasedControllerAction[CampID, EntityID comparable, Camp generic.IdR[CampID], Entity generic.IdR[EntityID]] interface { TurnBasedControllerInfo[CampID, EntityID, Camp, Entity] // Finish 结束当前操作,将立即切换到下一个操作实体 Finish() // Refresh 刷新当前操作实体的行动超时时间并返回新的行动超时时间 Refresh(duration time.Duration) time.Time }
type TurnBasedControllerInfo ¶ added in v0.2.7
type TurnBasedControllerInfo[CampID, EntityID comparable, Camp generic.IdR[CampID], Entity generic.IdR[EntityID]] interface { // GetRound 获取当前回合数 GetRound() int // GetCamp 获取当前操作阵营 GetCamp() Camp // GetEntity 获取当前操作实体 GetEntity() Entity // GetActionTimeoutDuration 获取当前行动超时时长 GetActionTimeoutDuration() time.Duration // GetActionStartTime 获取当前行动开始时间 GetActionStartTime() time.Time // GetActionEndTime 获取当前行动结束时间 GetActionEndTime() time.Time // Stop 在当前回合执行完毕后停止回合进程 Stop() }
type TurnBasedEntityActionFinishEventHandler ¶ added in v0.2.7
type TurnBasedEntityActionFinishEventHandler[CampID, EntityID comparable, Camp generic.IdR[CampID], Entity generic.IdR[EntityID]] func(controller TurnBasedControllerInfo[CampID, EntityID, Camp, Entity])
type TurnBasedEntityActionSubmitEventHandler ¶ added in v0.2.7
type TurnBasedEntityActionSubmitEventHandler[CampID, EntityID comparable, Camp generic.IdR[CampID], Entity generic.IdR[EntityID]] func(controller TurnBasedControllerInfo[CampID, EntityID, Camp, Entity])
type TurnBasedEntityActionTimeoutEventHandler ¶ added in v0.2.7
type TurnBasedEntityActionTimeoutEventHandler[CampID, EntityID comparable, Camp generic.IdR[CampID], Entity generic.IdR[EntityID]] func(controller TurnBasedControllerInfo[CampID, EntityID, Camp, Entity])
type TurnBasedEntitySwitchEventHandler ¶ added in v0.2.7
type TurnBasedEntitySwitchEventHandler[CampID, EntityID comparable, Camp generic.IdR[CampID], Entity generic.IdR[EntityID]] func(controller TurnBasedControllerAction[CampID, EntityID, Camp, Entity])
type TurnBasedRoundChangeEventHandler ¶ added in v0.2.7
type TurnBasedRoundChangeEventHandler[CampID, EntityID comparable, Camp generic.IdR[CampID], Entity generic.IdR[EntityID]] func(controller TurnBasedControllerInfo[CampID, EntityID, Camp, Entity])