builtin

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2023 License: MIT Imports: 21 Imported by: 0

Documentation

Overview

Package builtin 包含了通用游戏相关的接口的内置实现

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrCannotAddNegativeOrZeroItem = errors.New("cannot add items with negative quantities or zero")
	ErrItemNotExist                = errors.New("item not exist")
	ErrItemInsufficientQuantity    = errors.New("item insufficient quantity")
	ErrItemContainerIsFull         = errors.New("item container is full")
	ErrItemContainerNotExist       = errors.New("item container not exist")
)
View Source
var (
	ErrRankingListNotExistCompetitor = errors.New("ranking list not exist competitor")
	ErrRankingListIndexErr           = errors.New("ranking list index error")
	ErrRankingListNonexistentRanking = errors.New("nonexistent ranking")
)
View Source
var (
	ErrRoomPlayerLimit = errors.New("the number of players in the room has reached the upper limit") // 玩家数量达到上限
	ErrRoomNoHasMaster = errors.New("room not has master, can't kick player")
	ErrRoomNotIsOwner  = errors.New("not is room owner, can't kick player")
)
View Source
var (
	ErrWorldPlayerLimit = errors.New("the number of players in the world has reached the upper limit") // 玩家数量达到上限
	ErrWorldReleased    = errors.New("the world has been released")                                    // 世界已被释放
)
View Source
var (
	ErrRoomNotHasPlayer = errors.New("player not exist")
)

Functions

This section is empty.

Types

type AOI2D

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

func NewAOI2D

func NewAOI2D(width, height, areaWidth, areaHeight int) *AOI2D

func (*AOI2D) AddEntity

func (slf *AOI2D) AddEntity(entity game.AOIEntity2D)

func (*AOI2D) DeleteEntity

func (slf *AOI2D) DeleteEntity(entity game.AOIEntity2D)

func (*AOI2D) GetFocus

func (slf *AOI2D) GetFocus(guid int64) map[int64]game.AOIEntity2D

func (*AOI2D) OnEntityJoinVisionEvent

func (slf *AOI2D) OnEntityJoinVisionEvent(entity, target game.AOIEntity2D)

func (*AOI2D) OnEntityLeaveVisionEvent

func (slf *AOI2D) OnEntityLeaveVisionEvent(entity, target game.AOIEntity2D)

func (*AOI2D) Refresh

func (slf *AOI2D) Refresh(entity game.AOIEntity2D)

func (*AOI2D) RegEntityJoinVisionEvent

func (slf *AOI2D) RegEntityJoinVisionEvent(handle game.EntityJoinVisionEventHandle)

func (*AOI2D) RegEntityLeaveVisionEvent

func (slf *AOI2D) RegEntityLeaveVisionEvent(handle game.EntityLeaveVisionEventHandle)

func (*AOI2D) SetAreaSize

func (slf *AOI2D) SetAreaSize(width, height int)

func (*AOI2D) SetSize

func (slf *AOI2D) SetSize(width, height int)

type Actor

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

func NewActor

func NewActor(guid int64) *Actor

func (*Actor) GetGuid

func (slf *Actor) GetGuid() int64

func (*Actor) SetGuid

func (slf *Actor) SetGuid(guid int64)

type Attrs

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

func NewAttrs

func NewAttrs() *Attrs

func (*Attrs) ChangeAttrFloat32

func (slf *Attrs) ChangeAttrFloat32(id int, value float32)

func (*Attrs) ChangeAttrFloat64

func (slf *Attrs) ChangeAttrFloat64(id int, value float64)

func (*Attrs) ChangeAttrHugeInt

func (slf *Attrs) ChangeAttrHugeInt(id int, value *huge.Int)

func (*Attrs) ChangeAttrInt

func (slf *Attrs) ChangeAttrInt(id int, value int)

func (*Attrs) ChangeAttrInt16

func (slf *Attrs) ChangeAttrInt16(id int, value int16)

func (*Attrs) ChangeAttrInt32

func (slf *Attrs) ChangeAttrInt32(id int, value int32)

func (*Attrs) ChangeAttrInt64

func (slf *Attrs) ChangeAttrInt64(id int, value int64)

func (*Attrs) ChangeAttrInt8

func (slf *Attrs) ChangeAttrInt8(id int, value int8)

func (*Attrs) ChangeAttrUint

func (slf *Attrs) ChangeAttrUint(id int, value uint)

func (*Attrs) ChangeAttrUint16

func (slf *Attrs) ChangeAttrUint16(id int, value uint16)

func (*Attrs) ChangeAttrUint32

func (slf *Attrs) ChangeAttrUint32(id int, value uint32)

func (*Attrs) ChangeAttrUint64

func (slf *Attrs) ChangeAttrUint64(id int, value uint64)

func (*Attrs) ChangeAttrUint8

func (slf *Attrs) ChangeAttrUint8(id int, value uint8)

func (*Attrs) GetAttrFloat32

func (slf *Attrs) GetAttrFloat32(id int) float32

func (*Attrs) GetAttrFloat64

func (slf *Attrs) GetAttrFloat64(id int) float64

func (*Attrs) GetAttrHugeInt

func (slf *Attrs) GetAttrHugeInt(id int) *huge.Int

func (*Attrs) GetAttrInt

func (slf *Attrs) GetAttrInt(id int) int

func (*Attrs) GetAttrInt16

func (slf *Attrs) GetAttrInt16(id int) int16

func (*Attrs) GetAttrInt32

func (slf *Attrs) GetAttrInt32(id int) int32

func (*Attrs) GetAttrInt64

func (slf *Attrs) GetAttrInt64(id int) int64

func (*Attrs) GetAttrInt8

func (slf *Attrs) GetAttrInt8(id int) int8

func (*Attrs) GetAttrUint

func (slf *Attrs) GetAttrUint(id int) uint

func (*Attrs) GetAttrUint16

func (slf *Attrs) GetAttrUint16(id int) uint16

func (*Attrs) GetAttrUint32

func (slf *Attrs) GetAttrUint32(id int) uint32

func (*Attrs) GetAttrUint64

func (slf *Attrs) GetAttrUint64(id int) uint64

func (*Attrs) GetAttrUint8

func (slf *Attrs) GetAttrUint8(id int) uint8

func (*Attrs) OnAttrChangeEvent

func (slf *Attrs) OnAttrChangeEvent(id int)

func (*Attrs) OnAttrIdChangeEvent

func (slf *Attrs) OnAttrIdChangeEvent(id int)

func (*Attrs) RegAttrChangeEvent

func (slf *Attrs) RegAttrChangeEvent(handle game.AttrChangeEventHandle)

func (*Attrs) RegAttrIdChangeEvent

func (slf *Attrs) RegAttrIdChangeEvent(id int, handle game.AttrChangeEventHandle)

func (*Attrs) SetAttrFloat32

func (slf *Attrs) SetAttrFloat32(id int, value float32)

func (*Attrs) SetAttrFloat64

func (slf *Attrs) SetAttrFloat64(id int, value float64)

func (*Attrs) SetAttrHugeInt

func (slf *Attrs) SetAttrHugeInt(id int, value *huge.Int)

func (*Attrs) SetAttrInt

func (slf *Attrs) SetAttrInt(id int, value int)

func (*Attrs) SetAttrInt16

func (slf *Attrs) SetAttrInt16(id int, value int16)

func (*Attrs) SetAttrInt32

func (slf *Attrs) SetAttrInt32(id int, value int32)

func (*Attrs) SetAttrInt64

func (slf *Attrs) SetAttrInt64(id int, value int64)

func (*Attrs) SetAttrInt8

func (slf *Attrs) SetAttrInt8(id int, value int8)

func (*Attrs) SetAttrUint

func (slf *Attrs) SetAttrUint(id int, value uint)

func (*Attrs) SetAttrUint16

func (slf *Attrs) SetAttrUint16(id int, value uint16)

func (*Attrs) SetAttrUint32

func (slf *Attrs) SetAttrUint32(id int, value uint32)

func (*Attrs) SetAttrUint64

func (slf *Attrs) SetAttrUint64(id int, value uint64)

func (*Attrs) SetAttrUint8

func (slf *Attrs) SetAttrUint8(id int, value uint8)

type FSM

type FSM[State comparable, Data any] struct {
	// contains filtered or unexported fields
}

func NewFSM

func NewFSM[State comparable, Data any](data Data) *FSM[State, Data]

func (*FSM[State, Data]) Change

func (slf *FSM[State, Data]) Change(state State)

func (*FSM[State, Data]) HasState

func (slf *FSM[State, Data]) HasState(state State) bool

func (*FSM[State, Data]) Register

func (slf *FSM[State, Data]) Register(state game.FSMState[State, Data])

func (*FSM[State, Data]) Unregister

func (slf *FSM[State, Data]) Unregister(state State)

func (*FSM[State, Data]) Update

func (slf *FSM[State, Data]) Update()

type FSMState

type FSMState[State comparable, Data any] struct {
	// contains filtered or unexported fields
}

func NewFSMState

func NewFSMState[State comparable, Data any](state State, enter game.FSMStateEnterHandle[Data], update game.FSMStateUpdateHandle[Data], exit game.FSMStateExitHandle[Data]) *FSMState[State, Data]

func (*FSMState[State, Data]) Enter

func (slf *FSMState[State, Data]) Enter(data Data)

func (*FSMState[State, Data]) Exit

func (slf *FSMState[State, Data]) Exit(data Data)

func (*FSMState[State, Data]) GetState

func (slf *FSMState[State, Data]) GetState() State

func (*FSMState[State, Data]) Update

func (slf *FSMState[State, Data]) Update(data Data)

type Gameplay

type Gameplay struct {
	*offset.Time
	// contains filtered or unexported fields
}

func NewGameplay

func NewGameplay() *Gameplay

func (*Gameplay) GameStart

func (slf *Gameplay) GameStart(handle func() error) error

func (*Gameplay) GetCurrentTime

func (slf *Gameplay) GetCurrentTime() time.Time

func (*Gameplay) GetTime

func (slf *Gameplay) GetTime() *offset.Time

func (*Gameplay) OnGameplayReleaseEvent

func (slf *Gameplay) OnGameplayReleaseEvent()

func (*Gameplay) OnGameplayStartEvent

func (slf *Gameplay) OnGameplayStartEvent()

func (*Gameplay) OnGameplayTimeChangeEvent

func (slf *Gameplay) OnGameplayTimeChangeEvent()

func (*Gameplay) RegGameplayReleaseEvent

func (slf *Gameplay) RegGameplayReleaseEvent(handle game.GameplayReleaseEventHandle)

func (*Gameplay) RegGameplayStartEvent

func (slf *Gameplay) RegGameplayStartEvent(handle game.GameplayStartEventHandle)

func (*Gameplay) RegGameplayTimeChangeEvent

func (slf *Gameplay) RegGameplayTimeChangeEvent(handle game.GameplayTimeChangeEventHandle)

func (*Gameplay) Release

func (slf *Gameplay) Release()

func (*Gameplay) SetTimeOffset

func (slf *Gameplay) SetTimeOffset(offset time.Duration)

type GameplayOver

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

func NewGameplayOver

func NewGameplayOver() *GameplayOver

func (*GameplayOver) GameOver

func (slf *GameplayOver) GameOver()

func (*GameplayOver) OnGameplayOverEvent

func (slf *GameplayOver) OnGameplayOverEvent()

func (*GameplayOver) RegGameplayOverEvent

func (slf *GameplayOver) RegGameplayOverEvent(handle game.GameplayOverEventHandle)

type GameplayTime

type GameplayTime struct {
	game.Gameplay
	game.GameplayOver
	// contains filtered or unexported fields
}

func NewGameplayTime

func NewGameplayTime(gameplay game.Gameplay, gameplayOver game.GameplayOver, options ...GameplayTimeOption) *GameplayTime

func (*GameplayTime) ChangeEndTime

func (slf *GameplayTime) ChangeEndTime(d time.Duration)

func (*GameplayTime) GetEndTime

func (slf *GameplayTime) GetEndTime() time.Time

func (*GameplayTime) Release

func (slf *GameplayTime) Release()

func (*GameplayTime) SetEndTime

func (slf *GameplayTime) SetEndTime(t time.Time)

type GameplayTimeOption

type GameplayTimeOption func(time *GameplayTime)

func WithGameplayTimeTicker

func WithGameplayTimeTicker(id int64, ticker *timer.Ticker) GameplayTimeOption

func WithGameplayTimeWheelSize

func WithGameplayTimeWheelSize(size int) GameplayTimeOption

type Item

type Item[ItemID comparable] struct {
	// contains filtered or unexported fields
}

func NewItem

func NewItem[ItemID comparable](id ItemID) *Item[ItemID]

func (*Item[ItemID]) GetID

func (slf *Item[ItemID]) GetID() ItemID

func (*Item[ItemID]) IsSame

func (slf *Item[ItemID]) IsSame(item game.Item[ItemID]) bool

type ItemContainer

type ItemContainer[ItemID comparable, Item game.Item[ItemID]] struct {
	// contains filtered or unexported fields
}

func NewItemContainer

func NewItemContainer[ItemID comparable, Item game.Item[ItemID]](options ...ItemContainerOption[ItemID, Item]) *ItemContainer[ItemID, Item]

func (*ItemContainer[ItemID, Item]) AddItem

func (slf *ItemContainer[ItemID, Item]) AddItem(item Item, count *huge.Int) (guid int64, err error)

func (*ItemContainer[ItemID, Item]) CheckAllowAdd

func (slf *ItemContainer[ItemID, Item]) CheckAllowAdd(item Item, count *huge.Int) error

func (*ItemContainer[ItemID, Item]) CheckDeductItem

func (slf *ItemContainer[ItemID, Item]) CheckDeductItem(guid int64, count *huge.Int) error

func (*ItemContainer[ItemID, Item]) Clear

func (slf *ItemContainer[ItemID, Item]) Clear()

func (*ItemContainer[ItemID, Item]) DeductItem

func (slf *ItemContainer[ItemID, Item]) DeductItem(guid int64, count *huge.Int) error

func (*ItemContainer[ItemID, Item]) ExistItem

func (slf *ItemContainer[ItemID, Item]) ExistItem(guid int64) bool

func (*ItemContainer[ItemID, Item]) ExistItemWithID

func (slf *ItemContainer[ItemID, Item]) ExistItemWithID(id ItemID) bool

func (*ItemContainer[ItemID, Item]) GetItem

func (slf *ItemContainer[ItemID, Item]) GetItem(guid int64) (game.ItemContainerMember[ItemID, Item], error)

func (*ItemContainer[ItemID, Item]) GetItems

func (slf *ItemContainer[ItemID, Item]) GetItems() []game.ItemContainerMember[ItemID, Item]

func (*ItemContainer[ItemID, Item]) GetItemsFull

func (slf *ItemContainer[ItemID, Item]) GetItemsFull() []game.ItemContainerMember[ItemID, Item]

func (*ItemContainer[ItemID, Item]) GetItemsMap

func (slf *ItemContainer[ItemID, Item]) GetItemsMap() map[int64]game.ItemContainerMember[ItemID, Item]

func (*ItemContainer[ItemID, Item]) GetSize

func (slf *ItemContainer[ItemID, Item]) GetSize() int

func (*ItemContainer[ItemID, Item]) GetSizeLimit

func (slf *ItemContainer[ItemID, Item]) GetSizeLimit() int

func (*ItemContainer[ItemID, Item]) Remove

func (slf *ItemContainer[ItemID, Item]) Remove(guid int64)

func (*ItemContainer[ItemID, Item]) RemoveWithID

func (slf *ItemContainer[ItemID, Item]) RemoveWithID(id ItemID)

func (*ItemContainer[ItemID, Item]) SetExpandSize

func (slf *ItemContainer[ItemID, Item]) SetExpandSize(size int)

func (*ItemContainer[ItemID, Item]) TransferTo

func (slf *ItemContainer[ItemID, Item]) TransferTo(guid int64, count *huge.Int, target game.ItemContainer[ItemID, Item]) error

type ItemContainerMember

type ItemContainerMember[ItemID comparable, I game.Item[ItemID]] struct {
	// contains filtered or unexported fields
}

func NewItemContainerMember

func NewItemContainerMember[ItemID comparable, I game.Item[ItemID]](guid int64, item I) *ItemContainerMember[ItemID, I]

func (*ItemContainerMember[ItemID, I]) GetCount

func (slf *ItemContainerMember[ItemID, I]) GetCount() *huge.Int

func (*ItemContainerMember[ItemID, I]) GetGUID

func (slf *ItemContainerMember[ItemID, I]) GetGUID() int64

func (*ItemContainerMember[ItemID, I]) GetID

func (slf *ItemContainerMember[ItemID, I]) GetID() ItemID

func (*ItemContainerMember[ItemID, I]) GetItem

func (slf *ItemContainerMember[ItemID, I]) GetItem() I

type ItemContainerOption

type ItemContainerOption[ItemID comparable, Item game.Item[ItemID]] func(container *ItemContainer[ItemID, Item])

func WithItemContainerSizeLimit

func WithItemContainerSizeLimit[ItemID comparable, Item game.Item[ItemID]](sizeLimit int) ItemContainerOption[ItemID, Item]

WithItemContainerSizeLimit 通过特定的物品容器非堆叠数量上限创建物品容器

func WithItemContainerStackLimit

func WithItemContainerStackLimit[ItemID comparable, Item game.Item[ItemID]](id ItemID, stackLimit *huge.Int) ItemContainerOption[ItemID, Item]

WithItemContainerStackLimit 通过设置特定物品堆叠数量创建容器

type Player

type Player[ID comparable] struct {
	// contains filtered or unexported fields
}

Player 游戏玩家

func NewPlayer

func NewPlayer[ID comparable](id ID, conn *server.Conn) *Player[ID]

func (*Player[ID]) Close

func (slf *Player[ID]) Close()

Close 关闭玩家

func (*Player[ID]) GetID

func (slf *Player[ID]) GetID() ID

func (*Player[ID]) Send

func (slf *Player[ID]) Send(packet []byte, messageType ...int)

Send 向该玩家发送数据

func (*Player[ID]) UseConn

func (slf *Player[ID]) UseConn(conn *server.Conn)

type RankingList

type RankingList[CompetitorID comparable, Score generic.Ordered] struct {
	// contains filtered or unexported fields
}

func NewRankingList

func NewRankingList[CompetitorID comparable, Score generic.Ordered](options ...RankingListOption[CompetitorID, Score]) *RankingList[CompetitorID, Score]

NewRankingList 创建一个排名从0开始的排行榜

func (*RankingList[CompetitorID, Score]) Clear

func (slf *RankingList[CompetitorID, Score]) Clear()

func (*RankingList[CompetitorID, Score]) Cmp

func (slf *RankingList[CompetitorID, Score]) Cmp(s1, s2 Score) int

func (*RankingList[CompetitorID, Score]) Competitor

func (slf *RankingList[CompetitorID, Score]) Competitor(competitorId CompetitorID, score Score)

func (*RankingList[CompetitorID, Score]) CompetitorIncrease

func (slf *RankingList[CompetitorID, Score]) CompetitorIncrease(competitorId CompetitorID, score Score)

func (*RankingList[CompetitorID, Score]) GetAllCompetitor

func (slf *RankingList[CompetitorID, Score]) GetAllCompetitor() []CompetitorID

func (*RankingList[CompetitorID, Score]) GetCompetitor

func (slf *RankingList[CompetitorID, Score]) GetCompetitor(rank int) (competitorId CompetitorID, err error)

func (*RankingList[CompetitorID, Score]) GetCompetitorWithRange

func (slf *RankingList[CompetitorID, Score]) GetCompetitorWithRange(start, end int) ([]CompetitorID, error)

func (*RankingList[CompetitorID, Score]) GetRank

func (slf *RankingList[CompetitorID, Score]) GetRank(competitorId CompetitorID) (int, error)

func (*RankingList[CompetitorID, Score]) GetScore

func (slf *RankingList[CompetitorID, Score]) GetScore(competitorId CompetitorID) (score Score, err error)

func (*RankingList[CompetitorID, Score]) MarshalJSON

func (slf *RankingList[CompetitorID, Score]) MarshalJSON() ([]byte, error)

func (*RankingList[CompetitorID, Score]) OnRankChangeEvent

func (slf *RankingList[CompetitorID, Score]) OnRankChangeEvent(competitorId CompetitorID, oldRank, newRank int, oldScore, newScore Score)

func (*RankingList[CompetitorID, Score]) OnRankClearBeforeEvent

func (slf *RankingList[CompetitorID, Score]) OnRankClearBeforeEvent()

func (*RankingList[CompetitorID, Score]) RegRankChangeEvent

func (slf *RankingList[CompetitorID, Score]) RegRankChangeEvent(handle game.RankChangeEventHandle[CompetitorID, Score])

func (*RankingList[CompetitorID, Score]) RegRankClearBeforeEvent

func (slf *RankingList[CompetitorID, Score]) RegRankClearBeforeEvent(handle game.RankClearBeforeEventHandle[CompetitorID, Score])

func (*RankingList[CompetitorID, Score]) RemoveCompetitor

func (slf *RankingList[CompetitorID, Score]) RemoveCompetitor(competitorId CompetitorID)

func (*RankingList[CompetitorID, Score]) Size

func (slf *RankingList[CompetitorID, Score]) Size() int

func (*RankingList[CompetitorID, Score]) UnmarshalJSON

func (slf *RankingList[CompetitorID, Score]) UnmarshalJSON(bytes []byte) error

type RankingListOption

type RankingListOption[CompetitorID comparable, Score generic.Ordered] func(list *RankingList[CompetitorID, Score])

func WithRankingListASC

func WithRankingListASC[CompetitorID comparable, Score generic.Ordered]() RankingListOption[CompetitorID, Score]

WithRankingListASC 通过升序的方式创建排行榜

  • 默认情况下为降序

func WithRankingListCount

func WithRankingListCount[CompetitorID comparable, Score generic.Ordered](rankCount int) RankingListOption[CompetitorID, Score]

WithRankingListCount 通过限制排行榜竞争者数量来创建排行榜

  • 默认情况下允许100位竞争者

type Room

type Room[PlayerID comparable, Player game.Player[PlayerID]] struct {
	// contains filtered or unexported fields
}

Room 默认的内置游戏房间实现

  • 实现了最大人数控制、房主、踢出玩家、玩家维护等功能
  • 支持并发安全和非并发安全的模式

func NewRoom

func NewRoom[PlayerID comparable, Player game.Player[PlayerID]](guid int64, options ...RoomOption[PlayerID, Player]) *Room[PlayerID, Player]

NewRoom 创建一个默认的内置游戏房间 Room

func (*Room[PlayerID, Player]) ChangeOwner

func (slf *Room[PlayerID, Player]) ChangeOwner(id PlayerID)

ChangeOwner 改变房主

  • 当房间为无主模式(WithRoomNoMaster)时,将不会发生任何变化

func (*Room[PlayerID, Player]) GetGuid

func (slf *Room[PlayerID, Player]) GetGuid() int64

GetGuid 获取房间唯一标识

func (*Room[PlayerID, Player]) GetPlayer

func (slf *Room[PlayerID, Player]) GetPlayer(id PlayerID) Player

GetPlayer 根据玩家id获取玩家

func (*Room[PlayerID, Player]) GetPlayerCount

func (slf *Room[PlayerID, Player]) GetPlayerCount() int

GetPlayerCount 获取玩家数量

func (*Room[PlayerID, Player]) GetPlayerLimit

func (slf *Room[PlayerID, Player]) GetPlayerLimit() int

GetPlayerLimit 获取最大玩家上限

func (*Room[PlayerID, Player]) GetPlayers

func (slf *Room[PlayerID, Player]) GetPlayers() hash.MapReadonly[PlayerID, Player]

GetPlayers 获取所有玩家

func (*Room[PlayerID, Player]) IsExistPlayer

func (slf *Room[PlayerID, Player]) IsExistPlayer(id PlayerID) bool

IsExistPlayer 房间内是否存在某玩家

func (*Room[PlayerID, Player]) IsOwner

func (slf *Room[PlayerID, Player]) IsOwner(id PlayerID) bool

IsOwner 检查特定玩家是否是房主

  • 当房间为无主模式(WithRoomNoMaster)时,将会始终返回false

func (*Room[PlayerID, Player]) Join

func (slf *Room[PlayerID, Player]) Join(player Player) error

Join 控制玩家加入到该房间

func (*Room[PlayerID, Player]) KickOut

func (slf *Room[PlayerID, Player]) KickOut(id, target PlayerID, reason string) error

KickOut 以某种原因踢出特定玩家

  • 当设置了房间踢出玩家的检查处理函数(WithRoomKickPlayerCheckHandle)时,将会根据检查结果进行处理,即便是无主模式。其他情况如下
  • 如果是无主模式(WithRoomNoMaster),将会返回错误
  • 如果不是房主发起的踢出玩家,将会返回错误

func (*Room[PlayerID, Player]) Leave

func (slf *Room[PlayerID, Player]) Leave(id PlayerID)

Leave 控制玩家离开房间

func (*Room[PlayerID, Player]) OnPlayerJoinRoomEvent

func (slf *Room[PlayerID, Player]) OnPlayerJoinRoomEvent(player Player)

func (*Room[PlayerID, Player]) OnPlayerKickedOutEvent

func (slf *Room[PlayerID, Player]) OnPlayerKickedOutEvent(executor, kicked PlayerID, reason string)

func (*Room[PlayerID, Player]) OnPlayerLeaveRoomEvent

func (slf *Room[PlayerID, Player]) OnPlayerLeaveRoomEvent(player Player)

func (*Room[PlayerID, Player]) RegPlayerJoinRoomEvent

func (slf *Room[PlayerID, Player]) RegPlayerJoinRoomEvent(handle game.PlayerJoinRoomEventHandle[PlayerID, Player])

RegPlayerJoinRoomEvent 玩家进入房间时将立即执行被注册的事件处理函数

func (*Room[PlayerID, Player]) RegPlayerKickedOutEvent

func (slf *Room[PlayerID, Player]) RegPlayerKickedOutEvent(handle game.PlayerKickedOutEventHandle[PlayerID, Player])

RegPlayerKickedOutEvent 当玩家被踢出游戏时将立即执行被注册的事件处理函数

func (*Room[PlayerID, Player]) RegPlayerLeaveRoomEvent

func (slf *Room[PlayerID, Player]) RegPlayerLeaveRoomEvent(handle game.PlayerLeaveRoomEventHandle[PlayerID, Player])

RegPlayerLeaveRoomEvent 玩家离开房间时将立即执行被注册的事件处理函数

type RoomManager

type RoomManager[PlayerID comparable, Room game.Room[PlayerID, game.Player[PlayerID]]] struct {
	// contains filtered or unexported fields
}

RoomManager 房间管理器

func NewRoomManager

func NewRoomManager[PlayerID comparable, Room game.Room[PlayerID, game.Player[PlayerID]]]() *RoomManager[PlayerID, Room]

func (*RoomManager[PlayerID, Room]) AddRoom

func (slf *RoomManager[PlayerID, Room]) AddRoom(room Room)

AddRoom 添加房间到房间管理器中

func (*RoomManager[PlayerID, Room]) CloseRoom

func (slf *RoomManager[PlayerID, Room]) CloseRoom(guid int64)

CloseRoom 关闭特定guid的房间

func (*RoomManager[PlayerID, Room]) GenGuid

func (slf *RoomManager[PlayerID, Room]) GenGuid() int64

GenGuid 生成一个新的房间guid

type RoomOption

type RoomOption[PlayerID comparable, Player game.Player[PlayerID]] func(room *Room[PlayerID, Player])

RoomOption 房间构建可选项

func WithRoomKickPlayerCheckHandle

func WithRoomKickPlayerCheckHandle[PlayerID comparable, Player game.Player[PlayerID]](handle func(room *Room[PlayerID, Player], id, target PlayerID) error) RoomOption[PlayerID, Player]

WithRoomKickPlayerCheckHandle 设置房间踢出玩家的检查处理函数

  • 当没有设置该函数时,如果不是房主,将无法进行踢出

func WithRoomNoMaster

func WithRoomNoMaster[PlayerID comparable, Player game.Player[PlayerID]]() RoomOption[PlayerID, Player]

WithRoomNoMaster 设置房间为无主的

func WithRoomPlayerLimit

func WithRoomPlayerLimit[PlayerID comparable, Player game.Player[PlayerID]](playerLimit int) RoomOption[PlayerID, Player]

WithRoomPlayerLimit 限制房间的玩家数量上限

func WithRoomSync

func WithRoomSync[PlayerID comparable, Player game.Player[PlayerID]]() RoomOption[PlayerID, Player]

WithRoomSync 通过线程安全的方式创建房间

type RoomSeat

type RoomSeat[PlayerID comparable, Player game.Player[PlayerID]] struct {
	game.Room[PlayerID, Player]
	// contains filtered or unexported fields
}

RoomSeat 包含座位号的默认内置房间实现,依赖于游戏房间(game.Room)实现

  • 实现了对玩家座位号的管理,分别为自动管理(WithRoomSeatAutoManage)及手工管理,默认清空下为手工管理

func NewRoomSeat

func NewRoomSeat[PlayerID comparable, Player game.Player[PlayerID]](room game.Room[PlayerID, Player], options ...RoomSeatOption[PlayerID, Player]) *RoomSeat[PlayerID, Player]

NewRoomSeat 基于特定游戏房间(game.Room)的实现创建一个支持座位号管理的房间实现(RoomSeat)

func (*RoomSeat[PlayerID, Player]) AddSeat

func (slf *RoomSeat[PlayerID, Player]) AddSeat(id PlayerID)

AddSeat 为特定玩家添加座位

  • 当座位存在空缺的时候,玩家将会优先在空缺位置坐下,否则将会在末位追加

func (*RoomSeat[PlayerID, Player]) AddSeatWithAssign

func (slf *RoomSeat[PlayerID, Player]) AddSeatWithAssign(id PlayerID, seat int)

AddSeatWithAssign 将玩家添加到特定的座位

  • 如果位置已经有玩家,将会与其进行更换

func (*RoomSeat[PlayerID, Player]) GetFirstSeat

func (slf *RoomSeat[PlayerID, Player]) GetFirstSeat() int

GetFirstSeat 获取第一个未缺席的座位号

func (*RoomSeat[PlayerID, Player]) GetNextSeat

func (slf *RoomSeat[PlayerID, Player]) GetNextSeat(seat int) int

GetNextSeat 获取特定座位号下一个未缺席的座位号

func (*RoomSeat[PlayerID, Player]) GetNextSeatVacancy

func (slf *RoomSeat[PlayerID, Player]) GetNextSeatVacancy(seat int) int

GetNextSeatVacancy 获取特定座位号下一个座位号

  • 缺席将不会被忽略

func (*RoomSeat[PlayerID, Player]) GetPlayerIDWithSeat

func (slf *RoomSeat[PlayerID, Player]) GetPlayerIDWithSeat(seat int) (playerId PlayerID, err error)

GetPlayerIDWithSeat 获取特定座位号的玩家

func (*RoomSeat[PlayerID, Player]) GetSeat

func (slf *RoomSeat[PlayerID, Player]) GetSeat(id PlayerID) (int, error)

GetSeat 获取玩家座位号

func (*RoomSeat[PlayerID, Player]) GetSeatInfo

func (slf *RoomSeat[PlayerID, Player]) GetSeatInfo() []*PlayerID

GetSeatInfo 获取所有座位号

  • 在非补位模式(WithRoomSeatFillIn)下由于座位号可能存在缺席的情况,所以需要根据是否为空指针进行判断

func (*RoomSeat[PlayerID, Player]) GetSeatInfoMap

func (slf *RoomSeat[PlayerID, Player]) GetSeatInfoMap() map[int]PlayerID

GetSeatInfoMap 获取座位号及其对应的玩家信息

  • 缺席情况将被忽略

func (*RoomSeat[PlayerID, Player]) GetSeatInfoMapVacancy

func (slf *RoomSeat[PlayerID, Player]) GetSeatInfoMapVacancy() map[int]*PlayerID

GetSeatInfoMapVacancy 获取座位号及其对应的玩家信息

  • 缺席情况将不会被忽略

func (*RoomSeat[PlayerID, Player]) GetSeatInfoWithPlayerIDMap

func (slf *RoomSeat[PlayerID, Player]) GetSeatInfoWithPlayerIDMap() map[PlayerID]int

GetSeatInfoWithPlayerIDMap 获取玩家及其座位号信息

func (*RoomSeat[PlayerID, Player]) RemovePlayerSeat

func (slf *RoomSeat[PlayerID, Player]) RemovePlayerSeat(id PlayerID)

RemovePlayerSeat 删除玩家座位

  • 受补位模式(WithRoomSeatFillIn)影响

func (*RoomSeat[PlayerID, Player]) RemoveSeat

func (slf *RoomSeat[PlayerID, Player]) RemoveSeat(seat int)

RemoveSeat 删除特定座位的玩家

  • 受补位模式(WithRoomSeatFillIn)影响

func (*RoomSeat[PlayerID, Player]) SetSeat

func (slf *RoomSeat[PlayerID, Player]) SetSeat(id PlayerID, seat int) error

SetSeat 设置玩家的座位号

  • 如果玩家没有预先添加过座位将会返回错误
  • 如果位置已经有玩家,将会与其进行更换

type RoomSeatOption

type RoomSeatOption[PlayerID comparable, Player game.Player[PlayerID]] func(seat *RoomSeat[PlayerID, Player])

func WithRoomSeatAutoManage

func WithRoomSeatAutoManage[PlayerID comparable, Player game.Player[PlayerID]]() RoomSeatOption[PlayerID, Player]

WithRoomSeatAutoManage 通过自动管理的方式创建带有座位号的房间

  • 默认情况下需要自行维护房间用户的座位号信息
  • 自动管理模式下,将注册房间的 Room.RegPlayerJoinRoomEvent 和 Room.RegPlayerLeaveRoomEvent 事件以便玩家在加入或者离开时维护座位信息

func WithRoomSeatFillIn

func WithRoomSeatFillIn[PlayerID comparable, Player game.Player[PlayerID]]() RoomSeatOption[PlayerID, Player]

WithRoomSeatFillIn 通过补位的方式创建带有座位号的房间

  • 默认情况下玩家离开座位不会影响其他玩家
  • 补位情况下,靠前的玩家离开座位将有后方玩家向前补位

type World

type World[PlayerID comparable, Player game.Player[PlayerID]] struct {
	// contains filtered or unexported fields
}

World 游戏世界的内置实现,实现了基本的游戏世界接口

func NewWorld

func NewWorld[PlayerID comparable, Player game.Player[PlayerID]](guid int64, options ...WorldOption[PlayerID, Player]) *World[PlayerID, Player]

NewWorld 创建一个内置的游戏世界

func (*World[PlayerID, Player]) AddActor

func (slf *World[PlayerID, Player]) AddActor(actor game.Actor)

func (*World[PlayerID, Player]) GetActor

func (slf *World[PlayerID, Player]) GetActor(guid int64) game.Actor

func (*World[PlayerID, Player]) GetActors

func (slf *World[PlayerID, Player]) GetActors() hash.MapReadonly[int64, game.Actor]

func (*World[PlayerID, Player]) GetGuid

func (slf *World[PlayerID, Player]) GetGuid() int64

func (*World[PlayerID, Player]) GetPlayer

func (slf *World[PlayerID, Player]) GetPlayer(id PlayerID) Player

func (*World[PlayerID, Player]) GetPlayerActor

func (slf *World[PlayerID, Player]) GetPlayerActor(id PlayerID, guid int64) game.Actor

func (*World[PlayerID, Player]) GetPlayerActors

func (slf *World[PlayerID, Player]) GetPlayerActors(id PlayerID) hash.MapReadonly[int64, game.Actor]

func (*World[PlayerID, Player]) GetPlayerLimit

func (slf *World[PlayerID, Player]) GetPlayerLimit() int

func (*World[PlayerID, Player]) GetPlayers

func (slf *World[PlayerID, Player]) GetPlayers() hash.MapReadonly[PlayerID, Player]

func (*World[PlayerID, Player]) IsExistActor

func (slf *World[PlayerID, Player]) IsExistActor(guid int64) bool

func (*World[PlayerID, Player]) IsExistPlayer

func (slf *World[PlayerID, Player]) IsExistPlayer(id PlayerID) bool

func (*World[PlayerID, Player]) IsOwner

func (slf *World[PlayerID, Player]) IsOwner(id PlayerID, guid int64) bool

func (*World[PlayerID, Player]) Join

func (slf *World[PlayerID, Player]) Join(player Player) error

func (*World[PlayerID, Player]) Leave

func (slf *World[PlayerID, Player]) Leave(id PlayerID)

func (*World[PlayerID, Player]) OnActorAnnihilationEvent

func (slf *World[PlayerID, Player]) OnActorAnnihilationEvent(actor game.Actor)

func (*World[PlayerID, Player]) OnActorGeneratedEvent

func (slf *World[PlayerID, Player]) OnActorGeneratedEvent(actor game.Actor)

func (*World[PlayerID, Player]) OnActorOwnerChangeEvent

func (slf *World[PlayerID, Player]) OnActorOwnerChangeEvent(actor game.Actor, old, new PlayerID, isolated bool)

func (*World[PlayerID, Player]) OnPlayerJoinWorldEvent

func (slf *World[PlayerID, Player]) OnPlayerJoinWorldEvent(player Player)

func (*World[PlayerID, Player]) OnPlayerLeaveWorldEvent

func (slf *World[PlayerID, Player]) OnPlayerLeaveWorldEvent(player Player)

func (*World[PlayerID, Player]) OnWorldReleaseEvent

func (slf *World[PlayerID, Player]) OnWorldReleaseEvent()

func (*World[PlayerID, Player]) OnWorldResetEvent

func (slf *World[PlayerID, Player]) OnWorldResetEvent()

func (*World[PlayerID, Player]) RegActorAnnihilationEvent

func (slf *World[PlayerID, Player]) RegActorAnnihilationEvent(handle game.ActorAnnihilationEventHandle[PlayerID, Player])

func (*World[PlayerID, Player]) RegActorGeneratedEvent

func (slf *World[PlayerID, Player]) RegActorGeneratedEvent(handle game.ActorGeneratedEventHandle[PlayerID, Player])

func (*World[PlayerID, Player]) RegActorOwnerChangeEvent

func (slf *World[PlayerID, Player]) RegActorOwnerChangeEvent(handle game.ActorOwnerChangeEventHandle[PlayerID, Player])

func (*World[PlayerID, Player]) RegPlayerJoinWorldEvent

func (slf *World[PlayerID, Player]) RegPlayerJoinWorldEvent(handle game.PlayerJoinWorldEventHandle[PlayerID, Player])

func (*World[PlayerID, Player]) RegPlayerLeaveWorldEvent

func (slf *World[PlayerID, Player]) RegPlayerLeaveWorldEvent(handle game.PlayerLeaveWorldEventHandle[PlayerID, Player])

func (*World[PlayerID, Player]) RegWorldReleaseEvent

func (slf *World[PlayerID, Player]) RegWorldReleaseEvent(handle game.WorldReleaseEventHandle[PlayerID, Player])

func (*World[PlayerID, Player]) RegWorldResetEvent

func (slf *World[PlayerID, Player]) RegWorldResetEvent(handle game.WorldResetEventHandle[PlayerID, Player])

func (*World[PlayerID, Player]) Release

func (slf *World[PlayerID, Player]) Release()

func (*World[PlayerID, Player]) RemoveActor

func (slf *World[PlayerID, Player]) RemoveActor(guid int64)

func (*World[PlayerID, Player]) RemoveActorOwner

func (slf *World[PlayerID, Player]) RemoveActorOwner(guid int64)

func (*World[PlayerID, Player]) Reset

func (slf *World[PlayerID, Player]) Reset()

func (*World[PlayerID, Player]) SetActorOwner

func (slf *World[PlayerID, Player]) SetActorOwner(guid int64, id PlayerID)

type WorldOption

type WorldOption[PlayerID comparable, Player game.Player[PlayerID]] func(world *World[PlayerID, Player])

WorldOption 世界构建可选项

func WithWorldPlayerLimit

func WithWorldPlayerLimit[PlayerID comparable, Player game.Player[PlayerID]](playerLimit int) WorldOption[PlayerID, Player]

WithWorldPlayerLimit 限制世界的玩家数量上限

Jump to

Keyboard shortcuts

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