#include "Chr_Equipment.h"
#include "Global/Global_Game.h"
#include "Actor/Object/CharacterObject.h"

void Chr_Equipment::Init(CharacterObject *parent)
{
    // 判断是否转职读取不同的配置
    GlobalCharacterScript::JobConfig JobInfo;
    if (parent->GrowType == -1)
    {
        JobInfo = Global_Game::GetInstance().CharacterConfigs[parent->Job].baseJobConfig;
    }
    else
    {
        GlobalCharacterScript::CharacterConfig Config = Global_Game::GetInstance().CharacterConfigs[parent->Job];
        JobInfo = Config.growtypeJobConfig[parent->GrowType];
    }

    // 读取默认时装
    for (auto &pair : JobInfo.defaultAvatarList)
    {
        std::string PartName = pair.first;
        int Index = pair.second;
        RefPtr<Equipment> equip = new Equipment();
        equip->Init(Index);
        this->_default_equip[PartName] = equip;
    }
}

RefPtr<Equipment> Chr_Equipment::GetEquip(std::string part)
{
    // 先看真实穿戴 如果没有     看默认   如果没有 返回空
    if (_real_equip.count(part) > 0)
        return _real_equip[part];
    if (_default_equip.count(part) > 0)
        return _default_equip[part];
    return nullptr;
}