HarvestableInfo.xml, Achievements.xml, Loot.xml, NPCInfo.xml and Shops.xml.

This commit is contained in:
cdemeyer-teachx
2025-11-12 08:40:55 +09:00
parent 998313be3c
commit a0f7a0f799
11 changed files with 819 additions and 0 deletions

View File

@@ -0,0 +1,67 @@
#pragma once
#include <string>
#include <vector>
#include <unordered_map>
#include <tinyxml2.h>
#include "constants.h"
namespace cursebreaker {
struct AchievementRequirement
{
ActionType action{};
uint16_t targetId{}; // e.g., item id, npc id, etc.
uint16_t count{};
std::string description;
};
struct Achievement
{
uint16_t id{};
uint16_t points{};
uint16_t category{};
std::string name;
std::string description;
std::string icon;
std::vector<AchievementRequirement> requirements;
Achievement() = default;
};
// Achievements configuration manager
class AchievementsConfig {
public:
static AchievementsConfig& getInstance() {
static AchievementsConfig instance;
return instance;
}
bool loadFromXML(const std::string& filepath);
const Achievement* getAchievementById(int id) const;
const std::unordered_map<int, Achievement>& getAllAchievements() const { return m_achievements; }
private:
AchievementsConfig() = default;
~AchievementsConfig() = default;
AchievementsConfig(const AchievementsConfig&) = delete;
AchievementsConfig& operator=(const AchievementsConfig&) = delete;
std::unordered_map<int, Achievement> m_achievements;
// Helper methods for parsing
void parseAchievement(tinyxml2::XMLElement* achievementElement);
void parseRequirements(tinyxml2::XMLElement* achievementElement, Achievement& achievement);
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);
};
// Helper functions for enum conversions
ActionType stringToActionType(const std::string& str);
} // namespace cursebreaker

View File

@@ -0,0 +1,65 @@
#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

61
include/configs/loot.hpp Normal file
View File

@@ -0,0 +1,61 @@
#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

68
include/configs/npcs.hpp Normal file
View File

@@ -0,0 +1,68 @@
#pragma once
#include <string>
#include <vector>
#include <unordered_map>
#include <tinyxml2.h>
#include "constants.h"
#include "items.hpp" // for stringToStatType
namespace cursebreaker {
struct NPCStat
{
StatType type{};
uint16_t value{};
};
struct NPC
{
uint16_t id{};
uint16_t level{};
uint16_t health{};
uint16_t mana{};
uint16_t experience{};
uint16_t lootTableId{};
std::string name;
std::string description;
std::string faction;
std::vector<NPCStat> stats;
std::vector<uint16_t> lootItems; // alternative simple loot
NPC() = default;
};
// NPCs configuration manager
class NPCsConfig {
public:
static NPCsConfig& getInstance() {
static NPCsConfig instance;
return instance;
}
bool loadFromXML(const std::string& filepath);
const NPC* getNPCById(int id) const;
const std::unordered_map<int, NPC>& getAllNPCs() const { return m_npcs; }
private:
NPCsConfig() = default;
~NPCsConfig() = default;
NPCsConfig(const NPCsConfig&) = delete;
NPCsConfig& operator=(const NPCsConfig&) = delete;
std::unordered_map<int, NPC> m_npcs;
// Helper methods for parsing
void parseNPC(tinyxml2::XMLElement* npcElement);
void parseStats(tinyxml2::XMLElement* npcElement, NPC& npc);
void parseLoot(tinyxml2::XMLElement* npcElement, NPC& npc);
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

61
include/configs/shops.hpp Normal file
View File

@@ -0,0 +1,61 @@
#pragma once
#include <string>
#include <vector>
#include <unordered_map>
#include <tinyxml2.h>
#include "constants.h"
namespace cursebreaker {
struct ShopItem
{
uint16_t itemId{};
uint16_t price{};
uint16_t stock{}; // -1 for unlimited
uint16_t levelRequired{};
};
struct Shop
{
uint16_t id{};
std::string name;
std::string description;
std::string location;
std::vector<ShopItem> inventory;
Shop() = default;
};
// Shops configuration manager
class ShopsConfig {
public:
static ShopsConfig& getInstance() {
static ShopsConfig instance;
return instance;
}
bool loadFromXML(const std::string& filepath);
const Shop* getShopById(int id) const;
const std::unordered_map<int, Shop>& getAllShops() const { return m_shops; }
private:
ShopsConfig() = default;
~ShopsConfig() = default;
ShopsConfig(const ShopsConfig&) = delete;
ShopsConfig& operator=(const ShopsConfig&) = delete;
std::unordered_map<int, Shop> m_shops;
// Helper methods for parsing
void parseShop(tinyxml2::XMLElement* shopElement);
void parseInventory(tinyxml2::XMLElement* shopElement, Shop& shop);
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