#include "CharacterConfig.h"
#include "Asset/AssetManager.h"
#include "Tool/Tool_String.h"
namespace GlobalCharacterScript
{
    JobConfig InitJobConfig(std::string JobInfoPath)
    {
        JobConfig Config;
        ScriptData Data = AssetManager::GetInstance().GetScriptInfo(JobInfoPath);
        while (!Data.IsEnd())
        {
            std::string Segment = Data.Get();
            if (Segment == "[职业名称]")
                Config.name = Data.Get();
            else if (Segment == "[生命值上限]")
                Config.maxHP = std::stof(Data.Get());
            else if (Segment == "[魔法值上限]")
                Config.maxMP = std::stof(Data.Get());
            else if (Segment == "[生命值回复速率]")
                Config.hpRecoverRate = std::stof(Data.Get());
            else if (Segment == "[魔法值回复速率]")
                Config.mpRecoverRate = std::stof(Data.Get());
            else if (Segment == "[力量]")
                Config.strength = std::stof(Data.Get());
            else if (Segment == "[智力]")
                Config.intelligence = std::stof(Data.Get());
            else if (Segment == "[体力]")
                Config.stamina = std::stof(Data.Get());
            else if (Segment == "[精神]")
                Config.spirit = std::stof(Data.Get());
            else if (Segment == "[移动速度]")
                Config.moveSpeed = std::stof(Data.Get());
            else if (Segment == "[攻击速度]")
                Config.attackSpeed = std::stof(Data.Get());
            else if (Segment == "[释放速度]")
                Config.castSpeed = std::stof(Data.Get());
            else if (Segment == "[硬直]")
                Config.stunResist = std::stof(Data.Get());
            else if (Segment == "[跳跃力]")
                Config.jumpPower = std::stof(Data.Get());
            else if (Segment == "[跳跃速度]")
                Config.jumpSpeed = std::stof(Data.Get());
            else if (Segment == "[火属性抗性]")
                Config.fireResist = std::stof(Data.Get());
            else if (Segment == "[冰属性抗性]")
                Config.iceResist = std::stof(Data.Get());
            else if (Segment == "[光属性抗性]")
                Config.lightResist = std::stof(Data.Get());
            else if (Segment == "[暗属性抗性]")
                Config.darkResist = std::stof(Data.Get());
            else if (Segment == "[默认技能]")
            {
                while (true)
                {
                    std::string Ret = Data.Get();
                    if (Ret == "[/默认技能]")
                        break;
                    Config.skillList.push_back(std::stoi(Ret));
                }
            }
            else if (Segment == "[默认时装]")
            {
                while (true)
                {
                    std::string Ret = Data.Get();
                    if (Ret == "[/默认时装]")
                        break;
                    std::string Index = Data.Get();
                    Config.defaultAvatarList[Ret] = std::stoi(Index);
                }
            }
        }

        return Config;
    }

    CharacterConfig InitCharacterConfig(std::string JobInfoPath)
    {
        CharacterConfig Config;
        ScriptData Data = AssetManager::GetInstance().GetScriptInfo(std::string("character/") + JobInfoPath);
        while (!Data.IsEnd())
        {
            std::string Segment = Data.Get();
            if (Segment == "[职业标签]")
            {
                std::string JobTab = Data.Get();
                Config.jobTag = JobTab.substr(1, JobTab.size() - 2);
            }
            else if (Segment == "[基础职业属性]")
            {
                Config.baseGrowtypePath = Data.Get();
                Config.baseJobConfig = InitJobConfig(Tool_toLowerCase(Config.baseGrowtypePath));
            }
            else if (Segment == "[转职职业属性]")
            {
                while (true)
                {
                    std::string Ret = Data.Get();
                    if (Ret == "[/转职职业属性]")
                        break;
                    Config.growtypePath.push_back(Ret);
                    Config.growtypeJobConfig.push_back(InitJobConfig(Tool_toLowerCase(Ret)));
                }
            }
            else if (Segment == "[动作动画]")
            {
                while (true)
                {
                    std::string Ret = Data.Get();
                    if (Ret == "[/动作动画]")
                        break;
                    std::string path = Data.Get();
                    Config.animationPath[Ret] = path;
                }
            }
        }
        return Config;
    }

    std::vector<CharacterConfig> InitCharacterLst()
    {
        std::vector<CharacterConfig> Config;
        // 先读取角色职业lst
        ScriptData Data = AssetManager::GetInstance().GetScriptInfo("character/character.lst");
        while (!Data.IsEnd())
        {
            std::string Index = Data.Get();
            std::string JobInfoPath = Data.Get();
            // 读取职业 //TODO 现在只有鬼剑士更改了文件 其他职业读了会炸
            if (std::stoi(Index) <= 0)
                Config.push_back(InitCharacterConfig(Tool_toLowerCase(JobInfoPath)));
        }
        return Config;
    }
}