Randomize stats implemented with a correct integer distribution (equal probability for all numbers).

pull/28/head
sigonasr2 11 months ago
parent c2d9178de3
commit 73b72a8838
  1. 1
      Crawler/Crawler.cpp
  2. 17
      Crawler/Item.cpp
  3. 2
      Crawler/Item.h
  4. 2
      Crawler/Version.h

@ -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);

@ -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 "<<std::quoted(it)<<" does not exist in Item Database!");
std::shared_ptr<Item>newItem=(*_inventory.insert({it,std::make_shared<Item>(amt,it)})).second;
newItem->RandomizeStats();
if(ITEM_DATA[it].IsEquippable()){ //Do not stack equips!
for(uint32_t i=0;i<amt;i++){
InsertIntoSortedInv((*_inventory.insert({it,std::make_shared<Item>(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<Item>(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;
}

@ -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_ptr<Item>item);

@ -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

Loading…
Cancel
Save