OregonCore  revision fb2a440-git
Your Favourite TBC server
AuctionHouseObject Class Reference

#include <AuctionHouseMgr.h>

Public Types

typedef std::map< uint32, AuctionEntry * > AuctionEntryMap
 

Public Member Functions

 AuctionHouseObject ()
 
 ~AuctionHouseObject ()
 
uint32 Getcount ()
 
AuctionEntryMap::iterator GetAuctionsBegin ()
 
AuctionEntryMap::iterator GetAuctionsEnd ()
 
AuctionEntryGetAuction (uint32 id) const
 
void AddAuction (AuctionEntry *ah)
 
bool RemoveAuction (AuctionEntry *auction, uint32 item_template)
 
void Update ()
 
void BuildListBidderItems (WorldPacket &data, Player *player, uint32 &count, uint32 &totalcount)
 
void BuildListOwnerItems (WorldPacket &data, Player *player, uint32 &count, uint32 &totalcount)
 
void BuildListAuctionItems (WorldPacket &data, Player *player, std::wstring const &searchedname, uint32 listfrom, uint32 levelmin, uint32 levelmax, uint32 usable, uint32 inventoryType, uint32 itemClass, uint32 itemSubClass, uint32 quality, uint32 &count, uint32 &totalcount)
 

Private Attributes

AuctionEntryMap AuctionsMap
 
AuctionEntryMap::const_iterator next
 

Detailed Description

Definition at line 79 of file AuctionHouseMgr.h.

Member Typedef Documentation

Definition at line 93 of file AuctionHouseMgr.h.

Constructor & Destructor Documentation

AuctionHouseObject::AuctionHouseObject ( )
inline

Definition at line 83 of file AuctionHouseMgr.h.

84  {
85  next = AuctionsMap.begin();
86  }
AuctionEntryMap AuctionsMap
AuctionEntryMap::const_iterator next
AuctionHouseObject::~AuctionHouseObject ( )
inline

Definition at line 87 of file AuctionHouseMgr.h.

88  {
89  for (AuctionEntryMap::iterator itr = AuctionsMap.begin(); itr != AuctionsMap.end(); ++itr)
90  delete itr->second;
91  }
AuctionEntryMap AuctionsMap

Member Function Documentation

void AuctionHouseObject::AddAuction ( AuctionEntry ah)

Definition at line 493 of file AuctionHouseMgr.cpp.

References ASSERT, auctionbot, and AuctionEntry::Id.

Referenced by AuctionHouseBot::addNewAuctions(), and WorldSession::HandleAuctionSellItem().

494 {
495  ASSERT(ah);
496  AuctionsMap[ah->Id] = ah;
497  auctionbot.IncrementItemCounts(ah);
498 }
#define auctionbot
AuctionEntryMap AuctionsMap
#define ASSERT
Definition: Errors.h:29
void AuctionHouseObject::BuildListAuctionItems ( WorldPacket data,
Player player,
std::wstring const &  searchedname,
uint32  listfrom,
uint32  levelmin,
uint32  levelmax,
uint32  usable,
uint32  inventoryType,
uint32  itemClass,
uint32  itemSubClass,
uint32  quality,
uint32 count,
uint32 totalcount 
)

Definition at line 601 of file AuctionHouseMgr.cpp.

References AuctionEntry::BuildAuctionInfo(), Player::CanUseItem(), ItemTemplate::Class, EQUIP_ERR_OK, AuctionEntry::expire_time, Item::GetProto(), Player::GetSession(), WorldSession::GetSessionDbLocaleIndex(), Player::HasSpell(), ItemTemplate::InventoryType, ITEM_CLASS_RECIPE, AuctionEntry::item_guidlow, ItemTemplate::ItemId, ItemLocale::Name, ItemTemplate::Name1, ItemTemplate::Quality, ItemTemplate::RequiredLevel, sAuctionMgr, sObjectMgr, _Spell::SpellId, ItemTemplate::Spells, ItemTemplate::SubClass, sWorld, and Utf8FitTo().

Referenced by WorldSession::HandleAuctionListItems().

605 {
606  int loc_idx = player->GetSession()->GetSessionDbLocaleIndex();
607 
608  time_t curTime = sWorld.GetGameTime();
609 
610  for (AuctionEntryMap::const_iterator itr = AuctionsMap.begin(); itr != AuctionsMap.end(); ++itr)
611  {
612  AuctionEntry* Aentry = itr->second;
613  // Skip expired auctions
614  if (Aentry->expire_time < curTime)
615  continue;
616 
617  Item* item = sAuctionMgr->GetAItem(Aentry->item_guidlow);
618  if (!item)
619  continue;
620 
621  ItemTemplate const* proto = item->GetProto();
622 
623  if (itemClass != 0xffffffff && proto->Class != itemClass)
624  continue;
625 
626  if (itemSubClass != 0xffffffff && proto->SubClass != itemSubClass)
627  continue;
628 
629  if (inventoryType != 0xffffffff && proto->InventoryType != inventoryType)
630  continue;
631 
632  if (quality != 0xffffffff && proto->Quality < quality)
633  continue;
634 
635  if (levelmin != 0x00 && (proto->RequiredLevel < levelmin || (levelmax != 0x00 && proto->RequiredLevel > levelmax)))
636  continue;
637 
638  if (usable != 0x00)
639  {
640  if (player->CanUseItem(item) != EQUIP_ERR_OK)
641  continue;
642 
643  if (proto->Class == ITEM_CLASS_RECIPE)
644  if (player->HasSpell(proto->Spells[1].SpellId))
645  continue;
646  }
647 
648  std::string name = proto->Name1;
649  if (name.empty())
650  continue;
651 
652  // local name
653  if (loc_idx >= 0)
654  {
655  ItemLocale const* il = sObjectMgr.GetItemLocale(proto->ItemId);
656  if (il)
657  {
658  if (il->Name.size() > size_t(loc_idx) && !il->Name[loc_idx].empty())
659  name = il->Name[loc_idx];
660  }
661  }
662 
663  if (!wsearchedname.empty() && !Utf8FitTo(name, wsearchedname))
664  continue;
665 
666  if (count < 50 && totalcount >= listfrom)
667  {
668  ++count;
669  Aentry->BuildAuctionInfo(data);
670  }
671  ++totalcount;
672  }
673 }
bool Utf8FitTo(const std::string &str, std::wstring search)
Definition: Util.cpp:419
ItemTemplate const * GetProto() const
Definition: Item.cpp:460
uint32 InventoryType
bool BuildAuctionInfo(WorldPacket &data) const
uint32 item_guidlow
std::vector< std::string > Name
_Spell Spells[5]
uint32 SpellId
#define sObjectMgr
Definition: ObjectMgr.h:1285
bool HasSpell(uint32 spell) const override
Definition: Player.cpp:3755
AuctionEntryMap AuctionsMap
Definition: Item.h:196
uint32 RequiredLevel
time_t expire_time
int GetSessionDbLocaleIndex() const
Definition: WorldSession.h:237
#define sAuctionMgr
WorldSession * GetSession() const
Definition: Player.h:1944
#define sWorld
Definition: World.h:860
uint8 CanUseItem(Item *pItem, bool not_loading=true) const
Definition: Player.cpp:10072
void AuctionHouseObject::BuildListBidderItems ( WorldPacket data,
Player player,
uint32 count,
uint32 totalcount 
)

Definition at line 572 of file AuctionHouseMgr.cpp.

References AuctionEntry::bidder, and Object::GetGUIDLow().

Referenced by WorldSession::HandleAuctionListBidderItems().

573 {
574  for (AuctionEntryMap::const_iterator itr = AuctionsMap.begin(); itr != AuctionsMap.end(); ++itr)
575  {
576  AuctionEntry* Aentry = itr->second;
577  if (Aentry && Aentry->bidder == player->GetGUIDLow())
578  {
579  if (itr->second->BuildAuctionInfo(data))
580  ++count;
581 
582  ++totalcount;
583  }
584  }
585 }
uint32 GetGUIDLow() const
Definition: Object.h:166
AuctionEntryMap AuctionsMap
void AuctionHouseObject::BuildListOwnerItems ( WorldPacket data,
Player player,
uint32 count,
uint32 totalcount 
)

Definition at line 587 of file AuctionHouseMgr.cpp.

References AuctionEntry::BuildAuctionInfo(), Object::GetGUIDLow(), and AuctionEntry::owner.

Referenced by WorldSession::HandleAuctionListOwnerItems().

588 {
589  for (AuctionEntryMap::const_iterator itr = AuctionsMap.begin(); itr != AuctionsMap.end(); ++itr)
590  {
591  AuctionEntry* Aentry = itr->second;
592  if (Aentry && Aentry->owner == player->GetGUIDLow())
593  {
594  if (Aentry->BuildAuctionInfo(data))
595  ++count;
596  ++totalcount;
597  }
598  }
599 }
bool BuildAuctionInfo(WorldPacket &data) const
uint32 GetGUIDLow() const
Definition: Object.h:166
AuctionEntryMap AuctionsMap
AuctionEntry* AuctionHouseObject::GetAuction ( uint32  id) const
inline

Definition at line 109 of file AuctionHouseMgr.h.

References AuctionEntry::item_template.

Referenced by AuctionHouseBot::addNewAuctionBuyerBotBid(), WorldSession::HandleAuctionListBidderItems(), WorldSession::HandleAuctionPlaceBid(), and WorldSession::HandleAuctionRemoveItem().

110  {
111  AuctionEntryMap::const_iterator itr = AuctionsMap.find(id);
112  return itr != AuctionsMap.end() ? itr->second : NULL;
113  }
AuctionEntryMap AuctionsMap
AuctionEntryMap::iterator AuctionHouseObject::GetAuctionsBegin ( )
inline

Definition at line 100 of file AuctionHouseMgr.h.

Referenced by AuctionHouseBot::Commands(), and AuctionHouseBot::LoadValues().

101  {
102  return AuctionsMap.begin();
103  }
AuctionEntryMap AuctionsMap
AuctionEntryMap::iterator AuctionHouseObject::GetAuctionsEnd ( )
inline

Definition at line 104 of file AuctionHouseMgr.h.

Referenced by AuctionHouseBot::Commands(), and AuctionHouseBot::LoadValues().

105  {
106  return AuctionsMap.end();
107  }
AuctionEntryMap AuctionsMap
uint32 AuctionHouseObject::Getcount ( )
inline

Definition at line 95 of file AuctionHouseMgr.h.

Referenced by AuctionHouseBot::addNewAuctions(), and AuctionHouseBot::LoadValues().

96  {
97  return AuctionsMap.size();
98  }
AuctionEntryMap AuctionsMap
bool AuctionHouseObject::RemoveAuction ( AuctionEntry auction,
uint32  item_template 
)

Definition at line 500 of file AuctionHouseMgr.cpp.

References auctionbot, and AuctionEntry::Id.

Referenced by AuctionHouseBot::addNewAuctionBuyerBotBid(), WorldSession::HandleAuctionPlaceBid(), and WorldSession::HandleAuctionRemoveItem().

501 {
502  auctionbot.DecrementItemCounts(auction, item_template);
503  bool wasInMap = AuctionsMap.erase(auction->Id) ? true : false;
504 
505  // we need to delete the entry, it is not referenced any more
506  delete auction;
507  return wasInMap;
508 }
#define auctionbot
AuctionEntryMap AuctionsMap
void AuctionHouseObject::Update ( )
  • Either cancel the auction if there was no bidder
  • Or perform the transaction
  • In any case clear the auction

Definition at line 510 of file AuctionHouseMgr.cpp.

References Database::BeginTransaction(), AuctionEntry::bidder, CharacterDatabase, Database::CommitTransaction(), AuctionEntry::DeleteFromDB(), AuctionEntry::item_guidlow, AuctionEntry::item_template, Database::PQuery(), sAuctionMgr, and sWorld.

511 {
512  time_t curTime = sWorld.GetGameTime();
513  // Handle expired auctions
514 
515  // If storage is empty, no need to update. next == NULL in this case.
516  if (AuctionsMap.empty())
517  return;
518 
519  QueryResult_AutoPtr result = CharacterDatabase.PQuery("SELECT id FROM auctionhouse WHERE time <= %u ORDER BY TIME ASC", (uint32)curTime + 60);
520 
521  if (!result)
522  return;
523 
524  if (result->GetRowCount() == 0)
525  return;
526 
527  vector<uint32> expiredAuctions;
528 
529  do
530  {
531  uint32 tmpdata = result->Fetch()->GetUInt32();
532  expiredAuctions.push_back(tmpdata);
533  }
534  while (result->NextRow());
535 
536  while (!expiredAuctions.empty())
537  {
538  vector<uint32>::iterator iter = expiredAuctions.begin();
539 
540  // from auctionhousehandler.cpp, creates auction pointer & player pointer
541  AuctionEntry* auction = GetAuction(*iter);
542 
543  // Erase the auction from the vector.
544  expiredAuctions.erase(iter);
545 
546  if (!auction)
547  continue;
548 
550  if (auction->bidder == 0)
551  sAuctionMgr->SendAuctionExpiredMail(auction);
553  else
554  {
555  //we should send an "item sold" message if the seller is online
556  //we send the item to the winner
557  //we send the money to the seller
558  sAuctionMgr->SendAuctionSuccessfulMail(auction);
559  sAuctionMgr->SendAuctionWonMail(auction);
560  }
561 
564  auction->DeleteFromDB();
565  uint32 item_template = auction->item_template;
566  sAuctionMgr->RemoveAItem(auction->item_guidlow);
567  RemoveAuction(auction, item_template);
569  }
570 }
uint32 item_guidlow
bool BeginTransaction()
Definition: Database.cpp:533
QueryResult_AutoPtr PQuery(const char *format,...) ATTR_PRINTF(2
Definition: Database.cpp:400
AuctionEntry * GetAuction(uint32 id) const
void DeleteFromDB() const
bool CommitTransaction()
Definition: Database.cpp:551
AuctionEntryMap AuctionsMap
uint32 item_template
ACE_Refcounted_Auto_Ptr< QueryResult, ACE_Null_Mutex > QueryResult_AutoPtr
Definition: QueryResult.h:113
#define sAuctionMgr
bool RemoveAuction(AuctionEntry *auction, uint32 item_template)
#define sWorld
Definition: World.h:860
DatabaseType CharacterDatabase
Accessor to the character database.
Definition: Main.cpp:54
ACE_UINT32 uint32
Definition: Define.h:71

Member Data Documentation

AuctionEntryMap AuctionHouseObject::AuctionsMap
private

Definition at line 129 of file AuctionHouseMgr.h.

AuctionEntryMap::const_iterator AuctionHouseObject::next
private

Definition at line 132 of file AuctionHouseMgr.h.


The documentation for this class was generated from the following files: