TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
AuctionHouseObject Class Reference

#include <AuctionHouseMgr.h>

Public Types

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

Public Member Functions

 ~AuctionHouseObject ()
 
uint32 Getcount () const
 
AuctionEntryMap::iterator GetAuctionsBegin ()
 
AuctionEntryMap::iterator GetAuctionsEnd ()
 
AuctionEntryGetAuction (uint32 id) const
 
void AddAuction (AuctionEntry *auction)
 
bool RemoveAuction (AuctionEntry *auction)
 
void Update ()
 
void BuildListBidderItems (WorldPackets::AuctionHouse::AuctionListBidderItemsResult &packet, Player *player, uint32 &totalcount)
 
void BuildListOwnerItems (WorldPackets::AuctionHouse::AuctionListOwnerItemsResult &packet, Player *player, uint32 &totalcount)
 
void BuildListAuctionItems (WorldPackets::AuctionHouse::AuctionListItemsResult &packet, Player *player, std::wstring const &searchedname, uint32 listfrom, uint8 levelmin, uint8 levelmax, uint8 usable, uint32 inventoryType, uint32 itemClass, uint32 itemSubClass, uint32 quality, uint32 &totalcount)
 

Private Attributes

AuctionEntryMap AuctionsMap
 

Member Typedef Documentation

Constructor & Destructor Documentation

AuctionHouseObject::~AuctionHouseObject ( )
inline
104  {
105  for (AuctionEntryMap::iterator itr = AuctionsMap.begin(); itr != AuctionsMap.end(); ++itr)
106  delete itr->second;
107  }
AuctionEntryMap AuctionsMap
Definition: AuctionHouseMgr.h:135

Member Function Documentation

void AuctionHouseObject::AddAuction ( AuctionEntry auction)
557 {
558  ASSERT(auction);
559 
560  AuctionsMap[auction->Id] = auction;
561  sScriptMgr->OnAuctionAdd(this, auction);
562 }
uint32 Id
Definition: AuctionHouseMgr.h:69
AuctionEntryMap AuctionsMap
Definition: AuctionHouseMgr.h:135
#define ASSERT
Definition: Errors.h:55
#define sScriptMgr
Definition: ScriptMgr.h:837

+ Here is the caller graph for this function:

void AuctionHouseObject::BuildListAuctionItems ( WorldPackets::AuctionHouse::AuctionListItemsResult packet,
Player player,
std::wstring const searchedname,
uint32  listfrom,
uint8  levelmin,
uint8  levelmax,
uint8  usable,
uint32  inventoryType,
uint32  itemClass,
uint32  itemSubClass,
uint32  quality,
uint32 totalcount 
)
654 {
655  time_t curTime = sWorld->GetGameTime();
656 
657  for (AuctionEntryMap::const_iterator itr = AuctionsMap.begin(); itr != AuctionsMap.end(); ++itr)
658  {
659  AuctionEntry* Aentry = itr->second;
660  // Skip expired auctions
661  if (Aentry->expire_time < curTime)
662  continue;
663 
664  Item* item = sAuctionMgr->GetAItem(Aentry->itemGUIDLow);
665  if (!item)
666  continue;
667 
668  ItemTemplate const* proto = item->GetTemplate();
669 
670  if (itemClass != 0xffffffff && proto->GetClass() != itemClass)
671  continue;
672 
673  if (itemSubClass != 0xffffffff && proto->GetSubClass() != itemSubClass)
674  continue;
675 
676  if (inventoryType != 0xffffffff && proto->GetInventoryType() != InventoryType(inventoryType))
677  continue;
678 
679  if (quality != 0xffffffff && proto->GetQuality() != quality)
680  continue;
681 
682  if (levelmin != 0 && (proto->GetBaseRequiredLevel() < levelmin || (levelmax != 0 && proto->GetBaseRequiredLevel() > levelmax)))
683  continue;
684 
685  if (usable != 0 && player->CanUseItem(item) != EQUIP_ERR_OK)
686  continue;
687 
688  // Allow search by suffix (ie: of the Monkey) or partial name (ie: Monkey)
689  // No need to do any of this if no search term was entered
690  if (!wsearchedname.empty())
691  {
692  std::string name = proto->GetName(player->GetSession()->GetSessionDbcLocale());
693  if (name.empty())
694  continue;
695 
696  // DO NOT use GetItemEnchantMod(proto->RandomProperty) as it may return a result
697  // that matches the search but it may not equal item->GetItemRandomPropertyId()
698  // used in BuildAuctionInfo() which then causes wrong items to be listed
699  int32 propRefID = item->GetItemRandomPropertyId();
700 
701  if (propRefID)
702  {
703  // Append the suffix to the name (ie: of the Monkey) if one exists
704  // These are found in ItemRandomSuffix.dbc and ItemRandomProperties.dbc
705  // even though the DBC names seem misleading
706 
707  const char* suffix = nullptr;
708 
709  if (propRefID < 0)
710  {
711  const ItemRandomSuffixEntry* itemRandSuffix = sItemRandomSuffixStore.LookupEntry(-propRefID);
712  if (itemRandSuffix)
713  suffix = itemRandSuffix->Name->Str[player->GetSession()->GetSessionDbcLocale()];
714  }
715  else
716  {
717  const ItemRandomPropertiesEntry* itemRandProp = sItemRandomPropertiesStore.LookupEntry(propRefID);
718  if (itemRandProp)
719  suffix = itemRandProp->Name->Str[player->GetSession()->GetSessionDbcLocale()];
720  }
721 
722  // dbc local name
723  if (suffix)
724  {
725  // Append the suffix (ie: of the Monkey) to the name using localization
726  // or default enUS if localization is invalid
727  name += ' ';
728  name += suffix;
729  }
730  }
731 
732  // Perform the search (with or without suffix)
733  if (!Utf8FitTo(name, wsearchedname))
734  continue;
735  }
736 
737  // Add the item if no search term or if entered search term was found
738  if (packet.Items.size() < 50 && totalcount >= listfrom)
739  Aentry->BuildAuctionInfo(packet.Items, true);
740 
741  ++totalcount;
742  }
743 }
DB2Storage< ItemRandomSuffixEntry > sItemRandomSuffixStore("ItemRandomSuffix.db2", ItemRandomSuffixFormat, HOTFIX_SEL_ITEM_RANDOM_SUFFIX)
ObjectGuid::LowType itemGUIDLow
Definition: AuctionHouseMgr.h:71
Definition: AuctionHouseMgr.h:67
LocalizedString * Name
Definition: DB2Structure.h:776
uint32 GetClass() const
Definition: ItemTemplate.h:653
#define sWorld
Definition: World.h:887
int32 GetItemRandomPropertyId() const
Definition: Item.h:342
void BuildAuctionInfo(std::vector< WorldPackets::AuctionHouse::AuctionItem > &items, bool listAuctionItems) const
Definition: AuctionHouseMgr.cpp:746
InventoryType
Definition: ItemTemplate.h:330
std::vector< AuctionItem > Items
Definition: AuctionHousePackets.h:212
InventoryType GetInventoryType() const
Definition: ItemTemplate.h:664
LocalizedString * Name
Definition: DB2Structure.h:782
char const * Str[TOTAL_LOCALES]
Definition: Common.h:148
Definition: Item.h:48
AuctionEntryMap AuctionsMap
Definition: AuctionHouseMgr.h:135
bool Utf8FitTo(const std::string &str, std::wstring const &search)
Definition: Util.cpp:453
Definition: Item.h:259
int32_t int32
Definition: Define.h:146
char const * GetName(LocaleConstant locale) const
Definition: ItemTemplate.cpp:25
Definition: DB2Structure.h:779
time_t expire_time
Definition: AuctionHouseMgr.h:78
Definition: ItemTemplate.h:647
DB2Storage< ItemRandomPropertiesEntry > sItemRandomPropertiesStore("ItemRandomProperties.db2", ItemRandomPropertiesFormat, HOTFIX_SEL_ITEM_RANDOM_PROPERTIES)
uint32 GetSubClass() const
Definition: ItemTemplate.h:654
#define sAuctionMgr
Definition: AuctionHouseMgr.h:199
int32 GetBaseRequiredLevel() const
Definition: ItemTemplate.h:668
Definition: DB2Structure.h:771
ItemTemplate const * GetTemplate() const
Definition: Item.cpp:547
uint32 GetQuality() const
Definition: ItemTemplate.h:655

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void AuctionHouseObject::BuildListBidderItems ( WorldPackets::AuctionHouse::AuctionListBidderItemsResult packet,
Player player,
uint32 totalcount 
)
626 {
627  for (AuctionEntryMap::const_iterator itr = AuctionsMap.begin(); itr != AuctionsMap.end(); ++itr)
628  {
629  AuctionEntry* Aentry = itr->second;
630  if (Aentry && Aentry->bidder == player->GetGUID().GetCounter())
631  {
632  itr->second->BuildAuctionInfo(packet.Items, false);
633  ++totalcount;
634  }
635  }
636 }
Definition: AuctionHouseMgr.h:67
void BuildAuctionInfo(std::vector< WorldPackets::AuctionHouse::AuctionItem > &items, bool listAuctionItems) const
Definition: AuctionHouseMgr.cpp:746
AuctionEntryMap AuctionsMap
Definition: AuctionHouseMgr.h:135
std::vector< AuctionItem > Items
Definition: AuctionHousePackets.h:238
ObjectGuid::LowType bidder
Definition: AuctionHouseMgr.h:79

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void AuctionHouseObject::BuildListOwnerItems ( WorldPackets::AuctionHouse::AuctionListOwnerItemsResult packet,
Player player,
uint32 totalcount 
)
639 {
640  for (AuctionEntryMap::const_iterator itr = AuctionsMap.begin(); itr != AuctionsMap.end(); ++itr)
641  {
642  AuctionEntry* Aentry = itr->second;
643  if (Aentry && Aentry->owner == player->GetGUID().GetCounter())
644  {
645  Aentry->BuildAuctionInfo(packet.Items, false);
646  ++totalcount;
647  }
648  }
649 }
Definition: AuctionHouseMgr.h:67
void BuildAuctionInfo(std::vector< WorldPackets::AuctionHouse::AuctionItem > &items, bool listAuctionItems) const
Definition: AuctionHouseMgr.cpp:746
std::vector< AuctionItem > Items
Definition: AuctionHousePackets.h:226
AuctionEntryMap AuctionsMap
Definition: AuctionHouseMgr.h:135
ObjectGuid::LowType owner
Definition: AuctionHouseMgr.h:74

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

AuctionEntry* AuctionHouseObject::GetAuction ( uint32  id) const
inline
117  {
118  AuctionEntryMap::const_iterator itr = AuctionsMap.find(id);
119  return itr != AuctionsMap.end() ? itr->second : NULL;
120  }
arena_t NULL
Definition: jemalloc_internal.h:624
AuctionEntryMap AuctionsMap
Definition: AuctionHouseMgr.h:135

+ Here is the caller graph for this function:

AuctionEntryMap::iterator AuctionHouseObject::GetAuctionsBegin ( )
inline
113 {return AuctionsMap.begin();}
AuctionEntryMap AuctionsMap
Definition: AuctionHouseMgr.h:135

+ Here is the caller graph for this function:

AuctionEntryMap::iterator AuctionHouseObject::GetAuctionsEnd ( )
inline
114 {return AuctionsMap.end();}
AuctionEntryMap AuctionsMap
Definition: AuctionHouseMgr.h:135

+ Here is the caller graph for this function:

uint32 AuctionHouseObject::Getcount ( ) const
inline
111 { return uint32(AuctionsMap.size()); }
AuctionEntryMap AuctionsMap
Definition: AuctionHouseMgr.h:135
uint32_t uint32
Definition: g3dmath.h:168
bool AuctionHouseObject::RemoveAuction ( AuctionEntry auction)
565 {
566  bool wasInMap = AuctionsMap.erase(auction->Id) ? true : false;
567 
568  sScriptMgr->OnAuctionRemove(this, auction);
569 
570  // we need to delete the entry, it is not referenced any more
571  delete auction;
572  return wasInMap;
573 }
uint32 Id
Definition: AuctionHouseMgr.h:69
AuctionEntryMap AuctionsMap
Definition: AuctionHouseMgr.h:135
#define sScriptMgr
Definition: ScriptMgr.h:837

+ Here is the caller graph for this function:

void AuctionHouseObject::Update ( )
  • Handle expired auctions
  • filter auctions expired on next update
  • Either cancel the auction if there was no bidder
  • Or perform the transaction
  • In any case clear the auction
576 {
577  time_t curTime = sWorld->GetGameTime();
579 
580  // If storage is empty, no need to update. next == NULL in this case.
581  if (AuctionsMap.empty())
582  return;
583 
585 
586  for (AuctionEntryMap::iterator it = AuctionsMap.begin(); it != AuctionsMap.end();)
587  {
588  // from auctionhousehandler.cpp, creates auction pointer & player pointer
589  AuctionEntry* auction = it->second;
590  // Increment iterator due to AuctionEntry deletion
591  ++it;
592 
594  if (auction->expire_time > curTime + 60)
595  continue;
596 
598  if (auction->bidder == 0 && auction->bid == 0)
599  {
600  sAuctionMgr->SendAuctionExpiredMail(auction, trans);
601  sScriptMgr->OnAuctionExpire(this, auction);
602  }
604  else
605  {
606  //we should send an "item sold" message if the seller is online
607  //we send the item to the winner
608  //we send the money to the seller
609  sAuctionMgr->SendAuctionSuccessfulMail(auction, trans);
610  sAuctionMgr->SendAuctionWonMail(auction, trans);
611  sScriptMgr->OnAuctionSuccessful(this, auction);
612  }
613 
615  auction->DeleteFromDB(trans);
616 
617  sAuctionMgr->RemoveAItem(auction->itemGUIDLow);
618  RemoveAuction(auction);
619  }
620 
621  // Run DB changes
623 }
bool RemoveAuction(AuctionEntry *auction)
Definition: AuctionHouseMgr.cpp:564
ObjectGuid::LowType itemGUIDLow
Definition: AuctionHouseMgr.h:71
SQLTransaction BeginTransaction()
Begins an automanaged transaction pointer that will automatically rollback if not commited...
Definition: DatabaseWorkerPool.h:221
Definition: AuctionHouseMgr.h:67
void DeleteFromDB(SQLTransaction &trans) const
Definition: AuctionHouseMgr.cpp:800
#define sWorld
Definition: World.h:887
void CommitTransaction(SQLTransaction transaction)
Definition: DatabaseWorkerPool.cpp:179
AuctionEntryMap AuctionsMap
Definition: AuctionHouseMgr.h:135
uint32 bid
Definition: AuctionHouseMgr.h:76
time_t expire_time
Definition: AuctionHouseMgr.h:78
ObjectGuid::LowType bidder
Definition: AuctionHouseMgr.h:79
#define sAuctionMgr
Definition: AuctionHouseMgr.h:199
CharacterDatabaseWorkerPool CharacterDatabase
Accessor to the character database.
Definition: DatabaseEnv.cpp:21
#define sScriptMgr
Definition: ScriptMgr.h:837
std::shared_ptr< Transaction > SQLTransaction
Definition: Transaction.h:58

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Member Data Documentation

AuctionEntryMap AuctionHouseObject::AuctionsMap
private

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