70 lines
1.7 KiB
Go
70 lines
1.7 KiB
Go
package srvdata
|
|
|
|
import (
|
|
"mongo.games.com/game/protocol/server"
|
|
"mongo.games.com/game/protocol/webapi"
|
|
)
|
|
|
|
func init() {
|
|
DataMgr.RegisterLoader("DB_GameItem.dat", GameItemMgr)
|
|
}
|
|
|
|
var GameItemMgr = &GameItem{
|
|
Data: make(map[int32]*server.DB_GameItem),
|
|
Items: make(map[string]map[int32]*server.DB_GameItem),
|
|
AllItems: make(map[string][]*server.DB_GameItem),
|
|
}
|
|
|
|
type GameItem struct {
|
|
Data map[int32]*server.DB_GameItem // 配置表
|
|
Items map[string]map[int32]*server.DB_GameItem // 后台动态配置
|
|
AllItems map[string][]*server.DB_GameItem
|
|
}
|
|
|
|
func (m *GameItem) Load(fileFullPath string) error {
|
|
m.Data = make(map[int32]*server.DB_GameItem)
|
|
m.AllItems = make(map[string][]*server.DB_GameItem)
|
|
for _, v := range PBDB_GameItemMgr.Datas.GetArr() {
|
|
m.Data[v.GetId()] = v
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (m *GameItem) Reload(fileFullPath string) error {
|
|
return m.Load(fileFullPath)
|
|
}
|
|
|
|
func (m *GameItem) SetConfig(config *webapi.ItemConfig) {
|
|
if config != nil && len(config.GetItems()) > 0 {
|
|
m.AllItems = make(map[string][]*server.DB_GameItem)
|
|
m.Items[config.GetPlatform()] = make(map[int32]*server.DB_GameItem)
|
|
for _, vv := range config.GetItems() {
|
|
m.Items[config.GetPlatform()][vv.GetId()] = vv
|
|
}
|
|
}
|
|
}
|
|
|
|
func (m *GameItem) Get(platform string, id int32) *server.DB_GameItem {
|
|
if v, ok := m.Data[id]; ok {
|
|
return v
|
|
}
|
|
if v, ok := m.Items[platform]; ok {
|
|
if v, ok := v[id]; ok {
|
|
return v
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (m *GameItem) GetArr(platform string) []*server.DB_GameItem {
|
|
if len(m.AllItems[platform]) == 0 {
|
|
for _, v := range m.Data {
|
|
m.AllItems[platform] = append(m.AllItems[platform], v)
|
|
}
|
|
for _, v := range m.Items[platform] {
|
|
m.AllItems[platform] = append(m.AllItems[platform], v)
|
|
}
|
|
}
|
|
return m.AllItems[platform]
|
|
}
|