#include "pch.h"
#include "STL.h"



std::vector<DrawCodestruct>DrawCodeT1_STL;
std::vector<DrawCodestruct>DrawCodeT2_STL;
std::vector<DrawCodestruct>DrawCodeT3_STL;

//龙盒
#if defined DRAGONBOX_SWITCH
void STL::SyncDargonBox_STL()
{
    DargonState_STL["dargonmap"].sync = 0;
}

void STL::DrawDargonBox_STL(char* Buffer)
{
    std::cout << "插件收到的字符串:" << Buffer << std::endl;
    rapidjson::Document Dom;
    Dom.Parse(Buffer);

    //构造龙盒 模式
    //DrawDargonModel_STL(Dom["op"].GetInt());
    DargonModel_STL["op"] = Dom["op"].GetInt();
    DargonModel_STL["err"] = Dom["err"].GetInt();
    DargonModel_STL["port"] = Dom["port"].GetInt();

    if (DargonModel_STL["err"] != 0)return;//如果不是
    //构造res包 结构体
    Dargonresult Res_Buffer[10];
    if (DargonModel_STL["op"] == 4)
    {
        Res_Buffer[0].ItemIndex = Dom["result"][0]["item"].GetInt();
        Res_Buffer[0].ItemNum = Dom["result"][0]["num"].GetInt();
        Res_Buffer[0].ItemGrade = Dom["result"][0]["grade"].GetInt();
    }
    if (DargonModel_STL["op"] == 6)
    {
        for (int i = 0; i < 10; ++i)
        {
            Res_Buffer[i].ItemIndex = Dom["result"][i]["item"].GetInt();
            Res_Buffer[i].ItemNum = Dom["result"][i]["num"].GetInt();
            Res_Buffer[i].ItemGrade = Dom["result"][i]["grade"].GetInt();
        }
    }
    //构造龙盒总 结构体
    DargonMap M_Buffer;
    M_Buffer.LuckyValue = Dom["lucky_value"].GetInt();
    M_Buffer.sync = 1;
    M_Buffer.box_num = Dom["box_num"].GetInt();
    for (int b = 0; b < 10; ++b)
    {
        M_Buffer.Result[b] = Res_Buffer[b];
    }
    //构造 龙盒 奖励数据
    DargonState_STL["dargonmap"] = M_Buffer;
}

int STL::SelectDargonBox_STL(int Type , int Index)
{ 
    switch (Type)
    {
    case 0://物品ID
        return DargonState_STL["dargonmap"].Result[Index].ItemIndex;
        break;
    case 1://物品数量
        return DargonState_STL["dargonmap"].Result[Index].ItemNum;
        break;
    case 2://物品品级
        return DargonState_STL["dargonmap"].Result[Index].ItemGrade;
        break;
    case 3://幸运值
        return DargonState_STL["dargonmap"].LuckyValue;
        break;
    case 4://Sync
        return DargonState_STL["dargonmap"].sync;
        break;
    case 5://Box_num
        return DargonState_STL["dargonmap"].box_num;
        break;
    default:
        break;
    }
    return 404404404;
}

void STL::DrawDargonModel_STL(int Value)
{
    DargonModel_STL["op"] = Value;
}

int STL::SelectDargonModel_STL(int Type)
{
    switch (Type)
    {
    case 0:
        return DargonModel_STL["op"];
        break;
    case 1:
        return DargonModel_STL["err"];
        break;
    case 2:
        return DargonModel_STL["port"];
        break;
    }
    return 0;
}
#endif

//普通 STL
#if defined NORMAL_STL
int STL::Check_STL(std::string name,int Type,int idx)
{
    switch (Type)
    {
    case 0:
        return Int_STL.count(name);
        break;
    case 1:
        return Float_STL.count(name);
    case 2:
        return String_STL.count(name);
        break;
    case 3:
        return Bool_STL.count(name);
        break;
    case 4:
        return IntArr_STL[name].count(idx);
        break;
    case 5:
        return FloatArr_STL[name].count(idx);
        break;
    case 6:
        return StringArr_STL[name].count(idx);
        break;
    case 7:
        return BoolArr_STL[name].count(idx);
        break;
    default:
        return 0;
        break;
    }
}

void STL::BuildIntArr_STL(std::string name)
{
    //aod.emplace(0, 0);
    IntArr_STL.emplace(name, aod);
    //aod.clear();
}

void STL::BuildFloatArr_STL(std::string name)
{
    //bod.emplace(0, 0.0);
    FloatArr_STL.emplace(name, bod);
    //bod.clear();
}

void STL::BuildStringArr_STL(std::string name)
{
    //cod.emplace(0, "zero");
    StringArr_STL.emplace(name, cod);
    //cod.clear();
}

void STL::BuildBoolArr_STL(std::string name)
{
    //dod.emplace(0, false);
    BoolArr_STL.emplace(name, dod);
    //dod.clear();
}

void STL::SetIntArr_STL(std::string name, int idx, int value)
{
    IntArr_STL[name][idx] = value;
}

void STL::SetFloatArr_STL(std::string name, int idx, FLOAT value)
{
    FloatArr_STL[name][idx] = value;
}

void STL::SetStringArr_STL(std::string name, int idx, std::string value)
{
    StringArr_STL[name][idx] = value;
}

void STL::SetBoolArr_STL(std::string name, int idx, BOOL value)
{
    BoolArr_STL[name][idx] = value;
}

int STL::GetIntArr_STL(std::string name, int idx)
{
    return IntArr_STL[name][idx];
}

FLOAT STL::GetFloatArr_STL(std::string name, int idx)
{
    return FloatArr_STL[name][idx];
}

std::string STL::GetStringArr_STL(std::string name, int idx)
{
    return StringArr_STL[name][idx];
}

BOOL STL::GetBoolArr_STL(std::string name, int idx)
{
    return BoolArr_STL[name][idx];
}
#endif