50 lines
1.1 KiB
Go
50 lines
1.1 KiB
Go
package model
|
|
|
|
import (
|
|
"rocommon/util"
|
|
)
|
|
|
|
type FruitManager struct {
|
|
mapRouterNode string
|
|
socialNode string
|
|
updateTimer util.ServerTimer
|
|
Room *FruitRoom
|
|
players map[uint64]*FruitPlayer
|
|
}
|
|
|
|
func newFruitManager() *FruitManager {
|
|
fruitManager := &FruitManager{
|
|
Room: newFruitRoom(100000),
|
|
updateTimer: util.NewDurationTimer(util.GetTimeMilliseconds(), 1000),
|
|
players: make(map[uint64]*FruitPlayer),
|
|
}
|
|
return fruitManager
|
|
}
|
|
|
|
func (self *FruitManager) AddPlayer(uid uint64, name string) {
|
|
_, exist := self.players[uid]
|
|
if exist == false {
|
|
self.players[uid] = newFruitPlayer(uid, name)
|
|
}
|
|
self.players[uid].Online = true
|
|
}
|
|
|
|
func (self *FruitManager) RemovePlayer(uid uint64) {
|
|
//delete(self.players, uid)
|
|
_, exist := self.players[uid]
|
|
if exist {
|
|
self.players[uid].Online = false
|
|
}
|
|
}
|
|
|
|
func (self *FruitManager) GetPlayer(uid uint64) *FruitPlayer {
|
|
return self.players[uid]
|
|
}
|
|
|
|
func (self *FruitManager) Update(ms uint64) {
|
|
if !self.updateTimer.IsStart() || !self.updateTimer.IsExpired(ms) {
|
|
return
|
|
}
|
|
self.Room.Update()
|
|
}
|