Added item enhancement check functions, added priming requirements, and updated item enhancement function.

pull/28/head
sigonasr2 1 year ago
parent 318719d46f
commit 38bedb653d
  1. 10
      Crawler/AttributableStat.cpp
  2. 3
      Crawler/AttributableStat.h
  3. 5
      Crawler/Crawler.cpp
  4. 24
      Crawler/FunctionPriming.h
  5. 41
      Crawler/Item.cpp
  6. 6
      Crawler/Item.h
  7. 2
      Crawler/Merchant.cpp
  8. 2
      Crawler/Version.h

@ -58,8 +58,8 @@ ItemAttributable&ItemAttributable::operator+=(ItemAttributable&rhs){
return *this;
};
ItemAttribute::ItemAttribute(std::string_view name,bool isPct,bool showDecimal,std::string_view modifies)
:name(std::string(name)),isPct(isPct),showDecimal(showDecimal),modifies(std::string(modifies)){}
ItemAttribute::ItemAttribute(std::string_view originalName,std::string_view name,bool isPct,bool showDecimal,std::string_view modifies)
:originalName(std::string(originalName)),name(std::string(name)),isPct(isPct),showDecimal(showDecimal),modifies(std::string(modifies)){}
void ItemAttribute::Initialize(){
for(auto&[key,size]:DATA["Stats"]){
@ -71,7 +71,7 @@ void ItemAttribute::Initialize(){
if(DATA["Stats"][key].HasProperty("Show Decimal")){
showDecimal=DATA["Stats"][key]["Show Decimal"].GetBool();
}
attributes.insert(key,ItemAttribute(DATA["Stats"][key]["Display Name"].GetString(),DATA["Stats"][key]["Percentage"].GetBool(),showDecimal,modifies));
attributes.insert(key,ItemAttribute(key,DATA["Stats"][key]["Display Name"].GetString(),DATA["Stats"][key]["Percentage"].GetBool(),showDecimal,modifies));
}
attributes.SetInitialized();
}
@ -91,7 +91,7 @@ const bool ItemAttribute::DisplayAsPercent()const{
//WARNING! Implemented for map sorting!!!
const bool ItemAttribute::operator<(const ItemAttribute&rhs)const{
return name<rhs.name;
return originalName<rhs.originalName;
};
const std::string_view ItemAttribute::Modifies()const{
@ -167,7 +167,7 @@ float&operator-=(float&lhs,const ItemAttribute&rhs){
}
const bool ItemAttribute::operator==(const ItemAttribute&rhs)const{
return name==rhs.name;
return originalName==rhs.originalName;
};

@ -51,6 +51,7 @@ class Monster;
class ItemAttribute{
friend class Crawler;
std::string name;
std::string originalName;
bool isPct;
bool showDecimal=false;
std::string modifies="";
@ -58,7 +59,7 @@ class ItemAttribute{
static void Initialize();
public:
inline static safemap<std::string,ItemAttribute>attributes;
ItemAttribute(std::string_view name,bool isPct,bool showDecimal,std::string_view modifies=""sv);
ItemAttribute(std::string_view originalName,std::string_view name,bool isPct,bool showDecimal,std::string_view modifies=""sv);
static ItemAttribute&Get(const std::string_view name,const std::optional<std::variant<Player*,Monster*>>target={});
const std::string_view Name()const;
const std::string_view Modifies()const;

@ -192,6 +192,7 @@ bool Crawler::OnUserCreate(){
Inventory::AddItem("Minor Health Potion",16);
Inventory::AddItem("Bandages",10);
Inventory::AddItem("Green Slime Remains",1);
Inventory::AddItem("Blue Slime Remains",22);
Inventory::AddItem("Copper Armor");
Inventory::AddItem("Copper Pants");
@ -213,6 +214,10 @@ bool Crawler::OnUserCreate(){
Inventory::AddItem("Laser Sword");
Inventory::AddItem("Shell Sword");
if(Inventory::GetItem("Copper Armor").lock()->CanEnhanceItem()){
Inventory::GetItem("Copper Armor").lock()->EnhanceItem();
}
LoadLevel(LEVEL_NAMES["starting_map"_S]);
ChangePlayerClass(WARRIOR);

@ -45,6 +45,9 @@ struct FunctionPrimingData{
std::string dependentFunction="";
inline FunctionPrimingData(std::string dependentFunction)
:dependentFunction(dependentFunction){}
bool operator=(bool rhs){
return primed=rhs;
}
};
struct MerchantFunctionPrimingData:public FunctionPrimingData{
@ -52,12 +55,29 @@ struct MerchantFunctionPrimingData:public FunctionPrimingData{
uint32_t amt=0;
inline MerchantFunctionPrimingData(std::string dependentFunction)
:FunctionPrimingData(dependentFunction){}
virtual inline void Validate(IT item,uint32_t amt)const{
virtual inline void Validate(IT item,uint32_t amt){
if(!primed)ERR(std::format("WARNING! {} should be called before running this function! Priming Requirement!",dependentFunction));
if(this->item!=item)ERR(std::format("WARNING! Primed items are not matching! {}!={}",this->item,item));
if(this->amt!=amt)ERR(std::format("WARNING! Primed amounts are not matching! {}!={}",this->amt,amt));
primed=false;
}
bool operator=(bool rhs){
return primed=rhs;
}
};
struct ItemEnhancementFunctionPrimingData:public FunctionPrimingData{
IT item="";
uint8_t enhancementLevel=0;
inline ItemEnhancementFunctionPrimingData(std::string dependentFunction)
:FunctionPrimingData(dependentFunction){}
virtual inline void Validate(IT item,uint8_t enhancementLevel){
if(!primed)ERR(std::format("WARNING! {} should be called before running this function! Priming Requirement!",dependentFunction));
if(this->item!=item)ERR(std::format("WARNING! Primed items are not matching! {}!={}",this->item,item));
if(this->enhancementLevel!=enhancementLevel)ERR(std::format("WARNING! Primed enhancement levels are not matching! {}!={}",this->enhancementLevel,enhancementLevel));
primed=false;
}
inline bool operator=(bool rhs){
bool operator=(bool rhs){
return primed=rhs;
}
};

@ -59,6 +59,7 @@ std::map<EquipSlot,std::weak_ptr<Item>>Inventory::equipment;
std::map<std::string,EquipSlot>ItemInfo::nameToEquipSlot;
int Item::IsBlankStaticCallCounter=0;
safemap<int,float>Stats::maxDamageReductionTable;
ItemEnhancementFunctionPrimingData Item::enhanceFunctionPrimed("CanEnhanceItem()");
ItemInfo::ItemInfo()
:customProps({nullptr,nullptr}),img(nullptr){}
@ -705,8 +706,18 @@ const uint8_t Item::EnhancementLevel()const{
return enhancementLevel;
};
void Item::EnhanceItem(){
enhanceFunctionPrimed.Validate(ActualName(),EnhancementLevel());
if(enhancementLevel+1>"Item.Item Max Enhancement Level"_I)ERR("WARNING! Attempted to enhance "<<DisplayName()<<" beyond the cap of "<<"Item.Item Max Enhancement Level"_I);
enhancementLevel++;
const CraftingRequirement&consumedResources=GetEnhancementInfo()[EnhancementLevel()].craftingRequirement;
for(const Item&it:consumedResources.GetItems()){
Inventory::RemoveItem(it.ActualName(),it.Amt());
}
game->GetPlayer()->SetMoney(game->GetPlayer()->GetMoney()-consumedResources.GetCost());
};
const std::vector<std::pair<int,Stats>>&ItemSet::GetSetBonusBreakpoints()const{
@ -843,4 +854,32 @@ void EnhancementInfo::SetCraftingRequirements(const int enhanceLevel,const std::
}
EnhancementLevelInfo::EnhancementLevelInfo(const Stats&stats,const CraftingRequirement&craftingRequirement)
:stats(stats),craftingRequirement(craftingRequirement){}
:stats(stats),craftingRequirement(craftingRequirement){}
const bool Item::CanEnhanceItem()const{
if(!GetEnhancementInfo().CanBeEnhanced())return false;
const EnhancementLevelInfo&enhanceInfo=GetEnhancementInfo()[EnhancementLevel()+1];
if(EnhancementLevel()>="Item.Item Max Enhancement Level"_I)return false;
if(game->GetPlayer()->GetMoney()<enhanceInfo.craftingRequirement.GetCost())return false;
for(const Item&it:enhanceInfo.craftingRequirement.GetItems()){
if(Inventory::GetItemCount(ActualName())<it.Amt()){
return false;
}
}
enhanceFunctionPrimed.enhancementLevel=EnhancementLevel();
enhanceFunctionPrimed.item=ActualName();
return enhanceFunctionPrimed=true;
}
const EnhancementInfo&ItemInfo::GetEnhancementInfo()const{
return enhancement;
}
const EnhancementInfo&Item::GetEnhancementInfo()const{
return it->GetEnhancementInfo();
}
const bool EnhancementInfo::CanBeEnhanced()const{
return enhancementStats.size()=="Item.Item Max Enhancement Level"_I+1&&craftingRequirements.size()=="Item.Item Max Enhancement Level"_I+1;
};

@ -46,6 +46,7 @@ All rights reserved.
#include <optional>
#include "Merchant.h"
#include "CraftingRequirement.h"
#include "FunctionPriming.h"
class Crawler;
class ItemInfo;
@ -119,6 +120,7 @@ private:
public:
void SetAttribute(int enhanceLevel,ItemAttribute attribute,float value);
void SetCraftingRequirements(const int enhanceLevel,const std::vector<Item>&requiredItems,const uint32_t goldCost);
const bool CanBeEnhanced()const;
const EnhancementLevelInfo operator[](int level)const;
const size_t size()const;
};
@ -157,6 +159,7 @@ private:
void SetAmt(uint32_t newAmt);
static int IsBlankStaticCallCounter;
const bool _IsBlank()const;
static ItemEnhancementFunctionPrimingData enhanceFunctionPrimed;
public:
Item();
Item(uint32_t amt,IT item,uint8_t enhancementLevel=0);
@ -178,6 +181,7 @@ public:
const bool IsBlank()const;
const uint8_t EnhancementLevel()const;
void EnhanceItem();
const bool CanEnhanceItem()const;
static std::shared_ptr<Item>BLANK;
const std::optional<const::ItemSet*const>ItemSet()const;
const bool IsEquippable()const;
@ -185,6 +189,7 @@ public:
const uint32_t SellValue()const;
const bool CanBeSold()const;
const bool CanBePurchased()const;
const EnhancementInfo&GetEnhancementInfo()const;
//Use ISBLANK macro instead!! This should not be called directly!!
static bool IsBlank(std::shared_ptr<Item>item);
//Use ISBLANK macro instead!! This should not be called directly!!
@ -293,6 +298,7 @@ public:
const bool CanBeSold()const;
const bool CanBePurchased()const;
const bool UseDuringCast()const;
const EnhancementInfo&GetEnhancementInfo()const;
};
class ItemOverlay{

@ -184,8 +184,6 @@ void Merchant::PurchaseItem(IT item,uint32_t amt){
Inventory::AddItem(item,amt);
game->GetPlayer()->SetMoney(game->GetPlayer()->GetMoney()-totalCost);
purchaseFunctionPrimed=false;
};
void Merchant::SellItem(IT item,uint32_t amt){
sellFunctionPrimed.Validate(item,amt);

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

Loading…
Cancel
Save