Documentation ¶
Index ¶
- Variables
- type RoomAddEntityEventHandle
- type RoomAssumeControlEventHandle
- type RoomChangePasswordEventHandle
- type RoomController
- func (slf *RoomController[EntityID, RoomID, Entity, Room]) AddEntity(entity Entity) error
- func (slf *RoomController[EntityID, RoomID, Entity, Room]) AddEntityByPassword(entity Entity, password string) error
- func (slf *RoomController[EntityID, RoomID, Entity, Room]) Broadcast(handler func(Entity), conditions ...func(Entity) bool)
- func (slf *RoomController[EntityID, RoomID, Entity, Room]) ChangePassword(password *string)
- func (slf *RoomController[EntityID, RoomID, Entity, Room]) ContainEntity(id EntityID) bool
- func (slf *RoomController[EntityID, RoomID, Entity, Room]) Destroy()
- func (slf *RoomController[EntityID, RoomID, Entity, Room]) GetEmptySeat() []int
- func (slf *RoomController[EntityID, RoomID, Entity, Room]) GetEntities() map[EntityID]Entity
- func (slf *RoomController[EntityID, RoomID, Entity, Room]) GetEntity(id EntityID) Entity
- func (slf *RoomController[EntityID, RoomID, Entity, Room]) GetEntityCount() int
- func (slf *RoomController[EntityID, RoomID, Entity, Room]) GetEntityIDs() []EntityID
- func (slf *RoomController[EntityID, RoomID, Entity, Room]) GetNotEmptySeat() []int
- func (slf *RoomController[EntityID, RoomID, Entity, Room]) GetRoom() Room
- func (slf *RoomController[EntityID, RoomID, Entity, Room]) GetRoomID() RoomID
- func (slf *RoomController[EntityID, RoomID, Entity, Room]) GetRoomManager() *RoomManager[EntityID, RoomID, Entity, Room]
- func (slf *RoomController[EntityID, RoomID, Entity, Room]) GetSeat(entityId EntityID) int
- func (slf *RoomController[EntityID, RoomID, Entity, Room]) GetSeatEntities() map[EntityID]Entity
- func (slf *RoomController[EntityID, RoomID, Entity, Room]) GetSeatEntitiesByOrdered() []Entity
- func (slf *RoomController[EntityID, RoomID, Entity, Room]) GetSeatEntitiesByOrderedAndContainsEmpty() []Entity
- func (slf *RoomController[EntityID, RoomID, Entity, Room]) GetSeatEntity(seat int) (entity Entity)
- func (slf *RoomController[EntityID, RoomID, Entity, Room]) GetSeatEntityCount() int
- func (slf *RoomController[EntityID, RoomID, Entity, Room]) HasEntity(id EntityID) bool
- func (slf *RoomController[EntityID, RoomID, Entity, Room]) HasSeat(entityId EntityID) bool
- func (slf *RoomController[EntityID, RoomID, Entity, Room]) JoinSeat(entityId EntityID, seat ...int) error
- func (slf *RoomController[EntityID, RoomID, Entity, Room]) LeaveSeat(entityId EntityID)
- func (slf *RoomController[EntityID, RoomID, Entity, Room]) RemoveAllEntities()
- func (slf *RoomController[EntityID, RoomID, Entity, Room]) RemoveEntity(id EntityID)
- type RoomControllerOptions
- type RoomDestroyEventHandle
- type RoomManager
- func (slf *RoomManager[EntityID, RoomID, Entity, Room]) AssumeControl(room Room, options ...*RoomControllerOptions) *RoomController[EntityID, RoomID, Entity, Room]
- func (slf *RoomManager[EntityID, RoomID, Entity, Room]) Broadcast(handler func(Entity), conditions ...func(Entity) bool)
- func (slf *RoomManager[EntityID, RoomID, Entity, Room]) DestroyRoom(id RoomID)
- func (slf *RoomManager[EntityID, RoomID, Entity, Room]) GetEntityRooms(entityId EntityID) map[RoomID]*RoomController[EntityID, RoomID, Entity, Room]
- func (slf *RoomManager[EntityID, RoomID, Entity, Room]) GetRoom(id RoomID) *RoomController[EntityID, RoomID, Entity, Room]
- func (slf *RoomManager[EntityID, RoomID, Entity, Room]) GetRoomCount() int
- func (slf *RoomManager[EntityID, RoomID, Entity, Room]) GetRoomIDs() []RoomID
- func (slf *RoomManager[EntityID, RoomID, Entity, Room]) GetRooms() map[RoomID]*RoomController[EntityID, RoomID, Entity, Room]
- func (slf *RoomManager[EntityID, RoomID, Entity, Room]) HasEntity(entityId EntityID) bool
- func (slf RoomManager) OnRoomAddEntityEvent(controller *RoomController[EntityID, RoomID, Entity, Room], entity Entity)
- func (slf RoomManager) OnRoomAssumeControlEvent(controller *RoomController[EntityID, RoomID, Entity, Room])
- func (slf RoomManager) OnRoomChangePasswordEvent(controller *RoomController[EntityID, RoomID, Entity, Room], ...)
- func (slf RoomManager) OnRoomDestroyEvent(controller *RoomController[EntityID, RoomID, Entity, Room])
- func (slf RoomManager) OnRoomRemoveEntityEvent(controller *RoomController[EntityID, RoomID, Entity, Room], entity Entity)
- func (slf RoomManager) RegRoomAddEntityEvent(handle RoomAddEntityEventHandle[EntityID, RoomID, Entity, Room])
- func (slf RoomManager) RegRoomAssumeControlEvent(handle RoomAssumeControlEventHandle[EntityID, RoomID, Entity, Room])
- func (slf RoomManager) RegRoomChangePasswordEvent(handle RoomChangePasswordEventHandle[EntityID, RoomID, Entity, Room])
- func (slf RoomManager) RegRoomDestroyEvent(handle RoomDestroyEventHandle[EntityID, RoomID, Entity, Room])
- func (slf RoomManager) RegRoomRemoveEntityEvent(handle RoomRemoveEntityEventHandle[EntityID, RoomID, Entity, Room])
- type RoomRemoveEntityEventHandle
Constants ¶
This section is empty.
Variables ¶
var ( // ErrRoomFull 房间已满 ErrRoomFull = errors.New("room is full") // ErrSeatNotEmpty 座位上已经有实体 ErrSeatNotEmpty = errors.New("seat is not empty") // ErrNotInRoom 实体不在房间中 ErrNotInRoom = errors.New("not in room") // ErrRoomPasswordNotMatch 房间密码不匹配 ErrRoomPasswordNotMatch = errors.New("room password not match") // ErrPermissionDenied 权限不足 ErrPermissionDenied = errors.New("permission denied") )
Functions ¶
This section is empty.
Types ¶
type RoomAddEntityEventHandle ¶
type RoomAddEntityEventHandle[EntityID comparable, RoomID comparable, Entity generic.IdR[EntityID], Room generic.IdR[RoomID]] func(controller *RoomController[EntityID, RoomID, Entity, Room], entity Entity)
type RoomAssumeControlEventHandle ¶
type RoomAssumeControlEventHandle[EntityID comparable, RoomID comparable, Entity generic.IdR[EntityID], Room generic.IdR[RoomID]] func(controller *RoomController[EntityID, RoomID, Entity, Room])
type RoomChangePasswordEventHandle ¶
type RoomChangePasswordEventHandle[EntityID comparable, RoomID comparable, Entity generic.IdR[EntityID], Room generic.IdR[RoomID]] func(controller *RoomController[EntityID, RoomID, Entity, Room], oldPassword, password *string)
type RoomController ¶
type RoomController[EntityID comparable, RoomID comparable, Entity generic.IdR[EntityID], Room generic.IdR[RoomID]] struct { // contains filtered or unexported fields }
RoomController 对房间进行操作的控制器,由 RoomManager 接管后返回
func (*RoomController[EntityID, RoomID, Entity, Room]) AddEntity ¶
func (slf *RoomController[EntityID, RoomID, Entity, Room]) AddEntity(entity Entity) error
AddEntity 添加实体
func (*RoomController[EntityID, RoomID, Entity, Room]) AddEntityByPassword ¶
func (slf *RoomController[EntityID, RoomID, Entity, Room]) AddEntityByPassword(entity Entity, password string) error
AddEntityByPassword 通过房间密码添加实体
func (*RoomController[EntityID, RoomID, Entity, Room]) Broadcast ¶
func (slf *RoomController[EntityID, RoomID, Entity, Room]) Broadcast(handler func(Entity), conditions ...func(Entity) bool)
Broadcast 广播消息
func (*RoomController[EntityID, RoomID, Entity, Room]) ChangePassword ¶
func (slf *RoomController[EntityID, RoomID, Entity, Room]) ChangePassword(password *string)
ChangePassword 修改房间密码
- 当房间密码为 nil 时,将会取消密码
func (*RoomController[EntityID, RoomID, Entity, Room]) ContainEntity ¶
func (slf *RoomController[EntityID, RoomID, Entity, Room]) ContainEntity(id EntityID) bool
ContainEntity 房间内是否包含实体
func (*RoomController[EntityID, RoomID, Entity, Room]) Destroy ¶
func (slf *RoomController[EntityID, RoomID, Entity, Room]) Destroy()
Destroy 销毁房间
func (*RoomController[EntityID, RoomID, Entity, Room]) GetEmptySeat ¶
func (slf *RoomController[EntityID, RoomID, Entity, Room]) GetEmptySeat() []int
GetEmptySeat 获取空座位
- 空座位需要在有对象离开座位后才可能出现
func (*RoomController[EntityID, RoomID, Entity, Room]) GetEntities ¶
func (slf *RoomController[EntityID, RoomID, Entity, Room]) GetEntities() map[EntityID]Entity
GetEntities 获取所有实体
func (*RoomController[EntityID, RoomID, Entity, Room]) GetEntity ¶
func (slf *RoomController[EntityID, RoomID, Entity, Room]) GetEntity(id EntityID) Entity
GetEntity 获取实体
func (*RoomController[EntityID, RoomID, Entity, Room]) GetEntityCount ¶
func (slf *RoomController[EntityID, RoomID, Entity, Room]) GetEntityCount() int
GetEntityCount 获取实体数量
func (*RoomController[EntityID, RoomID, Entity, Room]) GetEntityIDs ¶
func (slf *RoomController[EntityID, RoomID, Entity, Room]) GetEntityIDs() []EntityID
GetEntityIDs 获取所有实体ID
func (*RoomController[EntityID, RoomID, Entity, Room]) GetNotEmptySeat ¶
func (slf *RoomController[EntityID, RoomID, Entity, Room]) GetNotEmptySeat() []int
GetNotEmptySeat 获取非空座位
func (*RoomController[EntityID, RoomID, Entity, Room]) GetRoom ¶
func (slf *RoomController[EntityID, RoomID, Entity, Room]) GetRoom() Room
GetRoom 获取原始房间实例
func (*RoomController[EntityID, RoomID, Entity, Room]) GetRoomID ¶
func (slf *RoomController[EntityID, RoomID, Entity, Room]) GetRoomID() RoomID
GetRoomID 获取房间ID
func (*RoomController[EntityID, RoomID, Entity, Room]) GetRoomManager ¶
func (slf *RoomController[EntityID, RoomID, Entity, Room]) GetRoomManager() *RoomManager[EntityID, RoomID, Entity, Room]
GetRoomManager 获取房间管理器
func (*RoomController[EntityID, RoomID, Entity, Room]) GetSeat ¶
func (slf *RoomController[EntityID, RoomID, Entity, Room]) GetSeat(entityId EntityID) int
GetSeat 获取座位
func (*RoomController[EntityID, RoomID, Entity, Room]) GetSeatEntities ¶
func (slf *RoomController[EntityID, RoomID, Entity, Room]) GetSeatEntities() map[EntityID]Entity
GetSeatEntities 获取座位上的实体
func (*RoomController[EntityID, RoomID, Entity, Room]) GetSeatEntitiesByOrdered ¶
func (slf *RoomController[EntityID, RoomID, Entity, Room]) GetSeatEntitiesByOrdered() []Entity
GetSeatEntitiesByOrdered 有序的获取座位上的实体
func (*RoomController[EntityID, RoomID, Entity, Room]) GetSeatEntitiesByOrderedAndContainsEmpty ¶
func (slf *RoomController[EntityID, RoomID, Entity, Room]) GetSeatEntitiesByOrderedAndContainsEmpty() []Entity
GetSeatEntitiesByOrderedAndContainsEmpty 获取有序的座位上的实体,包含空座位
func (*RoomController[EntityID, RoomID, Entity, Room]) GetSeatEntity ¶
func (slf *RoomController[EntityID, RoomID, Entity, Room]) GetSeatEntity(seat int) (entity Entity)
GetSeatEntity 获取座位上的实体
func (*RoomController[EntityID, RoomID, Entity, Room]) GetSeatEntityCount ¶
func (slf *RoomController[EntityID, RoomID, Entity, Room]) GetSeatEntityCount() int
GetSeatEntityCount 获取座位上的实体数量
func (*RoomController[EntityID, RoomID, Entity, Room]) HasEntity ¶
func (slf *RoomController[EntityID, RoomID, Entity, Room]) HasEntity(id EntityID) bool
HasEntity 判断是否有实体
func (*RoomController[EntityID, RoomID, Entity, Room]) HasSeat ¶
func (slf *RoomController[EntityID, RoomID, Entity, Room]) HasSeat(entityId EntityID) bool
HasSeat 判断是否有座位
func (*RoomController[EntityID, RoomID, Entity, Room]) JoinSeat ¶
func (slf *RoomController[EntityID, RoomID, Entity, Room]) JoinSeat(entityId EntityID, seat ...int) error
JoinSeat 设置特定对象加入座位,当具体的座位不存在的时候,将会自动分配座位
- 当目标座位存在玩家或未添加到房间中的时候,将会返回错误
func (*RoomController[EntityID, RoomID, Entity, Room]) LeaveSeat ¶
func (slf *RoomController[EntityID, RoomID, Entity, Room]) LeaveSeat(entityId EntityID)
LeaveSeat 离开座位
func (*RoomController[EntityID, RoomID, Entity, Room]) RemoveAllEntities ¶
func (slf *RoomController[EntityID, RoomID, Entity, Room]) RemoveAllEntities()
RemoveAllEntities 移除所有实体
func (*RoomController[EntityID, RoomID, Entity, Room]) RemoveEntity ¶
func (slf *RoomController[EntityID, RoomID, Entity, Room]) RemoveEntity(id EntityID)
RemoveEntity 移除实体
- 当实体被移除时如果实体在座位上,将会自动离开座位
type RoomControllerOptions ¶
type RoomControllerOptions struct {
// contains filtered or unexported fields
}
func NewRoomControllerOptions ¶
func NewRoomControllerOptions() *RoomControllerOptions
NewRoomControllerOptions 创建房间控制器选项
func (*RoomControllerOptions) WithMaxEntityCount ¶
func (slf *RoomControllerOptions) WithMaxEntityCount(maxEntityCount int) *RoomControllerOptions
WithMaxEntityCount 设置房间最大实体数量
func (*RoomControllerOptions) WithPassword ¶
func (slf *RoomControllerOptions) WithPassword(password string) *RoomControllerOptions
WithPassword 设置房间密码
type RoomDestroyEventHandle ¶
type RoomDestroyEventHandle[EntityID comparable, RoomID comparable, Entity generic.IdR[EntityID], Room generic.IdR[RoomID]] func(controller *RoomController[EntityID, RoomID, Entity, Room])
type RoomManager ¶
type RoomManager[EntityID comparable, RoomID comparable, Entity generic.IdR[EntityID], Room generic.IdR[RoomID]] struct { // contains filtered or unexported fields }
RoomManager 房间管理器
func NewRoomManager ¶
func NewRoomManager[EntityID comparable, RoomID comparable, Entity generic.IdR[EntityID], Room generic.IdR[RoomID]]() *RoomManager[EntityID, RoomID, Entity, Room]
NewRoomManager 创建房间管理器
func (*RoomManager[EntityID, RoomID, Entity, Room]) AssumeControl ¶
func (slf *RoomManager[EntityID, RoomID, Entity, Room]) AssumeControl(room Room, options ...*RoomControllerOptions) *RoomController[EntityID, RoomID, Entity, Room]
AssumeControl 将房间控制权交由 RoomManager 接管
func (*RoomManager[EntityID, RoomID, Entity, Room]) Broadcast ¶
func (slf *RoomManager[EntityID, RoomID, Entity, Room]) Broadcast(handler func(Entity), conditions ...func(Entity) bool)
Broadcast 向所有房间对象广播消息
func (*RoomManager[EntityID, RoomID, Entity, Room]) DestroyRoom ¶
func (slf *RoomManager[EntityID, RoomID, Entity, Room]) DestroyRoom(id RoomID)
DestroyRoom 销毁房间
func (*RoomManager[EntityID, RoomID, Entity, Room]) GetEntityRooms ¶
func (slf *RoomManager[EntityID, RoomID, Entity, Room]) GetEntityRooms(entityId EntityID) map[RoomID]*RoomController[EntityID, RoomID, Entity, Room]
GetEntityRooms 获取特定对象所在的房间
func (*RoomManager[EntityID, RoomID, Entity, Room]) GetRoom ¶
func (slf *RoomManager[EntityID, RoomID, Entity, Room]) GetRoom(id RoomID) *RoomController[EntityID, RoomID, Entity, Room]
GetRoom 获取房间
func (*RoomManager[EntityID, RoomID, Entity, Room]) GetRoomCount ¶
func (slf *RoomManager[EntityID, RoomID, Entity, Room]) GetRoomCount() int
GetRoomCount 获取房间数量
func (*RoomManager[EntityID, RoomID, Entity, Room]) GetRoomIDs ¶
func (slf *RoomManager[EntityID, RoomID, Entity, Room]) GetRoomIDs() []RoomID
GetRoomIDs 获取所有房间ID
func (*RoomManager[EntityID, RoomID, Entity, Room]) GetRooms ¶
func (slf *RoomManager[EntityID, RoomID, Entity, Room]) GetRooms() map[RoomID]*RoomController[EntityID, RoomID, Entity, Room]
GetRooms 获取所有房间
func (*RoomManager[EntityID, RoomID, Entity, Room]) HasEntity ¶
func (slf *RoomManager[EntityID, RoomID, Entity, Room]) HasEntity(entityId EntityID) bool
HasEntity 判断特定对象是否在任一房间中
func (RoomManager) OnRoomAddEntityEvent ¶
func (slf RoomManager) OnRoomAddEntityEvent(controller *RoomController[EntityID, RoomID, Entity, Room], entity Entity)
OnRoomAddEntityEvent 房间添加对象事件
func (RoomManager) OnRoomAssumeControlEvent ¶
func (slf RoomManager) OnRoomAssumeControlEvent(controller *RoomController[EntityID, RoomID, Entity, Room])
OnRoomAssumeControlEvent 房间接管事件
func (RoomManager) OnRoomChangePasswordEvent ¶
func (slf RoomManager) OnRoomChangePasswordEvent(controller *RoomController[EntityID, RoomID, Entity, Room], oldPassword, password *string)
OnRoomChangePasswordEvent 房间修改密码事件
func (RoomManager) OnRoomDestroyEvent ¶
func (slf RoomManager) OnRoomDestroyEvent(controller *RoomController[EntityID, RoomID, Entity, Room])
OnRoomDestroyEvent 房间销毁事件
func (RoomManager) OnRoomRemoveEntityEvent ¶
func (slf RoomManager) OnRoomRemoveEntityEvent(controller *RoomController[EntityID, RoomID, Entity, Room], entity Entity)
OnRoomRemoveEntityEvent 房间移除对象事件
func (RoomManager) RegRoomAddEntityEvent ¶
func (slf RoomManager) RegRoomAddEntityEvent(handle RoomAddEntityEventHandle[EntityID, RoomID, Entity, Room])
RegRoomAddEntityEvent 注册房间添加对象事件
func (RoomManager) RegRoomAssumeControlEvent ¶
func (slf RoomManager) RegRoomAssumeControlEvent(handle RoomAssumeControlEventHandle[EntityID, RoomID, Entity, Room])
RegRoomAssumeControlEvent 注册房间接管事件
func (RoomManager) RegRoomChangePasswordEvent ¶
func (slf RoomManager) RegRoomChangePasswordEvent(handle RoomChangePasswordEventHandle[EntityID, RoomID, Entity, Room])
RegRoomChangePasswordEvent 注册房间修改密码事件
func (RoomManager) RegRoomDestroyEvent ¶
func (slf RoomManager) RegRoomDestroyEvent(handle RoomDestroyEventHandle[EntityID, RoomID, Entity, Room])
RegRoomDestroyEvent 注册房间销毁事件
func (RoomManager) RegRoomRemoveEntityEvent ¶
func (slf RoomManager) RegRoomRemoveEntityEvent(handle RoomRemoveEntityEventHandle[EntityID, RoomID, Entity, Room])
RegRoomRemoveEntityEvent 注册房间移除对象事件
type RoomRemoveEntityEventHandle ¶
type RoomRemoveEntityEventHandle[EntityID comparable, RoomID comparable, Entity generic.IdR[EntityID], Room generic.IdR[RoomID]] func(controller *RoomController[EntityID, RoomID, Entity, Room], entity Entity)