Traveling merchant randomized data is now saved

Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
pull/35/head
Nic0Nic0Nii 10 months ago
parent 78374d1c1a
commit 2bbd5e9ee4
  1. 37
      Adventures in Lestoria/Merchant.cpp
  2. 7
      Adventures in Lestoria/Merchant.h
  3. 2
      Adventures in Lestoria/SaveFile.cpp
  4. 8
      Adventures in Lestoria/assets/config/shops/Chapter 2 Merchants.txt
  5. 8
      Adventures in Lestoria/assets/config/shops/Chapter 3 Merchants.txt
  6. 8
      Adventures in Lestoria/assets/config/shops/Chapter 4 Merchants.txt
  7. 8
      Adventures in Lestoria/assets/config/shops/Chapter 5 Merchants.txt
  8. 8
      Adventures in Lestoria/assets/config/shops/Chapter 6 Merchants.txt

@ -30,7 +30,7 @@ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
Portions of this software are copyright © 2023 The FreeType
Portions of this software are copyright <EFBFBD> 2023 The FreeType
Project (www.freetype.org). Please see LICENSE_FT.txt for more information.
All rights reserved.
*/
@ -67,8 +67,9 @@ const std::vector<std::weak_ptr<Item>>&Merchant::GetShopItems(ITCategory categor
return sortedItems[category];
}
Merchant&Merchant::AddMerchant(Chapter chapter){
Merchant&Merchant::AddMerchant(Chapter chapter,std::string_view keyName){
merchants[chapter].push_back({});
merchants[chapter].back().keyName=keyName;
return merchants[chapter].back();
}
@ -103,7 +104,7 @@ void Merchant::Initialize(){
utils::datafile&chapterMerchantInfo=DATA["Merchant"][std::format("Chapter {}",chapter)];
for(auto&[key,size]:chapterMerchantInfo){
utils::datafile&data=chapterMerchantInfo.GetProperty(key);
Merchant&newMerchant=AddMerchant(chapter);
Merchant&newMerchant=AddMerchant(chapter,key);
for(int itemNumber=1;auto&[key,size]:data){
if(key=="DisplayName")newMerchant.displayName=data[key].GetString();
else
@ -127,6 +128,7 @@ void Merchant::Initialize(){
}
merchantCount++;
}
if(merchantCount==0)ERR(std::format("WARNING! No merchants available for Chapter {}!",chapter));
std::cout<<std::format("Added {} merchants to Chapter {}",merchantCount,chapter)<<std::endl;
}
Merchant::RandomizeTravelingMerchant();
@ -210,12 +212,29 @@ void Merchant::SellItem(std::weak_ptr<Item>item,uint32_t amt){
};
void Merchant::RandomizeTravelingMerchant(){
travelingMerchant=GetRandomMerchant(game->GetCurrentChapter());
for(auto&[key,items]:ITEM_CATEGORIES){
Menu::MerchantInventorySlotsUpdated(key);
}
UpdateSortedItemsList();
SetTravelingMerchant(const_cast<Merchant&>(GetRandomMerchant(game->GetCurrentChapter())).GetKeyName());
};
Merchant&Merchant::GetCurrentTravelingMerchant(){
return travelingMerchant;
};
};
std::string_view Merchant::GetKeyName()const{
return keyName;
}
void Merchant::SetTravelingMerchant(std::string_view key){
for(auto&[merchantKey,merchantList]:merchants){
auto it=std::find_if(merchantList.begin(),merchantList.end(),[&](const Merchant&merchant){return merchant.GetKeyName()==key;});
if(it!=merchantList.end()){
travelingMerchant=*it;
for(auto&[key,items]:ITEM_CATEGORIES){
Menu::MerchantInventorySlotsUpdated(key);
}
UpdateSortedItemsList();
return;
}
}
std::cout<<std::format("WARNING! Could not set traveling merchant with key {}!",std::string(key))<<std::endl;
std::cout<<"Falling back to a randomized merchant."<<std::endl;
RandomizeTravelingMerchant();
}

@ -30,7 +30,7 @@ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
Portions of this software are copyright © 2023 The FreeType
Portions of this software are copyright <EFBFBD> 2023 The FreeType
Project (www.freetype.org). Please see LICENSE_FT.txt for more information.
All rights reserved.
*/
@ -45,6 +45,7 @@ using ITCategory=std::string;
class Merchant{
public:
static void RandomizeTravelingMerchant();
static void SetTravelingMerchant(std::string_view key);
static Merchant&GetCurrentTravelingMerchant();
const std::string&GetDisplayName()const;
const std::vector<std::shared_ptr<Item>>&GetShopItems()const;
@ -54,9 +55,10 @@ public:
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);
std::string_view GetKeyName()const;
public:
static void Initialize();
static Merchant&AddMerchant(Chapter chapter);
static Merchant&AddMerchant(Chapter chapter,std::string_view keyName);
private:
static MerchantFunctionPrimingData purchaseFunctionPrimed;
static MerchantFunctionPrimingData sellFunctionPrimed;
@ -64,6 +66,7 @@ private:
static const Merchant&GetRandomMerchant(Chapter chapter);
static std::map<Chapter,std::vector<Merchant>>merchants;
std::string displayName;
std::string keyName;
std::vector<std::shared_ptr<Item>>shopItems;
static std::map<ITCategory,std::vector<std::weak_ptr<Item>>>sortedItems;
static void UpdateSortedItemsList();

@ -119,6 +119,7 @@ const void SaveFile::SaveGame(){
saveFile["Chapter"].SetInt(game->GetCurrentChapter());
saveFile["Save Name"].SetString(std::string(GetSaveFileName()));
saveFile["Game Time"].SetReal(game->GetRuntime());
saveFile["TravelingMerchant"].SetString(std::string(Merchant::GetCurrentTravelingMerchant().GetKeyName()));
utils::datafile::Write(saveFile,"save_file_path"_S+std::format("save.{:04}",saveFileID));
utils::datafile metadata;
if(onlineMode){
@ -246,6 +247,7 @@ void SaveFile::LoadFile(){
SaveFile::SetSaveFileName(loadFile["Save Name"].GetString());
game->SetRuntime(loadFile["Game Time"].GetReal());
game->GetPlayer()->RecalculateEquipStats();
if(loadFile.HasProperty("TravelingMerchant"))Merchant::SetTravelingMerchant(loadFile["TravelingMerchant"].GetString());
GameState::ChangeState(States::OVERWORLD_MAP,0.5f);
}else{

@ -2,6 +2,12 @@ Merchant
{
Chapter 2
{
Chapter2_A
{
DisplayName = Merchant
# Specify items this merchant sells. Add an optional quantity as a second argument. Not specifying a second argument will give the shop infinite supply.
Item[1] = Minor Health Potion
Item[2] = Minor Mana Potion
}
}
}

@ -2,6 +2,12 @@ Merchant
{
Chapter 3
{
Chapter3_A
{
DisplayName = Merchant
# Specify items this merchant sells. Add an optional quantity as a second argument. Not specifying a second argument will give the shop infinite supply.
Item[1] = Minor Health Potion
Item[2] = Minor Mana Potion
}
}
}

@ -2,6 +2,12 @@ Merchant
{
Chapter 4
{
Chapter4_A
{
DisplayName = Merchant
# Specify items this merchant sells. Add an optional quantity as a second argument. Not specifying a second argument will give the shop infinite supply.
Item[1] = Minor Health Potion
Item[2] = Minor Mana Potion
}
}
}

@ -2,6 +2,12 @@ Merchant
{
Chapter 5
{
Chapter5_A
{
DisplayName = Merchant
# Specify items this merchant sells. Add an optional quantity as a second argument. Not specifying a second argument will give the shop infinite supply.
Item[1] = Minor Health Potion
Item[2] = Minor Mana Potion
}
}
}

@ -2,6 +2,12 @@ Merchant
{
Chapter 6
{
Chapter6_A
{
DisplayName = Merchant
# Specify items this merchant sells. Add an optional quantity as a second argument. Not specifying a second argument will give the shop infinite supply.
Item[1] = Minor Health Potion
Item[2] = Minor Mana Potion
}
}
}
Loading…
Cancel
Save