* 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; typedef uint64 OBJECT_HANDLE;
//#define MULTI_THREAD_MAP #define MULTI_THREAD_MAP
#ifdef MULTI_THREAD_MAP #ifdef MULTI_THREAD_MAP
#define MAP_BASED_RAND_GEN #define MAP_BASED_RAND_GEN
#endif #endif
@@ -156,6 +156,10 @@ typedef uint64 OBJECT_HANDLE;
# endif # endif
#endif #endif
#ifndef CLIENT_VER
#define CLIENT_VER 313
#endif
#endif //TRINITY_DEFINE_H #endif //TRINITY_DEFINE_H
+291 -129
View File
@@ -1,12 +1,34 @@
#include "AuctionHouseBot.h" #include "AuctionHouseBot.h"
#include "ObjectMgr.h" #include "ObjectMgr.h"
#include "AuctionHouseMgr.h" #include "AuctionHouseMgr.h"
#if CLIENT_VER > 300
#else if CLIENT_VER > 100
#include <vector>
#endif
#include "Policies/SingletonImp.h" #include "Policies/SingletonImp.h"
INSTANTIATE_SINGLETON_1(AuctionHouseBot); INSTANTIATE_SINGLETON_1(AuctionHouseBot);
using namespace std; 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() AuctionHouseBot::AuctionHouseBot()
{ {
debug_Out = false; debug_Out = false;
@@ -31,7 +53,9 @@ AuctionHouseBot::AuctionHouseBot()
DisableBeta_PTR_Unused = false; DisableBeta_PTR_Unused = false;
DisablePermEnchant = false; DisablePermEnchant = false;
#if CLIENT_VER > 300
DisableConjured = false; DisableConjured = false;
#endif
DisableGems = false; DisableGems = false;
DisableMoney = false; DisableMoney = false;
DisableMoneyLoot = false; DisableMoneyLoot = false;
@@ -92,10 +116,26 @@ void AuctionHouseBot::addNewAuctions(Player *AHBplayer, AHBConfig *config)
return; return;
} }
AuctionHouseEntry const* ahEntry = auctionmgr.GetAuctionHouseEntry(config->GetAHFID());
AuctionHouseObject* auctionHouse = auctionmgr.GetAuctionsMap(config->GetAHFID());
uint32 minItems = config->GetMinItems(); uint32 minItems = config->GetMinItems();
uint32 maxItems = config->GetMaxItems(); 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(); uint32 auctions = auctionHouse->Getcount();
if (auctions >= minItems) if (auctions >= minItems)
@@ -111,7 +151,7 @@ void AuctionHouseBot::addNewAuctions(Player *AHBplayer, AHBConfig *config)
} }
uint32 items = 0; uint32 items = 0;
if ((maxItems - auctions) > ItemsPerCycle) if ((maxItems - auctions) >= ItemsPerCycle)
items = ItemsPerCycle; items = ItemsPerCycle;
else else
items = (maxItems - auctions); items = (maxItems - auctions);
@@ -158,87 +198,30 @@ void AuctionHouseBot::addNewAuctions(Player *AHBplayer, AHBConfig *config)
+ whiteIcount + greenIcount + blueIcount + purpleIcount + whiteIcount + greenIcount + blueIcount + purpleIcount
+ orangeIcount + yellowIcount; + orangeIcount + yellowIcount;
uint32 greyTGoods = 0; uint32 greyTGoods = config->GetItemCounts(AHB_GREY_TG);
uint32 whiteTGoods = 0; uint32 whiteTGoods = config->GetItemCounts(AHB_WHITE_TG);
uint32 greenTGoods = 0; uint32 greenTGoods = config->GetItemCounts(AHB_GREEN_TG);
uint32 blueTGoods = 0; uint32 blueTGoods = config->GetItemCounts(AHB_BLUE_TG);
uint32 purpleTGoods = 0; uint32 purpleTGoods = config->GetItemCounts(AHB_PURPLE_TG);
uint32 orangeTGoods = 0; uint32 orangeTGoods = config->GetItemCounts(AHB_ORANGE_TG);
uint32 yellowTGoods = 0; uint32 yellowTGoods = config->GetItemCounts(AHB_YELLOW_TG);
uint32 greyItems = 0; uint32 greyItems = config->GetItemCounts(AHB_GREY_I);
uint32 whiteItems = 0; uint32 whiteItems = config->GetItemCounts(AHB_WHITE_I);
uint32 greenItems = 0; uint32 greenItems = config->GetItemCounts(AHB_GREEN_I);
uint32 blueItems = 0; uint32 blueItems = config->GetItemCounts(AHB_BLUE_I);
uint32 purpleItems = 0; uint32 purpleItems = config->GetItemCounts(AHB_PURPLE_I);
uint32 orangeItems = 0; uint32 orangeItems = config->GetItemCounts(AHB_ORANGE_I);
uint32 yellowItems = 0; uint32 yellowItems = config->GetItemCounts(AHB_YELLOW_I);
if (debug_Out) sLog.outString("AHSeller: %u items", items);
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;
}
}
}
}
// only insert a few at a time, so as not to peg the processor // only insert a few at a time, so as not to peg the processor
for (uint32 cnt = 1;cnt <= items;cnt++) for (uint32 cnt = 1;cnt <= items;cnt++)
{ {
if (debug_Out) sLog.outString("AHSeller: %u count", cnt);
uint32 itemID = 0; uint32 itemID = 0;
uint32 loopBreaker = 0;
uint32 itemColor = 99; uint32 itemColor = 99;
while (itemID == 0 && loopBreaker < 50) while (itemID == 0)
{ {
uint32 choice = urand(0, 13); uint32 choice = urand(0, 13);
itemColor = choice; itemColor = choice;
@@ -347,8 +330,8 @@ void AuctionHouseBot::addNewAuctions(Player *AHBplayer, AHBConfig *config)
if (debug_Out) sLog.outError("AHSeller: itemID Switch - Default Reached"); if (debug_Out) sLog.outError("AHSeller: itemID Switch - Default Reached");
break; break;
} }
++loopBreaker;
} }
if (itemID == 0) if (itemID == 0)
{ {
if (debug_Out) sLog.outError("AHSeller: Item::CreateItem() - ItemID is 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* item = Item::CreateItem(itemID, 1, AHBplayer);
item->AddToUpdateQueueOf(AHBplayer);
if (item == NULL) if (item == NULL)
{ {
if (debug_Out) sLog.outError("AHSeller: Item::CreateItem() returned NULL"); if (debug_Out) sLog.outError("AHSeller: Item::CreateItem() returned NULL");
break; break;
} }
item->AddToUpdateQueueOf(AHBplayer);
uint32 randomPropertyId = Item::GenerateItemRandomPropertyId(itemID); uint32 randomPropertyId = Item::GenerateItemRandomPropertyId(itemID);
if (randomPropertyId != 0) 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 // 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); if (debug_Out) sLog.outError("AHBuyer: Quality %u not Supported", prototype->Quality);
item->RemoveFromUpdateQueueOf(AHBplayer);
continue; continue;
} }
@@ -505,31 +489,51 @@ void AuctionHouseBot::addNewAuctionBuyerBotBid(Player *AHBplayer, AHBConfig *con
return; 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 // Fetches content of selected AH
AuctionHouseObject* auctionHouse = auctionmgr.GetAuctionsMap(config->GetAHFID()); AuctionHouseObject* auctionHouse = auctionmgr.GetAuctionsMap(config->GetAHFID());
vector<uint32> possibleBids; vector<uint32> possibleBids;
for (AuctionHouseObject::AuctionEntryMap::const_iterator itr = auctionHouse->GetAuctionsBegin();itr != auctionHouse->GetAuctionsEnd();++itr) do
{ {
// Check if the auction is ours uint32 tmpdata = result->Fetch()->GetUInt32();
// 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;
possibleBids.push_back(tmpdata); possibleBids.push_back(tmpdata);
//if (debug_Out) sLog.outString("AHBuyer: I have not bid on %u"), itr->second->Id; }while (result->NextRow());
} delete result;
else
{
//if (debug_Out) sLog.outString("AHBuyer: I have bid on %u"), itr->second->Id;
}
}
for (uint32 count = 1;count <= config->GetBidsPerInterval();++count) for (uint32 count = 1;count <= config->GetBidsPerInterval();++count)
{ {
@@ -554,7 +558,6 @@ void AuctionHouseBot::addNewAuctionBuyerBotBid(Player *AHBplayer, AHBConfig *con
if (!auction) if (!auction)
{ {
if (debug_Out) sLog.outError("AHBuyer: Item doesn't exist, perhaps bought already?");
continue; continue;
} }
@@ -698,18 +701,10 @@ void AuctionHouseBot::addNewAuctionBuyerBotBid(Player *AHBplayer, AHBConfig *con
else else
{ {
//buyout //buyout
if (AHBplayer->GetGUIDLow() == auction->bidder) if ((auction->bidder) && (AHBplayer->GetGUIDLow() != auction->bidder))
{
//pl->ModifyMoney(-int32(auction->buyout - auction->bid));
}
else
{
//pl->ModifyMoney(-int32(auction->buyout));
if (auction->bidder)
{ {
session->SendAuctionOutbiddedMail(auction, auction->buyout); session->SendAuctionOutbiddedMail(auction, auction->buyout);
} }
}
auction->bidder = AHBplayer->GetGUIDLow(); auction->bidder = AHBplayer->GetGUIDLow();
auction->bid = auction->buyout; auction->bid = auction->buyout;
@@ -717,14 +712,10 @@ void AuctionHouseBot::addNewAuctionBuyerBotBid(Player *AHBplayer, AHBConfig *con
auctionmgr.SendAuctionSalePendingMail(auction); auctionmgr.SendAuctionSalePendingMail(auction);
auctionmgr.SendAuctionSuccessfulMail(auction); auctionmgr.SendAuctionSuccessfulMail(auction);
auctionmgr.SendAuctionWonMail(auction); auctionmgr.SendAuctionWonMail(auction);
// Remove item from auctionhouse
auctionmgr.RemoveAItem(auction->item_guidlow);
// Remove auction
auctionHouse->RemoveAuction(auction->Id);
// Remove from database
auction->DeleteFromDB(); 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); _AHBplayer.MinimalLoadFromDB(NULL, AHBplayerGUID);
ObjectAccessor::Instance().AddObject(&_AHBplayer); 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 // Add New Bids
if (!sWorld.getConfig(CONFIG_ALLOW_TWO_SIDE_INTERACTION_AUCTION)) 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); DisableBeta_PTR_Unused = sConfig.GetBoolDefault("AuctionHouseBot.DisableBeta_PTR_Unused", false);
DisablePermEnchant = sConfig.GetBoolDefault("AuctionHouseBot.DisablePermEnchant", false); DisablePermEnchant = sConfig.GetBoolDefault("AuctionHouseBot.DisablePermEnchant", false);
#if CLIENT_VER > 300
DisableConjured = sConfig.GetBoolDefault("AuctionHouseBot.DisableConjured", false); DisableConjured = sConfig.GetBoolDefault("AuctionHouseBot.DisableConjured", false);
#endif
DisableGems = sConfig.GetBoolDefault("AuctionHouseBot.DisableGems", false); DisableGems = sConfig.GetBoolDefault("AuctionHouseBot.DisableGems", false);
DisableMoney = sConfig.GetBoolDefault("AuctionHouseBot.DisableMoney", false); DisableMoney = sConfig.GetBoolDefault("AuctionHouseBot.DisableMoney", false);
DisableMoneyLoot = sConfig.GetBoolDefault("AuctionHouseBot.DisableMoneyLoot", false); DisableMoneyLoot = sConfig.GetBoolDefault("AuctionHouseBot.DisableMoneyLoot", false);
@@ -844,7 +851,6 @@ void AuctionHouseBot::Initialize()
DisableTGsAboveReqSkillRank = sConfig.GetIntDefault("AuctionHouseBot.DisableTGsAboveReqSkillRank", 0); DisableTGsAboveReqSkillRank = sConfig.GetIntDefault("AuctionHouseBot.DisableTGsAboveReqSkillRank", 0);
//End Filters //End Filters
if (!sWorld.getConfig(CONFIG_ALLOW_TWO_SIDE_INTERACTION_AUCTION)) if (!sWorld.getConfig(CONFIG_ALLOW_TWO_SIDE_INTERACTION_AUCTION))
{ {
LoadValues(&AllianceConfig); LoadValues(&AllianceConfig);
@@ -878,7 +884,9 @@ void AuctionHouseBot::Initialize()
"SELECT item FROM fishing_loot_template UNION " "SELECT item FROM fishing_loot_template UNION "
"SELECT item FROM gameobject_loot_template UNION " "SELECT item FROM gameobject_loot_template UNION "
"SELECT item FROM item_loot_template UNION " "SELECT item FROM item_loot_template UNION "
#if CLIENT_VER > 300
"SELECT item FROM milling_loot_template UNION " "SELECT item FROM milling_loot_template UNION "
#endif
"SELECT item FROM pickpocketing_loot_template UNION " "SELECT item FROM pickpocketing_loot_template UNION "
"SELECT item FROM prospecting_loot_template UNION " "SELECT item FROM prospecting_loot_template UNION "
"SELECT item FROM skinning_loot_template"; "SELECT item FROM skinning_loot_template";
@@ -909,23 +917,23 @@ void AuctionHouseBot::Initialize()
switch (prototype->Bonding) switch (prototype->Bonding)
{ {
case 0: case NO_BIND:
if (!No_Bind) if (!No_Bind)
continue; continue;
break; break;
case 1: case BIND_WHEN_PICKED_UP:
if (!Bind_When_Picked_Up) if (!Bind_When_Picked_Up)
continue; continue;
break; break;
case 2: case BIND_WHEN_EQUIPED:
if (!Bind_When_Equipped) if (!Bind_When_Equipped)
continue; continue;
break; break;
case 3: case BIND_WHEN_USE:
if (!Bind_When_Use) if (!Bind_When_Use)
continue; continue;
break; break;
case 4: case BIND_QUEST_ITEM:
if (!Bind_Quest_Item) if (!Bind_Quest_Item)
continue; continue;
break; break;
@@ -1058,12 +1066,14 @@ void AuctionHouseBot::Initialize()
continue; continue;
} }
#if CLIENT_VER > 300
// Disable conjured items // Disable conjured items
if ((DisableConjured) && (prototype->IsConjuredConsumable())) if ((DisableConjured) && (prototype->IsConjuredConsumable()))
{ {
if (debug_Out_Filters) sLog.outString("AuctionHouseBot: Item %u disabled (Conjured Consumable)", prototype->ItemId); if (debug_Out_Filters) sLog.outString("AuctionHouseBot: Item %u disabled (Conjured Consumable)", prototype->ItemId);
continue; continue;
} }
#endif
// Disable gems // Disable gems
if ((DisableGems) && (prototype->Class == ITEM_CLASS_GEM)) if ((DisableGems) && (prototype->Class == ITEM_CLASS_GEM))
@@ -1305,49 +1315,49 @@ void AuctionHouseBot::Initialize()
switch (prototype->Quality) switch (prototype->Quality)
{ {
case 0: case AHB_GREY:
if (prototype->Class == ITEM_CLASS_TRADE_GOODS) if (prototype->Class == ITEM_CLASS_TRADE_GOODS)
greyTradeGoodsBin.push_back(itemID); greyTradeGoodsBin.push_back(itemID);
else else
greyItemsBin.push_back(itemID); greyItemsBin.push_back(itemID);
break; break;
case 1: case AHB_WHITE:
if (prototype->Class == ITEM_CLASS_TRADE_GOODS) if (prototype->Class == ITEM_CLASS_TRADE_GOODS)
whiteTradeGoodsBin.push_back(itemID); whiteTradeGoodsBin.push_back(itemID);
else else
whiteItemsBin.push_back(itemID); whiteItemsBin.push_back(itemID);
break; break;
case 2: case AHB_GREEN:
if (prototype->Class == ITEM_CLASS_TRADE_GOODS) if (prototype->Class == ITEM_CLASS_TRADE_GOODS)
greenTradeGoodsBin.push_back(itemID); greenTradeGoodsBin.push_back(itemID);
else else
greenItemsBin.push_back(itemID); greenItemsBin.push_back(itemID);
break; break;
case 3: case AHB_BLUE:
if (prototype->Class == ITEM_CLASS_TRADE_GOODS) if (prototype->Class == ITEM_CLASS_TRADE_GOODS)
blueTradeGoodsBin.push_back(itemID); blueTradeGoodsBin.push_back(itemID);
else else
blueItemsBin.push_back(itemID); blueItemsBin.push_back(itemID);
break; break;
case 4: case AHB_PURPLE:
if (prototype->Class == ITEM_CLASS_TRADE_GOODS) if (prototype->Class == ITEM_CLASS_TRADE_GOODS)
purpleTradeGoodsBin.push_back(itemID); purpleTradeGoodsBin.push_back(itemID);
else else
purpleItemsBin.push_back(itemID); purpleItemsBin.push_back(itemID);
break; break;
case 5: case AHB_ORANGE:
if (prototype->Class == ITEM_CLASS_TRADE_GOODS) if (prototype->Class == ITEM_CLASS_TRADE_GOODS)
orangeTradeGoodsBin.push_back(itemID); orangeTradeGoodsBin.push_back(itemID);
else else
orangeItemsBin.push_back(itemID); orangeItemsBin.push_back(itemID);
break; break;
case 6: case AHB_YELLOW:
if (prototype->Class == ITEM_CLASS_TRADE_GOODS) if (prototype->Class == ITEM_CLASS_TRADE_GOODS)
yellowTradeGoodsBin.push_back(itemID); yellowTradeGoodsBin.push_back(itemID);
else else
@@ -1374,6 +1384,7 @@ void AuctionHouseBot::Initialize()
sLog.outError("AuctionHouseBot: No items"); sLog.outError("AuctionHouseBot: No items");
AHBSeller = 0; AHBSeller = 0;
} }
sLog.outString("AuctionHouseBot:"); sLog.outString("AuctionHouseBot:");
sLog.outString("loaded %u grey trade goods", greyTradeGoodsBin.size()); sLog.outString("loaded %u grey trade goods", greyTradeGoodsBin.size());
sLog.outString("loaded %u white trade goods", whiteTradeGoodsBin.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"); 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) void AuctionHouseBot::Commands(uint32 command, uint32 ahMapID, uint32 col, char* args)
{ {
AHBConfig *config; AHBConfig *config;
@@ -1709,6 +1794,83 @@ void AuctionHouseBot::LoadValues(AHBConfig *config)
sLog.outString("maxStackOrange = %u", config->GetMaxStack(AHB_ORANGE)); sLog.outString("maxStackOrange = %u", config->GetMaxStack(AHB_ORANGE));
sLog.outString("maxStackYellow = %u", config->GetMaxStack(AHB_YELLOW)); 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) if (AHBBuyer)
{ {
+245
View File
@@ -3,7 +3,11 @@
#include "World.h" #include "World.h"
#include "Config/ConfigEnv.h" #include "Config/ConfigEnv.h"
#if CLIENT_VER > 300
#include "ace/Vector_T.h" #include "ace/Vector_T.h"
#else if CLIENT_VER > 100
#include <vector>
#endif
#define AHB_GREY 0 #define AHB_GREY 0
#define AHB_WHITE 1 #define AHB_WHITE 1
@@ -110,6 +114,22 @@ private:
uint32 orangeip; uint32 orangeip;
uint32 yellowip; 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: public:
AHBConfig(uint32 ahid) AHBConfig(uint32 ahid)
{ {
@@ -876,6 +896,225 @@ public:
break; 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) void SetBidsPerInterval(uint32 value)
{ {
buyerBidsPerInterval = value; buyerBidsPerInterval = value;
@@ -891,6 +1130,7 @@ public:
class AuctionHouseBot class AuctionHouseBot
{ {
private: private:
#if CLIENT_VER > 300
ACE_Vector<uint32> npcItems; ACE_Vector<uint32> npcItems;
ACE_Vector<uint32> lootItems; ACE_Vector<uint32> lootItems;
ACE_Vector<uint32> greyTradeGoodsBin; ACE_Vector<uint32> greyTradeGoodsBin;
@@ -907,6 +1147,7 @@ private:
ACE_Vector<uint32> purpleItemsBin; ACE_Vector<uint32> purpleItemsBin;
ACE_Vector<uint32> orangeItemsBin; ACE_Vector<uint32> orangeItemsBin;
ACE_Vector<uint32> yellowItemsBin; ACE_Vector<uint32> yellowItemsBin;
#endif
bool debug_Out; bool debug_Out;
bool debug_Out_Filters; bool debug_Out_Filters;
@@ -937,7 +1178,9 @@ private:
bool DisableBeta_PTR_Unused; bool DisableBeta_PTR_Unused;
bool DisablePermEnchant; bool DisablePermEnchant;
#if CLIENT_VER > 300
bool DisableConjured; bool DisableConjured;
#endif
bool DisableGems; bool DisableGems;
bool DisableMoney; bool DisableMoney;
bool DisableMoneyLoot; bool DisableMoneyLoot;
@@ -995,6 +1238,8 @@ public:
void Update(); void Update();
void Initialize(); void Initialize();
void LoadValues(AHBConfig*); void LoadValues(AHBConfig*);
void DecrementItemCounts(AuctionEntry* ah, uint32 item_template);
void IncrementItemCounts(AuctionEntry* ah);
void Commands(uint32, uint32, uint32, char*); void Commands(uint32, uint32, uint32, char*);
uint32 GetAHBplayerGUID() { return AHBplayerGUID; }; uint32 GetAHBplayerGUID() { return AHBplayerGUID; };
}; };
+103 -102
View File
@@ -36,7 +36,7 @@
//post-incrementation is always slower than pre-incrementation ! //post-incrementation is always slower than pre-incrementation !
//void called when player click on auctioneer npc //void called when player click on auctioneer npc
void WorldSession::HandleAuctionHelloOpcode( WorldPacket & recv_data ) void WorldSession::HandleAuctionHelloOpcode(WorldPacket & recv_data)
{ {
uint64 guid; //NPC guid uint64 guid; //NPC guid
recv_data >> guid; recv_data >> guid;
@@ -44,44 +44,44 @@ void WorldSession::HandleAuctionHelloOpcode( WorldPacket & recv_data )
Creature *unit = GetPlayer()->GetNPCIfCanInteractWith(guid,UNIT_NPC_FLAG_AUCTIONEER); Creature *unit = GetPlayer()->GetNPCIfCanInteractWith(guid,UNIT_NPC_FLAG_AUCTIONEER);
if (!unit) if (!unit)
{ {
sLog.outDebug( "WORLD: HandleAuctionHelloOpcode - Unit (GUID: %u) not found or you can't interact with him.", uint32(GUID_LOPART(guid)) ); sLog.outDebug("WORLD: HandleAuctionHelloOpcode - Unit (GUID: %u) not found or you can't interact with him.", uint32(GUID_LOPART(guid)));
return; return;
} }
// remove fake death // remove fake death
if(GetPlayer()->hasUnitState(UNIT_STAT_DIED)) if (GetPlayer()->hasUnitState(UNIT_STAT_DIED))
GetPlayer()->RemoveAurasByType(SPELL_AURA_FEIGN_DEATH); GetPlayer()->RemoveAurasByType(SPELL_AURA_FEIGN_DEATH);
SendAuctionHello(guid, unit); SendAuctionHello(guid, unit);
} }
//this void causes that auction window is opened //this void causes that auction window is opened
void WorldSession::SendAuctionHello( uint64 guid, Creature* unit ) void WorldSession::SendAuctionHello(uint64 guid, Creature* unit)
{ {
AuctionHouseEntry const* ahEntry = AuctionHouseMgr::GetAuctionHouseEntry(unit->getFaction()); AuctionHouseEntry const* ahEntry = AuctionHouseMgr::GetAuctionHouseEntry(unit->getFaction());
if(!ahEntry) if (!ahEntry)
return; return;
WorldPacket data( MSG_AUCTION_HELLO, 12 ); WorldPacket data(MSG_AUCTION_HELLO, 12);
data << (uint64) guid; data << (uint64) guid;
data << (uint32) ahEntry->houseId; data << (uint32) ahEntry->houseId;
SendPacket( &data ); SendPacket(&data);
} }
//call this method when player bids, creates, or deletes auction //call this method when player bids, creates, or deletes auction
void WorldSession::SendAuctionCommandResult(uint32 auctionId, uint32 Action, uint32 ErrorCode, uint32 bidError ) void WorldSession::SendAuctionCommandResult(uint32 auctionId, uint32 Action, uint32 ErrorCode, uint32 bidError)
{ {
WorldPacket data( SMSG_AUCTION_COMMAND_RESULT, 16 ); WorldPacket data(SMSG_AUCTION_COMMAND_RESULT, 16);
data << auctionId; data << auctionId;
data << Action; data << Action;
data << ErrorCode; data << ErrorCode;
if ( !ErrorCode && Action ) if (!ErrorCode && Action)
data << bidError; //when bid, then send 0, once... data << bidError; //when bid, then send 0, once...
SendPacket(&data); SendPacket(&data);
} }
//this function sends notification, if bidder is online //this function sends notification, if bidder is online
void WorldSession::SendAuctionBidderNotification( uint32 location, uint32 auctionId, uint64 bidder, uint32 bidSum, uint32 diff, uint32 item_template) void WorldSession::SendAuctionBidderNotification(uint32 location, uint32 auctionId, uint64 bidder, uint32 bidSum, uint32 diff, uint32 item_template)
{ {
WorldPacket data(SMSG_AUCTION_BIDDER_NOTIFICATION, (8*4)); WorldPacket data(SMSG_AUCTION_BIDDER_NOTIFICATION, (8*4));
data << uint32(location); data << uint32(location);
@@ -95,7 +95,7 @@ void WorldSession::SendAuctionBidderNotification( uint32 location, uint32 auctio
} }
//this void causes on client to display: "Your auction sold" //this void causes on client to display: "Your auction sold"
void WorldSession::SendAuctionOwnerNotification( AuctionEntry* auction) void WorldSession::SendAuctionOwnerNotification(AuctionEntry* auction)
{ {
WorldPacket data(SMSG_AUCTION_OWNER_NOTIFICATION, (7*4)); WorldPacket data(SMSG_AUCTION_OWNER_NOTIFICATION, (7*4));
data << auction->Id; data << auction->Id;
@@ -115,37 +115,37 @@ void WorldSession::SendAuctionOutbiddedMail(AuctionEntry *auction, uint32 newPri
Player *oldBidder = objmgr.GetPlayer(oldBidder_guid); Player *oldBidder = objmgr.GetPlayer(oldBidder_guid);
uint32 oldBidder_accId = 0; uint32 oldBidder_accId = 0;
if(!oldBidder) if (!oldBidder)
oldBidder_accId = objmgr.GetPlayerAccountIdByGUID(oldBidder_guid); oldBidder_accId = objmgr.GetPlayerAccountIdByGUID(oldBidder_guid);
// old bidder exist // old bidder exist
if(oldBidder || oldBidder_accId) if (oldBidder || oldBidder_accId)
{ {
std::ostringstream msgAuctionOutbiddedSubject; std::ostringstream msgAuctionOutbiddedSubject;
msgAuctionOutbiddedSubject << auction->item_template << ":0:" << AUCTION_OUTBIDDED; msgAuctionOutbiddedSubject << auction->item_template << ":0:" << AUCTION_OUTBIDDED;
if (oldBidder && !_player) if (oldBidder && !_player)
oldBidder->GetSession()->SendAuctionBidderNotification( auction->GetHouseId(), auction->Id, auctionbot.GetAHBplayerGUID(), newPrice, auction->GetAuctionOutBid(), auction->item_template); oldBidder->GetSession()->SendAuctionBidderNotification(auction->GetHouseId(), auction->Id, auctionbot.GetAHBplayerGUID(), newPrice, auction->GetAuctionOutBid(), auction->item_template);
if (oldBidder && _player) if (oldBidder && _player)
oldBidder->GetSession()->SendAuctionBidderNotification( auction->GetHouseId(), auction->Id, _player->GetGUID(), newPrice, auction->GetAuctionOutBid(), auction->item_template); oldBidder->GetSession()->SendAuctionBidderNotification(auction->GetHouseId(), auction->Id, _player->GetGUID(), newPrice, auction->GetAuctionOutBid(), auction->item_template);
WorldSession::SendMailTo(oldBidder, MAIL_AUCTION, MAIL_STATIONERY_AUCTION, auction->GetHouseId(), auction->bidder, msgAuctionOutbiddedSubject.str(), 0, NULL, auction->bid, 0, MAIL_CHECK_MASK_NONE); WorldSession::SendMailTo(oldBidder, MAIL_AUCTION, MAIL_STATIONERY_AUCTION, auction->GetHouseId(), auction->bidder, msgAuctionOutbiddedSubject.str(), 0, NULL, auction->bid, 0, MAIL_CHECK_MASK_NONE);
} }
} }
//this function sends mail, when auction is cancelled to old bidder //this function sends mail, when auction is cancelled to old bidder
void WorldSession::SendAuctionCancelledToBidderMail( AuctionEntry* auction ) void WorldSession::SendAuctionCancelledToBidderMail(AuctionEntry* auction)
{ {
uint64 bidder_guid = MAKE_NEW_GUID(auction->bidder, 0, HIGHGUID_PLAYER); uint64 bidder_guid = MAKE_NEW_GUID(auction->bidder, 0, HIGHGUID_PLAYER);
Player *bidder = objmgr.GetPlayer(bidder_guid); Player *bidder = objmgr.GetPlayer(bidder_guid);
uint32 bidder_accId = 0; uint32 bidder_accId = 0;
if(!bidder) if (!bidder)
bidder_accId = objmgr.GetPlayerAccountIdByGUID(bidder_guid); bidder_accId = objmgr.GetPlayerAccountIdByGUID(bidder_guid);
// bidder exist // bidder exist
if(bidder || bidder_accId) if (bidder || bidder_accId)
{ {
std::ostringstream msgAuctionCancelledSubject; std::ostringstream msgAuctionCancelledSubject;
msgAuctionCancelledSubject << auction->item_template << ":0:" << AUCTION_CANCELLED_TO_BIDDER; msgAuctionCancelledSubject << auction->item_template << ":0:" << AUCTION_CANCELLED_TO_BIDDER;
@@ -155,7 +155,7 @@ void WorldSession::SendAuctionCancelledToBidderMail( AuctionEntry* auction )
} }
//this void creates new auction and adds auction to some auctionhouse //this void creates new auction and adds auction to some auctionhouse
void WorldSession::HandleAuctionSellItem( WorldPacket & recv_data ) void WorldSession::HandleAuctionSellItem(WorldPacket & recv_data)
{ {
uint64 auctioneer, item; uint64 auctioneer, item;
uint32 etime, bid, buyout; uint32 etime, bid, buyout;
@@ -169,21 +169,24 @@ void WorldSession::HandleAuctionSellItem( WorldPacket & recv_data )
Creature *pCreature = GetPlayer()->GetNPCIfCanInteractWith(auctioneer,UNIT_NPC_FLAG_AUCTIONEER); Creature *pCreature = GetPlayer()->GetNPCIfCanInteractWith(auctioneer,UNIT_NPC_FLAG_AUCTIONEER);
if (!pCreature) if (!pCreature)
{ {
sLog.outDebug( "WORLD: HandleAuctionSellItem - Unit (GUID: %u) not found or you can't interact with him.", uint32(GUID_LOPART(auctioneer)) ); sLog.outDebug("WORLD: HandleAuctionSellItem - Unit (GUID: %u) not found or you can't interact with him.", uint32(GUID_LOPART(auctioneer)));
return; return;
} }
AuctionHouseEntry const* auctionHouseEntry = AuctionHouseMgr::GetAuctionHouseEntry(pCreature->getFaction()); AuctionHouseEntry const* auctionHouseEntry = AuctionHouseMgr::GetAuctionHouseEntry(pCreature->getFaction());
if(!auctionHouseEntry) if (!auctionHouseEntry)
{ {
sLog.outDebug( "WORLD: HandleAuctionSellItem - Unit (GUID: %u) has wrong faction.", uint32(GUID_LOPART(auctioneer)) ); sLog.outDebug("WORLD: HandleAuctionSellItem - Unit (GUID: %u) has wrong faction.", uint32(GUID_LOPART(auctioneer)));
return; return;
} }
sLog.outDebug("WORLD: HandleAuctionSellItem - ETIME: %u", etime);
// client send time in minutes, convert to common used sec time // client send time in minutes, convert to common used sec time
etime *= MINUTE; etime *= MINUTE;
sLog.outDebug("WORLD: HandleAuctionSellItem - ETIME: %u", etime);
// client understand only 3 auction time // client understand only 3 auction time
switch(etime) switch(etime)
{ {
@@ -196,25 +199,25 @@ void WorldSession::HandleAuctionSellItem( WorldPacket & recv_data )
} }
// remove fake death // remove fake death
if(GetPlayer()->hasUnitState(UNIT_STAT_DIED)) if (GetPlayer()->hasUnitState(UNIT_STAT_DIED))
GetPlayer()->RemoveAurasByType(SPELL_AURA_FEIGN_DEATH); GetPlayer()->RemoveAurasByType(SPELL_AURA_FEIGN_DEATH);
Item *it = pl->GetItemByGuid( item ); Item *it = pl->GetItemByGuid(item);
//do not allow to sell already auctioned items //do not allow to sell already auctioned items
if(auctionmgr.GetAItem(GUID_LOPART(item))) if (auctionmgr.GetAItem(GUID_LOPART(item)))
{ {
sLog.outError("AuctionError, player %s is sending item id: %u, but item is already in another auction", pl->GetName(), GUID_LOPART(item)); sLog.outError("AuctionError, player %s is sending item id: %u, but item is already in another auction", pl->GetName(), GUID_LOPART(item));
SendAuctionCommandResult(0, AUCTION_SELL_ITEM, AUCTION_INTERNAL_ERROR); SendAuctionCommandResult(0, AUCTION_SELL_ITEM, AUCTION_INTERNAL_ERROR);
return; return;
} }
// prevent sending bag with items (cheat: can be placed in bag after adding equiped empty bag to auction) // prevent sending bag with items (cheat: can be placed in bag after adding equiped empty bag to auction)
if(!it) if (!it)
{ {
SendAuctionCommandResult(0, AUCTION_SELL_ITEM, AUCTION_ITEM_NOT_FOUND); SendAuctionCommandResult(0, AUCTION_SELL_ITEM, AUCTION_ITEM_NOT_FOUND);
return; return;
} }
if(!it->CanBeTraded()) if (!it->CanBeTraded())
{ {
SendAuctionCommandResult(0, AUCTION_SELL_ITEM, AUCTION_INTERNAL_ERROR); SendAuctionCommandResult(0, AUCTION_SELL_ITEM, AUCTION_INTERNAL_ERROR);
return; return;
@@ -226,29 +229,29 @@ void WorldSession::HandleAuctionSellItem( WorldPacket & recv_data )
return; return;
} }
AuctionHouseObject* auctionHouse = auctionmgr.GetAuctionsMap( pCreature->getFaction() ); AuctionHouseObject* auctionHouse = auctionmgr.GetAuctionsMap(pCreature->getFaction());
//we have to take deposit : //we have to take deposit :
uint32 deposit = auctionmgr.GetAuctionDeposit( auctionHouseEntry, etime, it ); uint32 deposit = auctionmgr.GetAuctionDeposit(auctionHouseEntry, etime, it);
if ( pl->GetMoney() < deposit ) if (pl->GetMoney() < deposit)
{ {
SendAuctionCommandResult(0, AUCTION_SELL_ITEM, AUCTION_NOT_ENOUGHT_MONEY); SendAuctionCommandResult(0, AUCTION_SELL_ITEM, AUCTION_NOT_ENOUGHT_MONEY);
return; return;
} }
if( GetSecurity() > SEC_PLAYER && sWorld.getConfig(CONFIG_GM_LOG_TRADE) ) if (GetSecurity() > SEC_PLAYER && sWorld.getConfig(CONFIG_GM_LOG_TRADE))
{ {
sLog.outCommand(GetAccountId(),"GM %s (Account: %u) create auction: %s (Entry: %u Count: %u)", sLog.outCommand(GetAccountId(),"GM %s (Account: %u) create auction: %s (Entry: %u Count: %u)",
GetPlayerName(),GetAccountId(),it->GetProto()->Name1,it->GetEntry(),it->GetCount()); GetPlayerName(),GetAccountId(),it->GetProto()->Name1,it->GetEntry(),it->GetCount());
} }
pl->ModifyMoney( -int32(deposit) ); pl->ModifyMoney(-int32(deposit));
uint32 auction_time = uint32(etime * sWorld.getRate(RATE_AUCTION_TIME)); uint32 auction_time = uint32(etime * sWorld.getRate(RATE_AUCTION_TIME));
AuctionEntry *AH = new AuctionEntry; AuctionEntry *AH = new AuctionEntry;
AH->Id = objmgr.GenerateAuctionID(); AH->Id = objmgr.GenerateAuctionID();
if(sWorld.getConfig(CONFIG_ALLOW_TWO_SIDE_INTERACTION_AUCTION)) if (sWorld.getConfig(CONFIG_ALLOW_TWO_SIDE_INTERACTION_AUCTION))
AH->auctioneer = 23442; AH->auctioneer = 23442;
else else
AH->auctioneer = GUID_LOPART(auctioneer); AH->auctioneer = GUID_LOPART(auctioneer);
@@ -264,10 +267,10 @@ void WorldSession::HandleAuctionSellItem( WorldPacket & recv_data )
AH->auctionHouseEntry = auctionHouseEntry; 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()); 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); auctionHouse->AddAuction(AH);
auctionmgr.AddAItem(it); pl->MoveItemFromInventory(it->GetBagSlot(), it->GetSlot(), true);
pl->MoveItemFromInventory( it->GetBagSlot(), it->GetSlot(), true);
CharacterDatabase.BeginTransaction(); CharacterDatabase.BeginTransaction();
it->DeleteFromInventoryDB(); it->DeleteFromInventoryDB();
@@ -280,7 +283,7 @@ void WorldSession::HandleAuctionSellItem( WorldPacket & recv_data )
} }
//this function is called when client bids or buys out auction //this function is called when client bids or buys out auction
void WorldSession::HandleAuctionPlaceBid( WorldPacket & recv_data ) void WorldSession::HandleAuctionPlaceBid(WorldPacket & recv_data)
{ {
uint64 auctioneer; uint64 auctioneer;
uint32 auctionId; uint32 auctionId;
@@ -294,37 +297,37 @@ void WorldSession::HandleAuctionPlaceBid( WorldPacket & recv_data )
Creature *pCreature = GetPlayer()->GetNPCIfCanInteractWith(auctioneer,UNIT_NPC_FLAG_AUCTIONEER); Creature *pCreature = GetPlayer()->GetNPCIfCanInteractWith(auctioneer,UNIT_NPC_FLAG_AUCTIONEER);
if (!pCreature) if (!pCreature)
{ {
sLog.outDebug( "WORLD: HandleAuctionPlaceBid - Unit (GUID: %u) not found or you can't interact with him.", uint32(GUID_LOPART(auctioneer)) ); sLog.outDebug("WORLD: HandleAuctionPlaceBid - Unit (GUID: %u) not found or you can't interact with him.", uint32(GUID_LOPART(auctioneer)));
return; return;
} }
// remove fake death // remove fake death
if(GetPlayer()->hasUnitState(UNIT_STAT_DIED)) if (GetPlayer()->hasUnitState(UNIT_STAT_DIED))
GetPlayer()->RemoveAurasByType(SPELL_AURA_FEIGN_DEATH); GetPlayer()->RemoveAurasByType(SPELL_AURA_FEIGN_DEATH);
AuctionHouseObject* auctionHouse = auctionmgr.GetAuctionsMap( pCreature->getFaction() ); AuctionHouseObject* auctionHouse = auctionmgr.GetAuctionsMap(pCreature->getFaction());
AuctionEntry *auction = auctionHouse->GetAuction(auctionId); AuctionEntry *auction = auctionHouse->GetAuction(auctionId);
Player *pl = GetPlayer(); Player *pl = GetPlayer();
if( !auction || auction->owner == pl->GetGUIDLow() ) if (!auction || auction->owner == pl->GetGUIDLow())
{ {
//you cannot bid your own auction: //you cannot bid your own auction:
SendAuctionCommandResult( 0, AUCTION_PLACE_BID, CANNOT_BID_YOUR_AUCTION_ERROR ); SendAuctionCommandResult(0, AUCTION_PLACE_BID, CANNOT_BID_YOUR_AUCTION_ERROR);
return; return;
} }
// impossible have online own another character (use this for speedup check in case online owner) // impossible have online own another character (use this for speedup check in case online owner)
Player* auction_owner = objmgr.GetPlayer(MAKE_NEW_GUID(auction->owner, 0, HIGHGUID_PLAYER)); Player* auction_owner = objmgr.GetPlayer(MAKE_NEW_GUID(auction->owner, 0, HIGHGUID_PLAYER));
if( !auction_owner && objmgr.GetPlayerAccountIdByGUID(MAKE_NEW_GUID(auction->owner, 0, HIGHGUID_PLAYER)) == pl->GetSession()->GetAccountId()) if (!auction_owner && objmgr.GetPlayerAccountIdByGUID(MAKE_NEW_GUID(auction->owner, 0, HIGHGUID_PLAYER)) == pl->GetSession()->GetAccountId())
{ {
//you cannot bid your another character auction: //you cannot bid your another character auction:
SendAuctionCommandResult( 0, AUCTION_PLACE_BID, CANNOT_BID_YOUR_AUCTION_ERROR ); SendAuctionCommandResult(0, AUCTION_PLACE_BID, CANNOT_BID_YOUR_AUCTION_ERROR);
return; return;
} }
// cheating // cheating
if(price <= auction->bid) if (price <= auction->bid)
return; return;
// price too low for next bid if not buyout // price too low for next bid if not buyout
@@ -346,20 +349,20 @@ void WorldSession::HandleAuctionPlaceBid( WorldPacket & recv_data )
{ {
if (auction->bidder > 0) if (auction->bidder > 0)
{ {
if ( auction->bidder == pl->GetGUIDLow() ) if (auction->bidder == pl->GetGUIDLow())
{ {
pl->ModifyMoney( -int32(price - auction->bid)); pl->ModifyMoney(-int32(price - auction->bid));
} }
else else
{ {
// mail to last bidder and return money // mail to last bidder and return money
SendAuctionOutbiddedMail( auction , price ); SendAuctionOutbiddedMail(auction , price);
pl->ModifyMoney( -int32(price) ); pl->ModifyMoney(-int32(price));
} }
} }
else else
{ {
pl->ModifyMoney( -int32(price) ); pl->ModifyMoney(-int32(price));
} }
auction->bidder = pl->GetGUIDLow(); auction->bidder = pl->GetGUIDLow();
auction->bid = price; auction->bid = price;
@@ -368,38 +371,36 @@ void WorldSession::HandleAuctionPlaceBid( WorldPacket & recv_data )
// after this update we should save player's money ... // after this update we should save player's money ...
CharacterDatabase.PExecute("UPDATE auctionhouse SET buyguid = '%u',lastbid = '%u' WHERE id = '%u'", auction->bidder, auction->bid, auction->Id); CharacterDatabase.PExecute("UPDATE auctionhouse SET buyguid = '%u',lastbid = '%u' WHERE id = '%u'", auction->bidder, auction->bid, auction->Id);
SendAuctionCommandResult(auction->Id, AUCTION_PLACE_BID, AUCTION_OK, 0 ); SendAuctionCommandResult(auction->Id, AUCTION_PLACE_BID, AUCTION_OK, 0);
} }
else else
{ {
//buyout: //buyout:
if (pl->GetGUIDLow() == auction->bidder ) if (pl->GetGUIDLow() == auction->bidder)
{ {
pl->ModifyMoney(-int32(auction->buyout - auction->bid)); pl->ModifyMoney(-int32(auction->buyout - auction->bid));
} }
else else
{ {
pl->ModifyMoney(-int32(auction->buyout)); pl->ModifyMoney(-int32(auction->buyout));
if ( auction->bidder ) //buyout for bidded auction .. if (auction->bidder) //buyout for bidded auction ..
{ {
SendAuctionOutbiddedMail( auction, auction->buyout ); SendAuctionOutbiddedMail(auction, auction->buyout);
} }
} }
auction->bidder = pl->GetGUIDLow(); auction->bidder = pl->GetGUIDLow();
auction->bid = auction->buyout; auction->bid = auction->buyout;
GetPlayer()->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_HIGHEST_AUCTION_BID, auction->buyout); GetPlayer()->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_HIGHEST_AUCTION_BID, auction->buyout);
auctionmgr.SendAuctionSalePendingMail( auction ); auctionmgr.SendAuctionSalePendingMail(auction);
auctionmgr.SendAuctionSuccessfulMail( auction ); auctionmgr.SendAuctionSuccessfulMail(auction);
auctionmgr.SendAuctionWonMail( auction ); auctionmgr.SendAuctionWonMail(auction);
SendAuctionCommandResult(auction->Id, AUCTION_PLACE_BID, AUCTION_OK); SendAuctionCommandResult(auction->Id, AUCTION_PLACE_BID, AUCTION_OK);
auctionmgr.RemoveAItem(auction->item_guidlow);
auctionHouse->RemoveAuction(auction->Id);
auction->DeleteFromDB(); auction->DeleteFromDB();
uint32 item_template = auction->item_template;
delete auction; auctionmgr.RemoveAItem(auction->item_guidlow);
auctionHouse->RemoveAuction(auction, item_template);
} }
CharacterDatabase.BeginTransaction(); CharacterDatabase.BeginTransaction();
pl->SaveInventoryAndGoldToDB(); pl->SaveInventoryAndGoldToDB();
@@ -407,26 +408,26 @@ void WorldSession::HandleAuctionPlaceBid( WorldPacket & recv_data )
} }
//this void is called when auction_owner cancels his auction //this void is called when auction_owner cancels his auction
void WorldSession::HandleAuctionRemoveItem( WorldPacket & recv_data ) void WorldSession::HandleAuctionRemoveItem(WorldPacket & recv_data)
{ {
uint64 auctioneer; uint64 auctioneer;
uint32 auctionId; uint32 auctionId;
recv_data >> auctioneer; recv_data >> auctioneer;
recv_data >> auctionId; recv_data >> auctionId;
//sLog.outDebug( "Cancel AUCTION AuctionID: %u", auctionId); //sLog.outDebug("Cancel AUCTION AuctionID: %u", auctionId);
Creature *pCreature = GetPlayer()->GetNPCIfCanInteractWith(auctioneer,UNIT_NPC_FLAG_AUCTIONEER); Creature *pCreature = GetPlayer()->GetNPCIfCanInteractWith(auctioneer,UNIT_NPC_FLAG_AUCTIONEER);
if (!pCreature) if (!pCreature)
{ {
sLog.outDebug( "WORLD: HandleAuctionRemoveItem - Unit (GUID: %u) not found or you can't interact with him.", uint32(GUID_LOPART(auctioneer)) ); sLog.outDebug("WORLD: HandleAuctionRemoveItem - Unit (GUID: %u) not found or you can't interact with him.", uint32(GUID_LOPART(auctioneer)));
return; return;
} }
// remove fake death // remove fake death
if(GetPlayer()->hasUnitState(UNIT_STAT_DIED)) if (GetPlayer()->hasUnitState(UNIT_STAT_DIED))
GetPlayer()->RemoveAurasByType(SPELL_AURA_FEIGN_DEATH); GetPlayer()->RemoveAurasByType(SPELL_AURA_FEIGN_DEATH);
AuctionHouseObject* auctionHouse = auctionmgr.GetAuctionsMap( pCreature->getFaction() ); AuctionHouseObject* auctionHouse = auctionmgr.GetAuctionsMap(pCreature->getFaction());
AuctionEntry *auction = auctionHouse->GetAuction(auctionId); AuctionEntry *auction = auctionHouse->GetAuction(auctionId);
Player *pl = GetPlayer(); Player *pl = GetPlayer();
@@ -439,11 +440,11 @@ void WorldSession::HandleAuctionRemoveItem( WorldPacket & recv_data )
if (auction->bidder > 0) // If we have a bidder, we have to send him the money he paid if (auction->bidder > 0) // If we have a bidder, we have to send him the money he paid
{ {
uint32 auctionCut = auction->GetAuctionCut(); uint32 auctionCut = auction->GetAuctionCut();
if ( pl->GetMoney() < auctionCut ) //player doesn't have enough money, maybe message needed if (pl->GetMoney() < auctionCut) //player doesn't have enough money, maybe message needed
return; return;
//some auctionBidderNotification would be needed, but don't know that parts.. //some auctionBidderNotification would be needed, but don't know that parts..
SendAuctionCancelledToBidderMail( auction ); SendAuctionCancelledToBidderMail(auction);
pl->ModifyMoney( -int32(auctionCut) ); pl->ModifyMoney(-int32(auctionCut));
} }
// Return the item by mail // Return the item by mail
std::ostringstream msgAuctionCanceledOwner; std::ostringstream msgAuctionCanceledOwner;
@@ -458,32 +459,32 @@ void WorldSession::HandleAuctionRemoveItem( WorldPacket & recv_data )
else else
{ {
sLog.outError("Auction id: %u has non-existed item (item guid : %u)!!!", auction->Id, auction->item_guidlow); sLog.outError("Auction id: %u has non-existed item (item guid : %u)!!!", auction->Id, auction->item_guidlow);
SendAuctionCommandResult( 0, AUCTION_CANCEL, AUCTION_INTERNAL_ERROR ); SendAuctionCommandResult(0, AUCTION_CANCEL, AUCTION_INTERNAL_ERROR);
return; return;
} }
} }
else else
{ {
SendAuctionCommandResult( 0, AUCTION_CANCEL, AUCTION_INTERNAL_ERROR ); SendAuctionCommandResult(0, AUCTION_CANCEL, AUCTION_INTERNAL_ERROR);
//this code isn't possible ... maybe there should be assert //this code isn't possible ... maybe there should be assert
sLog.outError("CHEATER : %u, he tried to cancel auction (id: %u) of another player, or auction is NULL", pl->GetGUIDLow(), auctionId ); sLog.outError("CHEATER : %u, he tried to cancel auction (id: %u) of another player, or auction is NULL", pl->GetGUIDLow(), auctionId);
return; return;
} }
//inform player, that auction is removed //inform player, that auction is removed
SendAuctionCommandResult( auction->Id, AUCTION_CANCEL, AUCTION_OK ); SendAuctionCommandResult(auction->Id, AUCTION_CANCEL, AUCTION_OK);
// Now remove the auction // Now remove the auction
CharacterDatabase.BeginTransaction(); CharacterDatabase.BeginTransaction();
auction->DeleteFromDB();
pl->SaveInventoryAndGoldToDB(); pl->SaveInventoryAndGoldToDB();
CharacterDatabase.CommitTransaction(); CharacterDatabase.CommitTransaction();
auctionmgr.RemoveAItem( auction->item_guidlow ); auction->DeleteFromDB();
auctionHouse->RemoveAuction( auction->Id ); uint32 item_template = auction->item_template;
delete auction; auctionmgr.RemoveAItem(auction->item_guidlow);
auctionHouse->RemoveAuction(auction, item_template);
} }
//called when player lists his bids //called when player lists his bids
void WorldSession::HandleAuctionListBidderItems( WorldPacket & recv_data ) void WorldSession::HandleAuctionListBidderItems(WorldPacket & recv_data)
{ {
uint64 guid; //NPC guid uint64 guid; //NPC guid
uint32 listfrom; //page of auctions uint32 listfrom; //page of auctions
@@ -492,37 +493,37 @@ void WorldSession::HandleAuctionListBidderItems( WorldPacket & recv_data )
recv_data >> guid; recv_data >> guid;
recv_data >> listfrom; // not used in fact (this list not have page control in client) recv_data >> listfrom; // not used in fact (this list not have page control in client)
recv_data >> outbiddedCount; recv_data >> outbiddedCount;
if (recv_data.size() != (16 + outbiddedCount * 4 )) if (recv_data.size() != (16 + outbiddedCount * 4))
{ {
sLog.outError("Client sent bad opcode!!! with count: %u and size : %lu (must be: %u)", outbiddedCount, (unsigned long)recv_data.size(),(16 + outbiddedCount * 4 )); sLog.outError("Client sent bad opcode!!! with count: %u and size : %lu (must be: %u)", outbiddedCount, (unsigned long)recv_data.size(),(16 + outbiddedCount * 4));
outbiddedCount = 0; outbiddedCount = 0;
} }
Creature *pCreature = GetPlayer()->GetNPCIfCanInteractWith(guid,UNIT_NPC_FLAG_AUCTIONEER); Creature *pCreature = GetPlayer()->GetNPCIfCanInteractWith(guid,UNIT_NPC_FLAG_AUCTIONEER);
if (!pCreature) if (!pCreature)
{ {
sLog.outDebug( "WORLD: HandleAuctionListBidderItems - Unit (GUID: %u) not found or you can't interact with him.", uint32(GUID_LOPART(guid)) ); sLog.outDebug("WORLD: HandleAuctionListBidderItems - Unit (GUID: %u) not found or you can't interact with him.", uint32(GUID_LOPART(guid)));
return; return;
} }
// remove fake death // remove fake death
if(GetPlayer()->hasUnitState(UNIT_STAT_DIED)) if (GetPlayer()->hasUnitState(UNIT_STAT_DIED))
GetPlayer()->RemoveAurasByType(SPELL_AURA_FEIGN_DEATH); GetPlayer()->RemoveAurasByType(SPELL_AURA_FEIGN_DEATH);
AuctionHouseObject* auctionHouse = auctionmgr.GetAuctionsMap( pCreature->getFaction() ); AuctionHouseObject* auctionHouse = auctionmgr.GetAuctionsMap(pCreature->getFaction());
WorldPacket data( SMSG_AUCTION_BIDDER_LIST_RESULT, (4+4+4) ); WorldPacket data(SMSG_AUCTION_BIDDER_LIST_RESULT, (4+4+4));
Player *pl = GetPlayer(); Player *pl = GetPlayer();
data << (uint32) 0; //add 0 as count data << (uint32) 0; //add 0 as count
uint32 count = 0; uint32 count = 0;
uint32 totalcount = 0; uint32 totalcount = 0;
while ( outbiddedCount > 0) //add all data, which client requires while (outbiddedCount > 0) //add all data, which client requires
{ {
--outbiddedCount; --outbiddedCount;
uint32 outbiddedAuctionId; uint32 outbiddedAuctionId;
recv_data >> outbiddedAuctionId; recv_data >> outbiddedAuctionId;
AuctionEntry * auction = auctionHouse->GetAuction( outbiddedAuctionId ); AuctionEntry * auction = auctionHouse->GetAuction(outbiddedAuctionId);
if ( auction && auction->BuildAuctionInfo(data)) if (auction && auction->BuildAuctionInfo(data))
{ {
++totalcount; ++totalcount;
++count; ++count;
@@ -530,14 +531,14 @@ void WorldSession::HandleAuctionListBidderItems( WorldPacket & recv_data )
} }
auctionHouse->BuildListBidderItems(data,pl,count,totalcount); auctionHouse->BuildListBidderItems(data,pl,count,totalcount);
data.put<uint32>( 0, count ); // add count to placeholder data.put<uint32>(0, count); // add count to placeholder
data << totalcount; data << totalcount;
data << (uint32)300; //unk 2.3.0 data << (uint32)300; //unk 2.3.0
SendPacket(&data); SendPacket(&data);
} }
//this void sends player info about his auctions //this void sends player info about his auctions
void WorldSession::HandleAuctionListOwnerItems( WorldPacket & recv_data ) void WorldSession::HandleAuctionListOwnerItems(WorldPacket & recv_data)
{ {
uint32 listfrom; uint32 listfrom;
uint64 guid; uint64 guid;
@@ -548,17 +549,17 @@ void WorldSession::HandleAuctionListOwnerItems( WorldPacket & recv_data )
Creature *pCreature = GetPlayer()->GetNPCIfCanInteractWith(guid,UNIT_NPC_FLAG_AUCTIONEER); Creature *pCreature = GetPlayer()->GetNPCIfCanInteractWith(guid,UNIT_NPC_FLAG_AUCTIONEER);
if (!pCreature) if (!pCreature)
{ {
sLog.outDebug( "WORLD: HandleAuctionListOwnerItems - Unit (GUID: %u) not found or you can't interact with him.", uint32(GUID_LOPART(guid)) ); sLog.outDebug("WORLD: HandleAuctionListOwnerItems - Unit (GUID: %u) not found or you can't interact with him.", uint32(GUID_LOPART(guid)));
return; return;
} }
// remove fake death // remove fake death
if(GetPlayer()->hasUnitState(UNIT_STAT_DIED)) if (GetPlayer()->hasUnitState(UNIT_STAT_DIED))
GetPlayer()->RemoveAurasByType(SPELL_AURA_FEIGN_DEATH); GetPlayer()->RemoveAurasByType(SPELL_AURA_FEIGN_DEATH);
AuctionHouseObject* auctionHouse = auctionmgr.GetAuctionsMap( pCreature->getFaction() ); AuctionHouseObject* auctionHouse = auctionmgr.GetAuctionsMap(pCreature->getFaction());
WorldPacket data( SMSG_AUCTION_OWNER_LIST_RESULT, (4+4+4) ); WorldPacket data(SMSG_AUCTION_OWNER_LIST_RESULT, (4+4+4));
data << (uint32) 0; // amount place holder data << (uint32) 0; // amount place holder
uint32 count = 0; uint32 count = 0;
@@ -572,7 +573,7 @@ void WorldSession::HandleAuctionListOwnerItems( WorldPacket & recv_data )
} }
//this void is called when player clicks on search button //this void is called when player clicks on search button
void WorldSession::HandleAuctionListItems( WorldPacket & recv_data ) void WorldSession::HandleAuctionListItems(WorldPacket & recv_data)
{ {
std::string searchedname; std::string searchedname;
uint8 levelmin, levelmax, usable; uint8 levelmin, levelmax, usable;
@@ -590,27 +591,27 @@ void WorldSession::HandleAuctionListItems( WorldPacket & recv_data )
Creature *pCreature = GetPlayer()->GetNPCIfCanInteractWith(guid,UNIT_NPC_FLAG_AUCTIONEER); Creature *pCreature = GetPlayer()->GetNPCIfCanInteractWith(guid,UNIT_NPC_FLAG_AUCTIONEER);
if (!pCreature) if (!pCreature)
{ {
sLog.outDebug( "WORLD: HandleAuctionListItems - Unit (GUID: %u) not found or you can't interact with him.", uint32(GUID_LOPART(guid)) ); sLog.outDebug("WORLD: HandleAuctionListItems - Unit (GUID: %u) not found or you can't interact with him.", uint32(GUID_LOPART(guid)));
return; return;
} }
// remove fake death // remove fake death
if(GetPlayer()->hasUnitState(UNIT_STAT_DIED)) if (GetPlayer()->hasUnitState(UNIT_STAT_DIED))
GetPlayer()->RemoveAurasByType(SPELL_AURA_FEIGN_DEATH); GetPlayer()->RemoveAurasByType(SPELL_AURA_FEIGN_DEATH);
AuctionHouseObject* auctionHouse = auctionmgr.GetAuctionsMap( pCreature->getFaction() ); AuctionHouseObject* auctionHouse = auctionmgr.GetAuctionsMap(pCreature->getFaction());
//sLog.outDebug("Auctionhouse search (GUID: %u TypeId: %u)", , list from: %u, searchedname: %s, levelmin: %u, levelmax: %u, auctionSlotID: %u, auctionMainCategory: %u, auctionSubCategory: %u, quality: %u, usable: %u", //sLog.outDebug("Auctionhouse search (GUID: %u TypeId: %u)", , list from: %u, searchedname: %s, levelmin: %u, levelmax: %u, auctionSlotID: %u, auctionMainCategory: %u, auctionSubCategory: %u, quality: %u, usable: %u",
// GUID_LOPART(guid),GuidHigh2TypeId(GUID_HIPART(guid)), listfrom, searchedname.c_str(), levelmin, levelmax, auctionSlotID, auctionMainCategory, auctionSubCategory, quality, usable); // GUID_LOPART(guid),GuidHigh2TypeId(GUID_HIPART(guid)), listfrom, searchedname.c_str(), levelmin, levelmax, auctionSlotID, auctionMainCategory, auctionSubCategory, quality, usable);
WorldPacket data( SMSG_AUCTION_LIST_RESULT, (4+4+4) ); WorldPacket data(SMSG_AUCTION_LIST_RESULT, (4+4+4));
uint32 count = 0; uint32 count = 0;
uint32 totalcount = 0; uint32 totalcount = 0;
data << (uint32) 0; data << (uint32) 0;
// converting string that we try to find to lower case // converting string that we try to find to lower case
std::wstring wsearchedname; std::wstring wsearchedname;
if(!Utf8toWStr(searchedname,wsearchedname)) if (!Utf8toWStr(searchedname,wsearchedname))
return; return;
wstrToLower(wsearchedname); wstrToLower(wsearchedname);
@@ -626,7 +627,7 @@ void WorldSession::HandleAuctionListItems( WorldPacket & recv_data )
SendPacket(&data); SendPacket(&data);
} }
void WorldSession::HandleAuctionListPendingSales( WorldPacket & recv_data ) void WorldSession::HandleAuctionListPendingSales(WorldPacket & recv_data)
{ {
sLog.outDebug("CMSG_AUCTION_LIST_PENDING_SALES"); sLog.outDebug("CMSG_AUCTION_LIST_PENDING_SALES");
recv_data.hexlike(); recv_data.hexlike();
@@ -635,7 +636,7 @@ void WorldSession::HandleAuctionListPendingSales( WorldPacket & recv_data )
WorldPacket data(SMSG_AUCTION_LIST_PENDING_SALES, 4); WorldPacket data(SMSG_AUCTION_LIST_PENDING_SALES, 4);
data << uint32(count); // count data << uint32(count); // count
/*for(uint32 i = 0; i < count; ++i) /*for (uint32 i = 0; i < count; ++i)
{ {
data << ""; // string data << ""; // string
data << ""; // string data << ""; // string
+96 -138
View File
@@ -35,7 +35,7 @@
#include "ProgressBar.h" #include "ProgressBar.h"
INSTANTIATE_SINGLETON_1( AuctionHouseMgr ); INSTANTIATE_SINGLETON_1(AuctionHouseMgr);
AuctionHouseMgr::AuctionHouseMgr() AuctionHouseMgr::AuctionHouseMgr()
{ {
@@ -43,22 +43,22 @@ AuctionHouseMgr::AuctionHouseMgr()
AuctionHouseMgr::~AuctionHouseMgr() AuctionHouseMgr::~AuctionHouseMgr()
{ {
for(ItemMap::const_iterator itr = mAitems.begin(); itr != mAitems.end(); ++itr) for (ItemMap::const_iterator itr = mAitems.begin(); itr != mAitems.end(); ++itr)
delete itr->second; delete itr->second;
} }
AuctionHouseObject * AuctionHouseMgr::GetAuctionsMap( uint32 factionTemplateId ) AuctionHouseObject * AuctionHouseMgr::GetAuctionsMap(uint32 factionTemplateId)
{ {
if(sWorld.getConfig(CONFIG_ALLOW_TWO_SIDE_INTERACTION_AUCTION)) if (sWorld.getConfig(CONFIG_ALLOW_TWO_SIDE_INTERACTION_AUCTION))
return &mNeutralAuctions; return &mNeutralAuctions;
// team have linked auction houses // team have linked auction houses
FactionTemplateEntry const* u_entry = sFactionTemplateStore.LookupEntry(factionTemplateId); FactionTemplateEntry const* u_entry = sFactionTemplateStore.LookupEntry(factionTemplateId);
if(!u_entry) if (!u_entry)
return &mNeutralAuctions; return &mNeutralAuctions;
else if(u_entry->ourMask & FACTION_MASK_ALLIANCE) else if (u_entry->ourMask & FACTION_MASK_ALLIANCE)
return &mAllianceAuctions; return &mAllianceAuctions;
else if(u_entry->ourMask & FACTION_MASK_HORDE) else if (u_entry->ourMask & FACTION_MASK_HORDE)
return &mHordeAuctions; return &mHordeAuctions;
else else
return &mNeutralAuctions; return &mNeutralAuctions;
@@ -67,60 +67,49 @@ AuctionHouseObject * AuctionHouseMgr::GetAuctionsMap( uint32 factionTemplateId )
uint32 AuctionHouseMgr::GetAuctionDeposit(AuctionHouseEntry const* entry, uint32 time, Item *pItem) uint32 AuctionHouseMgr::GetAuctionDeposit(AuctionHouseEntry const* entry, uint32 time, Item *pItem)
{ {
uint32 MSV = pItem->GetProto()->SellPrice; uint32 MSV = pItem->GetProto()->SellPrice;
double deposit; int32 deposit;
double faction_pct; uint32 timeHr = (((time / 60) / 60) / 12);
if (MSV > 0) if (MSV > 0)
{ {
if(sWorld.getConfig(CONFIG_ALLOW_TWO_SIDE_INTERACTION_AUCTION)) deposit = (int32)floor((double)MSV * (((double)(entry->depositPercent * 3) / 100.0f * (double)sWorld.getRate(RATE_AUCTION_DEPOSIT) * (double)pItem->GetCount()))) * timeHr;
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 );
} }
else else
{ {
faction_pct = 0.0f; deposit = 0;
deposit = 0.0f;
} }
sLog.outDebug("SellPrice:\t\t%u", MSV); 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 Time1:\t\t%u", time);
sLog.outDebug("Auction Time2:\t\t%u", MIN_AUCTION_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("Count:\t\t\t%u", pItem->GetCount());
sLog.outDebug("Deposit:\t\t%f", deposit);
if (deposit > 0) if (deposit > 0)
return (uint32)deposit; {
sLog.outDebug("Deposit:\t\t%u", deposit);
return deposit;
}
else else
{
sLog.outDebug("Deposit:\t\t0");
return 0; return 0;
}
} }
//does not clear ram //does not clear ram
void AuctionHouseMgr::SendAuctionWonMail( AuctionEntry *auction ) void AuctionHouseMgr::SendAuctionWonMail(AuctionEntry *auction)
{ {
Item *pItem = GetAItem(auction->item_guidlow); Item *pItem = GetAItem(auction->item_guidlow);
if(!pItem) if (!pItem)
return; return;
uint32 bidder_accId = 0;
uint32 bidder_security = 0;
uint64 bidder_guid = MAKE_NEW_GUID(auction->bidder, 0, HIGHGUID_PLAYER); uint64 bidder_guid = MAKE_NEW_GUID(auction->bidder, 0, HIGHGUID_PLAYER);
Player *bidder = objmgr.GetPlayer(bidder_guid); Player *bidder = objmgr.GetPlayer(bidder_guid);
uint32 bidder_accId = 0;
// data for gm.log // data for gm.log
if( sWorld.getConfig(CONFIG_GM_LOG_TRADE) ) if (sWorld.getConfig(CONFIG_GM_LOG_TRADE))
{ {
uint32 bidder_security = 0;
std::string bidder_name; std::string bidder_name;
if (bidder) if (bidder)
{ {
@@ -133,17 +122,16 @@ void AuctionHouseMgr::SendAuctionWonMail( AuctionEntry *auction )
bidder_accId = objmgr.GetPlayerAccountIdByGUID(bidder_guid); bidder_accId = objmgr.GetPlayerAccountIdByGUID(bidder_guid);
bidder_security = accmgr.GetSecurity(bidder_accId); bidder_security = accmgr.GetSecurity(bidder_accId);
if(bidder_security > SEC_PLAYER ) // not do redundant DB requests if (bidder_security > SEC_PLAYER) // not do redundant DB requests
{ {
if(!objmgr.GetPlayerNameByGUID(bidder_guid,bidder_name)) if (!objmgr.GetPlayerNameByGUID(bidder_guid,bidder_name))
bidder_name = objmgr.GetTrinityStringForDBCLocale(LANG_UNKNOWN); bidder_name = objmgr.GetTrinityStringForDBCLocale(LANG_UNKNOWN);
} }
} }
if (bidder_security > SEC_PLAYER)
if( bidder_security > SEC_PLAYER )
{ {
std::string owner_name; std::string owner_name;
if(!objmgr.GetPlayerNameByGUID(auction->owner,owner_name)) if (!objmgr.GetPlayerNameByGUID(auction->owner,owner_name))
owner_name = objmgr.GetTrinityStringForDBCLocale(LANG_UNKNOWN); owner_name = objmgr.GetTrinityStringForDBCLocale(LANG_UNKNOWN);
uint32 owner_accid = objmgr.GetPlayerAccountIdByGUID(auction->owner); uint32 owner_accid = objmgr.GetPlayerAccountIdByGUID(auction->owner);
@@ -152,11 +140,9 @@ 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); 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 // receiver exist
if(bidder || bidder_accId) if (bidder || bidder_accId)
{ {
std::ostringstream msgAuctionWonSubject; std::ostringstream msgAuctionWonSubject;
msgAuctionWonSubject << auction->item_template << ":0:" << AUCTION_WON; msgAuctionWonSubject << auction->item_template << ":0:" << AUCTION_WON;
@@ -165,10 +151,10 @@ void AuctionHouseMgr::SendAuctionWonMail( AuctionEntry *auction )
msgAuctionWonBody.width(16); msgAuctionWonBody.width(16);
msgAuctionWonBody << std::right << std::hex << auction->owner; msgAuctionWonBody << std::right << std::hex << auction->owner;
msgAuctionWonBody << std::dec << ":" << auction->bid << ":" << auction->buyout; msgAuctionWonBody << std::dec << ":" << auction->bid << ":" << auction->buyout;
sLog.outDebug( "AuctionWon body string : %s", msgAuctionWonBody.str().c_str() ); sLog.outDebug("AuctionWon body string : %s", msgAuctionWonBody.str().c_str());
//prepare mail data... : //prepare mail data... :
uint32 itemTextId = objmgr.CreateItemText( msgAuctionWonBody.str() ); uint32 itemTextId = objmgr.CreateItemText(msgAuctionWonBody.str());
// set owner to bidder (to prevent delete item with sender char deleting) // set owner to bidder (to prevent delete item with sender char deleting)
// owner in `data` will set at mail receive and item extracting // owner in `data` will set at mail receive and item extracting
@@ -179,29 +165,19 @@ void AuctionHouseMgr::SendAuctionWonMail( AuctionEntry *auction )
mi.AddItem(auction->item_guidlow, auction->item_template, pItem); mi.AddItem(auction->item_guidlow, auction->item_template, pItem);
if (bidder) if (bidder)
bidder->GetSession()->SendAuctionBidderNotification( auction->GetHouseId(), auction->Id, bidder_guid, 0, 0, auction->item_template); 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); 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 ) void AuctionHouseMgr::SendAuctionSalePendingMail(AuctionEntry * auction)
{ {
uint64 owner_guid = MAKE_NEW_GUID(auction->owner, 0, HIGHGUID_PLAYER); uint64 owner_guid = MAKE_NEW_GUID(auction->owner, 0, HIGHGUID_PLAYER);
Player *owner = objmgr.GetPlayer(owner_guid); Player *owner = objmgr.GetPlayer(owner_guid);
uint32 owner_accId = objmgr.GetPlayerAccountIdByGUID(owner_guid);
// owner exist (online or offline) // owner exist (online or offline)
if(owner || objmgr.GetPlayerAccountIdByGUID(owner_guid)) if (owner || owner_accId)
{ {
std::ostringstream msgAuctionSalePendingSubject; std::ostringstream msgAuctionSalePendingSubject;
msgAuctionSalePendingSubject << auction->item_template << ":0:" << AUCTION_SALE_PENDING; msgAuctionSalePendingSubject << auction->item_template << ":0:" << AUCTION_SALE_PENDING;
@@ -219,24 +195,20 @@ void AuctionHouseMgr::SendAuctionSalePendingMail( AuctionEntry * auction )
sLog.outDebug("AuctionSalePending body string : %s", msgAuctionSalePendingBody.str().c_str()); sLog.outDebug("AuctionSalePending body string : %s", msgAuctionSalePendingBody.str().c_str());
uint32 itemTextId = objmgr.CreateItemText( msgAuctionSalePendingBody.str() ); uint32 itemTextId = objmgr.CreateItemText(msgAuctionSalePendingBody.str());
WorldSession::SendMailTo(owner, MAIL_AUCTION, MAIL_STATIONERY_AUCTION, auction->GetHouseId(), auction->owner, msgAuctionSalePendingSubject.str(), itemTextId, NULL, 0, 0, MAIL_CHECK_MASK_AUCTION); WorldSession::SendMailTo(owner, MAIL_AUCTION, MAIL_STATIONERY_AUCTION, auction->GetHouseId(), auction->owner, msgAuctionSalePendingSubject.str(), itemTextId, NULL, 0, 0, MAIL_CHECK_MASK_AUCTION);
} }
} }
//call this method to send mail to auction owner, when auction is successful, it does not clear ram //call this method to send mail to auction owner, when auction is successful, it does not clear ram
void AuctionHouseMgr::SendAuctionSuccessfulMail( AuctionEntry * auction ) void AuctionHouseMgr::SendAuctionSuccessfulMail(AuctionEntry * auction)
{ {
uint64 owner_guid = MAKE_NEW_GUID(auction->owner, 0, HIGHGUID_PLAYER); uint64 owner_guid = MAKE_NEW_GUID(auction->owner, 0, HIGHGUID_PLAYER);
Player *owner = objmgr.GetPlayer(owner_guid); Player *owner = objmgr.GetPlayer(owner_guid);
uint32 owner_accId = objmgr.GetPlayerAccountIdByGUID(owner_guid);
uint32 owner_accId = 0;
if(!owner)
owner_accId = objmgr.GetPlayerAccountIdByGUID(owner_guid);
// owner exist // owner exist
if(owner || owner_accId) if (owner || owner_accId)
{ {
std::ostringstream msgAuctionSuccessfulSubject; std::ostringstream msgAuctionSuccessfulSubject;
msgAuctionSuccessfulSubject << auction->item_template << ":0:" << AUCTION_SUCCESSFUL; msgAuctionSuccessfulSubject << auction->item_template << ":0:" << AUCTION_SUCCESSFUL;
@@ -251,71 +223,53 @@ void AuctionHouseMgr::SendAuctionSuccessfulMail( AuctionEntry * auction )
sLog.outDebug("AuctionSuccessful body string : %s", auctionSuccessfulBody.str().c_str()); sLog.outDebug("AuctionSuccessful body string : %s", auctionSuccessfulBody.str().c_str());
uint32 itemTextId = objmgr.CreateItemText( auctionSuccessfulBody.str() ); uint32 itemTextId = objmgr.CreateItemText(auctionSuccessfulBody.str());
uint32 profit = auction->bid + auction->deposit - auctionCut; uint32 profit = auction->bid + auction->deposit - auctionCut;
if (owner)
{
//FIXME: what do if owner offline //FIXME: what do if owner offline
if (owner && owner->GetGUIDLow() != auctionbot.GetAHBplayerGUID())
{
owner->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_HIGHEST_AUCTION_SOLD, auction->bid); owner->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_HIGHEST_AUCTION_SOLD, auction->bid);
//send auction owner notification, bidder must be current! //send auction owner notification, bidder must be current!
owner->GetSession()->SendAuctionOwnerNotification( auction ); 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)); 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));
} }
} }
//does not clear ram //does not clear ram
void AuctionHouseMgr::SendAuctionExpiredMail( AuctionEntry * auction ) void AuctionHouseMgr::SendAuctionExpiredMail(AuctionEntry * auction)
{ //return an item in auction to its owner by mail { //return an item in auction to its owner by mail
Item *pItem = GetAItem(auction->item_guidlow); Item *pItem = GetAItem(auction->item_guidlow);
if(!pItem) if (!pItem)
{
sLog.outError("Auction item (GUID: %u) not found, and lost.",auction->item_guidlow);
return; return;
}
uint64 owner_guid = MAKE_NEW_GUID(auction->owner, 0, HIGHGUID_PLAYER); uint64 owner_guid = MAKE_NEW_GUID(auction->owner, 0, HIGHGUID_PLAYER);
Player *owner = objmgr.GetPlayer(owner_guid); Player *owner = objmgr.GetPlayer(owner_guid);
uint32 owner_accId = objmgr.GetPlayerAccountIdByGUID(owner_guid);
uint32 owner_accId = 0;
if(!owner)
owner_accId = objmgr.GetPlayerAccountIdByGUID(owner_guid);
// owner exist // owner exist
if(owner || owner_accId) if (owner || owner_accId)
{ {
std::ostringstream subject; std::ostringstream subject;
subject << auction->item_template << ":0:" << AUCTION_EXPIRED; subject << auction->item_template << ":0:" << AUCTION_EXPIRED;
if ( owner ) if (owner && owner->GetGUIDLow() != auctionbot.GetAHBplayerGUID())
owner->GetSession()->SendAuctionOwnerNotification( auction ); owner->GetSession()->SendAuctionOwnerNotification(auction);
else
RemoveAItem(pItem->GetGUIDLow()); // we have to remove the item, before we delete it !!
MailItemsInfo mi; MailItemsInfo mi;
mi.AddItem(auction->item_guidlow, auction->item_template, pItem); 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); 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() void AuctionHouseMgr::LoadAuctionItems()
{ {
// data needs to be at first place for Item::LoadFromDB // data needs to be at first place for Item::LoadFromDB
QueryResult *result = CharacterDatabase.Query( "SELECT data,itemguid,item_template FROM auctionhouse JOIN item_instance ON itemguid = guid" ); QueryResult *result = CharacterDatabase.Query("SELECT data,itemguid,item_template FROM auctionhouse JOIN item_instance ON itemguid = guid");
if( !result ) if (!result)
{ {
barGoLink bar(1); barGoLink bar(1);
bar.step(); bar.step();
@@ -324,7 +278,7 @@ void AuctionHouseMgr::LoadAuctionItems()
return; return;
} }
barGoLink bar( result->GetRowCount() ); barGoLink bar(result->GetRowCount());
uint32 count = 0; uint32 count = 0;
@@ -339,15 +293,15 @@ void AuctionHouseMgr::LoadAuctionItems()
ItemPrototype const *proto = objmgr.GetItemPrototype(item_template); ItemPrototype const *proto = objmgr.GetItemPrototype(item_template);
if(!proto) if (!proto)
{ {
sLog.outError( "ObjectMgr::LoadAuctionItems: Unknown item (GUID: %u id: #%u) in auction, skipped.", item_guid,item_template); sLog.outError("ObjectMgr::LoadAuctionItems: Unknown item (GUID: %u id: #%u) in auction, skipped.", item_guid,item_template);
continue; continue;
} }
Item *item = NewItemOrBag(proto); Item *item = NewItemOrBag(proto);
if(!item->LoadFromDB(item_guid,0, result)) if (!item->LoadFromDB(item_guid,0, result))
{ {
delete item; delete item;
continue; continue;
@@ -356,17 +310,17 @@ void AuctionHouseMgr::LoadAuctionItems()
++count; ++count;
} }
while( result->NextRow() ); while(result->NextRow());
delete result; delete result;
sLog.outString(); sLog.outString();
sLog.outString( ">> Loaded %u auction items", count ); sLog.outString(">> Loaded %u auction items", count);
} }
void AuctionHouseMgr::LoadAuctions() void AuctionHouseMgr::LoadAuctions()
{ {
QueryResult *result = CharacterDatabase.Query("SELECT COUNT(*) FROM auctionhouse"); QueryResult *result = CharacterDatabase.Query("SELECT COUNT(*) FROM auctionhouse");
if( !result ) if (!result)
{ {
barGoLink bar(1); barGoLink bar(1);
bar.step(); bar.step();
@@ -379,7 +333,7 @@ void AuctionHouseMgr::LoadAuctions()
uint32 AuctionCount=fields[0].GetUInt32(); uint32 AuctionCount=fields[0].GetUInt32();
delete result; delete result;
if(!AuctionCount) if (!AuctionCount)
{ {
barGoLink bar(1); barGoLink bar(1);
bar.step(); bar.step();
@@ -388,8 +342,8 @@ void AuctionHouseMgr::LoadAuctions()
return; return;
} }
result = CharacterDatabase.Query( "SELECT id,auctioneerguid,itemguid,item_template,itemowner,buyoutprice,time,buyguid,lastbid,startbid,deposit FROM auctionhouse" ); result = CharacterDatabase.Query("SELECT id,auctioneerguid,itemguid,item_template,itemowner,buyoutprice,time,buyguid,lastbid,startbid,deposit FROM auctionhouse");
if( !result ) if (!result)
{ {
barGoLink bar(1); barGoLink bar(1);
bar.step(); bar.step();
@@ -398,7 +352,7 @@ void AuctionHouseMgr::LoadAuctions()
return; return;
} }
barGoLink bar( AuctionCount ); barGoLink bar(AuctionCount);
AuctionEntry *aItem; AuctionEntry *aItem;
@@ -422,7 +376,7 @@ void AuctionHouseMgr::LoadAuctions()
aItem->deposit = fields[10].GetUInt32(); aItem->deposit = fields[10].GetUInt32();
CreatureData const* auctioneerData = objmgr.GetCreatureData(aItem->auctioneer); CreatureData const* auctioneerData = objmgr.GetCreatureData(aItem->auctioneer);
if(!auctioneerData) if (!auctioneerData)
{ {
aItem->DeleteFromDB(); aItem->DeleteFromDB();
sLog.outError("Auction %u has not a existing auctioneer (GUID : %u)", aItem->Id, aItem->auctioneer); sLog.outError("Auction %u has not a existing auctioneer (GUID : %u)", aItem->Id, aItem->auctioneer);
@@ -431,7 +385,7 @@ void AuctionHouseMgr::LoadAuctions()
} }
CreatureInfo const* auctioneerInfo = objmgr.GetCreatureTemplate(auctioneerData->id); CreatureInfo const* auctioneerInfo = objmgr.GetCreatureTemplate(auctioneerData->id);
if(!auctioneerInfo) if (!auctioneerInfo)
{ {
aItem->DeleteFromDB(); aItem->DeleteFromDB();
sLog.outError("Auction %u has not a existing auctioneer (GUID : %u Entry: %u)", aItem->Id, aItem->auctioneer,auctioneerData->id); sLog.outError("Auction %u has not a existing auctioneer (GUID : %u Entry: %u)", aItem->Id, aItem->auctioneer,auctioneerData->id);
@@ -440,7 +394,7 @@ void AuctionHouseMgr::LoadAuctions()
} }
aItem->auctionHouseEntry = AuctionHouseMgr::GetAuctionHouseEntry(auctioneerInfo->faction_A); aItem->auctionHouseEntry = AuctionHouseMgr::GetAuctionHouseEntry(auctioneerInfo->faction_A);
if(!aItem->auctionHouseEntry) if (!aItem->auctionHouseEntry)
{ {
aItem->DeleteFromDB(); aItem->DeleteFromDB();
sLog.outError("Auction %u has auctioneer (GUID : %u Entry: %u) with wrong faction %u", sLog.outError("Auction %u has auctioneer (GUID : %u Entry: %u) with wrong faction %u",
@@ -451,7 +405,7 @@ void AuctionHouseMgr::LoadAuctions()
// check if sold item exists for guid // check if sold item exists for guid
// and item_template in fact (GetAItem will fail if problematic in result check in ObjectMgr::LoadAuctionItems) // and item_template in fact (GetAItem will fail if problematic in result check in ObjectMgr::LoadAuctionItems)
if ( !GetAItem( aItem->item_guidlow ) ) if (!GetAItem(aItem->item_guidlow))
{ {
aItem->DeleteFromDB(); aItem->DeleteFromDB();
sLog.outError("Auction %u has not a existing item : %u", aItem->Id, aItem->item_guidlow); sLog.outError("Auction %u has not a existing item : %u", aItem->Id, aItem->item_guidlow);
@@ -459,23 +413,23 @@ void AuctionHouseMgr::LoadAuctions()
continue; continue;
} }
GetAuctionsMap( auctioneerInfo->faction_A )->AddAuction(aItem); GetAuctionsMap(auctioneerInfo->faction_A)->AddAuction(aItem);
} while (result->NextRow()); } while (result->NextRow());
delete result; delete result;
sLog.outString(); sLog.outString();
sLog.outString( ">> Loaded %u auctions", AuctionCount ); sLog.outString(">> Loaded %u auctions", AuctionCount);
} }
void AuctionHouseMgr::AddAItem( Item* it ) void AuctionHouseMgr::AddAItem(Item* it)
{ {
ASSERT( it ); ASSERT(it);
ASSERT( mAitems.find(it->GetGUIDLow()) == mAitems.end()); ASSERT(mAitems.find(it->GetGUIDLow()) == mAitems.end());
mAitems[it->GetGUIDLow()] = it; mAitems[it->GetGUIDLow()] = it;
} }
bool AuctionHouseMgr::RemoveAItem( uint32 id ) bool AuctionHouseMgr::RemoveAItem(uint32 id)
{ {
ItemMap::iterator i = mAitems.find(id); ItemMap::iterator i = mAitems.find(id);
if (i == mAitems.end()) if (i == mAitems.end())
@@ -497,7 +451,7 @@ AuctionHouseEntry const* AuctionHouseMgr::GetAuctionHouseEntry(uint32 factionTem
{ {
uint32 houseid = 7; // goblin auction house uint32 houseid = 7; // goblin auction house
if(!sWorld.getConfig(CONFIG_ALLOW_TWO_SIDE_INTERACTION_AUCTION)) if (!sWorld.getConfig(CONFIG_ALLOW_TWO_SIDE_INTERACTION_AUCTION))
{ {
//FIXME: found way for proper auctionhouse selection by another way //FIXME: found way for proper auctionhouse selection by another way
// AuctionHouse.dbc have faction field with _player_ factions associated with auction house races. // AuctionHouse.dbc have faction field with _player_ factions associated with auction house races.
@@ -517,11 +471,11 @@ AuctionHouseEntry const* AuctionHouseMgr::GetAuctionHouseEntry(uint32 factionTem
default: // for unknown case default: // for unknown case
{ {
FactionTemplateEntry const* u_entry = sFactionTemplateStore.LookupEntry(factionTemplateId); FactionTemplateEntry const* u_entry = sFactionTemplateStore.LookupEntry(factionTemplateId);
if(!u_entry) if (!u_entry)
houseid = 7; // goblin auction house houseid = 7; // goblin auction house
else if(u_entry->ourMask & FACTION_MASK_ALLIANCE) else if (u_entry->ourMask & FACTION_MASK_ALLIANCE)
houseid = 1; // human auction house houseid = 1; // human auction house
else if(u_entry->ourMask & FACTION_MASK_HORDE) else if (u_entry->ourMask & FACTION_MASK_HORDE)
houseid = 6; // orc auction house houseid = 6; // orc auction house
else else
houseid = 7; // goblin auction house houseid = 7; // goblin auction house
@@ -555,7 +509,7 @@ void AuctionHouseObject::Update()
///- Either cancel the auction if there was no bidder ///- Either cancel the auction if there was no bidder
if (itr->second->bidder == 0) if (itr->second->bidder == 0)
{ {
auctionmgr.SendAuctionExpiredMail( itr->second ); auctionmgr.SendAuctionExpiredMail(itr->second);
} }
///- Or perform the transaction ///- Or perform the transaction
else else
@@ -563,15 +517,15 @@ void AuctionHouseObject::Update()
//we should send an "item sold" message if the seller is online //we should send an "item sold" message if the seller is online
//we send the item to the winner //we send the item to the winner
//we send the money to the seller //we send the money to the seller
auctionmgr.SendAuctionSuccessfulMail( itr->second ); auctionmgr.SendAuctionSuccessfulMail(itr->second);
auctionmgr.SendAuctionWonMail( itr->second ); auctionmgr.SendAuctionWonMail(itr->second);
} }
///- In any case clear the auction ///- In any case clear the auction
itr->second->DeleteFromDB(); itr->second->DeleteFromDB();
uint32 item_template = itr->second->item_template;
auctionmgr.RemoveAItem(itr->second->item_guidlow); auctionmgr.RemoveAItem(itr->second->item_guidlow);
delete itr->second; RemoveAuction(itr->second, item_template);
RemoveAuction(itr->first);
} }
// only check 50 items per update to not peg the CPU // only check 50 items per update to not peg the CPU
@@ -587,7 +541,7 @@ void AuctionHouseObject::BuildListBidderItems(WorldPacket& data, Player* player,
for (AuctionEntryMap::const_iterator itr = AuctionsMap.begin();itr != AuctionsMap.end();++itr) for (AuctionEntryMap::const_iterator itr = AuctionsMap.begin();itr != AuctionsMap.end();++itr)
{ {
AuctionEntry *Aentry = itr->second; AuctionEntry *Aentry = itr->second;
if( Aentry && Aentry->bidder == player->GetGUIDLow() ) if (Aentry && Aentry->bidder == player->GetGUIDLow())
{ {
if (itr->second->BuildAuctionInfo(data)) if (itr->second->BuildAuctionInfo(data))
++count; ++count;
@@ -601,9 +555,9 @@ void AuctionHouseObject::BuildListOwnerItems(WorldPacket& data, Player* player,
for (AuctionEntryMap::const_iterator itr = AuctionsMap.begin();itr != AuctionsMap.end();++itr) for (AuctionEntryMap::const_iterator itr = AuctionsMap.begin();itr != AuctionsMap.end();++itr)
{ {
AuctionEntry *Aentry = itr->second; AuctionEntry *Aentry = itr->second;
if( Aentry && Aentry->owner == player->GetGUIDLow() ) if (Aentry && Aentry->owner == player->GetGUIDLow())
{ {
if(Aentry->BuildAuctionInfo(data)) if (Aentry->BuildAuctionInfo(data))
++count; ++count;
++totalcount; ++totalcount;
} }
@@ -641,15 +595,15 @@ void AuctionHouseObject::BuildListAuctionItems(WorldPacket& data, Player* player
if (levelmin != 0x00 && (proto->RequiredLevel < levelmin || (levelmax != 0x00 && proto->RequiredLevel > levelmax))) if (levelmin != 0x00 && (proto->RequiredLevel < levelmin || (levelmax != 0x00 && proto->RequiredLevel > levelmax)))
continue; continue;
if (usable != 0x00 && player->CanUseItem( item ) != EQUIP_ERR_OK) if (usable != 0x00 && player->CanUseItem(item) != EQUIP_ERR_OK)
continue; continue;
std::string name = proto->Name1; std::string name = proto->Name1;
if(name.empty()) if (name.empty())
continue; continue;
// local name // local name
if ( loc_idx >= 0 ) if (loc_idx >= 0)
{ {
ItemLocale const *il = objmgr.GetItemLocale(proto->ItemId); ItemLocale const *il = objmgr.GetItemLocale(proto->ItemId);
if (il) if (il)
@@ -659,7 +613,7 @@ void AuctionHouseObject::BuildListAuctionItems(WorldPacket& data, Player* player
} }
} }
if (!wsearchedname.empty() && !Utf8FitTo(name, wsearchedname) ) if (!wsearchedname.empty() && !Utf8FitTo(name, wsearchedname))
continue; continue;
if (count < 50 && totalcount >= listfrom) if (count < 50 && totalcount >= listfrom)
@@ -708,13 +662,17 @@ bool AuctionEntry::BuildAuctionInfo(WorldPacket & data) const
uint32 AuctionEntry::GetAuctionCut() 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 /// the sum of outbid is (1% from current bid)*5, if bid is very small, it is 1c
uint32 AuctionEntry::GetAuctionOutBid() const uint32 AuctionEntry::GetAuctionOutBid() const
{ {
uint32 outbid = (bid / 100) * 5; uint32 outbid = (uint32)((double)bid / 100.0f) * 5;
if (!outbid) if (!outbid)
outbid = 1; outbid = 1;
return outbid; return outbid;
+14 -9
View File
@@ -25,6 +25,8 @@
#include "SharedDefines.h" #include "SharedDefines.h"
#include "AuctionHouseBot.h"
class Item; class Item;
class Player; class Player;
class WorldPacket; class WorldPacket;
@@ -93,19 +95,21 @@ class AuctionHouseObject
void AddAuction(AuctionEntry *ah) void AddAuction(AuctionEntry *ah)
{ {
ASSERT( ah ); ASSERT(ah);
AuctionsMap[ah->Id] = ah; AuctionsMap[ah->Id] = ah;
auctionbot.IncrementItemCounts(ah);
} }
AuctionEntry* GetAuction(uint32 id) const AuctionEntry* GetAuction(uint32 id) const
{ {
AuctionEntryMap::const_iterator itr = AuctionsMap.find( id ); AuctionEntryMap::const_iterator itr = AuctionsMap.find(id);
return itr != AuctionsMap.end() ? itr->second : NULL; 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(); void Update();
@@ -132,7 +136,8 @@ class AuctionHouseMgr
typedef UNORDERED_MAP<uint32, Item*> ItemMap; typedef UNORDERED_MAP<uint32, Item*> ItemMap;
AuctionHouseObject* GetAuctionsMap( uint32 factionTemplateId ); AuctionHouseObject* GetAuctionsMap(uint32 factionTemplateId);
AuctionHouseObject* GetBidsMap(uint32 factionTemplateId);
Item* GetAItem(uint32 id) Item* GetAItem(uint32 id)
{ {
@@ -145,10 +150,10 @@ class AuctionHouseMgr
} }
//auction messages //auction messages
void SendAuctionWonMail( AuctionEntry * auction ); void SendAuctionWonMail(AuctionEntry * auction);
void SendAuctionSalePendingMail( AuctionEntry * auction ); void SendAuctionSalePendingMail(AuctionEntry * auction);
void SendAuctionSuccessfulMail( AuctionEntry * auction ); void SendAuctionSuccessfulMail(AuctionEntry * auction);
void SendAuctionExpiredMail( AuctionEntry * auction ); void SendAuctionExpiredMail(AuctionEntry * auction);
static uint32 GetAuctionDeposit(AuctionHouseEntry const* entry, uint32 time, Item *pItem); static uint32 GetAuctionDeposit(AuctionHouseEntry const* entry, uint32 time, Item *pItem);
static AuctionHouseEntry const* GetAuctionHouseEntry(uint32 factionTemplateId); static AuctionHouseEntry const* GetAuctionHouseEntry(uint32 factionTemplateId);
+306 -306
View File
File diff suppressed because it is too large Load Diff