From 73b72a88382d6c2aeffbb2cdd186081626cc3396 Mon Sep 17 00:00:00 2001 From: sigonasr2 Date: Sun, 31 Dec 2023 15:47:18 -0600 Subject: [PATCH] Randomize stats implemented with a correct integer distribution (equal probability for all numbers). --- Crawler/Crawler.cpp | 1 + Crawler/Item.cpp | 17 ++++++++++++----- Crawler/Item.h | 2 +- Crawler/Version.h | 2 +- 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/Crawler/Crawler.cpp b/Crawler/Crawler.cpp index f567f24a..2832db02 100644 --- a/Crawler/Crawler.cpp +++ b/Crawler/Crawler.cpp @@ -216,6 +216,7 @@ bool Crawler::OnUserCreate(){ Inventory::AddItem("Wooden Sword"); Inventory::AddItem("Laser Sword"); Inventory::AddItem("Shell Sword"); + Inventory::AddItem("Ring of the Slime King"); LoadLevel(LEVEL_NAMES["starting_map"_S]); ChangePlayerClass(WARRIOR); diff --git a/Crawler/Item.cpp b/Crawler/Item.cpp index 644fd9b2..1efe989d 100644 --- a/Crawler/Item.cpp +++ b/Crawler/Item.cpp @@ -380,16 +380,19 @@ Item::Item(uint32_t amt,IT item,uint8_t enhancementLevel) void Inventory::AddItem(IT it,uint32_t amt,bool monsterDrop){ if(!ITEM_DATA.count(it))ERR("Item "<newItem=(*_inventory.insert({it,std::make_shared(amt,it)})).second; + newItem->RandomizeStats(); + if(ITEM_DATA[it].IsEquippable()){ //Do not stack equips! for(uint32_t i=0;i(amt,it)})).second); + InsertIntoSortedInv(newItem); } goto SkipAddingStackableItem; } else //There are two places to manipulate items in (Both the sorted inventory and the actual inventory) if(!_inventory.count(it)){ - InsertIntoSortedInv((*_inventory.insert({it,std::make_shared(amt,it)})).second); + InsertIntoSortedInv(newItem); }else{ auto inventory=_inventory.equal_range(it); if(std::accumulate(inventory.first,inventory.second,0, @@ -1050,8 +1053,8 @@ const uint8_t EnhancementInfo::AvailableChapter()const{ const Stats&Item::RandomStats()const{ return randomizedStats; }; -void Item::SetRandomStat(const ItemAttribute attr,const float val){ - randomizedStats.A(attr)=val; +void Item::RandomizeStats(){ + randomizedStats=it->RandomizeStats(); }; const Stats ItemInfo::GetMinStats()const{ @@ -1064,7 +1067,11 @@ Stats ItemInfo::RandomizeStats(){ Stats randomRolls; for(auto&[attr,minVal]:minStats){ float diff=maxStats.A(attr)-minVal; - randomRolls.A(attr)=util::random(diff)+minVal; + if(attr.ShowAsDecimal()){ + randomRolls.A(attr)=util::random(diff)+minVal; + }else{ + randomRolls.A(attr)=floor(util::random(diff+1)+minVal); //We must add 1 because we are going to floor the value to prevent the edges from having half as likely probability as all other numbers. + } } return randomRolls; } \ No newline at end of file diff --git a/Crawler/Item.h b/Crawler/Item.h index cf43fc26..d374d085 100644 --- a/Crawler/Item.h +++ b/Crawler/Item.h @@ -202,7 +202,7 @@ public: const bool CanBeSold()const; const bool CanBePurchased()const; const Stats&RandomStats()const; - void SetRandomStat(const ItemAttribute attr,const float val); + void RandomizeStats(); const EnhancementInfo&GetEnhancementInfo()const; //Use ISBLANK macro instead!! This should not be called directly!! static bool IsBlank(std::shared_ptritem); diff --git a/Crawler/Version.h b/Crawler/Version.h index e09b5ee9..55ac3e84 100644 --- a/Crawler/Version.h +++ b/Crawler/Version.h @@ -39,7 +39,7 @@ All rights reserved. #define VERSION_MAJOR 0 #define VERSION_MINOR 2 #define VERSION_PATCH 1 -#define VERSION_BUILD 5119 +#define VERSION_BUILD 5122 #define stringify(a) stringify_(a) #define stringify_(a) #a