package main import ( "mongo.games.com/game/protocol/server" "mongo.games.com/game/srvdata" ) var GameFreeMgrEx = &PBDB_GameFreeMgrEx{ DbGameFreeId: make(map[string]int32), DbGameDif: make(map[int32]map[int32]string), DbGameDifByGFI: make(map[int32]string), DbGameFreeMgr: make(map[string]*server.DB_GameFree), } type PBDB_GameFreeMgrEx struct { DbGameFreeId map[string]int32 //key为GameDif DbGameDif map[int32]map[int32]string //key为 GameId GameMode DbGameDifByGFI map[int32]string //key 为 DBGameFreeId DbGameFreeMgr map[string]*server.DB_GameFree //key为GameDif } func (this *PBDB_GameFreeMgrEx) Load(fileFullPath string) error { for _, gfm := range srvdata.PBDB_GameFreeMgr.Datas.Arr { if _, ok := this.DbGameFreeId[gfm.GetGameDif()]; !ok { this.DbGameFreeId[gfm.GetGameDif()] = gfm.GetId() } if _, ok := this.DbGameDif[gfm.GetGameId()]; !ok { this.DbGameDif[gfm.GetGameId()] = make(map[int32]string) } this.DbGameDif[gfm.GetGameId()][gfm.GetGameMode()] = gfm.GetGameDif() this.DbGameDifByGFI[gfm.GetId()] = gfm.GetGameDif() this.DbGameFreeMgr[gfm.GetGameDif()] = gfm } return nil } func (this *PBDB_GameFreeMgrEx) Reload(fileFullPath string) error { return this.Load(fileFullPath) } // 查询当前游戏的DBGameFreeMgr func (this *PBDB_GameFreeMgrEx) GetDBGameFreeMgrByGameDif(gameDif string) *server.DB_GameFree { return this.DbGameFreeMgr[gameDif] } // 查询当前游戏的GameDif func (this *PBDB_GameFreeMgrEx) GetGameDifByGameFreeId(dbGameFreeId int32) string { if str, ok := this.DbGameDifByGFI[dbGameFreeId]; ok { return str } return "" } // 查询当前游戏的GameDif func (this *PBDB_GameFreeMgrEx) GetGameDifByGameIdAndMode(gameId, gameMode int32) string { if data, ok := this.DbGameDif[gameId]; ok { if str, ok2 := data[gameMode]; ok2 { return str } } return "" } // 查询当前游戏的GameFreeId func (this *PBDB_GameFreeMgrEx) GetGameFreeIdByGameDif(gameDif string) int32 { if d, ok := this.DbGameFreeId[gameDif]; ok { return d } return 0 } func init() { srvdata.DataMgr.RegisterLoader("DB_GameFree.dat", GameFreeMgrEx) }