1 Star 0 Fork 0

wuzpdev/goworld

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
OnlineService.go 1.29 KB
一键复制 编辑 原始数据 按行查看 历史
seis 提交于 2017-11-07 00:49 . DefineAttrs on entities or components
package main
import (
"github.com/xiaonanln/goworld/engine/common"
"github.com/xiaonanln/goworld/engine/entity"
"github.com/xiaonanln/goworld/engine/gwlog"
)
type avatarInfo struct {
name string
level int
}
// OnlineService is the service entity for maintain total online avatar infos
type OnlineService struct {
entity.Entity
avatars map[common.EntityID]*avatarInfo
maxlevel int
}
func (s *OnlineService) DefineAttrs(desc *entity.EntityTypeDesc) {
}
// OnInit initialize OnlineService fields
func (s *OnlineService) OnInit() {
s.avatars = map[common.EntityID]*avatarInfo{}
}
// OnCreated is called when OnlineService is created
func (s *OnlineService) OnCreated() {
gwlog.Infof("Registering OnlineService ...")
s.DeclareService("OnlineService")
}
// CheckIn is called when Avatars login
func (s *OnlineService) CheckIn(avatarID common.EntityID, name string, level int) {
s.avatars[avatarID] = &avatarInfo{
name: name,
level: level,
}
if level > s.maxlevel {
s.maxlevel = level
}
gwlog.Infof("%s CHECK IN: %s %s %d, total online %d", s, avatarID, name, level, len(s.avatars))
}
// CheckOut is called when Avatars logout
func (s *OnlineService) CheckOut(avatarID common.EntityID) {
delete(s.avatars, avatarID)
gwlog.Infof("%s CHECK OUT: %s, total online %d", s, avatarID, len(s.avatars))
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/wuzpdev/goworld.git
git@gitee.com:wuzpdev/goworld.git
wuzpdev
goworld
goworld
v0.1.1

搜索帮助

0d507c66 1850385 C8b1a773 1850385