Added Merchant/Buy/Sell Menu windows. Added sorted item callbacks for traveling merchant inventory modifications.
This commit is contained in:
+28
-2
@@ -36,18 +36,22 @@ All rights reserved.
|
||||
*/
|
||||
#pragma endregion
|
||||
|
||||
#include "Menu.h"
|
||||
#include "Merchant.h"
|
||||
#include "Crawler.h"
|
||||
|
||||
INCLUDE_game
|
||||
INCLUDE_ITEM_CATEGORIES
|
||||
|
||||
std::map<Chapter,std::vector<Merchant>>Merchant::merchants;
|
||||
std::map<ITCategory,std::vector<Item*>>Merchant::sortedItems;
|
||||
MerchantFunctionPrimingData Merchant::purchaseFunctionPrimed("CanPurchaseItem()");
|
||||
MerchantFunctionPrimingData Merchant::sellFunctionPrimed("CanSellItem()");
|
||||
Merchant Merchant::travelingMerchant;
|
||||
|
||||
const Merchant&Merchant::GetRandomMerchant(Chapter chapter){
|
||||
return merchants[chapter][rand()%(merchants[chapter].size()-1)];
|
||||
const Merchant&newMerchant=merchants[chapter][rand()%(merchants[chapter].size()-1)];
|
||||
return newMerchant;
|
||||
}
|
||||
|
||||
const std::string&Merchant::GetDisplayName()const{
|
||||
@@ -58,6 +62,10 @@ const std::vector<Item>&Merchant::GetShopItems()const{
|
||||
return shopItems;
|
||||
}
|
||||
|
||||
const std::vector<Item*>&Merchant::GetShopItems(ITCategory category){
|
||||
return sortedItems[category];
|
||||
}
|
||||
|
||||
Merchant&Merchant::AddMerchant(Chapter chapter){
|
||||
merchants[chapter].push_back({});
|
||||
return merchants[chapter].back();
|
||||
@@ -65,6 +73,20 @@ Merchant&Merchant::AddMerchant(Chapter chapter){
|
||||
|
||||
void Merchant::AddItem(IT item,uint32_t amt,uint8_t enhancementLevel){
|
||||
shopItems.push_back(Item{amt,item,enhancementLevel});
|
||||
if(&GetCurrentTravelingMerchant()==this){
|
||||
UpdateSortedItemsList();
|
||||
Menu::MerchantInventorySlotsUpdated(ITEM_DATA[item].Category());
|
||||
}
|
||||
}
|
||||
|
||||
void Merchant::UpdateSortedItemsList(){
|
||||
const Merchant&merchant=GetCurrentTravelingMerchant();
|
||||
for(auto&[key,items]:ITEM_CATEGORIES){
|
||||
sortedItems[key].clear();
|
||||
}
|
||||
std::for_each(merchant.shopItems.begin(),merchant.shopItems.end(),[](const Item&item){
|
||||
sortedItems[item.Category()].push_back(const_cast<Item*>(&item));
|
||||
});
|
||||
}
|
||||
|
||||
INCLUDE_DATA
|
||||
@@ -137,7 +159,7 @@ bool Merchant::CanSellItem(IT item,uint32_t amt)const{
|
||||
};
|
||||
void Merchant::PurchaseItem(IT item,uint32_t amt){
|
||||
purchaseFunctionPrimed.Validate(item,amt);
|
||||
|
||||
|
||||
uint32_t totalCost=0U;
|
||||
for(Item&it:shopItems){
|
||||
if(it==item){
|
||||
@@ -181,6 +203,10 @@ void Merchant::SellItem(IT item,uint32_t amt){
|
||||
|
||||
void Merchant::RandomizeTravelingMerchant(){
|
||||
travelingMerchant=GetRandomMerchant(game->GetCurrentChapter());
|
||||
for(auto&[key,items]:ITEM_CATEGORIES){
|
||||
Menu::MerchantInventorySlotsUpdated(key);
|
||||
}
|
||||
UpdateSortedItemsList();
|
||||
};
|
||||
Merchant&Merchant::GetCurrentTravelingMerchant(){
|
||||
return travelingMerchant;
|
||||
|
||||
Reference in New Issue
Block a user