Implement equip generated item descriptions.
This commit is contained in:
parent
4ac42fbd7e
commit
5a6080b98f
@ -80,6 +80,7 @@ class Stats;
|
||||
|
||||
class ItemAttributable{
|
||||
friend class ItemInfo;
|
||||
protected:
|
||||
std::map<ItemAttribute,int>attributes;
|
||||
private:
|
||||
inline static std::map<std::string,ItemAttribute>stringToAttribute;
|
||||
@ -117,6 +118,9 @@ public:
|
||||
inline static AttributeData GetDisplayInfo(ItemAttribute a){
|
||||
return data[a];
|
||||
}
|
||||
inline static std::string GetAttributeName(ItemAttribute attr){
|
||||
return data[attr].name;
|
||||
}
|
||||
inline static ItemAttribute GetAttributeFromString(std::string attrName){
|
||||
return stringToAttribute[attrName];
|
||||
};
|
||||
|
@ -90,6 +90,7 @@ void ItemInfo::InitializeItems(){
|
||||
|
||||
auto ReadItems=[&](datafile&data){
|
||||
for(auto&[key,value]:data.GetKeys()){
|
||||
if(key=="")ERR("Failed to read an item block ,no name specified!");
|
||||
std::string imgPath="assets/"+"item_img_directory"_S+key+".png";
|
||||
Renderable&img=GFX["item_img_directory"_S+key+".png"];
|
||||
img.Load(imgPath);
|
||||
@ -188,7 +189,8 @@ void ItemInfo::InitializeItems(){
|
||||
Menu::inventoryListeners.SetInitialized();
|
||||
|
||||
for(auto&[name,info]:ITEM_DATA){
|
||||
if(info.description.length()==0)ERR("WARNING! Item "<<info.name<<" does not have a description!");
|
||||
Item tempItem{1,name};
|
||||
if(tempItem.Description().length()==0)ERR("WARNING! Item "<<info.name<<" does not have a description!");
|
||||
}
|
||||
|
||||
std::cout<<ITEM_DATA.size()<<" items have been loaded."<<std::endl;
|
||||
@ -372,12 +374,37 @@ uint32_t Item::Amt(){
|
||||
return amt;
|
||||
};
|
||||
std::string Item::Name(){
|
||||
return it->Name();
|
||||
std::string name=it->Name();
|
||||
if(IsEquippable()&&EnhancementLevel()>0){
|
||||
name+=" [+"+std::to_string(EnhancementLevel())+"]";
|
||||
}
|
||||
return name;
|
||||
};
|
||||
bool Item::IsEquippable()const{
|
||||
return Category()=="Equipment"||Category()=="Accessories";
|
||||
}
|
||||
std::string Item::Description(){
|
||||
return it->Description();
|
||||
std::string description=it->Description();
|
||||
if(IsEquippable()){
|
||||
description+='\n';
|
||||
description+=GetStats().GetStatsString();
|
||||
if(ItemSet()){
|
||||
const ::ItemSet*const set=ItemSet().value();
|
||||
description+="\n"+set->GetSetName()+" Set - ";
|
||||
const std::map<::ItemSet,int>&itemSetCounts=Inventory::GetEquippedItemSets();
|
||||
for(bool first=true;const auto&[pieceCount,bonuses]:set->GetSetBonusBreakpoints()){
|
||||
if(itemSetCounts.count(*set)&&pieceCount<=itemSetCounts.at(*set)){
|
||||
description+="#56E346";
|
||||
}
|
||||
if(!first)description+=" ";
|
||||
description+="("+std::to_string(pieceCount)+"): "+bonuses.GetStatsString()+"#FFFFFF";
|
||||
first=false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return description;
|
||||
};
|
||||
ITCategory Item::Category(){
|
||||
const ITCategory Item::Category()const{
|
||||
return it->Category();
|
||||
};
|
||||
Decal*Item::Decal(){
|
||||
@ -496,6 +523,7 @@ void ItemSet::AddSetBonus(std::string setName,int pieceCount,Stats&bonuses){
|
||||
for(int i=pieceCount;i<sets[setName].setBonuses.size();i++){
|
||||
sets[setName].setBonuses[i]+=bonuses;
|
||||
}
|
||||
sets[setName].setBonusBreakpoints.push_back({pieceCount,bonuses});
|
||||
}
|
||||
|
||||
void Inventory::EquipItem(Item&it,EquipSlot slot){
|
||||
@ -560,7 +588,7 @@ Stats ItemInfo::GetStats(int enhancementLevel){
|
||||
return enhancement[enhancementLevel];
|
||||
}
|
||||
|
||||
Stats Item::GetStats()const{
|
||||
const Stats Item::GetStats()const{
|
||||
if(it==nullptr)return{};
|
||||
return it->GetStats(enhancementLevel);
|
||||
};
|
||||
@ -569,6 +597,43 @@ const size_t EnhancementInfo::size()const{
|
||||
return enhancementStats.size();
|
||||
};
|
||||
|
||||
const const const std::optional<const const const ItemSet const const const*const const const>Item::ItemSet()const const const{ //I was bored, okay?
|
||||
const const const std::optional<const const const ItemSet const const const*const const const>&Item::ItemSet()const const const{ //I was bored, okay?
|
||||
return it->ItemSet();
|
||||
};
|
||||
};
|
||||
|
||||
uint8_t Item::EnhancementLevel()const{
|
||||
return enhancementLevel;
|
||||
};
|
||||
void Item::EnhanceItem(){
|
||||
if(enhancementLevel+1>"Item.Item Max Enhancement Level"_I)ERR("WARNING! Attempted to enhance "<<Name()<<" beyond the cap of "<<"Item.Item Max Enhancement Level"_I);
|
||||
enhancementLevel++;
|
||||
};
|
||||
|
||||
const std::vector<std::pair<int,Stats>>&ItemSet::GetSetBonusBreakpoints()const{
|
||||
return setBonusBreakpoints;
|
||||
};
|
||||
|
||||
const std::map<ItemSet,int>Inventory::GetEquippedItemSets(){
|
||||
std::map<ItemSet,int>setCounts;
|
||||
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;
|
||||
if(equip->ItemSet()){
|
||||
setCounts[*equip->ItemSet().value()]++;
|
||||
}
|
||||
}
|
||||
return setCounts;
|
||||
}
|
||||
|
||||
const std::string Stats::GetStatsString()const{
|
||||
std::string description="";
|
||||
for(bool first=true;const auto&[attr,val]:attributes){
|
||||
if(!first){
|
||||
description+=" ";
|
||||
}
|
||||
description+=ItemAttributable::GetAttributeName(attr)+": "+std::to_string(val)+(ItemAttributable::GetDisplayInfo(attr).displayAsPercent?"%":"");
|
||||
first=false;
|
||||
}
|
||||
return description;
|
||||
}
|
@ -79,6 +79,13 @@ public:
|
||||
}
|
||||
return *this;
|
||||
};
|
||||
auto begin()const{
|
||||
return attributes.begin();
|
||||
}
|
||||
auto end()const{
|
||||
return attributes.end();
|
||||
}
|
||||
const std::string GetStatsString()const;
|
||||
};
|
||||
|
||||
struct EnhancementInfo{
|
||||
@ -96,6 +103,7 @@ class ItemSet{
|
||||
static std::map<std::string,ItemSet>sets;
|
||||
std::array<Stats,8>setBonuses;
|
||||
std::string name;
|
||||
std::vector<std::pair<int,Stats>>setBonusBreakpoints;
|
||||
public:
|
||||
//NO CONSTRUCTOR REQUIRED!
|
||||
//Specify the piece count(1-8) for a set bonus to be applied.
|
||||
@ -106,6 +114,7 @@ public:
|
||||
bool operator<(const ItemSet&rhs)const{
|
||||
return name<rhs.name;
|
||||
}
|
||||
const std::vector<std::pair<int,Stats>>&GetSetBonusBreakpoints()const;
|
||||
};
|
||||
|
||||
class Item{
|
||||
@ -117,23 +126,26 @@ private:
|
||||
uint32_t amt;
|
||||
uint8_t enhancementLevel;
|
||||
ItemInfo*it;
|
||||
bool IsEquippable()const;
|
||||
public:
|
||||
Item();
|
||||
Item(uint32_t amt,IT item,uint8_t enhancementLevel=0);
|
||||
uint32_t Amt();
|
||||
std::string Name();
|
||||
std::string Description();
|
||||
ITCategory Category();
|
||||
const ITCategory Category()const;
|
||||
EquipSlot GetEquipSlot();
|
||||
Decal*Decal();
|
||||
Stats GetStats()const;
|
||||
const Stats GetStats()const;
|
||||
ItemScript&OnUseAction();
|
||||
float CastTime();
|
||||
float CooldownTime();
|
||||
bool IsBlank();
|
||||
uint8_t EnhancementLevel()const;
|
||||
void EnhanceItem();
|
||||
static Item BLANK;
|
||||
bool operator==(const Item&rhs)const;
|
||||
const std::optional<const ItemSet *const>ItemSet()const;
|
||||
const std::optional<const ItemSet *const>&ItemSet()const;
|
||||
};
|
||||
|
||||
class Inventory{
|
||||
@ -155,6 +167,7 @@ public:
|
||||
static void UnequipItem(EquipSlot slot);
|
||||
static EquipSlot GetSlotEquippedIn(Item&it);
|
||||
static Item*GetEquip(EquipSlot slot);
|
||||
static const std::map<ItemSet,int>GetEquippedItemSets();
|
||||
|
||||
static bool SwapItems(ITCategory itemCategory,uint32_t slot1,uint32_t slot2);
|
||||
//Makes sure this is a valid category. Will error out if it doesn't exist! Use for ERROR HANDLING!
|
||||
|
@ -867,18 +867,17 @@ const int Player::GetBaseStat(ItemAttribute a)const{
|
||||
|
||||
void PlayerStats::RecalculateEquipStats(){
|
||||
baseStats.copyTo(equipStats);
|
||||
std::map<ItemSet,int>setCounts;
|
||||
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);a<ItemAttribute::ENUM_END;a=ItemAttribute(int(a)+1)){
|
||||
equipStats.A(a)+=equip->GetStats().A(a);
|
||||
}
|
||||
if(equip->ItemSet().has_value()){
|
||||
setCounts[*equip->ItemSet().value()]++;
|
||||
equipStats.A(a)+=equip->GetStats().A_Read(a);
|
||||
}
|
||||
}
|
||||
|
||||
const std::map<ItemSet,int>&setCounts=Inventory::GetEquippedItemSets();
|
||||
|
||||
for(const auto&[set,equipCount]:setCounts){
|
||||
const Stats&setStats=set[equipCount];
|
||||
for(ItemAttribute a=ItemAttribute(int(ItemAttribute::ENUM_START)+1);a<ItemAttribute::ENUM_END;a=ItemAttribute(int(a)+1)){
|
||||
|
@ -39,7 +39,7 @@ All rights reserved.
|
||||
#define VERSION_MAJOR 0
|
||||
#define VERSION_MINOR 2
|
||||
#define VERSION_PATCH 1
|
||||
#define VERSION_BUILD 3653
|
||||
#define VERSION_BUILD 3669
|
||||
|
||||
#define stringify(a) stringify_(a)
|
||||
#define stringify_(a) #a
|
||||
|
@ -380,6 +380,7 @@ Equipment
|
||||
Slot = Pants
|
||||
PartofSet = Bone
|
||||
ItemCategory = Equipment
|
||||
Description = Pants made out of hardened bone.
|
||||
|
||||
# Stat Values of the item based on Enhancement level.
|
||||
# See ItemSets.txt for valid stat names
|
||||
|
@ -9,6 +9,8 @@ Item
|
||||
{
|
||||
# Amount of time to wait before an item can be used again (Global).
|
||||
Item Cooldown Time = 5.0
|
||||
# The maximum enhancement level of equipment.
|
||||
Item Max Enhancement Level = 10
|
||||
}
|
||||
ItemDrop
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user