Files
cursebreaker-parser/include/configs/harvestables.hpp

65 lines
1.8 KiB
C++

#pragma once
#include <string>
#include <vector>
#include <unordered_map>
#include <tinyxml2.h>
#include "constants.h"
#include "items.hpp" // for stringToSkillType
namespace cursebreaker {
struct HarvestableLootEntry
{
uint16_t itemId{};
uint16_t amount{};
uint16_t chance{}; // percentage chance
};
struct Harvestable
{
uint16_t id{};
uint16_t level{};
uint16_t respawnTime{}; // in seconds or minutes, TBD
SkillType skill{};
std::string name;
std::string description;
std::vector<HarvestableLootEntry> loot;
Harvestable() = default;
};
// Harvestables configuration manager
class HarvestablesConfig {
public:
static HarvestablesConfig& getInstance() {
static HarvestablesConfig instance;
return instance;
}
bool loadFromXML(const std::string& filepath);
const Harvestable* getHarvestableById(int id) const;
const std::unordered_map<int, Harvestable>& getAllHarvestables() const { return m_harvestables; }
private:
HarvestablesConfig() = default;
~HarvestablesConfig() = default;
HarvestablesConfig(const HarvestablesConfig&) = delete;
HarvestablesConfig& operator=(const HarvestablesConfig&) = delete;
std::unordered_map<int, Harvestable> m_harvestables;
// Helper methods for parsing
void parseHarvestable(tinyxml2::XMLElement* harvestableElement);
void parseLoot(tinyxml2::XMLElement* harvestableElement, Harvestable& harvestable);
std::string getAttributeValue(tinyxml2::XMLElement* element, const char* attribute, const std::string& defaultValue = "");
int getAttributeValueInt(tinyxml2::XMLElement* element, const char* attribute, int defaultValue = 0);
bool getAttributeValueBool(tinyxml2::XMLElement* element, const char* attribute, bool defaultValue = false);
};
} // namespace cursebreaker