Fixed bug regarding having multiple sellable equips in your inventory and being able to sell multiple extra copies of them. Also fixed inventory not updating upon selling an item.

pull/28/head
sigonasr2 1 year ago
parent 5a9396fbcb
commit fccf24c0c9
  1. 2
      Crawler/Crawler.cpp
  2. 13
      Crawler/Item.cpp
  3. 5
      Crawler/Item.h
  4. 1
      Crawler/Menu.cpp
  5. 10
      Crawler/Merchant.cpp
  6. 2
      Crawler/Merchant.h
  7. 4
      Crawler/MerchantWindow.cpp
  8. 2
      Crawler/SellItemWindow.cpp
  9. 4
      Crawler/TODO.txt
  10. 2
      Crawler/Version.h
  11. BIN
      Crawler/assets/Campaigns/World_Map.png

@ -216,7 +216,7 @@ bool Crawler::OnUserCreate(){
Inventory::AddItem("Wooden Sword");
Inventory::AddItem("Laser Sword");
Inventory::AddItem("Shell Sword");
Inventory::AddItem("Ring of the Slime King",4);
Inventory::AddItem("Ring of the Slime King",3);
LoadLevel(LEVEL_NAMES["starting_map"_S]);
ChangePlayerClass(WARRIOR);

@ -383,7 +383,7 @@ void Inventory::AddItem(IT it,uint32_t amt,bool monsterDrop){
if(ITEM_DATA[it].IsEquippable()){ //Do not stack equips!
for(uint32_t i=0;i<amt;i++){
std::shared_ptr<Item>newItem=(*_inventory.insert({it,std::make_shared<Item>(amt,it)})).second;
std::shared_ptr<Item>newItem=(*_inventory.insert({it,std::make_shared<Item>(1,it)})).second;
newItem->RandomizeStats();
InsertIntoSortedInv(newItem);
}
@ -444,6 +444,7 @@ bool Inventory::UseItem(IT it,uint32_t amt){
//Returns true if the item has been consumed completely and there are 0 remaining of that type in our inventory.
bool Inventory::RemoveItem(std::weak_ptr<Item>itemRef,ITCategory inventory,uint32_t amt){
if(amt==0)ERR("WARNING! Trying to remove zero of an item makes no sense.");
#pragma region Calculate Inventory to Manipulate
std::vector<std::shared_ptr<Item>>&inv=sortedInv.at(inventory);
bool eraseFromLootWindow=false;
@ -468,7 +469,7 @@ bool Inventory::RemoveItem(std::weak_ptr<Item>itemRef,ITCategory inventory,uint3
}
//There are two places to manipulate items in (Both the sorted inventory and the actual inventory)
if (!itemAmt)return false;
if(!itemAmt)return false;
if (amt>=itemAmt){
inv.erase(inv.begin()+count); //Clears it from the detected sorted inventory as well!
@ -480,8 +481,12 @@ bool Inventory::RemoveItem(std::weak_ptr<Item>itemRef,ITCategory inventory,uint3
Menu::InventorySlotsUpdated(inventory);
return true;
}else{
if(!eraseFromLootWindow){
itemRef.lock()->amt-=amt;
if(itemRef.lock()->IsEquippable()){ //Since equipment doesn't stack, if we have more than one piece we have to still remove that piece.
size_t erased=std::erase_if(_inventory,[&](const std::pair<const IT,std::shared_ptr<Item>>data){return data.second==itemRef;});
if(erased!=1)ERR(std::format("Did not erase a single element, instead erased {} elements.",erased));
inv.erase(inv.begin()+count); //Clears it from the detected sorted inventory as well!
Menu::InventorySlotsUpdated(inventory);
return true;
}else{
itemRef.lock()->amt-=amt; //Don't touch the sorted inventory unless this is monster loot or stage loot because there's only "1" of this item in the entry list.
}

@ -106,6 +106,7 @@ public:
return attributes.size();
}
const std::string GetStatsString(CompactText compact=NON_COMPACT)const;
friend const bool operator==(const Stats&lhs,const Stats&rhs){return lhs.attributes==rhs.attributes;}
};
class Stats;
@ -212,9 +213,9 @@ public:
static bool IsBlank(std::shared_ptr<Item>item);
//Use ISBLANK macro instead!! This should not be called directly!!
static bool IsBlank(std::weak_ptr<Item>item);
friend const bool operator==(std::shared_ptr<Item>lhs,std::shared_ptr<Item>rhs){return lhs->it==rhs->it;};
friend const bool operator==(std::shared_ptr<Item>lhs,std::shared_ptr<Item>rhs){return lhs->it==rhs->it&&lhs->randomizedStats==rhs->randomizedStats;};
friend const bool operator==(std::shared_ptr<Item>lhs,const IT&rhs){return lhs->ActualName()==rhs;};
friend const bool operator==(std::weak_ptr<Item>lhs,std::weak_ptr<Item>rhs){return !lhs.expired()&&!rhs.expired()&&lhs.lock()->it==rhs.lock()->it;};
friend const bool operator==(std::weak_ptr<Item>lhs,std::weak_ptr<Item>rhs){return !lhs.expired()&&!rhs.expired()&&lhs.lock()->it==rhs.lock()->it&&lhs.lock()->randomizedStats==rhs.lock()->randomizedStats;};
friend const bool operator==(std::weak_ptr<Item>lhs,const IT&rhs){return !lhs.expired()&&lhs.lock()->ActualName()==rhs;};
friend const bool operator==(const IT&lhs,std::weak_ptr<Item>rhs){return operator==(rhs,lhs);};
friend const bool operator==(const IT&lhs,std::shared_ptr<Item>rhs){return operator==(rhs,lhs);};

@ -182,6 +182,7 @@ void Menu::MenuSelect(Crawler*game){
}
void Menu::Update(Crawler*game){
if(buttons.count(selection.y)==0)selection={-1,-1};
if(selection.x<0||selection.x>=buttons[selection.y].size()){selection={-1,-1};}
if(draggingComponent==nullptr){

@ -149,14 +149,12 @@ bool Merchant::CanPurchaseItem(IT item,uint32_t amt)const{
!foundItem.expired()&&
game->GetPlayer()->GetMoney()>=foundItem.lock()->BuyValue()*amt;
};
bool Merchant::CanSellItem(IT item,uint32_t amt)const{
const ItemInfo&it=ITEM_DATA[item];
bool Merchant::CanSellItem(std::weak_ptr<Item>item,uint32_t amt)const{
sellFunctionPrimed.amt=amt;
sellFunctionPrimed.item=item;
sellFunctionPrimed.item=item.lock()->ActualName();
return sellFunctionPrimed=
it.CanBeSold()&&
Inventory::GetItemCount(item)>=amt;
item.lock()->CanBeSold()&&
item.lock()->Amt()>=amt;
};
void Merchant::PurchaseItem(IT item,uint32_t amt){
purchaseFunctionPrimed.Validate(item,amt);

@ -53,7 +53,7 @@ public:
const static std::vector<std::weak_ptr<Item>>&GetShopItems(ITCategory category);
void AddItem(IT item,uint32_t amt=1,uint8_t enhancementLevel=0U);
bool CanPurchaseItem(IT item,uint32_t amt=1U)const;
bool CanSellItem(IT item,uint32_t amt=1U)const;
bool CanSellItem(std::weak_ptr<Item>IT,uint32_t amt=1U)const;
void PurchaseItem(IT item,uint32_t amt=1U);
void SellItem(std::weak_ptr<Item>,uint32_t amt=1U);
public:

@ -159,13 +159,13 @@ void Menu::InitializeMerchantWindow(){
Component<MenuLabel>(SELL_ITEM,"Amount to sell Amount Label")->SetLabel("1");
Component<MenuLabel>(SELL_ITEM,"Total Price Amount Label")->SetLabel(std::to_string(item->GetItem().lock()->SellValue()));
Merchant&merchant=Merchant::GetCurrentTravelingMerchant();
bool canPurchase=merchant.CanSellItem(item->GetItem().lock()->ActualName(),1);
bool canPurchase=merchant.CanSellItem(item->GetItem(),1);
std::string colorCode="";
if(!canPurchase)colorCode="#FF0000";
Component<MenuLabel>(SELL_ITEM,"Total Price Amount Label")->SetLabel(colorCode+std::to_string(item->GetItem().lock()->SellValue()));
Component<MenuLabel>(SELL_ITEM,"Item Sell Header")->SetLabel("Selling "+item->GetItem().lock()->DisplayName());
Component<MenuComponent>(SELL_ITEM,"Sell Button")->SetGrayedOut(!merchant.CanSellItem(item->GetItem().lock()->ActualName(),1));
Component<MenuComponent>(SELL_ITEM,"Sell Button")->SetGrayedOut(!merchant.CanSellItem(item->GetItem(),1));
Menu::OpenMenu(SELL_ITEM);
}
return true;

@ -53,7 +53,7 @@ void Menu::InitializeSellItemWindow(){
Merchant&merchant=Merchant::GetCurrentTravelingMerchant();
const std::weak_ptr<Item>item=Component<ItemMenuLabel>(SELL_ITEM,"Item Sell Header")->GetItem();
bool canSell=merchant.CanSellItem(item.lock()->ActualName(),GetQuantity());
bool canSell=merchant.CanSellItem(item,GetQuantity());
std::string colorCode="";
if(!canSell)colorCode="#FF0000";

@ -1,9 +1,5 @@
January 1st
===========
Randomized Item Stats
- Get Item may return multiples of the same item.
- Removing an item with multiples require a specific item to be selected.
- Gear should never stack.
The Hub / NPC Interactions
Save/Load Game
- Save Inventory Items/Equips

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

Binary file not shown.

After

Width:  |  Height:  |  Size: 105 KiB

Loading…
Cancel
Save