package srvdata

import "mongo.games.com/game/protocol/server"

var MatchLevelMgr = &MatchLevel{
	DBGameFreeId: map[int32][]*server.DB_GameMatchLevel{},
}

type MatchLevel struct {
	DBGameFreeId map[int32][]*server.DB_GameMatchLevel
}

func (m *MatchLevel) Load(fileFullPath string) error {
	m.DBGameFreeId = make(map[int32][]*server.DB_GameMatchLevel)
	for _, v := range PBDB_GameMatchLevelMgr.Datas.GetArr() {
		m.DBGameFreeId[v.GameFreeId] = append(m.DBGameFreeId[v.GameFreeId], v)
	}
	return nil
}

func (m *MatchLevel) Reload(fileFullPath string) error {
	return m.Load(fileFullPath)
}

func (m *MatchLevel) Get(gamefreeid, level int32) *server.DB_GameMatchLevel {
	arr, ok := m.DBGameFreeId[gamefreeid]
	if !ok {
		arr = m.DBGameFreeId[0] // 默认配置
	}
	if len(arr) > 0 {
		for _, v := range arr {
			if v.GetMatchLevel() == level {
				return v
			}
		}
	}
	// 给个默认值
	return &server.DB_GameMatchLevel{
		Id:            0,
		GameFreeId:    0,
		MatchLevel:    0,
		RobotUpRatio:  50,
		UpGrade:       []int32{40, 70, 100, 130, 160, 190, 420, 480, 540, 600},
		UpGradeOdds:   []int32{200, 220, 90, 85, 80, 75, 70, 65, 60, 55},
		DownGrade:     []int32{20, 40, 60, 80, 100, 120, 140, 160, 180, 200},
		DownGradeOdds: []int32{300, 300, 85, 60, 55, 50, 45, 40, 35, 30},
	}
}

func init() {
	DataMgrAfter.RegisterLoader("DB_GameMatchLevel.dat", MatchLevelMgr)
}
