package gmdata

// 天赋
type PlayerTalent struct {
	TalentId   int    `json:"talent_Id"`
	TalentName string `json:"talent_name"`
	Number     int    `json:"number"`
}

// 宝物
type PlayerTreasure struct {
	Id    int64  `json:"ID"`
	Name  string `json:"name"`
	Level int    `json:"level"`
	Star  int    `json:"star"`
}

// 角色
type PlayerRole struct {
	Id   int64  `json:"ID"`
	Name string `json:"name"`
}

// 关卡
type PlayerChapter struct {
	ID         int64  `json:"ID"`
	Name       string `json:"name"`
	Difficulty int    `json:"difficulty"`
	Chapter    int    `json:"chapter"` //房间数量
}

// 武器
type PlayerWear struct {
	ID     int64  `json:"ID,omitempty"`
	Name   string `json:"name,omitempty"`
	RoleID int64  `json:"role,omitempty"`
}

type PlayerBody struct {
	Part  int    `json:"part,omitempty"`
	Name  string `json:"name,omitempty"`
	Level int    `json:"level,omitempty"`
	Step  int    `json:"step,omitempty"`
}

// 部件锻造
var BodyMap = map[int]string{
	1: "武器",
	2: "头盔",
	3: "护甲",
	4: "护符",
	5: "手套",
	6: "指环",
}

var (
	PlayerRoles     map[int64]PlayerRole
	PlayerChapters  map[int64]PlayerChapter
	PlayerTalents   map[int]PlayerTalent
	PlayerWears     map[int64]PlayerWear
	PlayerTreasures map[int64]PlayerTreasure
)

func LoadPlayerData(confPath string) error {
	err := LoadItemData(confPath, "Role.json", &PlayerRoles)
	if err != nil {
		return err
	}

	playerChapterArr := make([]PlayerChapter, 0)
	err = LoadItemData(confPath, "chapter.json", &playerChapterArr)
	if err != nil {
		return err
	}
	//转换成map
	PlayerChapters = make(map[int64]PlayerChapter)
	for _, item := range playerChapterArr {
		PlayerChapters[item.ID] = item
	}

	PlayerTalents = make(map[int]PlayerTalent)
	err = LoadItemData(confPath, "talent.json", &PlayerTalents)
	if err != nil {
		return err
	}

	err = LoadItemData(confPath, "wear.json", &PlayerWears)
	if err != nil {
		return err
	}
	err = LoadItemData(confPath, "treasureAttr.json", &PlayerTreasures)
	if err != nil {
		return err
	}
	return nil
}
