Parse Item sets from config. Fix constness of item set getter, and change AddSetBonus function to be statically used instead, makes more sense.

pull/28/head
sigonasr2 1 year ago
parent 0b912e199a
commit 6d4f024d3c
  1. 4
      Crawler/AttributableStat.h
  2. 3
      Crawler/Crawler.cpp
  3. 38
      Crawler/Item.cpp
  4. 16
      Crawler/Item.h
  5. 2
      Crawler/Version.h
  6. 3
      Crawler/assets/config/configuration.txt

@ -104,8 +104,8 @@ public:
inline int&get(ItemAttribute a){ inline int&get(ItemAttribute a){
return attributes[a]; return attributes[a];
} }
inline const int get_readOnly(ItemAttribute a)const{ inline const int get_readOnly(ItemAttribute a){
return attributes.at(a); return attributes[a];
} }
inline static AttributeData GetDisplayInfo(ItemAttribute a){ inline static AttributeData GetDisplayInfo(ItemAttribute a){
return data[a]; return data[a];

@ -123,6 +123,9 @@ Crawler::Crawler()
std::string ITEM_CONFIG = CONFIG_PATH + "item_config"_S; std::string ITEM_CONFIG = CONFIG_PATH + "item_config"_S;
utils::datafile::Read(DATA,ITEM_CONFIG); utils::datafile::Read(DATA,ITEM_CONFIG);
std::string ITEM_SET_CONFIG = CONFIG_PATH + "item_set_config"_S;
utils::datafile::Read(DATA,ITEM_SET_CONFIG);
for(auto&key:DATA.GetProperty("ItemConfiguration").GetKeys()){ for(auto&key:DATA.GetProperty("ItemConfiguration").GetKeys()){
std::string config = DATA["ItemConfiguration"][key.first].GetString(); std::string config = DATA["ItemConfiguration"][key.first].GetString();
utils::datafile::Read(DATA,CONFIG_PATH + "item_directory"_S + config); utils::datafile::Read(DATA,CONFIG_PATH + "item_directory"_S + config);

@ -80,6 +80,8 @@ void ItemInfo::InitializeItems(){
ItemAttributable::stringToAttribute[ItemAttributable::GetDisplayInfo(attr).name]=attr; ItemAttributable::stringToAttribute[ItemAttributable::GetDisplayInfo(attr).name]=attr;
} }
InitializeSets();
for(auto&key:DATA["ItemCategory"].GetKeys()){ for(auto&key:DATA["ItemCategory"].GetKeys()){
ITEM_CATEGORIES[key.first]; ITEM_CATEGORIES[key.first];
Inventory::sortedInv[key.first]; Inventory::sortedInv[key.first];
@ -93,6 +95,7 @@ void ItemInfo::InitializeItems(){
img.Load(imgPath); img.Load(imgPath);
std::string scriptName="",description="",category=""; std::string scriptName="",description="",category="";
std::string setName="";
float castTime=0; float castTime=0;
std::vector<std::string> slot; std::vector<std::string> slot;
float cooldownTime="Item.Item Cooldown Time"_F; float cooldownTime="Item.Item Cooldown Time"_F;
@ -123,6 +126,9 @@ void ItemInfo::InitializeItems(){
for(int i=0;i<data[key.first]["StatValues"].GetValueCount();i++){ for(int i=0;i<data[key.first]["StatValues"].GetValueCount();i++){
statValueList.push_back(ItemAttributable::GetAttributeFromString(data[key.first]["StatValues"].GetString(i))); statValueList.push_back(ItemAttributable::GetAttributeFromString(data[key.first]["StatValues"].GetString(i)));
} }
}else
if(keyName=="PartofSet"){
setName=data[key.first][keyName].GetString();
}else{ //THis is a custom override modifier for a script. NO-OP }else{ //THis is a custom override modifier for a script. NO-OP
} }
} }
@ -153,6 +159,7 @@ void ItemInfo::InitializeItems(){
it.castTime=castTime; it.castTime=castTime;
it.cooldownTime=cooldownTime; it.cooldownTime=cooldownTime;
it.slot=EquipSlot::NONE; it.slot=EquipSlot::NONE;
it.set=setName;
if(slot.size()>0){ if(slot.size()>0){
for(std::string&s:slot){ for(std::string&s:slot){
if(!nameToEquipSlot.count(s))ERR("WARNING! Tried to add item "<<it.name<<" to slot "<<s<<" which doesn't exist!"); if(!nameToEquipSlot.count(s))ERR("WARNING! Tried to add item "<<it.name<<" to slot "<<s<<" which doesn't exist!");
@ -468,7 +475,11 @@ const Stats&EnhancementInfo::operator[](int level)const{
return enhancementStats[level]; return enhancementStats[level];
} }
const ItemSet&Item::GetItemSet()const{ bool ItemInfo::HasItemSet(){
return ItemSet::sets.count(set);
}
const ItemSet&ItemInfo::ItemSet()const{
return ItemSet::sets[set]; return ItemSet::sets[set];
}; };
@ -477,10 +488,10 @@ const Stats&ItemSet::operator[](int setPieces)const{
return setBonuses[setPieces]; return setBonuses[setPieces];
}; };
void ItemSet::AddSetBonus(int pieceCount,const Stats&bonuses){ void ItemSet::AddSetBonus(std::string setName,int pieceCount,Stats&bonuses){
if(pieceCount<=0||pieceCount>=9)ERR("Piece count is invalid! Expecting a value (1-8) but got "<<pieceCount); if(pieceCount<=0||pieceCount>=9)ERR("Piece count is invalid! Expecting a value (1-8) but got "<<pieceCount);
for(int i=pieceCount-1;i<setBonuses.size();i++){ for(int i=pieceCount-1;i<sets[setName].setBonuses.size();i++){
setBonuses[i]+=bonuses; sets[setName].setBonuses[i]+=bonuses;
} }
} }
@ -516,4 +527,23 @@ void EnhancementInfo::SetAttribute(int enhanceLevel,ItemAttribute attribute,int
enhancementStats.push_back({}); enhancementStats.push_back({});
} }
enhancementStats[enhanceLevel].A(attribute)=value; enhancementStats[enhanceLevel].A(attribute)=value;
}
void ItemInfo::InitializeSets(){
for(auto&key:DATA["ItemSet"].GetKeys()){
std::string setName=key.first;
datafile&setInfo=DATA["ItemSet"][setName];
for(int pieceCount=1;pieceCount<=8;pieceCount++){
if(setInfo.HasProperty(std::to_string(pieceCount))){
datafile&statInfo=setInfo[std::to_string(pieceCount)];
Stats bonuses;
for(auto&key:statInfo.GetKeys()){
ItemAttribute attr=bonuses.GetAttributeFromString(key.first);
bonuses.A(attr)=statInfo[key.first].GetInt(0);
}
ItemSet::AddSetBonus(setName,pieceCount,bonuses);
}
}
}
} }

@ -67,9 +67,9 @@ enum class EquipSlot{
struct Stats:ItemAttributable{ struct Stats:ItemAttributable{
public: public:
inline Stats&operator+=(const Stats&rhs){ inline Stats&operator+=(Stats&rhs){
for(ItemAttribute a=ItemAttribute(int(ItemAttribute::ENUM_START)+1);a<ItemAttribute::ENUM_END;a=ItemAttribute(int(a)+1)){ for(ItemAttribute a=ItemAttribute(int(ItemAttribute::ENUM_START)+1);a<ItemAttribute::ENUM_END;a=ItemAttribute(int(a)+1)){
A(a)+=rhs.A_Read(a); A(a)+=rhs.get_readOnly(a);
} }
return *this; return *this;
}; };
@ -83,13 +83,14 @@ public:
const Stats&operator[](int level)const; const Stats&operator[](int level)const;
}; };
//You cannot create instances of this class, access sets from ItemSet::sets and add the appropriate set bonuses.
class ItemSet{ class ItemSet{
friend class Item; friend class ItemInfo;
static std::map<std::string,ItemSet>sets; static std::map<std::string,ItemSet>sets;
std::array<Stats,8>setBonuses; std::array<Stats,8>setBonuses;
public: public:
//Specify the piece count(1-8) for a set bonus to be applied. //Specify the piece count(1-8) for a set bonus to be applied.
void AddSetBonus(int pieceCount,const Stats&bonuses); static void AddSetBonus(std::string setName,int pieceCount,Stats&bonuses);
//Gets a set bonus based on number of pieces (1-8) //Gets a set bonus based on number of pieces (1-8)
const Stats&operator[](int setPieces)const; const Stats&operator[](int setPieces)const;
}; };
@ -101,7 +102,6 @@ private:
//The amount in the current item stack. //The amount in the current item stack.
uint32_t amt; uint32_t amt;
uint8_t enhancementLevel; uint8_t enhancementLevel;
std::string set;
ItemInfo*it; ItemInfo*it;
public: public:
Item(); Item();
@ -113,7 +113,6 @@ public:
EquipSlot GetEquipSlot(); EquipSlot GetEquipSlot();
Decal*Decal(); Decal*Decal();
ItemScript&OnUseAction(); ItemScript&OnUseAction();
const ItemSet&GetItemSet()const;
float CastTime(); float CastTime();
float CooldownTime(); float CooldownTime();
bool IsBlank(); bool IsBlank();
@ -178,6 +177,7 @@ class ItemInfo{
EquipSlot slot; EquipSlot slot;
EnhancementInfo enhancement; EnhancementInfo enhancement;
Decal*img; Decal*img;
std::string set;
//Returns true if the item can be used, false otherwise //Returns true if the item can be used, false otherwise
std::string useFunc=""; std::string useFunc="";
//Custom properties for this specific item's script. //Custom properties for this specific item's script.
@ -186,6 +186,7 @@ class ItemInfo{
private: private:
static void InitializeScripts(); static void InitializeScripts();
static void InitializeSets();
static std::map<std::string,EquipSlot>nameToEquipSlot; static std::map<std::string,EquipSlot>nameToEquipSlot;
public: public:
static void InitializeItems(); static void InitializeItems();
@ -201,6 +202,9 @@ public:
float CastTime(); float CastTime();
float CooldownTime(); float CooldownTime();
EquipSlot Slot(); EquipSlot Slot();
bool HasItemSet();
//NOTE: Not every item has a set! Verify with HasItemSet() first!
const ItemSet&ItemSet()const;
}; };
class ItemOverlay{ class ItemOverlay{

@ -39,7 +39,7 @@ All rights reserved.
#define VERSION_MAJOR 0 #define VERSION_MAJOR 0
#define VERSION_MINOR 2 #define VERSION_MINOR 2
#define VERSION_PATCH 1 #define VERSION_PATCH 1
#define VERSION_BUILD 3460 #define VERSION_BUILD 3470
#define stringify(a) stringify_(a) #define stringify(a) stringify_(a)
#define stringify_(a) #a #define stringify_(a) #a

@ -42,6 +42,9 @@ class_list = Warrior, Thief, Ranger, Trapper, Wizard, Witch
# Items Config # Items Config
item_config = items/items.txt item_config = items/items.txt
# Item Set Config
item_set_config = items/ItemSets.txt
# Path to items configuration # Path to items configuration
item_directory = items/ item_directory = items/

Loading…
Cancel
Save