game

package
v0.0.0-...-bfc2f26 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2024 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Code generated by proto_code_gen. DO NOT EDIT. https://github.com/fish-tennis/proto_code_gen

Index

Constants

View Source
const (
	// mongo表名
	GlobalEntityCollectionName = "global"
	// global表的key
	GlobalEntityCollectionKeyName = "key"
	// GlobalEntity在redis里的前缀
	GlobalEntityCachePrefix = GlobalEntityCollectionName
	// GlobalEntity在mongo表里的key
	GlobalEntityCollectionKey = "GlobalEntity"
)
View Source
const (
	// Player在redis里的前缀
	PlayerCachePrefix = "p"
)

Variables

This section is empty.

Functions

func AutoRegisterPlayerComponentProto

func AutoRegisterPlayerComponentProto(packetHandlerRegister PacketHandlerRegister)

根据proto的命名规则和玩家组件里消息回调的格式,通过反射自动生成消息的注册 类似Java的注解功能

func CreateNewActivity

func CreateNewActivity(activityCfgId int32, activities ActivityMgr, t time.Time) Activity

根据模板创建活动对象

func GetComponentIndex

func GetComponentIndex(componentName string) int

func GetPlayerComponentMap

func GetPlayerComponentMap() map[string]int

func GetPlayerMgr

func GetPlayerMgr() gentity.PlayerMgr

func InitGlobalEntityStructAndHandler

func InitGlobalEntityStructAndHandler()

注册GlobalEntity的结构体和消息回调

func InitPlayerComponentMap

func InitPlayerComponentMap()

func OfflinePlayerProcess

func OfflinePlayerProcess(playerId int64, data interface{}, f func(offlinePlayerId int64, offlineData interface{}) bool) bool

对离线玩家的数据处理

func OnCoinReq

func OnCoinReq(this *Money, req *pb.CoinReq)

请求加coin的消息回调 这种格式写的函数可以被proto_code_gen工具自动注册消息回调

func RegisterConditionCheckers

func RegisterConditionCheckers() *internal.ConditionMgr

func RegisterPlayerHandler

func RegisterPlayerHandler(cmd PacketCommand, handler func(player *Player, packet Packet))

func RegisterProgressCheckers

func RegisterProgressCheckers() *internal.ProgressMgr

func RoutePlayerPacket

func RoutePlayerPacket(playerId int64, cmd PacketCommand, message proto.Message, opts ...*RouteOptions) bool

路由玩家消息 如果目标玩家在本服务器,则直接路由到本服务器上的玩家 如果目标玩家在另一个服务器上,则转发到目标服务器 ServerA -> ServerB -> Player

DirectSendClientRouteOptions(): 消息直接转发给客户端,不做逻辑处理 ServerA -> ServerB -> Client

举例: 有人申请加入公会,公会广播该消息给公会成员,ServerB收到消息后,直接把消息发给客户端(Player.Send),而不需要放入玩家的逻辑消息队列(Player.OnRecvPacket)

SaveDbRouteOptions(): 消息先保存数据库再转发,防止丢失 举例: 公会会长同意了玩家A的入会申请,此时玩家A可能不在线,就把该消息存入玩家的数据库,待玩家下次上线时,从数据库取出该消息,并进行相应的逻辑处理

func SetPlayerMgr

func SetPlayerMgr(mgr gentity.PlayerMgr)

Types

type Activities

type Activities struct {
	PlayerMapDataComponent
	Data map[int32]Activity `db:"Data"`
}

活动模块

func NewActivities

func NewActivities(player *Player) *Activities

func (*Activities) AddAllActivities

func (this *Activities) AddAllActivities(t time.Time)

func (*Activities) AddNewActivity

func (this *Activities) AddNewActivity(activityCfg *cfg.ActivityCfg, t time.Time) Activity

func (*Activities) CanJoin

func (this *Activities) CanJoin(activityCfg *cfg.ActivityCfg, t time.Time) bool

检查活动是否能参加

func (*Activities) CheckEnd

func (this *Activities) CheckEnd(t time.Time)

检查已经结束的活动

func (*Activities) CheckEndTime

func (this *Activities) CheckEndTime(activityCfg *cfg.ActivityCfg, t time.Time) bool

检查活动时间是否结束

func (*Activities) CheckJoinTime

func (this *Activities) CheckJoinTime(activityCfg *cfg.ActivityCfg, t time.Time) bool

检查活动时间能否参加

func (*Activities) GetActivity

func (this *Activities) GetActivity(activityId int32) Activity

func (*Activities) LoadData

func (this *Activities) LoadData(sourceData map[int32][]byte)

func (*Activities) OnEvent

func (this *Activities) OnEvent(event interface{})

事件分发

func (*Activities) RemoveActivity

func (this *Activities) RemoveActivity(activityId int32)

type ActivityConditionArg

type ActivityConditionArg struct {
	Activities *Activities
	Activity   Activity
}

type ActivityDefault

type ActivityDefault struct {
	ChildActivity
	// 基础数据
	Base *pb.ActivityDefaultBaseData `db:"Base"`
}

默认活动模板,支持常见的简单活动

func (*ActivityDefault) Exchange

func (this *ActivityDefault) Exchange(exchangeCfgId int32)

兑换物品

商店也是一种兑换功能

func (*ActivityDefault) GetPropertyInt32

func (this *ActivityDefault) GetPropertyInt32(propertyName string) int32

func (*ActivityDefault) OnDateChange

func (this *ActivityDefault) OnDateChange(oldDate time.Time, curDate time.Time)

func (*ActivityDefault) OnEnd

func (this *ActivityDefault) OnEnd(t time.Time)

func (*ActivityDefault) OnEvent

func (this *ActivityDefault) OnEvent(event interface{})

func (*ActivityDefault) ReceiveReward

func (this *ActivityDefault) ReceiveReward(cfgId int32)

领取活动任务奖励

func (*ActivityDefault) Reset

func (this *ActivityDefault) Reset()

重置数据

type Bag

type Bag struct {
	BasePlayerComponent
	BagCountItem  *BagCountItem  `child:"CountItem"`
	BagUniqueItem *BagUniqueItem `child:"UniqueItem"`
}

背包模块 演示通过组合模式,整合多个不同的子背包模块,提供更高一级的背包接口

func NewBag

func NewBag(player *Player) *Bag

func (*Bag) AddItem

func (this *Bag) AddItem(cfgId int32, num int32) bool

func (*Bag) AddItems

func (this *Bag) AddItems(items []*pb.ItemNum)

func (*Bag) DelItems

func (this *Bag) DelItems(items []*pb.ItemNum)

func (*Bag) IsEnough

func (this *Bag) IsEnough(items []*pb.ItemNum) bool

type BagCountItem

type BagCountItem struct {
	gentity.BaseMapDirtyMark
	Items map[int32]int32 `db:"CountItem;plain"`
}

有数量的物品背包

func NewBagCountItem

func NewBagCountItem() *BagCountItem

func (*BagCountItem) AddItem

func (this *BagCountItem) AddItem(itemCfgId, addCount int32) int32

func (*BagCountItem) DelItem

func (this *BagCountItem) DelItem(itemCfgId, delCount int32) int32

func (*BagCountItem) GetItemCount

func (this *BagCountItem) GetItemCount(itemCfgId int32) int32

type BagUniqueItem

type BagUniqueItem struct {
	gentity.BaseMapDirtyMark
	Items map[int64]*pb.UniqueItem `db:"UniqueItem"`
}

不可叠加的物品背包

func NewBagUniqueItem

func NewBagUniqueItem() *BagUniqueItem

func (*BagUniqueItem) AddUniqueItem

func (this *BagUniqueItem) AddUniqueItem(uniqueItem *pb.UniqueItem) int32

func (*BagUniqueItem) DelItem

func (this *BagUniqueItem) DelItem(itemCfgId, delCount int32) int32

func (*BagUniqueItem) DelUniqueItem

func (this *BagUniqueItem) DelUniqueItem(uniqueId int64) int32

func (*BagUniqueItem) GetItemCount

func (this *BagUniqueItem) GetItemCount(itemCfgId int32) int32

type BaseInfo

type BaseInfo struct {
	PlayerDataComponent
	// plain表示明文存储,在保存到mongo时,不会进行proto序列化
	Data *pb.BaseInfo `db:"BaseInfo;plain"`
}

玩家基础信息组件

func NewBaseInfo

func NewBaseInfo(player *Player, data *pb.BaseInfo) *BaseInfo

func (*BaseInfo) GetOnlineSecondsThisTime

func (this *BaseInfo) GetOnlineSecondsThisTime() int32

本次登录在线时长

func (*BaseInfo) GetTotalOnlineSeconds

func (this *BaseInfo) GetTotalOnlineSeconds() int32

总在线时长

func (*BaseInfo) HandlePlayerEntryGameOk

func (this *BaseInfo) HandlePlayerEntryGameOk(_ gnet.PacketCommand, msg *pb.PlayerEntryGameOk)

玩家进游戏服成功,非客户端消息 这种格式写的函数可以自动注册非客户端的消息回调

func (*BaseInfo) IncExp

func (this *BaseInfo) IncExp(incExp int32)

func (*BaseInfo) OnEvent

func (this *BaseInfo) OnEvent(event interface{})

type BasePlayerComponent

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

玩家组件

func (*BasePlayerComponent) GetCacheKey

func (this *BasePlayerComponent) GetCacheKey() string

组件缓存key

func (*BasePlayerComponent) GetEntity

func (this *BasePlayerComponent) GetEntity() gentity.Entity

func (*BasePlayerComponent) GetName

func (this *BasePlayerComponent) GetName() string

组件名

func (*BasePlayerComponent) GetNameLower

func (this *BasePlayerComponent) GetNameLower() string

func (*BasePlayerComponent) GetPlayer

func (this *BasePlayerComponent) GetPlayer() *Player

关联的玩家对象

func (*BasePlayerComponent) GetPlayerId

func (this *BasePlayerComponent) GetPlayerId() int64

关联的玩家id

func (*BasePlayerComponent) SetEntity

func (this *BasePlayerComponent) SetEntity(entity gentity.Entity)

type ChildActivity

type ChildActivity struct {
	gentity.BaseDirtyMark
	BaseActivity
	Activities *Activities
}

子活动

func (*ChildActivity) GetActivityCfg

func (this *ChildActivity) GetActivityCfg() *cfg.ActivityCfg

活动配置数据

func (*ChildActivity) SetDirty

func (this *ChildActivity) SetDirty()

子活动设置脏标记时,玩家活动模块也设置脏标记

type ClientConnectionHandler

type ClientConnectionHandler struct {
	DefaultConnectionHandler
}

客户端连接的handler

func NewClientConnectionHandler

func NewClientConnectionHandler(protoCodec *ProtoCodec) *ClientConnectionHandler

func (*ClientConnectionHandler) OnRecvPacket

func (this *ClientConnectionHandler) OnRecvPacket(connection Connection, packet Packet)

type CurQuests

type CurQuests struct {
	gentity.BaseMapDirtyMark

	// struct tag里面没有设置保存字段名,会默认使用字段名的全小写形式
	Quests map[int32]*pb.QuestData `db:""`
	// contains filtered or unexported fields
}

当前任务列表

func (*CurQuests) Add

func (c *CurQuests) Add(questData *pb.QuestData)

func (*CurQuests) OnEvent

func (c *CurQuests) OnEvent(event interface{})

触发了事件,检查任务进度的更新

func (*CurQuests) Remove

func (c *CurQuests) Remove(questId int32)

type FinishedQuests

type FinishedQuests struct {
	gentity.BaseDirtyMark

	// struct tag里面没有设置保存字段名,会默认使用字段名的全小写形式
	Finished []int32 `db:"plain"` // 基础类型,设置明文存储
	// contains filtered or unexported fields
}

已完成的任务

func (*FinishedQuests) Add

func (f *FinishedQuests) Add(finishedQuestId int32)

type GlobalEntity

type GlobalEntity struct {
	gentity.BaseRoutineEntity
	// contains filtered or unexported fields
}

演示全局类的非玩家实体 这里演示的GlobalEntity,每个game进程一个实例

func CreateGlobalEntityFromDb

func CreateGlobalEntityFromDb() *GlobalEntity

从数据库加载的数据构造出GlobalEntity对象

func CreateTempGlobalEntity

func CreateTempGlobalEntity() *GlobalEntity

func GetGlobalEntity

func GetGlobalEntity() *GlobalEntity

func NewGlobalEntity

func NewGlobalEntity() *GlobalEntity

func (*GlobalEntity) GetProcessStatInfo

func (this *GlobalEntity) GetProcessStatInfo() *ProcessStatInfo

func (*GlobalEntity) LoadData

func (this *GlobalEntity) LoadData(data interface{}) error

func (*GlobalEntity) RunRoutine

func (this *GlobalEntity) RunRoutine() bool

func (*GlobalEntity) SaveCache

func (this *GlobalEntity) SaveCache(kvCache gentity.KvCache) error

func (*GlobalEntity) SaveDb

func (this *GlobalEntity) SaveDb(removeCacheAfterSaveDb bool) error

type Guild

type Guild struct {
	PlayerDataComponent
	Data *pb.PlayerGuildData `db:"Guild"`
}

玩家的公会模块

func NewGuild

func NewGuild(player *Player) *Guild

func (*Guild) GetGuildData

func (this *Guild) GetGuildData() *pb.PlayerGuildData

func (*Guild) HandleGuildJoinAgreeRes

func (this *Guild) HandleGuildJoinAgreeRes(cmd gnet.PacketCommand, msg *pb.GuildJoinAgreeRes)

玩家进游戏服成功,非客户端消息 这种格式写的函数可以自动注册非客户端的消息回调

func (*Guild) SetGuildId

func (this *Guild) SetGuildId(guildId int64)

type Hook

type Hook struct {
}

func (*Hook) OnApplicationExit

func (h *Hook) OnApplicationExit()

服务器关闭回调

func (*Hook) OnApplicationInit

func (h *Hook) OnApplicationInit(initArg interface{})

服务器初始化回调

type Money

type Money struct {
	PlayerDataComponent
	// 该字段必须导出(首字母大写)
	// 使用struct tag来标记该字段需要存数据库,可以设置存储字段名
	Data *pb.Money `db:"Money"`
}

玩家的钱财组件

func NewMoney

func NewMoney(player *Player) *Money

func (*Money) IncCoin

func (this *Money) IncCoin(coin int32)

func (*Money) IncDiamond

func (this *Money) IncDiamond(diamond int32)

func (*Money) OnCoinReq

func (this *Money) OnCoinReq(_ gnet.PacketCommand, req *pb.CoinReq)

请求加coin的消息回调 这种格式写的函数可以自动注册客户端消息回调

type PendingMessages

type PendingMessages struct {
	BasePlayerComponent
	Messages map[int64]*pb.RoutePlayerMessage `db:""`
}

待处理消息 该组件不会在玩家下线时保存数据库,也不保存缓存

func NewPendingMessages

func NewPendingMessages(player *Player) *PendingMessages

func (*PendingMessages) OnEvent

func (this *PendingMessages) OnEvent(event interface{})

事件接口

type Player

type Player struct {
	gentity.BaseRoutineEntity
	// contains filtered or unexported fields
}

玩家对象

func CreatePlayerFromData

func CreatePlayerFromData(playerData *pb.PlayerData) *Player

从加载的数据构造出玩家对象

func CreateTempPlayer

func CreateTempPlayer(playerId, accountId int64) *Player

func GetPlayer

func GetPlayer(playerId int64) *Player

func NewEmptyPlayer

func NewEmptyPlayer(playerId int64) *Player

func (*Player) FireConditionEvent

func (this *Player) FireConditionEvent(event interface{})

分发条件相关事件

func (*Player) FireEvent

func (this *Player) FireEvent(event interface{})

分发事件给组件

func (*Player) GetAccountId

func (this *Player) GetAccountId() int64

账号id

func (*Player) GetActivities

func (this *Player) GetActivities() *Activities

func (*Player) GetBag

func (this *Player) GetBag() *Bag

func (*Player) GetBaseInfo

func (this *Player) GetBaseInfo() *BaseInfo

func (*Player) GetComponent

func (this *Player) GetComponent(componentName string) gentity.Component

获取组件

func (*Player) GetConnection

func (this *Player) GetConnection() Connection

func (*Player) GetGuild

func (this *Player) GetGuild() *Guild

func (*Player) GetLevel

func (this *Player) GetLevel() int32

func (*Player) GetName

func (this *Player) GetName() string

玩家名(unique)

func (*Player) GetPropertyInt32

func (this *Player) GetPropertyInt32(propertyName string) int32

提供一个统一的属性值查询接口

func (*Player) GetQuest

func (this *Player) GetQuest() *Quest

func (*Player) GetRegionId

func (this *Player) GetRegionId() int32

区服id

func (*Player) OnDisconnect

func (this *Player) OnDisconnect(connection Connection)

func (*Player) OnRecvPacket

func (this *Player) OnRecvPacket(packet *ProtoPacket)

放入消息队列

func (*Player) ResetConnection

func (this *Player) ResetConnection()

func (*Player) RunRoutine

func (this *Player) RunRoutine() bool

开启消息处理协程 每个玩家一个独立的消息处理协程 除了登录消息,其他消息都在玩家自己的协程里处理,因此这里对本玩家的操作不需要加锁

func (*Player) SaveCache

func (this *Player) SaveCache(kvCache gentity.KvCache) error

func (*Player) SaveDb

func (this *Player) SaveDb(removeCacheAfterSaveDb bool) error

玩家数据保存数据库

func (*Player) Send

func (this *Player) Send(command PacketCommand, message proto.Message) bool

发包(protobuf) NOTE:调用Send(command,message)之后,不要再对message进行读写!

func (*Player) SendErrorRes

func (this *Player) SendErrorRes(errorReqCmd PacketCommand, errorMsg string) bool

通用的错误返回消息

func (*Player) SetConnection

func (this *Player) SetConnection(connection Connection, useGate bool)

设置关联的连接,支持客户端直连模式和网关模式

type PlayerComponent

type PlayerComponent interface {
	gentity.Component
	// 关联的玩家对象
	GetPlayer() *Player
}

玩家组件接口

type PlayerDataComponent

type PlayerDataComponent struct {
	BasePlayerComponent
	gentity.BaseDirtyMark
}

保存数据作为一个整体的玩家组件 当保存数据的任何一个字段更新时,作为一个整体进行缓存更新

func NewPlayerDataComponent

func NewPlayerDataComponent(player *Player, componentName string) *PlayerDataComponent

type PlayerMapDataComponent

type PlayerMapDataComponent struct {
	BasePlayerComponent
	gentity.BaseMapDirtyMark
}

保存数据为map格式的玩家组件 当对map的某一项增删改时,只对那一项进行缓存更新

func NewPlayerMapDataComponent

func NewPlayerMapDataComponent(player *Player, componentName string) *PlayerMapDataComponent

type ProcessStatInfo

type ProcessStatInfo struct {
	gentity.DataComponent
	// plain表示明文存储,在保存到mongo时,不会进行proto序列化
	Data *pb.ProcessStatInfo `db:"ProcessStatInfo;plain"`
}

进程统计信息组件

func NewProcessStatInfo

func NewProcessStatInfo(globalEntity *GlobalEntity, data *pb.ProcessStatInfo) *ProcessStatInfo

func (*ProcessStatInfo) HandleShutdownReq

func (this *ProcessStatInfo) HandleShutdownReq(cmd PacketCommand, req *pb.ShutdownReq)

func (*ProcessStatInfo) HandleStartupReq

func (this *ProcessStatInfo) HandleStartupReq(cmd PacketCommand, req *pb.StartupReq)

type Quest

type Quest struct {
	BasePlayerComponent
	// 保存数据的子模块:已完成的任务
	// 保存数据的子模块必须是导出字段(字段名大写开头)
	Finished *FinishedQuests `child:""`
	// 保存数据的子模块:当前任务列表
	Quests *CurQuests `child:""`
}

任务模块 有多个子模块

func NewQuest

func NewQuest(player *Player) *Quest

func (*Quest) OnEvent

func (this *Quest) OnEvent(event interface{})

事件接口

func (*Quest) OnFinishQuestReq

func (this *Quest) OnFinishQuestReq(reqCmd gnet.PacketCommand, req *pb.FinishQuestReq)

完成任务的消息回调 这种格式写的函数可以自动注册客户端消息回调

type RouteOptions

type RouteOptions struct {
	// true:消息直接发给客户端
	// false:放入玩家消息队列,消息将在玩家协程中被处理
	DirectSendClient bool

	// 路由到指定的服务器
	ToServerId int32

	// 先保存到数据库(player.pendingmessages),防止路由失败造成消息丢失
	SaveDb bool
}

路由参数

func DirectSendClientRouteOptions

func DirectSendClientRouteOptions() *RouteOptions

func NewRouteOptions

func NewRouteOptions() *RouteOptions

func SaveDbRouteOptions

func SaveDbRouteOptions() *RouteOptions

func (*RouteOptions) SetDirectSendClient

func (this *RouteOptions) SetDirectSendClient(directSendClient bool) *RouteOptions

set DirectSendClient

func (*RouteOptions) SetToServerId

func (this *RouteOptions) SetToServerId(toServerId int32) *RouteOptions

set ToServerId

Jump to

Keyboard shortcuts

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