fight

package
v0.2.8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 31, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Round

type Round[Data RoundData] struct {
	// contains filtered or unexported fields
}

Round 回合制游戏结构

func NewRound deprecated

func NewRound[Data RoundData](data Data, camps []*RoundCamp, roundGameOverVerifyHandle RoundGameOverVerifyHandle[Data], options ...RoundOption[Data]) *Round[Data]

NewRound 创建一个新的回合制游戏

  • data 游戏数据
  • camps 阵营
  • roundGameOverVerifyHandle 游戏结束验证函数
  • options 选项

Deprecated: 从 Minotaur 0.2.7 开始,由于设计原因已弃用,请尝试考虑使用 fight.TurnBased 进行代替

func (*Round[Data]) ActionFinish

func (slf *Round[Data]) ActionFinish()

ActionFinish 结束行动

func (*Round[Data]) ActionRefresh

func (slf *Round[Data]) ActionRefresh()

ActionRefresh 刷新行动超时时间

func (*Round[Data]) AllowAction

func (slf *Round[Data]) AllowAction(camp, entity int) bool

AllowAction 是否允许行动

func (*Round[Data]) CampAllowAction

func (slf *Round[Data]) CampAllowAction(camp int) bool

CampAllowAction 阵容是否允许行动

func (*Round[Data]) GetActionTimeoutTime added in v0.0.24

func (slf *Round[Data]) GetActionTimeoutTime() int64

GetActionTimeoutTime 获取行动超时时间

func (*Round[Data]) GetCurrent

func (slf *Round[Data]) GetCurrent() (camp, entity int)

GetCurrent 获取当前行动的阵营和对象

func (*Round[Data]) GetCurrentCamp

func (slf *Round[Data]) GetCurrentCamp() int

GetCurrentCamp 获取当前行动的阵营

func (*Round[Data]) GetCurrentRoundProgressRate

func (slf *Round[Data]) GetCurrentRoundProgressRate() float64

GetCurrentRoundProgressRate 获取当前回合进度

func (*Round[Data]) GetData

func (slf *Round[Data]) GetData() Data

GetData 获取游戏数据

func (*Round[Data]) GetRound

func (slf *Round[Data]) GetRound() int

GetRound 获取当前回合数

func (*Round[Data]) OnActionRefreshEvent added in v0.0.24

func (slf *Round[Data]) OnActionRefreshEvent()

OnActionRefreshEvent 触发行动刷新事件

func (*Round[Data]) OnActionTimeoutEvent

func (slf *Round[Data]) OnActionTimeoutEvent()

OnActionTimeoutEvent 触发行动超时事件

func (*Round[Data]) OnChangeEvent

func (slf *Round[Data]) OnChangeEvent()

OnChangeEvent 触发回合变更事件

func (*Round[Data]) OnGameOverEvent

func (slf *Round[Data]) OnGameOverEvent()

OnGameOverEvent 触发游戏结束事件

func (*Round[Data]) OnSwapCampEvent

func (slf *Round[Data]) OnSwapCampEvent()

OnSwapCampEvent 触发阵营交换事件

func (*Round[Data]) OnSwapEntityEvent

func (slf *Round[Data]) OnSwapEntityEvent()

OnSwapEntityEvent 触发实体交换事件

func (*Round[Data]) Release

func (slf *Round[Data]) Release()

Release 释放资源

func (*Round[Data]) Reset added in v0.0.24

func (slf *Round[Data]) Reset()

Reset 重置回合

func (*Round[Data]) SetCurrent

func (slf *Round[Data]) SetCurrent(campId int, entityId int)

SetCurrent 设置当前行动对象

func (*Round[Data]) SkipCamp

func (slf *Round[Data]) SkipCamp()

SkipCamp 跳过当前阵营剩余对象的行动

func (*Round[Data]) Start added in v0.0.24

func (slf *Round[Data]) Start()

Start 开始回合

  • 将通过传入的 Camp 进行初始化,Camp 为一个二维数组,每个数组内的元素都是一个行动标识

func (*Round[Data]) Stop added in v0.0.24

func (slf *Round[Data]) Stop()

Stop 停止回合

  • 停止回合时仅会停止行动超时计时器,其他所有数据均会保留
  • 若要重置回合,需要调用 Reset 方法

type RoundActionRefreshEvent added in v0.0.24

type RoundActionRefreshEvent[Data RoundData] func(round *Round[Data], campId, entity int)

type RoundActionTimeoutEvent

type RoundActionTimeoutEvent[Data RoundData] func(round *Round[Data], campId, entity int)

type RoundCamp

type RoundCamp struct {
	// contains filtered or unexported fields
}

RoundCamp 回合制游戏阵营

func NewRoundCamp

func NewRoundCamp(campId, entity int, entities ...int) *RoundCamp

NewRoundCamp 创建一个新的回合制游戏阵营

type RoundChangeEvent

type RoundChangeEvent[Data RoundData] func(round *Round[Data])

type RoundData

type RoundData interface {
}

RoundData 回合制游戏数据

type RoundGameOverEvent

type RoundGameOverEvent[Data RoundData] func(round *Round[Data])

type RoundGameOverVerifyHandle

type RoundGameOverVerifyHandle[Data RoundData] func(round *Round[Data]) bool

RoundGameOverVerifyHandle 回合制游戏结束验证函数

type RoundOption

type RoundOption[Data RoundData] func(round *Round[Data])

RoundOption 回合制游戏选项

func WithRoundActionRefreshEvent added in v0.0.24

func WithRoundActionRefreshEvent[Data RoundData](refreshEventHandle RoundActionRefreshEvent[Data]) RoundOption[Data]

WithRoundActionRefreshEvent 设置游戏的行动刷新事件

func WithRoundActionTimeout

func WithRoundActionTimeout[Data RoundData](timeout time.Duration) RoundOption[Data]

WithRoundActionTimeout 设置游戏的行动超时时间

func WithRoundActionTimeoutEvent

func WithRoundActionTimeoutEvent[Data RoundData](timeoutEventHandle RoundActionTimeoutEvent[Data]) RoundOption[Data]

WithRoundActionTimeoutEvent 设置游戏的超时事件

func WithRoundCampCounterclockwise

func WithRoundCampCounterclockwise[Data RoundData]() RoundOption[Data]

WithRoundCampCounterclockwise 设置游戏阵营逆序执行

func WithRoundChangeEvent

func WithRoundChangeEvent[Data RoundData](changeEventHandle RoundChangeEvent[Data]) RoundOption[Data]

WithRoundChangeEvent 设置游戏的回合变更事件

  • 该事件在触发时已经完成了回合的变更

func WithRoundEntityCounterclockwise

func WithRoundEntityCounterclockwise[Data RoundData]() RoundOption[Data]

WithRoundEntityCounterclockwise 设置游戏实体逆序执行

func WithRoundGameOverEvent

func WithRoundGameOverEvent[Data RoundData](gameOverEventHandle RoundGameOverEvent[Data]) RoundOption[Data]

WithRoundGameOverEvent 设置游戏的结束事件

func WithRoundShareAction

func WithRoundShareAction[Data RoundData](share bool) RoundOption[Data]

WithRoundShareAction 设置游戏的行动是否共享

func WithRoundSwapCampEvent

func WithRoundSwapCampEvent[Data RoundData](swapCampEventHandle RoundSwapCampEvent[Data]) RoundOption[Data]

WithRoundSwapCampEvent 设置游戏的阵营交换事件

  • 该事件在触发时已经完成了阵营的交换

func WithRoundSwapEntityEvent

func WithRoundSwapEntityEvent[Data RoundData](swapEntityEventHandle RoundSwapEntityEvent[Data]) RoundOption[Data]

WithRoundSwapEntityEvent 设置游戏的实体交换事件

  • 该事件在触发时已经完成了实体的交换

func WithRoundTicker

func WithRoundTicker[Data RoundData](ticker *timer.Ticker) RoundOption[Data]

WithRoundTicker 设置游戏的计时器

type RoundSwapCampEvent

type RoundSwapCampEvent[Data RoundData] func(round *Round[Data], campId int)

type RoundSwapEntityEvent

type RoundSwapEntityEvent[Data RoundData] func(round *Round[Data], campId, entity int)

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])

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL