* AHBot rewritten to cause less lag spikes when checking for bids and when adding new auctions.

* AH Deposit function rewritten to generate deposits closer to official.
* AH Mail system rewritten to fix some bugs.
* MULTI_THREAD_MAP enabled by default (I have no idea why this was commented out before)
* CLIENT_VER added for allowing parts of the code to be enabled/disabled depending on the client version supported.
  Only used in AHBot for now.
* Various code cleanups.

--HG--
branch : trunk
This commit is contained in:
Chaz Brown
2009-09-22 20:40:34 -04:00
parent a9086ea15a
commit 7aa91dd81b
7 changed files with 1062 additions and 687 deletions
+5 -1
View File
@@ -137,7 +137,7 @@ typedef uint32 DWORD;
typedef uint64 OBJECT_HANDLE;
//#define MULTI_THREAD_MAP
#define MULTI_THREAD_MAP
#ifdef MULTI_THREAD_MAP
#define MAP_BASED_RAND_GEN
#endif
@@ -156,6 +156,10 @@ typedef uint64 OBJECT_HANDLE;
# endif
#endif
#ifndef CLIENT_VER
#define CLIENT_VER 313
#endif
#endif //TRINITY_DEFINE_H
+291 -129
View File
@@ -1,12 +1,34 @@
#include "AuctionHouseBot.h"
#include "ObjectMgr.h"
#include "AuctionHouseMgr.h"
#if CLIENT_VER > 300
#else if CLIENT_VER > 100
#include <vector>
#endif
#include "Policies/SingletonImp.h"
INSTANTIATE_SINGLETON_1(AuctionHouseBot);
using namespace std;
#if CLIENT_VER > 300
#else if CLIENT_VER > 100
vector<uint32> npcItems;
vector<uint32> lootItems;
vector<uint32> greyTradeGoodsBin;
vector<uint32> whiteTradeGoodsBin;
vector<uint32> greenTradeGoodsBin;
vector<uint32> blueTradeGoodsBin;
vector<uint32> purpleTradeGoodsBin;
vector<uint32> orangeTradeGoodsBin;
vector<uint32> yellowTradeGoodsBin;
vector<uint32> greyItemsBin;
vector<uint32> whiteItemsBin;
vector<uint32> greenItemsBin;
vector<uint32> blueItemsBin;
vector<uint32> purpleItemsBin;
vector<uint32> orangeItemsBin;
vector<uint32> yellowItemsBin;
#endif
AuctionHouseBot::AuctionHouseBot()
{
debug_Out = false;
@@ -31,7 +53,9 @@ AuctionHouseBot::AuctionHouseBot()
DisableBeta_PTR_Unused = false;
DisablePermEnchant = false;
#if CLIENT_VER > 300
DisableConjured = false;
#endif
DisableGems = false;
DisableMoney = false;
DisableMoneyLoot = false;
@@ -92,10 +116,26 @@ void AuctionHouseBot::addNewAuctions(Player *AHBplayer, AHBConfig *config)
return;
}
AuctionHouseEntry const* ahEntry = auctionmgr.GetAuctionHouseEntry(config->GetAHFID());
AuctionHouseObject* auctionHouse = auctionmgr.GetAuctionsMap(config->GetAHFID());
uint32 minItems = config->GetMinItems();
uint32 maxItems = config->GetMaxItems();
if (maxItems == 0)
{
//if (debug_Out) sLog.outString("AHSeller: Auctions disabled");
return;
}
AuctionHouseEntry const* ahEntry = auctionmgr.GetAuctionHouseEntry(config->GetAHFID());
if (!ahEntry)
{
return;
}
AuctionHouseObject* auctionHouse = auctionmgr.GetAuctionsMap(config->GetAHFID());
if (!auctionHouse)
{
return;
}
uint32 auctions = auctionHouse->Getcount();
if (auctions >= minItems)
@@ -111,7 +151,7 @@ void AuctionHouseBot::addNewAuctions(Player *AHBplayer, AHBConfig *config)
}
uint32 items = 0;
if ((maxItems - auctions) > ItemsPerCycle)
if ((maxItems - auctions) >= ItemsPerCycle)
items = ItemsPerCycle;
else
items = (maxItems - auctions);
@@ -158,87 +198,30 @@ void AuctionHouseBot::addNewAuctions(Player *AHBplayer, AHBConfig *config)
+ whiteIcount + greenIcount + blueIcount + purpleIcount
+ orangeIcount + yellowIcount;
uint32 greyTGoods = 0;
uint32 whiteTGoods = 0;
uint32 greenTGoods = 0;
uint32 blueTGoods = 0;
uint32 purpleTGoods = 0;
uint32 orangeTGoods = 0;
uint32 yellowTGoods = 0;
uint32 greyTGoods = config->GetItemCounts(AHB_GREY_TG);
uint32 whiteTGoods = config->GetItemCounts(AHB_WHITE_TG);
uint32 greenTGoods = config->GetItemCounts(AHB_GREEN_TG);
uint32 blueTGoods = config->GetItemCounts(AHB_BLUE_TG);
uint32 purpleTGoods = config->GetItemCounts(AHB_PURPLE_TG);
uint32 orangeTGoods = config->GetItemCounts(AHB_ORANGE_TG);
uint32 yellowTGoods = config->GetItemCounts(AHB_YELLOW_TG);
uint32 greyItems = 0;
uint32 whiteItems = 0;
uint32 greenItems = 0;
uint32 blueItems = 0;
uint32 purpleItems = 0;
uint32 orangeItems = 0;
uint32 yellowItems = 0;
for (AuctionHouseObject::AuctionEntryMap::const_iterator itr = auctionHouse->GetAuctionsBegin();itr != auctionHouse->GetAuctionsEnd();++itr)
{
AuctionEntry *Aentry = itr->second;
Item *item = auctionmgr.GetAItem(Aentry->item_guidlow);
if (item)
{
ItemPrototype const *prototype = item->GetProto();
if (prototype)
{
switch (prototype->Quality)
{
case 0:
if (prototype->Class == ITEM_CLASS_TRADE_GOODS)
++greyTGoods;
else
++greyItems;
break;
case 1:
if (prototype->Class == ITEM_CLASS_TRADE_GOODS)
++whiteTGoods;
else
++whiteItems;
break;
case 2:
if (prototype->Class == ITEM_CLASS_TRADE_GOODS)
++greenTGoods;
else
++greenItems;
break;
case 3:
if (prototype->Class == ITEM_CLASS_TRADE_GOODS)
++blueTGoods;
else
++blueItems;
break;
case 4:
if (prototype->Class == ITEM_CLASS_TRADE_GOODS)
++purpleTGoods;
else
++purpleItems;
break;
case 5:
if (prototype->Class == ITEM_CLASS_TRADE_GOODS)
++orangeTGoods;
else
++orangeItems;
break;
case 6:
if (prototype->Class == ITEM_CLASS_TRADE_GOODS)
++yellowTGoods;
else
++yellowItems;
break;
}
}
}
}
uint32 greyItems = config->GetItemCounts(AHB_GREY_I);
uint32 whiteItems = config->GetItemCounts(AHB_WHITE_I);
uint32 greenItems = config->GetItemCounts(AHB_GREEN_I);
uint32 blueItems = config->GetItemCounts(AHB_BLUE_I);
uint32 purpleItems = config->GetItemCounts(AHB_PURPLE_I);
uint32 orangeItems = config->GetItemCounts(AHB_ORANGE_I);
uint32 yellowItems = config->GetItemCounts(AHB_YELLOW_I);
if (debug_Out) sLog.outString("AHSeller: %u items", items);
// only insert a few at a time, so as not to peg the processor
for (uint32 cnt = 1;cnt <= items;cnt++)
{
if (debug_Out) sLog.outString("AHSeller: %u count", cnt);
uint32 itemID = 0;
uint32 loopBreaker = 0;
uint32 itemColor = 99;
while (itemID == 0 && loopBreaker < 50)
while (itemID == 0)
{
uint32 choice = urand(0, 13);
itemColor = choice;
@@ -347,8 +330,8 @@ void AuctionHouseBot::addNewAuctions(Player *AHBplayer, AHBConfig *config)
if (debug_Out) sLog.outError("AHSeller: itemID Switch - Default Reached");
break;
}
++loopBreaker;
}
if (itemID == 0)
{
if (debug_Out) sLog.outError("AHSeller: Item::CreateItem() - ItemID is 0");
@@ -363,12 +346,12 @@ void AuctionHouseBot::addNewAuctions(Player *AHBplayer, AHBConfig *config)
}
Item* item = Item::CreateItem(itemID, 1, AHBplayer);
item->AddToUpdateQueueOf(AHBplayer);
if (item == NULL)
{
if (debug_Out) sLog.outError("AHSeller: Item::CreateItem() returned NULL");
break;
}
item->AddToUpdateQueueOf(AHBplayer);
uint32 randomPropertyId = Item::GenerateItemRandomPropertyId(itemID);
if (randomPropertyId != 0)
@@ -405,6 +388,7 @@ void AuctionHouseBot::addNewAuctions(Player *AHBplayer, AHBConfig *config)
{
// quality is something it shouldn't be, let's get out of here
if (debug_Out) sLog.outError("AHBuyer: Quality %u not Supported", prototype->Quality);
item->RemoveFromUpdateQueueOf(AHBplayer);
continue;
}
@@ -505,31 +489,51 @@ void AuctionHouseBot::addNewAuctionBuyerBotBid(Player *AHBplayer, AHBConfig *con
return;
}
/*
uint32 AuctioneerGUID = 0;
switch (config->GetAHID())
{
case 2:
AuctioneerGUID = 79707; //Human in stormwind.
break;
case 6:
AuctioneerGUID = 4656; //orc in Orgrimmar
break;
case 7:
AuctioneerGUID = 23442; //goblin in GZ
break;
default:
if (debug_Out) sLog.outError("AHSeller: GetAHID() - Default switch reached");
AuctioneerGUID = 23442; //default to neutral 7
break;
}
*/
QueryResult* result = CharacterDatabase.PQuery("SELECT id FROM auctionhouse WHERE itemowner<>%u AND buyguid<>%u", AHBplayerGUID, AHBplayerGUID);
if (!result)
{
delete result;
return;
}
if (result->GetRowCount() == 0)
{
delete result;
return;
}
// Fetches content of selected AH
AuctionHouseObject* auctionHouse = auctionmgr.GetAuctionsMap(config->GetAHFID());
vector<uint32> possibleBids;
for (AuctionHouseObject::AuctionEntryMap::const_iterator itr = auctionHouse->GetAuctionsBegin();itr != auctionHouse->GetAuctionsEnd();++itr)
do
{
// Check if the auction is ours
// if it is, we skip this iteration.
if (itr->second->owner == AHBplayerGUID)
{
//if (debug_Out) sLog.outString("AHBuyer: I own this item.");
continue;
}
// Check that we haven't bidded in this auction already.
if (itr->second->bidder != AHBplayerGUID)
{
uint32 tmpdata = itr->second->Id;
uint32 tmpdata = result->Fetch()->GetUInt32();
possibleBids.push_back(tmpdata);
//if (debug_Out) sLog.outString("AHBuyer: I have not bid on %u"), itr->second->Id;
}
else
{
//if (debug_Out) sLog.outString("AHBuyer: I have bid on %u"), itr->second->Id;
}
}
}while (result->NextRow());
delete result;
for (uint32 count = 1;count <= config->GetBidsPerInterval();++count)
{
@@ -554,7 +558,6 @@ void AuctionHouseBot::addNewAuctionBuyerBotBid(Player *AHBplayer, AHBConfig *con
if (!auction)
{
if (debug_Out) sLog.outError("AHBuyer: Item doesn't exist, perhaps bought already?");
continue;
}
@@ -698,18 +701,10 @@ void AuctionHouseBot::addNewAuctionBuyerBotBid(Player *AHBplayer, AHBConfig *con
else
{
//buyout
if (AHBplayer->GetGUIDLow() == auction->bidder)
{
//pl->ModifyMoney(-int32(auction->buyout - auction->bid));
}
else
{
//pl->ModifyMoney(-int32(auction->buyout));
if (auction->bidder)
if ((auction->bidder) && (AHBplayer->GetGUIDLow() != auction->bidder))
{
session->SendAuctionOutbiddedMail(auction, auction->buyout);
}
}
auction->bidder = AHBplayer->GetGUIDLow();
auction->bid = auction->buyout;
@@ -717,14 +712,10 @@ void AuctionHouseBot::addNewAuctionBuyerBotBid(Player *AHBplayer, AHBConfig *con
auctionmgr.SendAuctionSalePendingMail(auction);
auctionmgr.SendAuctionSuccessfulMail(auction);
auctionmgr.SendAuctionWonMail(auction);
// Remove item from auctionhouse
auctionmgr.RemoveAItem(auction->item_guidlow);
// Remove auction
auctionHouse->RemoveAuction(auction->Id);
// Remove from database
auction->DeleteFromDB();
delete auction;
uint32 item_template = auction->item_template;
auctionmgr.RemoveAItem(auction->item_guidlow);
auctionHouse->RemoveAuction(auction, item_template);
}
}
}
@@ -740,6 +731,20 @@ void AuctionHouseBot::Update()
_AHBplayer.MinimalLoadFromDB(NULL, AHBplayerGUID);
ObjectAccessor::Instance().AddObject(&_AHBplayer);
// Only for testing, this can likely be removed, once I know it's working as expected.
/*
AuctionHouseObject* auctionHouse1 = auctionmgr.GetAuctionsMap(55);
AuctionHouseObject* auctionHouse2 = auctionmgr.GetAuctionsMap(29);
AuctionHouseObject* auctionHouse3 = auctionmgr.GetAuctionsMap(120);
uint32 totalItemsAH = (auctionHouse1->Getcount() + auctionHouse2->Getcount() + auctionHouse3->Getcount());
uint32 totalItems = (AllianceConfig.TotalItemCounts() + HordeConfig.TotalItemCounts() + NeutralConfig.TotalItemCounts());
if (totalItemsAH != totalItems)
{
sLog.outError("AHBot: The AuctionHouses say there are %u auctions, but, I think there are %u auctions...", totalItemsAH, totalItems);
return;
}
*/
// Add New Bids
if (!sWorld.getConfig(CONFIG_ALLOW_TWO_SIDE_INTERACTION_AUCTION))
{
@@ -805,7 +810,9 @@ void AuctionHouseBot::Initialize()
DisableBeta_PTR_Unused = sConfig.GetBoolDefault("AuctionHouseBot.DisableBeta_PTR_Unused", false);
DisablePermEnchant = sConfig.GetBoolDefault("AuctionHouseBot.DisablePermEnchant", false);
#if CLIENT_VER > 300
DisableConjured = sConfig.GetBoolDefault("AuctionHouseBot.DisableConjured", false);
#endif
DisableGems = sConfig.GetBoolDefault("AuctionHouseBot.DisableGems", false);
DisableMoney = sConfig.GetBoolDefault("AuctionHouseBot.DisableMoney", false);
DisableMoneyLoot = sConfig.GetBoolDefault("AuctionHouseBot.DisableMoneyLoot", false);
@@ -844,7 +851,6 @@ void AuctionHouseBot::Initialize()
DisableTGsAboveReqSkillRank = sConfig.GetIntDefault("AuctionHouseBot.DisableTGsAboveReqSkillRank", 0);
//End Filters
if (!sWorld.getConfig(CONFIG_ALLOW_TWO_SIDE_INTERACTION_AUCTION))
{
LoadValues(&AllianceConfig);
@@ -878,7 +884,9 @@ void AuctionHouseBot::Initialize()
"SELECT item FROM fishing_loot_template UNION "
"SELECT item FROM gameobject_loot_template UNION "
"SELECT item FROM item_loot_template UNION "
#if CLIENT_VER > 300
"SELECT item FROM milling_loot_template UNION "
#endif
"SELECT item FROM pickpocketing_loot_template UNION "
"SELECT item FROM prospecting_loot_template UNION "
"SELECT item FROM skinning_loot_template";
@@ -909,23 +917,23 @@ void AuctionHouseBot::Initialize()
switch (prototype->Bonding)
{
case 0:
case NO_BIND:
if (!No_Bind)
continue;
break;
case 1:
case BIND_WHEN_PICKED_UP:
if (!Bind_When_Picked_Up)
continue;
break;
case 2:
case BIND_WHEN_EQUIPED:
if (!Bind_When_Equipped)
continue;
break;
case 3:
case BIND_WHEN_USE:
if (!Bind_When_Use)
continue;
break;
case 4:
case BIND_QUEST_ITEM:
if (!Bind_Quest_Item)
continue;
break;
@@ -1058,12 +1066,14 @@ void AuctionHouseBot::Initialize()
continue;
}
#if CLIENT_VER > 300
// Disable conjured items
if ((DisableConjured) && (prototype->IsConjuredConsumable()))
{
if (debug_Out_Filters) sLog.outString("AuctionHouseBot: Item %u disabled (Conjured Consumable)", prototype->ItemId);
continue;
}
#endif
// Disable gems
if ((DisableGems) && (prototype->Class == ITEM_CLASS_GEM))
@@ -1305,49 +1315,49 @@ void AuctionHouseBot::Initialize()
switch (prototype->Quality)
{
case 0:
case AHB_GREY:
if (prototype->Class == ITEM_CLASS_TRADE_GOODS)
greyTradeGoodsBin.push_back(itemID);
else
greyItemsBin.push_back(itemID);
break;
case 1:
case AHB_WHITE:
if (prototype->Class == ITEM_CLASS_TRADE_GOODS)
whiteTradeGoodsBin.push_back(itemID);
else
whiteItemsBin.push_back(itemID);
break;
case 2:
case AHB_GREEN:
if (prototype->Class == ITEM_CLASS_TRADE_GOODS)
greenTradeGoodsBin.push_back(itemID);
else
greenItemsBin.push_back(itemID);
break;
case 3:
case AHB_BLUE:
if (prototype->Class == ITEM_CLASS_TRADE_GOODS)
blueTradeGoodsBin.push_back(itemID);
else
blueItemsBin.push_back(itemID);
break;
case 4:
case AHB_PURPLE:
if (prototype->Class == ITEM_CLASS_TRADE_GOODS)
purpleTradeGoodsBin.push_back(itemID);
else
purpleItemsBin.push_back(itemID);
break;
case 5:
case AHB_ORANGE:
if (prototype->Class == ITEM_CLASS_TRADE_GOODS)
orangeTradeGoodsBin.push_back(itemID);
else
orangeItemsBin.push_back(itemID);
break;
case 6:
case AHB_YELLOW:
if (prototype->Class == ITEM_CLASS_TRADE_GOODS)
yellowTradeGoodsBin.push_back(itemID);
else
@@ -1374,6 +1384,7 @@ void AuctionHouseBot::Initialize()
sLog.outError("AuctionHouseBot: No items");
AHBSeller = 0;
}
sLog.outString("AuctionHouseBot:");
sLog.outString("loaded %u grey trade goods", greyTradeGoodsBin.size());
sLog.outString("loaded %u white trade goods", whiteTradeGoodsBin.size());
@@ -1394,6 +1405,80 @@ void AuctionHouseBot::Initialize()
sLog.outString("AuctionHouseBot now includes AHBuyer by Kerbe and Paradox");
}
void AuctionHouseBot::IncrementItemCounts(AuctionEntry* ah)
{
// from auctionhousehandler.cpp, creates auction pointer & player pointer
// get exact item information
Item *pItem = auctionmgr.GetAItem(ah->item_guidlow);
if (!pItem)
{
if (debug_Out) sLog.outError("AHBot: Item %u doesn't exist, perhaps bought already?", ah->item_guidlow);
return;
}
// get item prototype
ItemPrototype const* prototype = objmgr.GetItemPrototype(ah->item_template);
AHBConfig *config;
FactionTemplateEntry const* u_entry = sFactionTemplateStore.LookupEntry(ah->GetHouseId());
if (!u_entry)
{
if (debug_Out) sLog.outError("AHBot: %u returned as House ID. No Entry", ah->GetHouseId());
config = &NeutralConfig;
}
else if (u_entry->ourMask & FACTION_MASK_ALLIANCE)
{
if (debug_Out) sLog.outError("AHBot: %u returned as House ID. Alliance", ah->GetHouseId());
config = &AllianceConfig;
}
else if (u_entry->ourMask & FACTION_MASK_HORDE)
{
if (debug_Out) sLog.outError("AHBot: %u returned as House ID. Horde", ah->GetHouseId());
config = &HordeConfig;
}
else
{
if (debug_Out) sLog.outError("AHBot: %u returned as House ID. Neutral", ah->GetHouseId());
config = &NeutralConfig;
}
config->IncItemCounts(prototype->Class, prototype->Quality);
}
void AuctionHouseBot::DecrementItemCounts(AuctionEntry* ah, uint32 item_template)
{
// get item prototype
ItemPrototype const* prototype = objmgr.GetItemPrototype(item_template);
AHBConfig *config;
FactionTemplateEntry const* u_entry = sFactionTemplateStore.LookupEntry(ah->GetHouseId());
if (!u_entry)
{
if (debug_Out) sLog.outError("AHBot: %u returned as House ID. No Entry", ah->GetHouseId());
config = &NeutralConfig;
}
else if (u_entry->ourMask & FACTION_MASK_ALLIANCE)
{
if (debug_Out) sLog.outError("AHBot: %u returned as House ID. Alliance", ah->GetHouseId());
config = &AllianceConfig;
}
else if (u_entry->ourMask & FACTION_MASK_HORDE)
{
if (debug_Out) sLog.outError("AHBot: %u returned as House ID. Horde", ah->GetHouseId());
config = &HordeConfig;
}
else
{
if (debug_Out) sLog.outError("AHBot: %u returned as House ID. Neutral", ah->GetHouseId());
config = &NeutralConfig;
}
config->DecItemCounts(prototype->Class, prototype->Quality);
}
void AuctionHouseBot::Commands(uint32 command, uint32 ahMapID, uint32 col, char* args)
{
AHBConfig *config;
@@ -1709,6 +1794,83 @@ void AuctionHouseBot::LoadValues(AHBConfig *config)
sLog.outString("maxStackOrange = %u", config->GetMaxStack(AHB_ORANGE));
sLog.outString("maxStackYellow = %u", config->GetMaxStack(AHB_YELLOW));
}
AuctionHouseEntry const* ahEntry = auctionmgr.GetAuctionHouseEntry(config->GetAHFID());
AuctionHouseObject* auctionHouse = auctionmgr.GetAuctionsMap(config->GetAHFID());
config->ResetItemCounts();
uint32 auctions = auctionHouse->Getcount();
if (auctions)
{
for (AuctionHouseObject::AuctionEntryMap::const_iterator itr = auctionHouse->GetAuctionsBegin();itr != auctionHouse->GetAuctionsEnd();++itr)
{
AuctionEntry *Aentry = itr->second;
Item *item = auctionmgr.GetAItem(Aentry->item_guidlow);
if (item)
{
ItemPrototype const *prototype = item->GetProto();
if (prototype)
{
switch (prototype->Quality)
{
case 0:
if (prototype->Class == ITEM_CLASS_TRADE_GOODS)
config->IncItemCounts(AHB_GREY_TG);
else
config->IncItemCounts(AHB_GREY_I);
break;
case 1:
if (prototype->Class == ITEM_CLASS_TRADE_GOODS)
config->IncItemCounts(AHB_WHITE_TG);
else
config->IncItemCounts(AHB_WHITE_I);
break;
case 2:
if (prototype->Class == ITEM_CLASS_TRADE_GOODS)
config->IncItemCounts(AHB_GREEN_TG);
else
config->IncItemCounts(AHB_GREEN_I);
break;
case 3:
if (prototype->Class == ITEM_CLASS_TRADE_GOODS)
config->IncItemCounts(AHB_BLUE_TG);
else
config->IncItemCounts(AHB_BLUE_I);
break;
case 4:
if (prototype->Class == ITEM_CLASS_TRADE_GOODS)
config->IncItemCounts(AHB_PURPLE_TG);
else
config->IncItemCounts(AHB_PURPLE_I);
break;
case 5:
if (prototype->Class == ITEM_CLASS_TRADE_GOODS)
config->IncItemCounts(AHB_ORANGE_TG);
else
config->IncItemCounts(AHB_ORANGE_I);
break;
case 6:
if (prototype->Class == ITEM_CLASS_TRADE_GOODS)
config->IncItemCounts(AHB_YELLOW_TG);
else
config->IncItemCounts(AHB_YELLOW_I);
break;
}
}
}
}
}
if (debug_Out)
{
sLog.outString("Current Items in %s Auctionhouses:", CharacterDatabase.PQuery("SELECT name FROM auctionhousebot WHERE auctionhouse = %u",config->GetAHID())->Fetch()->GetString());
sLog.outString("Grey Trade Goods\t%u\tGrey Items\t%u", config->GetItemCounts(AHB_GREY_TG), config->GetItemCounts(AHB_GREY_I));
sLog.outString("White Trade Goods\t%u\tWhite Items\t%u", config->GetItemCounts(AHB_WHITE_TG), config->GetItemCounts(AHB_WHITE_I));
sLog.outString("Green Trade Goods\t%u\tGreen Items\t%u", config->GetItemCounts(AHB_GREEN_TG), config->GetItemCounts(AHB_GREEN_I));
sLog.outString("Blue Trade Goods\t%u\tBlue Items\t%u", config->GetItemCounts(AHB_BLUE_TG), config->GetItemCounts(AHB_BLUE_I));
sLog.outString("Purple Trade Goods\t%u\tPurple Items\t%u", config->GetItemCounts(AHB_PURPLE_TG), config->GetItemCounts(AHB_PURPLE_I));
sLog.outString("Orange Trade Goods\t%u\tOrange Items\t%u", config->GetItemCounts(AHB_ORANGE_TG), config->GetItemCounts(AHB_ORANGE_I));
sLog.outString("Yellow Trade Goods\t%u\tYellow Items\t%u", config->GetItemCounts(AHB_YELLOW_TG), config->GetItemCounts(AHB_YELLOW_I));
}
}
if (AHBBuyer)
{
+245
View File
@@ -3,7 +3,11 @@
#include "World.h"
#include "Config/ConfigEnv.h"
#if CLIENT_VER > 300
#include "ace/Vector_T.h"
#else if CLIENT_VER > 100
#include <vector>
#endif
#define AHB_GREY 0
#define AHB_WHITE 1
@@ -110,6 +114,22 @@ private:
uint32 orangeip;
uint32 yellowip;
uint32 greyTGoods;
uint32 whiteTGoods;
uint32 greenTGoods;
uint32 blueTGoods;
uint32 purpleTGoods;
uint32 orangeTGoods;
uint32 yellowTGoods;
uint32 greyItems;
uint32 whiteItems;
uint32 greenItems;
uint32 blueItems;
uint32 purpleItems;
uint32 orangeItems;
uint32 yellowItems;
public:
AHBConfig(uint32 ahid)
{
@@ -876,6 +896,225 @@ public:
break;
}
}
void DecItemCounts(uint32 Class, uint32 Quality)
{
switch(Class)
{
case ITEM_CLASS_TRADE_GOODS:
DecItemCounts(Quality);
break;
default:
DecItemCounts(Quality + 7);
break;
}
}
void DecItemCounts(uint32 color)
{
switch(color)
{
case AHB_GREY_TG:
--greyTGoods;
break;
case AHB_WHITE_TG:
--whiteTGoods;
break;
case AHB_GREEN_TG:
--greenTGoods;
break;
case AHB_BLUE_TG:
--blueTGoods;
break;
case AHB_PURPLE_TG:
--purpleTGoods;
break;
case AHB_ORANGE_TG:
--orangeTGoods;
break;
case AHB_YELLOW_TG:
--yellowTGoods;
break;
case AHB_GREY_I:
--greyItems;
break;
case AHB_WHITE_I:
--whiteItems;
break;
case AHB_GREEN_I:
--greenItems;
break;
case AHB_BLUE_I:
--blueItems;
break;
case AHB_PURPLE_I:
--purpleItems;
break;
case AHB_ORANGE_I:
--orangeItems;
break;
case AHB_YELLOW_I:
--yellowItems;
break;
default:
break;
}
}
void IncItemCounts(uint32 Class, uint32 Quality)
{
switch(Class)
{
case ITEM_CLASS_TRADE_GOODS:
IncItemCounts(Quality);
break;
default:
IncItemCounts(Quality + 7);
break;
}
}
void IncItemCounts(uint32 color)
{
switch(color)
{
case AHB_GREY_TG:
++greyTGoods;
break;
case AHB_WHITE_TG:
++whiteTGoods;
break;
case AHB_GREEN_TG:
++greenTGoods;
break;
case AHB_BLUE_TG:
++blueTGoods;
break;
case AHB_PURPLE_TG:
++purpleTGoods;
break;
case AHB_ORANGE_TG:
++orangeTGoods;
break;
case AHB_YELLOW_TG:
++yellowTGoods;
break;
case AHB_GREY_I:
++greyItems;
break;
case AHB_WHITE_I:
++whiteItems;
break;
case AHB_GREEN_I:
++greenItems;
break;
case AHB_BLUE_I:
++blueItems;
break;
case AHB_PURPLE_I:
++purpleItems;
break;
case AHB_ORANGE_I:
++orangeItems;
break;
case AHB_YELLOW_I:
++yellowItems;
break;
default:
break;
}
}
void ResetItemCounts()
{
greyTGoods = 0;
whiteTGoods = 0;
greenTGoods = 0;
blueTGoods = 0;
purpleTGoods = 0;
orangeTGoods = 0;
yellowTGoods = 0;
greyItems = 0;
whiteItems = 0;
greenItems = 0;
blueItems = 0;
purpleItems = 0;
orangeItems = 0;
yellowItems = 0;
}
uint32 TotalItemCounts()
{
return(
greyTGoods +
whiteTGoods +
greenTGoods +
blueTGoods +
purpleTGoods +
orangeTGoods +
yellowTGoods +
greyItems +
whiteItems +
greenItems +
blueItems +
purpleItems +
orangeItems +
yellowItems);
}
uint32 GetItemCounts(uint32 color)
{
switch(color)
{
case AHB_GREY_TG:
return greyTGoods;
break;
case AHB_WHITE_TG:
return whiteTGoods;
break;
case AHB_GREEN_TG:
return greenTGoods;
break;
case AHB_BLUE_TG:
return blueTGoods;
break;
case AHB_PURPLE_TG:
return purpleTGoods;
break;
case AHB_ORANGE_TG:
return orangeTGoods;
break;
case AHB_YELLOW_TG:
return yellowTGoods;
break;
case AHB_GREY_I:
return greyItems;
break;
case AHB_WHITE_I:
return whiteItems;
break;
case AHB_GREEN_I:
return greenItems;
break;
case AHB_BLUE_I:
return blueItems;
break;
case AHB_PURPLE_I:
return purpleItems;
break;
case AHB_ORANGE_I:
return orangeItems;
break;
case AHB_YELLOW_I:
return yellowItems;
break;
default:
return 0;
break;
}
}
void SetBidsPerInterval(uint32 value)
{
buyerBidsPerInterval = value;
@@ -891,6 +1130,7 @@ public:
class AuctionHouseBot
{
private:
#if CLIENT_VER > 300
ACE_Vector<uint32> npcItems;
ACE_Vector<uint32> lootItems;
ACE_Vector<uint32> greyTradeGoodsBin;
@@ -907,6 +1147,7 @@ private:
ACE_Vector<uint32> purpleItemsBin;
ACE_Vector<uint32> orangeItemsBin;
ACE_Vector<uint32> yellowItemsBin;
#endif
bool debug_Out;
bool debug_Out_Filters;
@@ -937,7 +1178,9 @@ private:
bool DisableBeta_PTR_Unused;
bool DisablePermEnchant;
#if CLIENT_VER > 300
bool DisableConjured;
#endif
bool DisableGems;
bool DisableMoney;
bool DisableMoneyLoot;
@@ -995,6 +1238,8 @@ public:
void Update();
void Initialize();
void LoadValues(AHBConfig*);
void DecrementItemCounts(AuctionEntry* ah, uint32 item_template);
void IncrementItemCounts(AuctionEntry* ah);
void Commands(uint32, uint32, uint32, char*);
uint32 GetAHBplayerGUID() { return AHBplayerGUID; };
};
+10 -9
View File
@@ -180,10 +180,13 @@ void WorldSession::HandleAuctionSellItem( WorldPacket & recv_data )
return;
}
sLog.outDebug("WORLD: HandleAuctionSellItem - ETIME: %u", etime);
// client send time in minutes, convert to common used sec time
etime *= MINUTE;
sLog.outDebug("WORLD: HandleAuctionSellItem - ETIME: %u", etime);
// client understand only 3 auction time
switch(etime)
{
@@ -264,9 +267,9 @@ void WorldSession::HandleAuctionSellItem( WorldPacket & recv_data )
AH->auctionHouseEntry = auctionHouseEntry;
sLog.outDetail("selling item %u to auctioneer %u with initial bid %u with buyout %u and with time %u (in sec) in auctionhouse %u", GUID_LOPART(item), AH->auctioneer, bid, buyout, auction_time, AH->GetHouseId());
auctionmgr.AddAItem(it);
auctionHouse->AddAuction(AH);
auctionmgr.AddAItem(it);
pl->MoveItemFromInventory(it->GetBagSlot(), it->GetSlot(), true);
CharacterDatabase.BeginTransaction();
@@ -394,12 +397,10 @@ void WorldSession::HandleAuctionPlaceBid( WorldPacket & recv_data )
auctionmgr.SendAuctionWonMail(auction);
SendAuctionCommandResult(auction->Id, AUCTION_PLACE_BID, AUCTION_OK);
auctionmgr.RemoveAItem(auction->item_guidlow);
auctionHouse->RemoveAuction(auction->Id);
auction->DeleteFromDB();
delete auction;
uint32 item_template = auction->item_template;
auctionmgr.RemoveAItem(auction->item_guidlow);
auctionHouse->RemoveAuction(auction, item_template);
}
CharacterDatabase.BeginTransaction();
pl->SaveInventoryAndGoldToDB();
@@ -474,12 +475,12 @@ void WorldSession::HandleAuctionRemoveItem( WorldPacket & recv_data )
SendAuctionCommandResult(auction->Id, AUCTION_CANCEL, AUCTION_OK);
// Now remove the auction
CharacterDatabase.BeginTransaction();
auction->DeleteFromDB();
pl->SaveInventoryAndGoldToDB();
CharacterDatabase.CommitTransaction();
auction->DeleteFromDB();
uint32 item_template = auction->item_template;
auctionmgr.RemoveAItem(auction->item_guidlow);
auctionHouse->RemoveAuction( auction->Id );
delete auction;
auctionHouse->RemoveAuction(auction, item_template);
}
//called when player lists his bids
+31 -73
View File
@@ -67,43 +67,34 @@ AuctionHouseObject * AuctionHouseMgr::GetAuctionsMap( uint32 factionTemplateId )
uint32 AuctionHouseMgr::GetAuctionDeposit(AuctionHouseEntry const* entry, uint32 time, Item *pItem)
{
uint32 MSV = pItem->GetProto()->SellPrice;
double deposit;
double faction_pct;
int32 deposit;
uint32 timeHr = (((time / 60) / 60) / 12);
if (MSV > 0)
{
if(sWorld.getConfig(CONFIG_ALLOW_TWO_SIDE_INTERACTION_AUCTION))
faction_pct = (0.75 * (double)sWorld.getRate(RATE_AUCTION_DEPOSIT));
else
{
FactionTemplateEntry const* u_entry = sFactionTemplateStore.LookupEntry(entry->houseId);
if(!u_entry)
faction_pct = (0.75 * (double)sWorld.getRate(RATE_AUCTION_DEPOSIT));
else if(u_entry->ourMask & FACTION_MASK_ALLIANCE)
faction_pct = (0.15 * (double)sWorld.getRate(RATE_AUCTION_DEPOSIT));
else if(u_entry->ourMask & FACTION_MASK_HORDE)
faction_pct = (0.15 * (double)sWorld.getRate(RATE_AUCTION_DEPOSIT));
else
faction_pct = (0.75 * (double)sWorld.getRate(RATE_AUCTION_DEPOSIT));
}
deposit = ((double)MSV * faction_pct * (double)pItem->GetCount()) * (double)(time / MIN_AUCTION_TIME );
deposit = (int32)floor((double)MSV * (((double)(entry->depositPercent * 3) / 100.0f * (double)sWorld.getRate(RATE_AUCTION_DEPOSIT) * (double)pItem->GetCount()))) * timeHr;
}
else
{
faction_pct = 0.0f;
deposit = 0.0f;
deposit = 0;
}
sLog.outDebug("SellPrice:\t\t%u", MSV);
sLog.outDebug("Deposit Percent:\t%f", faction_pct);
sLog.outDebug("Deposit Percent:\t%f", ((double)entry->depositPercent / 100.0f));
sLog.outDebug("Auction Time1:\t\t%u", time);
sLog.outDebug("Auction Time2:\t\t%u", MIN_AUCTION_TIME);
sLog.outDebug("Auction Time3:\t\t%u", (time / MIN_AUCTION_TIME ));
sLog.outDebug("Auction Time3:\t\t%u", timeHr);
sLog.outDebug("Count:\t\t\t%u", pItem->GetCount());
sLog.outDebug("Deposit:\t\t%f", deposit);
if (deposit > 0)
return (uint32)deposit;
{
sLog.outDebug("Deposit:\t\t%u", deposit);
return deposit;
}
else
{
sLog.outDebug("Deposit:\t\t0");
return 0;
}
}
//does not clear ram
void AuctionHouseMgr::SendAuctionWonMail(AuctionEntry *auction)
@@ -112,15 +103,13 @@ void AuctionHouseMgr::SendAuctionWonMail( AuctionEntry *auction )
if (!pItem)
return;
uint32 bidder_accId = 0;
uint32 bidder_security = 0;
uint64 bidder_guid = MAKE_NEW_GUID(auction->bidder, 0, HIGHGUID_PLAYER);
Player *bidder = objmgr.GetPlayer(bidder_guid);
uint32 bidder_accId = 0;
// data for gm.log
if (sWorld.getConfig(CONFIG_GM_LOG_TRADE))
{
uint32 bidder_security = 0;
std::string bidder_name;
if (bidder)
{
@@ -139,7 +128,6 @@ void AuctionHouseMgr::SendAuctionWonMail( AuctionEntry *auction )
bidder_name = objmgr.GetTrinityStringForDBCLocale(LANG_UNKNOWN);
}
}
if (bidder_security > SEC_PLAYER)
{
std::string owner_name;
@@ -152,8 +140,6 @@ void AuctionHouseMgr::SendAuctionWonMail( AuctionEntry *auction )
bidder_name.c_str(),bidder_accId,pItem->GetProto()->Name1,pItem->GetEntry(),pItem->GetCount(),auction->bid,owner_name.c_str(),owner_accid);
}
}
else if(!bidder)
bidder_accId = objmgr.GetPlayerAccountIdByGUID(bidder_guid);
// receiver exist
if (bidder || bidder_accId)
@@ -180,28 +166,18 @@ void AuctionHouseMgr::SendAuctionWonMail( AuctionEntry *auction )
if (bidder)
bidder->GetSession()->SendAuctionBidderNotification(auction->GetHouseId(), auction->Id, bidder_guid, 0, 0, auction->item_template);
else
RemoveAItem(pItem->GetGUIDLow()); // we have to remove the item, before we delete it !!
// will delete item or place to receiver mail list
WorldSession::SendMailTo(bidder, MAIL_AUCTION, MAIL_STATIONERY_AUCTION, auction->GetHouseId(), auction->bidder, msgAuctionWonSubject.str(), itemTextId, &mi, 0, 0, MAIL_CHECK_MASK_AUCTION);
}
// receiver not exist
else
{
CharacterDatabase.PExecute("DELETE FROM item_instance WHERE guid='%u'", pItem->GetGUIDLow());
RemoveAItem(pItem->GetGUIDLow()); // we have to remove the item, before we delete it !!
delete pItem;
}
}
void AuctionHouseMgr::SendAuctionSalePendingMail(AuctionEntry * auction)
{
uint64 owner_guid = MAKE_NEW_GUID(auction->owner, 0, HIGHGUID_PLAYER);
Player *owner = objmgr.GetPlayer(owner_guid);
uint32 owner_accId = objmgr.GetPlayerAccountIdByGUID(owner_guid);
// owner exist (online or offline)
if(owner || objmgr.GetPlayerAccountIdByGUID(owner_guid))
if (owner || owner_accId)
{
std::ostringstream msgAuctionSalePendingSubject;
msgAuctionSalePendingSubject << auction->item_template << ":0:" << AUCTION_SALE_PENDING;
@@ -230,11 +206,7 @@ void AuctionHouseMgr::SendAuctionSuccessfulMail( AuctionEntry * auction )
{
uint64 owner_guid = MAKE_NEW_GUID(auction->owner, 0, HIGHGUID_PLAYER);
Player *owner = objmgr.GetPlayer(owner_guid);
uint32 owner_accId = 0;
if(!owner)
owner_accId = objmgr.GetPlayerAccountIdByGUID(owner_guid);
uint32 owner_accId = objmgr.GetPlayerAccountIdByGUID(owner_guid);
// owner exist
if (owner || owner_accId)
{
@@ -255,14 +227,13 @@ void AuctionHouseMgr::SendAuctionSuccessfulMail( AuctionEntry * auction )
uint32 profit = auction->bid + auction->deposit - auctionCut;
if (owner)
{
//FIXME: what do if owner offline
if (owner && owner->GetGUIDLow() != auctionbot.GetAHBplayerGUID())
{
owner->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_HIGHEST_AUCTION_SOLD, auction->bid);
//send auction owner notification, bidder must be current!
owner->GetSession()->SendAuctionOwnerNotification(auction);
}
WorldSession::SendMailTo(owner, MAIL_AUCTION, MAIL_STATIONERY_AUCTION, auction->GetHouseId(), auction->owner, msgAuctionSuccessfulSubject.str(), itemTextId, NULL, profit, 0, MAIL_CHECK_MASK_AUCTION, sWorld.getConfig(CONFIG_MAIL_DELIVERY_DELAY));
}
}
@@ -272,42 +243,25 @@ void AuctionHouseMgr::SendAuctionExpiredMail( AuctionEntry * auction )
{ //return an item in auction to its owner by mail
Item *pItem = GetAItem(auction->item_guidlow);
if (!pItem)
{
sLog.outError("Auction item (GUID: %u) not found, and lost.",auction->item_guidlow);
return;
}
uint64 owner_guid = MAKE_NEW_GUID(auction->owner, 0, HIGHGUID_PLAYER);
Player *owner = objmgr.GetPlayer(owner_guid);
uint32 owner_accId = 0;
if(!owner)
owner_accId = objmgr.GetPlayerAccountIdByGUID(owner_guid);
uint32 owner_accId = objmgr.GetPlayerAccountIdByGUID(owner_guid);
// owner exist
if (owner || owner_accId)
{
std::ostringstream subject;
subject << auction->item_template << ":0:" << AUCTION_EXPIRED;
if ( owner )
if (owner && owner->GetGUIDLow() != auctionbot.GetAHBplayerGUID())
owner->GetSession()->SendAuctionOwnerNotification(auction);
else
RemoveAItem(pItem->GetGUIDLow()); // we have to remove the item, before we delete it !!
MailItemsInfo mi;
mi.AddItem(auction->item_guidlow, auction->item_template, pItem);
// will delete item or place to receiver mail list
WorldSession::SendMailTo(owner, MAIL_AUCTION, MAIL_STATIONERY_AUCTION, auction->GetHouseId(), GUID_LOPART(owner_guid), subject.str(), 0, &mi, 0, 0, MAIL_CHECK_MASK_NONE);
}
// owner not found
else
{
CharacterDatabase.PExecute("DELETE FROM item_instance WHERE guid='%u'",pItem->GetGUIDLow());
RemoveAItem(pItem->GetGUIDLow()); // we have to remove the item, before we delete it !!
delete pItem;
}
}
void AuctionHouseMgr::LoadAuctionItems()
@@ -569,9 +523,9 @@ void AuctionHouseObject::Update()
///- In any case clear the auction
itr->second->DeleteFromDB();
uint32 item_template = itr->second->item_template;
auctionmgr.RemoveAItem(itr->second->item_guidlow);
delete itr->second;
RemoveAuction(itr->first);
RemoveAuction(itr->second, item_template);
}
// only check 50 items per update to not peg the CPU
@@ -708,13 +662,17 @@ bool AuctionEntry::BuildAuctionInfo(WorldPacket & data) const
uint32 AuctionEntry::GetAuctionCut() const
{
return uint32(auctionHouseEntry->cutPercent * bid * sWorld.getRate(RATE_AUCTION_CUT) / 100.0f);
int32 cut = int32(((double)auctionHouseEntry->cutPercent / 100.0f) * (double)sWorld.getRate(RATE_AUCTION_CUT)) * bid;
if (cut > 0)
return cut;
else
return 0;
}
/// the sum of outbid is (1% from current bid)*5, if bid is very small, it is 1c
uint32 AuctionEntry::GetAuctionOutBid() const
{
uint32 outbid = (bid / 100) * 5;
uint32 outbid = (uint32)((double)bid / 100.0f) * 5;
if (!outbid)
outbid = 1;
return outbid;
+7 -2
View File
@@ -25,6 +25,8 @@
#include "SharedDefines.h"
#include "AuctionHouseBot.h"
class Item;
class Player;
class WorldPacket;
@@ -95,6 +97,7 @@ class AuctionHouseObject
{
ASSERT(ah);
AuctionsMap[ah->Id] = ah;
auctionbot.IncrementItemCounts(ah);
}
AuctionEntry* GetAuction(uint32 id) const
@@ -103,9 +106,10 @@ class AuctionHouseObject
return itr != AuctionsMap.end() ? itr->second : NULL;
}
bool RemoveAuction(uint32 id)
bool RemoveAuction(AuctionEntry *auction, uint32 item_template)
{
return AuctionsMap.erase(id) ? true : false;
auctionbot.DecrementItemCounts(auction, item_template);
return AuctionsMap.erase(auction->Id) ? true : false;
}
void Update();
@@ -133,6 +137,7 @@ class AuctionHouseMgr
typedef UNORDERED_MAP<uint32, Item*> ItemMap;
AuctionHouseObject* GetAuctionsMap(uint32 factionTemplateId);
AuctionHouseObject* GetBidsMap(uint32 factionTemplateId);
Item* GetAItem(uint32 id)
{