package orderCfg

import (
	"server/gamedata"
)

const (
	CFG_ORDER_DATA       = "OrderData"
	CFG_ORDER_CHESS_DATA = "OrderChessData"
	CFG_ORDER_NUM_DATA   = "OrderNumData"
)

func init() {
	gamedata.InitCfg(CFG_ORDER_DATA)
	gamedata.InitCfg(CFG_ORDER_CHESS_DATA)
	gamedata.InitCfg(CFG_ORDER_NUM_DATA)
}

func GetLvMin(EnergyMul int) int {
	data, err := gamedata.GetDataByIntKey(CFG_ORDER_DATA, EnergyMul)
	if err != nil {
		return 0
	}
	return gamedata.GetIntValue(data, "LvMin")
}

func GetLvMax(EnergyMul, N int) int {
	data, err := gamedata.GetData(CFG_ORDER_CHESS_DATA)
	if err != nil {
		return 0
	}
	for _, v := range data {
		dEnergy := gamedata.GetIntValue(v, "EnergyMul")
		Min := gamedata.GetIntValue(v, "MinN")
		Max := gamedata.GetIntValue(v, "MaxN")
		if dEnergy == EnergyMul {
			if N >= Min && N <= Max {
				return gamedata.GetIntValue(v, "MaxLv")
			}
		}
	}
	return 0
}

func GetOrderNum(Level int) int {
	data, err := gamedata.GetData(CFG_ORDER_NUM_DATA)
	if err != nil {
		return 0
	}
	for _, v := range data {
		Min := gamedata.GetIntValue(v, "Min")
		Max := gamedata.GetIntValue(v, "Max")
		if Level >= Min && Level <= Max {
			return gamedata.GetIntValue(v, "Num")
		}
	}
	return 0
}
