建档
This commit is contained in:
169
source_game/Asset/Common/Equipment.cpp
Normal file
169
source_game/Asset/Common/Equipment.cpp
Normal file
@@ -0,0 +1,169 @@
|
||||
#include "Equipment.h"
|
||||
#include "Global/Global_Game.h"
|
||||
#include "Asset/AssetManager.h"
|
||||
|
||||
int Equipment::GetJobIndex(std::string JobName)
|
||||
{
|
||||
if (JobName == "[swordman]")
|
||||
return 0;
|
||||
else if (JobName == "[fighter]")
|
||||
return 1;
|
||||
else if (JobName == "[gunner]")
|
||||
return 2;
|
||||
else if (JobName == "[mage]")
|
||||
return 3;
|
||||
else if (JobName == "[priest]")
|
||||
return 4;
|
||||
else if (JobName == "[atgunner]")
|
||||
return 5;
|
||||
else if (JobName == "[thief]")
|
||||
return 6;
|
||||
else if (JobName == "[atfighter]")
|
||||
return 7;
|
||||
else if (JobName == "[atmage]")
|
||||
return 8;
|
||||
else if (JobName == "[demonic swordman]")
|
||||
return 9;
|
||||
else if (JobName == "[creatormage]")
|
||||
return 10;
|
||||
return -1;
|
||||
}
|
||||
|
||||
ATTACH_TYPE Equipment::GetTradeType(std::string TradeType)
|
||||
{
|
||||
if (TradeType == "[free]")
|
||||
return ATTACH_TYPE::FREE;
|
||||
else if (TradeType == "[sealing]")
|
||||
return ATTACH_TYPE::SEALING;
|
||||
else if (TradeType == "[trade]")
|
||||
return ATTACH_TYPE::TRADE;
|
||||
else if (TradeType == "[account]")
|
||||
return ATTACH_TYPE::ACCOUNT;
|
||||
else if (TradeType == "[trade delete]")
|
||||
return ATTACH_TYPE::TRADE_DELETE;
|
||||
else if (TradeType == "[sealing trade]")
|
||||
return ATTACH_TYPE::SEALING_TRADE;
|
||||
return ATTACH_TYPE::FREE;
|
||||
}
|
||||
|
||||
bool Equipment::IsEmpty()
|
||||
{
|
||||
if (m_EquipmentPath.empty())
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
void Equipment::Init(int Index)
|
||||
{
|
||||
ConstructionByIndex(Index);
|
||||
}
|
||||
|
||||
void Equipment::Init(int Index, int Quality)
|
||||
{
|
||||
this->m_Quality = Quality;
|
||||
ConstructionByIndex(Index);
|
||||
}
|
||||
|
||||
void Equipment::ConstructionByIndex(int Index)
|
||||
{
|
||||
// 检查装备list有没有这件装备
|
||||
if (Global_Game::GetInstance().EquipmentPathMap.count(Index))
|
||||
{
|
||||
m_EquipmentPath = Global_Game::GetInstance().EquipmentPathMap[Index];
|
||||
// 读取装备信息
|
||||
ScriptData Data = AssetManager::GetInstance().GetScriptInfo(m_EquipmentPath);
|
||||
while (!Data.IsEnd())
|
||||
{
|
||||
std::string Segment = Data.Get();
|
||||
if (Segment == "[name]")
|
||||
{
|
||||
this->Name = Data.Get();
|
||||
}
|
||||
else if (Segment == "[name2]")
|
||||
{
|
||||
this->Name2 = Data.Get();
|
||||
}
|
||||
else if (Segment == "[grade]")
|
||||
{
|
||||
this->Grade = std::stoi(Data.Get());
|
||||
}
|
||||
else if (Segment == "[rarity]")
|
||||
{
|
||||
this->Rarity = std::stoi(Data.Get());
|
||||
}
|
||||
else if (Segment == "[usable job]")
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
std::string Buf = Data.Get();
|
||||
if (Buf == "[/usable job]")
|
||||
break;
|
||||
this->UsableJob[GetJobIndex(Buf)] = true;
|
||||
}
|
||||
}
|
||||
else if (Segment == "[attach type]")
|
||||
{
|
||||
this->TradeType = GetTradeType(Data.Get());
|
||||
}
|
||||
else if (Segment == "[minimum level]")
|
||||
{
|
||||
this->MinimumLevel = std::stoi(Data.Get());
|
||||
}
|
||||
else if (Segment == "[price]")
|
||||
{
|
||||
this->Price = std::stoi(Data.Get());
|
||||
}
|
||||
else if (Segment == "[repair price]")
|
||||
{
|
||||
this->RepairPrice = std::stoi(Data.Get());
|
||||
}
|
||||
else if (Segment == "[animation job]")
|
||||
{
|
||||
std::string JobString = Data.Get();
|
||||
int JobIndex = GetJobIndex(JobString);
|
||||
this->JobAni[JobIndex].clear();
|
||||
if (Data.Get() == "[variation]")
|
||||
{
|
||||
int Parm1 = std::stoi(Data.Get());
|
||||
int Parm2 = std::stoi(Data.Get());
|
||||
|
||||
while (true)
|
||||
{
|
||||
JobAnimation JobAniBuffer;
|
||||
JobAniBuffer.ImgFormat.clear();
|
||||
JobAniBuffer.ImgFormat.push_back(Parm1);
|
||||
JobAniBuffer.ImgFormat.push_back(Parm2);
|
||||
|
||||
std::string buf = Data.Get();
|
||||
if (buf == "[layer variation]")
|
||||
{
|
||||
JobAniBuffer.Layer = std::stoi(Data.Get());
|
||||
JobAniBuffer.AnimationGroup = Data.Get();
|
||||
this->JobAni[JobIndex].push_back(JobAniBuffer);
|
||||
// 调用两次 跳过原来的 [equipment ani script] 这个没有用
|
||||
std::string B1 = Data.Get();
|
||||
std::string B2 = Data.Get();
|
||||
}
|
||||
// 皮肤没有图层也没有动画组名称
|
||||
else if (m_EquipmentPath.find("skin") != std::string::npos)
|
||||
{
|
||||
JobAniBuffer.Layer = 0;
|
||||
JobAniBuffer.AnimationGroup = "null";
|
||||
this->JobAni[JobIndex].push_back(JobAniBuffer);
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
Data.Back();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
SDL_LogError(0, "没有编号为: %d 这件装备", Index);
|
||||
}
|
||||
}
|
||||
62
source_game/Asset/Common/Equipment.h
Normal file
62
source_game/Asset/Common/Equipment.h
Normal file
@@ -0,0 +1,62 @@
|
||||
#pragma once
|
||||
#include "EngineFrame/Component/Component.h"
|
||||
#include "Global/Global_Enum.h"
|
||||
class Equipment : public Component
|
||||
{
|
||||
public:
|
||||
// 职业动画结构体
|
||||
struct JobAnimation
|
||||
{
|
||||
// 图层
|
||||
int Layer;
|
||||
// 动画组名称
|
||||
std::string AnimationGroup;
|
||||
// IMG替换编号
|
||||
std::vector<int> ImgFormat = {0, 0};
|
||||
};
|
||||
|
||||
public:
|
||||
// 装备在PVF中的路径
|
||||
std::string m_EquipmentPath;
|
||||
|
||||
// 装备的品质
|
||||
int m_Quality = -1;
|
||||
|
||||
public:
|
||||
// 编号
|
||||
int Index = -1;
|
||||
// 名字
|
||||
std::string Name;
|
||||
// 别名
|
||||
std::string Name2;
|
||||
// 等级组
|
||||
int Grade = -1;
|
||||
// 稀有度
|
||||
int Rarity = -1;
|
||||
// 可用职业
|
||||
std::map<int, bool> UsableJob;
|
||||
// 交易类型
|
||||
ATTACH_TYPE TradeType;
|
||||
// 最小佩戴等级
|
||||
int MinimumLevel = 1;
|
||||
// 价值
|
||||
int Price = 0;
|
||||
// 维修价格
|
||||
int RepairPrice = 0;
|
||||
|
||||
// 职业动画
|
||||
std::map<int, std::vector<JobAnimation>> JobAni;
|
||||
|
||||
// 装备的属性
|
||||
|
||||
public:
|
||||
// 通过职业名字获取职业编号
|
||||
int GetJobIndex(std::string JobName);
|
||||
// 通过交易类型文字获取枚举值
|
||||
ATTACH_TYPE GetTradeType(std::string TradeType);
|
||||
bool IsEmpty();
|
||||
void Init(int Index);
|
||||
void Init(int Index, int Quality);
|
||||
// 通过装备编号构造装备
|
||||
void ConstructionByIndex(int Index);
|
||||
};
|
||||
126
source_game/Asset/Common/ObjectVars.h
Normal file
126
source_game/Asset/Common/ObjectVars.h
Normal file
@@ -0,0 +1,126 @@
|
||||
#pragma once
|
||||
|
||||
#include "Global/Global_Type.h"
|
||||
#include <optional>
|
||||
#include <stdexcept>
|
||||
|
||||
class ObjectVars
|
||||
{
|
||||
private:
|
||||
// 底层存储:key -> 数组(始终是vector,即使只有一个元素)
|
||||
ObjectVarsMap _data;
|
||||
|
||||
public:
|
||||
ObjectVars() = default;
|
||||
~ObjectVars() = default;
|
||||
|
||||
// 禁止拷贝(按需开启)
|
||||
ObjectVars(const ObjectVars &) = delete;
|
||||
ObjectVars &operator=(const ObjectVars &) = delete;
|
||||
|
||||
// 允许移动
|
||||
ObjectVars(ObjectVars &&) = default;
|
||||
ObjectVars &operator=(ObjectVars &&) = default;
|
||||
|
||||
// 1. 向key对应的数组添加元素(核心接口,无论添加几个元素都用这个)
|
||||
template <typename T>
|
||||
void Add(const std::string &key, const T &value)
|
||||
{
|
||||
static_assert(std::is_constructible_v<ObjectVarsType, T>, "不支持的类型(未在ObjectVarsType中定义)");
|
||||
_data[key].push_back(ObjectVarsType{value}); // 直接追加到数组,保证始终是数组形式
|
||||
}
|
||||
|
||||
// 2. 批量添加元素(一次添加多个值到数组)
|
||||
template <typename T>
|
||||
void AddAll(const std::string &key, const std::vector<T> &values)
|
||||
{
|
||||
static_assert(std::is_constructible_v<ObjectVarsType, T>, "不支持的类型(未在ObjectVarsType中定义)");
|
||||
for (const auto &val : values)
|
||||
{
|
||||
_data[key].push_back(ObjectVarsType{val});
|
||||
}
|
||||
}
|
||||
|
||||
// 3. 替换key对应的整个数组(覆盖原有所有元素)
|
||||
template <typename T>
|
||||
void SetArray(const std::string &key, const std::vector<T> &values)
|
||||
{
|
||||
static_assert(std::is_constructible_v<ObjectVarsType, T>, "不支持的类型(未在ObjectVarsType中定义)");
|
||||
// 先清空原有数据,再添加新数组
|
||||
_data[key].clear();
|
||||
AddAll(key, values);
|
||||
}
|
||||
|
||||
// 4. 获取key对应的整个数组(返回指定类型的vector,类型不匹配的元素会被过滤)
|
||||
template <typename T>
|
||||
std::vector<T> GetArray(const std::string &key) const
|
||||
{
|
||||
std::vector<T> result;
|
||||
auto it = _data.find(key);
|
||||
if (it == _data.end())
|
||||
{
|
||||
return result; // key不存在,返回空数组
|
||||
}
|
||||
// 只提取类型匹配的元素
|
||||
for (const auto &var : it->second)
|
||||
{
|
||||
if (const auto *val = std::get_if<T>(&var))
|
||||
{
|
||||
result.push_back(*val);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// 5. 获取数组中指定索引的元素(返回optional,索引越界或类型不匹配则返回nullopt)
|
||||
template <typename T>
|
||||
std::optional<T> GetAt(const std::string &key, size_t index) const
|
||||
{
|
||||
auto it = _data.find(key);
|
||||
if (it == _data.end() || index >= it->second.size())
|
||||
{
|
||||
return std::nullopt; // key不存在或索引越界
|
||||
}
|
||||
// 检查类型是否匹配
|
||||
if (const auto *val = std::get_if<T>(&it->second[index]))
|
||||
{
|
||||
return *val;
|
||||
}
|
||||
return std::nullopt; // 类型不匹配
|
||||
}
|
||||
|
||||
// 6. 检查key是否存在(无论数组是否为空)
|
||||
bool Has(const std::string &key) const
|
||||
{
|
||||
return _data.find(key) != _data.end();
|
||||
}
|
||||
|
||||
// 7. 获取数组长度(key不存在则返回0)
|
||||
size_t GetSize(const std::string &key) const
|
||||
{
|
||||
auto it = _data.find(key);
|
||||
return (it != _data.end()) ? it->second.size() : 0;
|
||||
}
|
||||
|
||||
// 8. 清空key对应的数组(保留key但数组为空)
|
||||
void ClearArray(const std::string &key)
|
||||
{
|
||||
auto it = _data.find(key);
|
||||
if (it != _data.end())
|
||||
{
|
||||
it->second.clear();
|
||||
}
|
||||
}
|
||||
|
||||
// 9. 删除整个key(包括数组)
|
||||
void Remove(const std::string &key)
|
||||
{
|
||||
_data.erase(key);
|
||||
}
|
||||
|
||||
// 10. 清空所有数据
|
||||
void ClearAll()
|
||||
{
|
||||
_data.clear();
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user