initial commit

This commit is contained in:
cdemeyer-teachx
2025-11-12 06:29:59 +09:00
commit 998313be3c
17 changed files with 1624 additions and 0 deletions

208
include/configs/constants.h Normal file
View File

@@ -0,0 +1,208 @@
#pragma once
#include <cstdint>
namespace cursebreaker {
enum class SkillType : uint8_t
{
woodcutting,
fishing,
swordsmanship,
mining,
archery,
magic,
defence,
blacksmithy,
tailoring,
carpentry,
alchemy,
cooking,
none,
};
enum class WorkbenchType : uint8_t
{
none,
anvil,
oven,
cooking,
carpenter,
tailor,
forge,
alchemist,
mystic,
};
enum class StatType : uint8_t
{
health,
accuracyPhysical,
accuracyMagical,
accuracyRanged,
damagePhysical,
damageMagical,
damageRanged,
resistancePhysical,
resistanceMagical,
resistanceRanged,
healing,
movementSpeed,
mana,
manaregen,
healthregen,
power,
critical,
DamageVsUndead,
DamageVsBeasts,
CritterSlaying,
none,
harvestingSpeedWoodcutting
};
enum class ItemType : uint8_t
{
weapon,
shield,
armor,
head,
resource,
consumable,
trinket,
bracelet
};
enum class ItemCategory : uint8_t
{
none,
bone,
bow,
crossbow,
constructable,
torch,
blacksmithhammer,
questitem,
heavyArmor,
warhammer,
shield,
hatchet,
blade,
armor,
pickaxe,
fish,
fishingrod,
shears,
hammer,
battleaxe,
morningstar,
wand,
staff,
dagger
};
enum class Tool : uint8_t
{
hatchet,
pickaxe,
broom,
fishingrod,
none
};
enum class SpellBookType : uint8_t
{
none,
spells,
abilities
};
enum class ActionType : uint8_t
{
NpcDeath,
PlayerDeath,
PlayerRespawn,
NpcInteract,
QuestUpdate,
QuestTimerEnd,
UseItemOnItem,
UseItemOnNpc,
ConsumeItem,
NpcCombatInteract,
none,
NpcKilledByPlayer,
EnterMap,
VarUpdated,
GrantAchievement,
PlayerKilledByNpc,
UseItem,
CraftItem,
HarvestItem,
BuyItem,
NpcTagKilledByPlayer,
UseAbility,
LootItem,
UseItemCategoryOnItem,
};
enum class Material : uint8_t
{
none,
copper,
iron,
imbersteel,
titanium,
spruce,
oak,
evark,
deadwood,
sheep,
troll,
ogre,
demon,
wool,
cotton,
flax,
jute,
};
enum class GenstatType : uint8_t
{
none,
dagger,
broadsword,
battleaxe,
greatsword,
morningstar,
hammer,
spear,
bow,
staff,
wand,
crossbow,
woodenshield,
wizardhat,
wizardrobe,
grandwizardhat,
grandwizardrobe,
leatherhood,
leatherbracelet,
leatherarmor,
studdedleatherhood,
studdedleatherbracelet,
studdedleatherarmor,
helmet,
shield,
armor,
platehelmet,
kiteshield,
platearmor,
};
struct StatValue
{
StatType type;
uint8_t value;
bool isPercentage;
};
};

103
include/configs/items.hpp Normal file
View File

@@ -0,0 +1,103 @@
#pragma once
#include <string>
#include <vector>
#include <unordered_map>
#include <tinyxml2.h>
#include "constants.h"
namespace cursebreaker {
struct CraftingItemEntry
{
uint16_t itemId{};
uint16_t amount{};
};
// Struct for item crafting requirements
struct ItemCrafting
{
WorkbenchType workbench;
SkillType craftingskill;
std::vector<CraftingItemEntry> craftingitems;
std::string checks;
ItemCrafting() = default;
};
// Main item struct
struct Item {
uint16_t id = 0;
uint16_t price = 0;
uint16_t abilityid = 0;
uint16_t learnabilityid = 0;
SkillType skill = SkillType::none;
ItemCategory category = ItemCategory::none;
ItemType slot = ItemType::resource;
Tool tool = Tool::none;
GenstatType generation = GenstatType::none;
uint8_t level = 0;
uint8_t foodlevel = 0;
uint8_t foodamount = 0;
uint8_t foodfrequency = 0;
uint8_t foodtime = 0;
uint8_t maxstack = 0;
uint8_t book = 0;
bool stackable : 1;
bool twohanded : 1;
bool undroppable : 1;
bool hidemilestone : 1;
std::string name;
std::string description;
std::string comment;
std::vector<StatValue> stats;
std::vector<ItemCrafting> craftings;
Item() = default;
};
// Helper functions for enum conversions
StatType stringToStatType(const std::string& str);
ItemCategory stringToItemCategory(const std::string& str);
ItemType stringToItemType(const std::string& str);
Tool stringToTool(const std::string& str);
SkillType stringToSkillType(const std::string& str);
WorkbenchType stringToWorkbenchType(const std::string& str);
GenstatType stringToGenstatType(const std::string& str);
// Items configuration manager
class ItemsConfig {
public:
static ItemsConfig& getInstance() {
static ItemsConfig instance;
return instance;
}
bool loadFromXML(const std::string& filepath);
const Item* getItemById(int id) const;
const std::unordered_map<int, Item>& getAllItems() const { return m_items; }
private:
ItemsConfig() = default;
~ItemsConfig() = default;
ItemsConfig(const ItemsConfig&) = delete;
ItemsConfig& operator=(const ItemsConfig&) = delete;
std::unordered_map<int, Item> m_items;
// Helper methods for parsing
void parseItem(tinyxml2::XMLElement* itemElement);
void parseStats(tinyxml2::XMLElement* itemElement, Item& item);
void parseCraftings(tinyxml2::XMLElement* itemElement, Item& item);
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