Skip to content

Commit

Permalink
[AHBOT] New item rarity system (affecting price and item stack calcul…
Browse files Browse the repository at this point in the history
…ations)
  • Loading branch information
ike3 committed Nov 2, 2018
1 parent f6260d2 commit 5677b7e
Show file tree
Hide file tree
Showing 9 changed files with 311 additions and 154 deletions.
58 changes: 51 additions & 7 deletions ahbot/AhBot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@ int AhBot::AddAuction(int auction, Category* category, ItemPrototype const* prot

price = category->GetPricingStrategy()->GetSellPrice(proto, auctionIds[auction]);

uint32 stackCount = category->GetStackCount(proto);
uint32 stackCount = urand(1, category->GetStackCount(proto));
if (!price || !stackCount)
return 0;

Expand Down Expand Up @@ -646,6 +646,12 @@ void AhBot::HandleCommand(string command)
return;
}

if (command == "dump")
{
Dump();
return;
}

uint32 itemId = atoi(command.c_str());
if (!itemId)
{
Expand Down Expand Up @@ -681,13 +687,13 @@ void AhBot::HandleCommand(string command)
<< GetAvailableMoney(auctionIds[auction])
<< ") ---\n";

out << "sell: " << ChatHelper::formatMoney(category->GetPricingStrategy()->GetSellPrice(proto, auctionIds[auction], true))
<< " (" << category->GetPricingStrategy()->ExplainSellPrice(proto, auctionIds[auction]) << ")"
<< "\n";
ostringstream exp1;
out << "sell: " << ChatHelper::formatMoney(category->GetPricingStrategy()->GetSellPrice(proto, auctionIds[auction], true, &exp1));
out << " (" << exp1.str().c_str() << ")\n";

out << "buy: " << ChatHelper::formatMoney(category->GetPricingStrategy()->GetBuyPrice(proto, auctionIds[auction]))
<< " (" << category->GetPricingStrategy()->ExplainBuyPrice(proto, auctionIds[auction]) << ")"
<< "\n";
ostringstream exp2;
out << "buy: " << ChatHelper::formatMoney(category->GetPricingStrategy()->GetBuyPrice(proto, auctionIds[auction], &exp2));
out << " (" << exp2.str().c_str() << ")\n";

out << "market: " << ChatHelper::formatMoney(category->GetPricingStrategy()->GetMarketPrice(proto->ItemId, auctionIds[auction]))
<< "\n";
Expand Down Expand Up @@ -1143,4 +1149,42 @@ void AhBot::CheckSendMail(uint32 bidder, uint32 price, AuctionEntry *entry)
SetTime("entry", entry->Id, entry->auctionHouseEntry->houseId, AHBOT_SENDMAIL, entry->expireTime);
}

void AhBot::Dump()
{
for (uint32 itemId = 0; itemId < sItemStorage.GetMaxEntry(); ++itemId)
{
ItemPrototype const* proto = sObjectMgr.GetItemPrototype(itemId);
if (!proto)
continue;

bool first = true;
for (int i=0; i<CategoryList::instance.size(); i++)
{
Category* category = CategoryList::instance[i];
if (category->Contains(proto))
{
vector<uint32> items = availableItems.Get(category);
if (find(items.begin(), items.end(), proto->ItemId) == items.end())
continue;

ostringstream out;
if (first)
{
out << proto->ItemId << " (" << proto->Name1 << ") x" << category->GetStackCount(proto) << " - ";
first = false;
}

int auction = 0;
const AuctionHouseEntry* ahEntry = sAuctionHouseStore.LookupEntry(auctionIds[auction]);
out << "SELL: "
<< ChatHelper::formatMoney(category->GetPricingStrategy()->GetSellPrice(proto, auctionIds[auction], true))
<< ", BUY: "
<< ChatHelper::formatMoney(category->GetPricingStrategy()->GetBuyPrice(proto, auctionIds[auction]))
<< " (" << category->GetDisplayName() << ")";
sLog.outString(out.str().c_str());
}
}
}
}

INSTANTIATE_SINGLETON_1( ahbot::AhBot );
1 change: 1 addition & 0 deletions ahbot/AhBot.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ namespace ahbot
void SetTime(string category, uint32 id, uint32 auctionHouse, uint32 type, uint32 value);
uint32 GetSellTime(uint32 itemId, uint32 auctionHouse, Category*& category);
void CheckSendMail(uint32 bidder, uint32 price, AuctionEntry *entry);
void Dump();

public:
static uint32 auctionIds[MAX_AUCTIONS];
Expand Down
4 changes: 3 additions & 1 deletion ahbot/Category.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "../botpch.h"
#include "Category.h"
#include "../playerbot/RandomItemMgr.h"
#include "ItemBag.h"
#include "AhBotConfig.h"
#include "PricingStrategy.h"
Expand All @@ -12,7 +13,8 @@ uint32 Category::GetStackCount(ItemPrototype const* proto)
if (proto->Quality > ITEM_QUALITY_UNCOMMON)
return 1;

return urand(1, proto->GetMaxStackSize());
double rarity = GetPricingStrategy()->GetRarityPriceMultiplier(proto->ItemId);
return (uint32)max(1.0, proto->GetMaxStackSize() / rarity);
}

uint32 Category::GetMaxAllowedItemAuctionCount(ItemPrototype const* proto)
Expand Down
52 changes: 0 additions & 52 deletions ahbot/Category.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,21 +50,6 @@ namespace ahbot
{
return 10;
}

virtual uint32 GetStackCount(ItemPrototype const* proto)
{
if (proto->Quality > ITEM_QUALITY_UNCOMMON)
return 1;

uint32 maxStackSize = proto->GetMaxStackSize();
if (maxStackSize == 1)
return 1;

if (maxStackSize <= 10)
return urand(1, 10);

return urand(1, 4) * maxStackSize / 5;
}
};

class Quest : public Category
Expand All @@ -84,21 +69,6 @@ namespace ahbot
{
return 5;
}

virtual uint32 GetStackCount(ItemPrototype const* proto)
{
if (proto->Quality > ITEM_QUALITY_UNCOMMON)
return 1;

uint32 maxStackSize = proto->GetMaxStackSize();
if (proto->Quality == ITEM_QUALITY_UNCOMMON && maxStackSize > 10)
maxStackSize = urand(1, 10);

if (maxStackSize > 20)
maxStackSize = urand(1, 20);

return maxStackSize;
}
};

class Trade : public Category
Expand All @@ -120,23 +90,6 @@ namespace ahbot
{
return 5;
}

virtual uint32 GetStackCount(ItemPrototype const* proto)
{
uint32 maxStack = proto->GetMaxStackSize();
if (maxStack < 2)
return maxStack;

switch (proto->Quality)
{
case ITEM_QUALITY_NORMAL:
return maxStack;
case ITEM_QUALITY_UNCOMMON:
return urand(1, maxStack);
}

return 1;
}
};

class Reagent : public Category
Expand Down Expand Up @@ -296,11 +249,6 @@ namespace ahbot
{
return 1;
}

virtual uint32 GetStackCount(ItemPrototype const* proto)
{
return proto->GetMaxStackSize();
}
};

class QualityCategoryWrapper : public Category
Expand Down
Loading

0 comments on commit 5677b7e

Please sign in to comment.