Move ItemEnchant's attributes into separate private variable allowing us to add a Setter and Getter for the attributes to call UpdateDescription function whenever an attribute is modified. Fix rounding display bug (use round instead of ceil) when comparing improvements/downgrade attributes in the character equip menu. (This handles values like 15.000001 and 14.99999 from screwing up the differential displays). Release Build 10729.
This commit is contained in:
parent
d28f27f59d
commit
0e3d57be24
@ -66,10 +66,10 @@ namespace CharacterMenuWindow{
|
||||
AttributeData{"Health",[]()->int{return game->GetPlayer()->GetMaxHealth();}},
|
||||
AttributeData{"Attack",[]()->int{return game->GetPlayer()->GetAttack();}},
|
||||
AttributeData{"Defense",[]()->int{return game->GetPlayer()->GetDefense();}},
|
||||
AttributeData{"Move Spd %",[]()->int{return ceil(game->GetPlayer()->GetMoveSpdMult()*100);}},
|
||||
AttributeData{"CDR",[]()->int{return ceil(game->GetPlayer()->GetCooldownReductionPct()*100);}},
|
||||
AttributeData{"Crit Rate",[]()->int{return ceil(game->GetPlayer()->GetCritRatePct()*100);}},
|
||||
AttributeData{"Crit Dmg",[]()->int{return ceil(game->GetPlayer()->GetCritDmgPct()*100);}},
|
||||
AttributeData{"Move Spd %",[]()->int{return round(game->GetPlayer()->GetMoveSpdMult()*100);}},
|
||||
AttributeData{"CDR",[]()->int{return round(game->GetPlayer()->GetCooldownReductionPct()*100);}},
|
||||
AttributeData{"Crit Rate",[]()->int{return round(game->GetPlayer()->GetCritRatePct()*100);}},
|
||||
AttributeData{"Crit Dmg",[]()->int{return round(game->GetPlayer()->GetCritDmgPct()*100);}},
|
||||
};
|
||||
const static std::array<std::string,8>slotNames{"Helmet","Weapon","Armor","Gloves","Pants","Shoes","Ring 1","Ring 2"};
|
||||
template<class T>
|
||||
|
@ -170,17 +170,11 @@ ItemEnchant::ItemEnchant(const std::string_view enchantName)
|
||||
for(const auto&[attr,val]:ItemEnchantInfo::ENCHANT_LIST.at(this->enchantName).minStatModifiers){
|
||||
float minVal=ItemEnchantInfo::ENCHANT_LIST.at(this->enchantName).minStatModifiers.A_Read(attr);
|
||||
float maxVal=ItemEnchantInfo::ENCHANT_LIST.at(this->enchantName).maxStatModifiers.A_Read(attr);
|
||||
if(minVal==maxVal)A(attr)=minVal;
|
||||
if(minVal==maxVal)SetAttribute(attr.ActualName(),minVal);
|
||||
else{
|
||||
const auto&randRange{std::ranges::iota_view(int(minVal),int(maxVal+1))};
|
||||
A(attr)=randRange[util::random()%randRange.size()];
|
||||
SetAttribute(attr.ActualName(),randRange[util::random()%randRange.size()]);
|
||||
}
|
||||
|
||||
const std::string wrappedConfigStr{std::vformat("{{{}}}",std::make_format_args(attr.ActualName()))};
|
||||
size_t configValInd{description.find(wrappedConfigStr)};
|
||||
if(configValInd==std::string::npos)continue;
|
||||
std::string formattedFloat{std::format("{}{}#FFFFFF",ItemEnchantInfo::enchantAttributeCol.toHTMLColorCode(),A_Read(attr))};
|
||||
description=description.replace(configValInd,wrappedConfigStr.length(),formattedFloat);
|
||||
}
|
||||
}
|
||||
|
||||
@ -248,3 +242,29 @@ const std::string ItemEnchant::RollRandomEnchant(){
|
||||
|
||||
return filteredEnchants[util::random()%filteredEnchants.size()].Name();
|
||||
}
|
||||
|
||||
void ItemEnchant::UpdateDescription(){
|
||||
description=ItemEnchantInfo::ENCHANT_LIST.at(this->enchantName).Description();
|
||||
for(const auto&[attr,val]:ItemEnchantInfo::ENCHANT_LIST.at(this->enchantName).minStatModifiers){
|
||||
const std::string wrappedConfigStr{std::vformat("{{{}}}",std::make_format_args(attr.ActualName()))};
|
||||
size_t configValInd{description.find(wrappedConfigStr)};
|
||||
if(configValInd==std::string::npos)continue;
|
||||
std::string formattedFloat{std::format("{}{}#FFFFFF",ItemEnchantInfo::enchantAttributeCol.toHTMLColorCode(),GetAttribute(attr.ActualName()))};
|
||||
description=description.replace(configValInd,wrappedConfigStr.length(),formattedFloat);
|
||||
}
|
||||
}
|
||||
|
||||
void ItemEnchant::SetAttribute(const std::string_view attr,const float val){
|
||||
stats.A(attr)=val;
|
||||
UpdateDescription();
|
||||
}
|
||||
const float&ItemEnchant::GetAttribute(const std::string_view attr)const{
|
||||
return stats.A_Read(attr);
|
||||
}
|
||||
|
||||
std::map<ItemAttribute,float>::const_iterator ItemEnchant::begin()const{
|
||||
return stats.begin();
|
||||
}
|
||||
std::map<ItemAttribute,float>::const_iterator ItemEnchant::end()const{
|
||||
return stats.end();
|
||||
}
|
@ -95,7 +95,7 @@ private:
|
||||
static std::unordered_map<ItemEnchantCategory,ItemEnchantCategoryData>ENCHANT_CATEGORIES;
|
||||
};
|
||||
|
||||
class ItemEnchant:public ItemAttributable{
|
||||
class ItemEnchant{
|
||||
public:
|
||||
ItemEnchant(const std::string_view enchantName);
|
||||
const std::string Name(ItemEnchantInfo::TextStyle style=ItemEnchantInfo::TextStyle::NORMAL)const;
|
||||
@ -104,8 +104,14 @@ public:
|
||||
const std::optional<ItemEnchantInfo::AbilitySlot>&AbilitySlot()const;
|
||||
//Rolls a class-appropriate random enchant.
|
||||
const static std::string RollRandomEnchant();
|
||||
void SetAttribute(const std::string_view attr,const float val);
|
||||
const float&GetAttribute(const std::string_view attr)const;
|
||||
std::map<ItemAttribute,float>::const_iterator begin()const;
|
||||
std::map<ItemAttribute,float>::const_iterator end()const;
|
||||
private:
|
||||
void UpdateDescription();
|
||||
const ItemEnchantInfo&GetEnchantInfo()const;
|
||||
std::string enchantName;
|
||||
std::string description;
|
||||
ItemAttributable stats;
|
||||
};
|
@ -1328,8 +1328,8 @@ void EntityStats::RecalculateEquipStats(){
|
||||
if(slot==EquipSlot::RING2&&equip.lock()->HasEnchant()){ //Special doubling-up ring logic.
|
||||
const bool IsNonCommonEnchant{equip.lock()->HasEnchant()&&equip.lock()->GetEnchant().value().Category()!=ItemEnchantInfo::ItemEnchantCategory::GENERAL};
|
||||
const bool Slot1HasSameEnchant{!ISBLANK(Inventory::GetEquip(EquipSlot::RING1))&&Inventory::GetEquip(EquipSlot::RING1).lock()->HasEnchant()&&Inventory::GetEquip(EquipSlot::RING1).lock()->GetEnchant().value().Name()==equip.lock()->GetEnchant().value().Name()};
|
||||
if(!IsNonCommonEnchant||!Slot1HasSameEnchant)equipStats.A(key)+=equip.lock()->GetEnchant().value().A_Read(key);
|
||||
}else if(equip.lock()->HasEnchant())equipStats.A(key)+=equip.lock()->GetEnchant().value().A_Read(key);
|
||||
if(!IsNonCommonEnchant||!Slot1HasSameEnchant)equipStats.A(key)+=equip.lock()->GetEnchant().value().GetAttribute(key);
|
||||
}else if(equip.lock()->HasEnchant())equipStats.A(key)+=equip.lock()->GetEnchant().value().GetAttribute(key);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -380,7 +380,7 @@ void SaveFile::LoadFile(){
|
||||
newItem.lock()->enchant=ItemEnchant{data["Enchant"]["Name"].GetString()};
|
||||
if(loadFile.GetProperty(std::format("Items.{}.Enchant",key)).HasProperty("Attributes")){
|
||||
for(auto&[attr,data]:loadFile.GetProperty(std::format("Items.{}.Enchant.Attributes",key)).GetOrderedKeys()){
|
||||
newItem.lock()->enchant.value().A(attr)=data.GetReal();
|
||||
newItem.lock()->enchant.value().SetAttribute(attr,data.GetReal());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -39,7 +39,7 @@ All rights reserved.
|
||||
#define VERSION_MAJOR 1
|
||||
#define VERSION_MINOR 2
|
||||
#define VERSION_PATCH 3
|
||||
#define VERSION_BUILD 10720
|
||||
#define VERSION_BUILD 10729
|
||||
|
||||
#define stringify(a) stringify_(a)
|
||||
#define stringify_(a) #a
|
||||
|
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user