Add player money functions. Implement Merchant transaction functions. Add Function Priming classes.

This commit is contained in:
2023-12-17 23:37:37 -06:00
parent 2b3c1ea1b4
commit f1aa872717
19 changed files with 350 additions and 93 deletions
+80 -31
View File
@@ -102,6 +102,8 @@ void ItemInfo::InitializeItems(){
std::vector<std::string> slot;
float cooldownTime="Item.Item Cooldown Time"_F;
std::vector<ItemAttribute>statValueList;
uint32_t sellValue=0;
uint32_t buyValue=0;
for(auto&[itemKey,itemValue]:data[key].GetKeys()){
std::string keyName=itemKey;
if(keyName=="Description"){
@@ -131,6 +133,12 @@ void ItemInfo::InitializeItems(){
}else
if(keyName=="PartofSet"){
setName=data[key][keyName].GetString();
}
if(keyName=="BuyValue"){
buyValue=data[key][keyName].GetInt();
}else
if(keyName=="SellValue"){
sellValue=data[key][keyName].GetInt();
}else{ //THis is a custom override modifier for a script. NO-OP
}
}
@@ -162,6 +170,8 @@ void ItemInfo::InitializeItems(){
it.cooldownTime=cooldownTime;
it.slot=EquipSlot::NONE;
it.set=setName;
it.buyValue=buyValue;
it.sellValue=sellValue;
if(slot.size()>0){
for(std::string&s:slot){
if(!nameToEquipSlot.count(s))ERR("WARNING! Tried to add item "<<it.name<<" to slot "<<s<<" which doesn't exist!");
@@ -294,7 +304,7 @@ bool Inventory::RemoveItem(IT it,ITCategory inventory,uint32_t amt){
}
int count=0;
for(Item&item:inv){
if(item.Name()==it)break;
if(item==it)break;
count++;
}
#pragma endregion
@@ -376,27 +386,31 @@ bool Inventory::SwapItems(ITCategory itemCategory,uint32_t slot1,uint32_t slot2)
return true;
}
uint32_t Item::Amt(){
uint32_t Item::Amt()const{
return amt;
};
std::string Item::Name(){
const std::string&Item::ActualName()const{
if(IsBlank())return "";
std::string name=it->Name();
return it->Name();
};
const std::string Item::DisplayName()const{
if(IsBlank())return "";
std::string name=ActualName();
if(IsEquippable()&&EnhancementLevel()>0){
name+=" [+"+std::to_string(EnhancementLevel())+"]";
}
return name;
};
bool Item::IsEquippable()const{
}
const bool Item::IsEquippable()const{
return Category()=="Equipment"||Category()=="Accessories";
}
std::string Item::Description(CompactText compact){
const std::string Item::Description(CompactText compact)const{
std::string description=it->Description();
if(IsEquippable()){
description+='\n';
description+=GetStats().GetStatsString(compact);
if(ItemSet()){
const ::ItemSet*const set=ItemSet().value();
const::ItemSet*const set=ItemSet().value();
if(compact==COMPACT){
description+="\n"+set->GetSetName()+" Set - ";
}else{
@@ -424,48 +438,52 @@ std::string Item::Description(CompactText compact){
const ITCategory Item::Category()const{
return it->Category();
};
::Decal*Item::Decal(){
const::Decal*const Item::Decal()const{
return it->Decal();
};
ItemScript&Item::OnUseAction(){
const ItemScript&Item::OnUseAction()const{
return it->OnUseAction();
};
std::string ItemInfo::Name(){
const std::string&ItemInfo::Name()const{
return name;
};
std::string ItemInfo::Description(){
const std::string&ItemInfo::Description()const{
return description;
};
ITCategory ItemInfo::Category(){
const ITCategory ItemInfo::Category()const{
return category;
};
::Decal*ItemInfo::Decal(){
const::Decal*const ItemInfo::Decal()const{
return img;
};
ItemScript&ItemInfo::OnUseAction(){
const ItemScript&ItemInfo::OnUseAction()const{
return ITEM_SCRIPTS.at(useFunc);
};
bool Item::IsBlank(){
const bool Item::IsBlank()const{
return amt==0||it==nullptr;
}
void Inventory::Clear(ITCategory itemCategory){
std::vector<Item>itemList=get(itemCategory); //We have to make a copy here because RemoveItem() will modify the list provided by get() inline.
for(Item&item:itemList){
size_t itemQuantity=GetItemCount(item.Name());//Normally we want to clear all the items that are actually in our inventory...But...
size_t itemQuantity=GetItemCount(item.ActualName());//Normally we want to clear all the items that are actually in our inventory...But...
if(itemCategory=="Monster Loot"||itemCategory=="Stage Loot"){//These do not affect the actual inventory, we just clear the lists.
itemQuantity=item.Amt();
}
RemoveItem(item.Name(),itemCategory,uint32_t(itemQuantity));
RemoveItem(item.ActualName(),itemCategory,uint32_t(itemQuantity));
}
}
bool Item::operator==(const Item&rhs)const{
const bool Item::operator==(const Item&rhs)const{
return it==rhs.it;
}
const bool Item::operator==(const IT&rhs)const{
return it->Name()==rhs;
}
ItemOverlay::ItemOverlay(ItemInfo item)
:it(item),width("ItemDrop.Item Drop Scale"_F*24+4+game->GetTextSizeProp(item.Name()).x*0.5f){
xOffset=-width;
@@ -487,7 +505,7 @@ void ItemOverlay::Draw(){
Pixel lightCol=Menu::GetCurrentTheme().GetButtonCol()*1.2f;
game->GradientFillRectDecal(pos,{item.width,8},darkCol,darkCol,darkCol,lightCol);
game->DrawRectDecal(pos,{item.width,8},Menu::GetCurrentTheme().GetHighlightCol());
game->DrawDecal(pos,item.it.Decal(),{itemScale,itemScale});
game->DrawDecal(pos,const_cast<Decal*>(item.it.Decal()),{itemScale,itemScale});
game->DrawShadowStringPropDecal(pos+vf2d{itemScale*24+2,2},item.it.Name(),WHITE,BLACK,{0.5f,0.7f});
counter++;
}
@@ -498,11 +516,11 @@ void ItemOverlay::AddToItemOverlay(const ItemInfo&it){
std::for_each(items.begin(),items.end(),[](ItemOverlay&it){it.ResetTimer();});
}
float ItemInfo::CastTime(){
const float ItemInfo::CastTime()const{
return castTime;
}
float ItemInfo::CooldownTime(){
const float ItemInfo::CooldownTime()const{
return cooldownTime;
}
@@ -510,11 +528,11 @@ void ItemOverlay::ResetTimer(){
timer=0;
}
float Item::CastTime(){
const float Item::CastTime()const{
return it->CastTime();
}
float Item::CooldownTime(){
const float Item::CooldownTime()const{
return it->CooldownTime();
}
@@ -524,7 +542,7 @@ const Stats&EnhancementInfo::operator[](int level)const{
const std::optional<const ItemSet *const>ItemInfo::ItemSet()const{
if(ItemSet::sets.count(set)){
return &ItemSet::sets[set];
return &ItemSet::sets.at(set);
}
return {};
};
@@ -560,17 +578,17 @@ EquipSlot Inventory::GetSlotEquippedIn(Item&it){
EquipSlot slot=EquipSlot(i);
Item*equip=GetEquip(slot);
if(equip==nullptr)continue;
if(equip->Name()==it.Name())return slot;
if(equip->ActualName()==it.ActualName())return slot;
}
return EquipSlot::NONE;
};
Item*Inventory::GetEquip(EquipSlot slot){
return Inventory::equipment[slot];
}
EquipSlot Item::GetEquipSlot(){
const EquipSlot Item::GetEquipSlot()const{
return it->Slot();
}
EquipSlot ItemInfo::Slot(){
const EquipSlot ItemInfo::Slot()const{
return slot;
}
@@ -600,7 +618,7 @@ void ItemInfo::InitializeSets(){
}
}
Stats ItemInfo::GetStats(int enhancementLevel){
const Stats&ItemInfo::GetStats(int enhancementLevel)const{
if(enhancement.size()<=enhancementLevel){
return {};
}
@@ -620,11 +638,11 @@ const std::optional<const ItemSet*const>Item::ItemSet()const{
return it->ItemSet();
};
uint8_t Item::EnhancementLevel()const{
const 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);
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++;
};
@@ -664,4 +682,35 @@ const std::string Stats::GetStatsString(CompactText compact)const{
ItemInfo&ItemInfo::operator[](const IT&item){
if(!ITEM_DATA.count(item))ERR("Item "<<std::quoted(item)<<" does not exist in the item database!");
return ITEM_DATA[item];
}
const uint32_t ItemInfo::GetBuyValue()const{
return buyValue;
}
const uint32_t ItemInfo::GetSellValue()const{
return sellValue;
}
const bool ItemInfo::CanBeSold()const{
return GetSellValue()>0;
}
const bool ItemInfo::CanBePurchased()const{
return GetBuyValue()>0;
}
const uint32_t Item::BuyValue()const{
return it->GetBuyValue();
}
const uint32_t Item::SellValue()const{
return it->GetSellValue();
}
const bool Item::CanBeSold()const{
return it->CanBeSold();
}
const bool Item::CanBePurchased()const{
return it->CanBePurchased();
}
void Item::SetAmt(uint32_t newAmt){
amt=newAmt;
}