DarkflameServer/dGame/dGrim/ResistanceProfile.cpp
wincent 5973430720 Grim LU
Wincent's attempt at making LU into something it isn't supposed to be, an ARPG.
2023-07-15 10:54:41 +02:00

68 lines
1.8 KiB
C++

#include "ResistanceProfile.h"
#include "tinyxml2.h"
std::map<int32_t, ResistanceProfile> ResistanceProfile::s_ResistanceProfiles;
void ResistanceProfile::LoadResistanceProfiles(const std::string& filename) {
tinyxml2::XMLDocument doc;
doc.LoadFile(filename.c_str());
auto root = doc.FirstChildElement("ResistanceProfiles");
for (auto element = root->FirstChildElement("ResistanceProfile"); element != nullptr; element = element->NextSiblingElement("ResistanceProfile")) {
// lot,lot,...
auto lots = element->Attribute("lot");
if (lots == nullptr) {
continue;
}
const auto& splits = GeneralUtils::SplitString(lots, ',');
for (const auto& split : splits) {
const auto lot = std::stoi(split);
ResistanceProfile resistanceProfile(lot);
for (auto resistanceElement = element->FirstChildElement("Resistance"); resistanceElement != nullptr; resistanceElement = resistanceElement->NextSiblingElement("Resistance")) {
auto statType = resistanceElement->IntAttribute("type");
auto value = resistanceElement->FloatAttribute("value");
resistanceProfile.AddResistanceProfile(static_cast<eStatTypes>(statType), value);
}
s_ResistanceProfiles.emplace(lot, resistanceProfile);
}
}
}
ResistanceProfile* ResistanceProfile::FindResistanceProfile(int32_t lot) {
const auto& it = s_ResistanceProfiles.find(lot);
if (it != s_ResistanceProfiles.end()) {
return &it->second;
}
return nullptr;
}
ResistanceProfile::ResistanceProfile(int32_t lot) {
this->m_Lot = lot;
}
void ResistanceProfile::AddResistanceProfile(eStatTypes statType, float value) {
m_ResistanceProfile[statType] = value;
}
float ResistanceProfile::GetResistanceProfile(eStatTypes statType) const {
const auto& it = m_ResistanceProfile.find(statType);
if (it != m_ResistanceProfile.end()) {
return it->second;
}
return 0.0f;
}