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

61 lines
1.6 KiB
C++

#pragma once
#include <string>
#include <vector>
#include <unordered_map>
#include <tinyxml2.h>
#include "constants.h"
namespace cursebreaker {
struct LootEntry
{
uint16_t itemId{};
uint16_t minAmount{};
uint16_t maxAmount{};
uint16_t chance{}; // percentage chance
uint16_t level{}; // minimum level required
};
struct LootTable
{
uint16_t id{};
std::string name;
std::string description;
std::vector<LootEntry> entries;
LootTable() = default;
};
// Loot configuration manager
class LootConfig {
public:
static LootConfig& getInstance() {
static LootConfig instance;
return instance;
}
bool loadFromXML(const std::string& filepath);
const LootTable* getLootTableById(int id) const;
const std::unordered_map<int, LootTable>& getAllLootTables() const { return m_lootTables; }
private:
LootConfig() = default;
~LootConfig() = default;
LootConfig(const LootConfig&) = delete;
LootConfig& operator=(const LootConfig&) = delete;
std::unordered_map<int, LootTable> m_lootTables;
// Helper methods for parsing
void parseLootTable(tinyxml2::XMLElement* lootTableElement);
void parseEntries(tinyxml2::XMLElement* lootTableElement, LootTable& lootTable);
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