package itemCfg

import (
	"server/gamedata"
	"server/pkg/github.com/name5566/leaf/log"
	"strconv"
	"strings"
)

var CFG_NAME = "Item"

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

func GetItemType(Id int) int {
	data, err := gamedata.GetDataByIntKey(CFG_NAME, Id)
	if err != nil {
		log.Debug("ItemCfg GetItemType Id:%v not found", Id)
		return 0
	}
	return gamedata.ParseInt(data["IType"])
}

func GetItemEffect(Id int) int {
	data, err := gamedata.GetDataByIntKey(CFG_NAME, Id)
	if err != nil {
		log.Debug("ItemCfg GetItemEffect Id:%v not found", Id)
		return 0
	}
	return gamedata.ParseInt(data["Effect"])
}

func GetItemEffectList(Id int) []int {
	data, err := gamedata.GetDataByIntKey(CFG_NAME, Id)
	if err != nil {
		log.Debug("ItemCfg GetItemEffect Id:%v not found", Id)
		return []int{}
	}
	var res []int
	str := gamedata.GetStringValue(data, "Effect")
	a := strings.Split(str, ",")
	for _, v := range a {
		b, _ := strconv.Atoi(v)
		res = append(res, b)
	}
	return res
}
