diff --git a/Crawler/AttributableStat.h b/Crawler/AttributableStat.h index 3b026384..cde922c5 100644 --- a/Crawler/AttributableStat.h +++ b/Crawler/AttributableStat.h @@ -108,8 +108,11 @@ public: inline int&get(ItemAttribute a){ return attributes[a]; } - inline const int get_readOnly(ItemAttribute a){ - return attributes[a]; + inline const int get_readOnly(ItemAttribute a)const{ + if(attributes.count(a)){ + return attributes.at(a); + } + return 0; } inline static AttributeData GetDisplayInfo(ItemAttribute a){ return data[a]; diff --git a/Crawler/Item.cpp b/Crawler/Item.cpp index 240bde0c..cb736e5f 100644 --- a/Crawler/Item.cpp +++ b/Crawler/Item.cpp @@ -474,12 +474,11 @@ const Stats&EnhancementInfo::operator[](int level)const{ return enhancementStats[level]; } -bool ItemInfo::HasItemSet(){ - return ItemSet::sets.count(set); -} - -const ItemSet&ItemInfo::ItemSet()const{ - return ItemSet::sets[set]; +const std::optionalItemInfo::ItemSet()const{ + if(ItemSet::sets.count(set)){ + return &ItemSet::sets[set]; + } + return {}; }; const Stats&ItemSet::operator[](int setPieces)const{ @@ -489,7 +488,8 @@ const Stats&ItemSet::operator[](int setPieces)const{ 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 "<Item::ItemSet()const{ + return it->ItemSet(); }; \ No newline at end of file diff --git a/Crawler/Item.h b/Crawler/Item.h index a648c99f..794f4098 100644 --- a/Crawler/Item.h +++ b/Crawler/Item.h @@ -95,11 +95,17 @@ class ItemSet{ friend class ItemInfo; static std::mapsets; std::arraysetBonuses; + std::string name; public: + //NO CONSTRUCTOR REQUIRED! //Specify the piece count(1-8) for a set bonus to be applied. static void AddSetBonus(std::string setName,int pieceCount,Stats&bonuses); //Gets a set bonus based on number of pieces (1-8) const Stats&operator[](int setPieces)const; + const std::string&GetSetName()const; + bool operator<(const ItemSet&rhs)const{ + return nameItemSet()const; }; class Inventory{ @@ -186,7 +193,7 @@ class ItemInfo{ EquipSlot slot; EnhancementInfo enhancement; Decal*img; - std::string set; + std::string set=""; //Returns true if the item can be used, false otherwise std::string useFunc=""; //Custom properties for this specific item's script. @@ -212,9 +219,7 @@ public: float CastTime(); float CooldownTime(); EquipSlot Slot(); - bool HasItemSet(); - //NOTE: Not every item has a set! Verify with HasItemSet() first! - const ItemSet&ItemSet()const; + const std::optionalItemSet()const; }; class ItemOverlay{ diff --git a/Crawler/Player.cpp b/Crawler/Player.cpp index 7aa5517e..237dd70d 100644 --- a/Crawler/Player.cpp +++ b/Crawler/Player.cpp @@ -867,11 +867,22 @@ const int Player::GetBaseStat(ItemAttribute a)const{ void PlayerStats::RecalculateEquipStats(){ baseStats.copyTo(equipStats); + std::mapsetCounts; for(int i=int(EquipSlot::HELMET);i<=int(EquipSlot::RING2);i<<=1){ EquipSlot slot=EquipSlot(i); Item*equip=Inventory::GetEquip(slot); + if(equip->IsBlank())continue; for(ItemAttribute a=ItemAttribute(int(ItemAttribute::ENUM_START)+1);aGetStats().A(a); + equipStats.A(a)+=equip->GetStats().A(a); + } + if(equip->ItemSet().has_value()){ + setCounts[*equip->ItemSet().value()]++; + } + } + for(const auto&[set,equipCount]:setCounts){ + const Stats&setStats=set[equipCount]; + for(ItemAttribute a=ItemAttribute(int(ItemAttribute::ENUM_START)+1);a