Ai
1 Star 0 Fork 0

wuzpdev/goworld

Create your Gitee Account
Explore and code with more than 13.5 million developers,Free private repositories !:)
Sign up
文件
Clone or Download
OnlineService.go 1.27 KB
Copy Edit Raw Blame History
seis authored 2018-06-14 00:00 +08:00 . create service entity: fix compile error
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) DescribeEntityType(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 ...")
}
// 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.6

Search