88 lines
2.0 KiB
Go
88 lines
2.0 KiB
Go
package srvdata
|
|
|
|
import "mongo.games.com/game/common"
|
|
|
|
func init() {
|
|
DataMgr.RegisterLoader("DB_GameFree.dat", GameFreeMgr)
|
|
}
|
|
|
|
var GameFreeMgr = &GameFree{
|
|
GameId: make(map[string][]int32),
|
|
GameMode: make(map[int32]map[int32][]int32),
|
|
}
|
|
|
|
type GameFree struct {
|
|
GameId map[string][]int32 // GameDif:[]GameId
|
|
GameMode map[int32]map[int32][]int32
|
|
}
|
|
|
|
func (this *GameFree) Load(fileFullPath string) error {
|
|
this.GameMode = make(map[int32]map[int32][]int32)
|
|
this.GameId = make(map[string][]int32)
|
|
for _, v := range PBDB_GameFreeMgr.Datas.Arr {
|
|
// GameMode
|
|
vv, ok := this.GameMode[v.GameId]
|
|
if !ok {
|
|
vv = make(map[int32][]int32)
|
|
this.GameMode[v.GameId] = vv
|
|
}
|
|
_, ok = vv[v.GameMode]
|
|
if !ok {
|
|
this.GameMode[v.GameId][v.GameMode] = []int32{v.Id}
|
|
} else {
|
|
this.GameMode[v.GameId][v.GameMode] = append(this.GameMode[v.GameId][v.GameMode], v.Id)
|
|
}
|
|
// GameId
|
|
this.GameId[v.GameDif] = append(this.GameId[v.GameDif], v.GameId)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (this *GameFree) Reload(fileFullPath string) error {
|
|
return this.Load(fileFullPath)
|
|
}
|
|
|
|
func (this *GameFree) GetGameFreeIds(gameId, gameMode int32) (ids []int32, gameType int32) {
|
|
mode, ok := this.GameMode[gameId]
|
|
if !ok {
|
|
return nil, 0
|
|
}
|
|
|
|
ids, ok = mode[gameMode]
|
|
if len(ids) > 0 {
|
|
data := PBDB_GameFreeMgr.GetData(ids[0])
|
|
if data != nil {
|
|
gameType = data.GameType
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
func (this *GameFree) GetGameId(gameDif string) []int32 {
|
|
return this.GameId[gameDif]
|
|
}
|
|
|
|
func (this *GameFree) IsGameDif(gameId int32, gameDif string) bool {
|
|
mode, ok := this.GameMode[gameId]
|
|
if !ok {
|
|
return false
|
|
}
|
|
for _, v := range mode {
|
|
if len(v) > 0 {
|
|
data := PBDB_GameFreeMgr.GetData(v[0])
|
|
if data == nil {
|
|
return false
|
|
}
|
|
return data.GameDif == gameDif
|
|
} else {
|
|
return false
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
// IsPlayerPool 需要统计在个人水池的游戏
|
|
func (this *GameFree) IsPlayerPool(gameId int) bool {
|
|
return this.IsGameDif(int32(gameId), common.GameDifTienlen) || this.IsGameDif(int32(gameId), common.GameDifThirteen)
|
|
}
|