package startOrderCfg

import (
	"server/gamedata"
	"strconv"
)

type StartOrderCfg struct {
}

var CFG_NAME = "StartOrder"

func init() {
	gamedata.InitCfg(CFG_NAME)
}

// 根据step 获取初始订单
func GetStartOrderByStep(id int) []*gamedata.StartOrderData {
	ret := make([]*gamedata.StartOrderData, 0)
	data, err := gamedata.GetData(CFG_NAME)
	if err != nil {
		return ret
	}
	for k, v := range data {
		record := v.(map[string]interface{})
		stepVal := gamedata.ParseInt(record["step"])
		var MergeList []int
		for _, vv := range record["merge_id_list"].([]interface{}) {
			MergeList = append(MergeList, gamedata.ParseInt(vv))
		}
		if int(stepVal) == id {
			OrderId, _ := strconv.Atoi(k)
			ret = append(ret, &gamedata.StartOrderData{
				Id:        OrderId,
				Step:      int(stepVal),
				MergeList: MergeList,
			})
		}
	}
	return ret
}
