AzerothCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
AuctionHouseObject Class Reference

#include "AuctionHouseMgr.h"

Public Types

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

Public Member Functions

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

Private Attributes

AuctionEntryMap _auctionsMap
 
AuctionEntryMap::const_iterator _next
 

Detailed Description

Member Typedef Documentation

◆ AuctionEntryMap

Constructor & Destructor Documentation

◆ AuctionHouseObject()

AuctionHouseObject::AuctionHouseObject ( )
inline
133{ _next = _auctionsMap.begin(); }
AuctionEntryMap _auctionsMap
Definition: AuctionHouseMgr.h:168
AuctionEntryMap::const_iterator _next
Definition: AuctionHouseMgr.h:171

References _auctionsMap, and _next.

◆ ~AuctionHouseObject()

AuctionHouseObject::~AuctionHouseObject ( )
inline
135 {
136 for (auto& itr : _auctionsMap)
137 delete itr.second;
138 }

References _auctionsMap.

Member Function Documentation

◆ AddAuction()

void AuctionHouseObject::AddAuction ( AuctionEntry auction)
638{
639 ASSERT(auction);
640
641 _auctionsMap[auction->Id] = auction;
642 sScriptMgr->OnAuctionAdd(this, auction);
643}
#define ASSERT
Definition: Errors.h:68
#define sScriptMgr
Definition: ScriptMgr.h:708
uint32 Id
Definition: AuctionHouseMgr.h:102

References _auctionsMap, ASSERT, AuctionEntry::Id, and sScriptMgr.

Referenced by WorldSession::HandleAuctionSellItem(), and AuctionHouseMgr::LoadAuctions().

◆ BuildListAuctionItems()

bool AuctionHouseObject::BuildListAuctionItems ( WorldPacket data,
Player player,
std::wstring const &  searchedname,
uint32  listfrom,
uint8  levelmin,
uint8  levelmax,
uint8  usable,
uint32  inventoryType,
uint32  itemClass,
uint32  itemSubClass,
uint32  quality,
uint32 count,
uint32 totalcount,
uint8  getAll,
AuctionSortOrderVector const &  sortOrder,
Milliseconds  searchTimeout 
)
737{
738 uint32 itrcounter = 0;
739
740 // Ensures that listfrom is not greater that auctions count
741 listfrom = std::min(listfrom, static_cast<uint32>(GetAuctions().size()));
742
743 std::vector<AuctionEntry*> auctionShortlist;
744
745 // pussywizard: optimization, this is a simplified case
746 if (itemClass == 0xffffffff && itemSubClass == 0xffffffff && inventoryType == 0xffffffff && quality == 0xffffffff && levelmin == 0x00 && levelmax == 0x00 && usable == 0x00 && wsearchedname.empty())
747 {
748 auto itr = GetAuctionsBegin();
749 for (; itr != GetAuctionsEnd(); ++itr)
750 {
751 auctionShortlist.push_back(itr->second);
752 }
753 }
754 else
755 {
756 auto curTime = GameTime::GetGameTime();
757
758 int loc_idx = player->GetSession()->GetSessionDbLocaleIndex();
759 int locdbc_idx = player->GetSession()->GetSessionDbcLocale();
760
761 for (AuctionEntryMap::const_iterator itr = _auctionsMap.begin(); itr != _auctionsMap.end(); ++itr)
762 {
763 if ((itrcounter++) % 100 == 0) // check condition every 100 iterations
764 {
765 if (GetMSTimeDiff(GameTime::GetGameTimeMS(), GetTimeMS()) >= searchTimeout) // pussywizard: stop immediately if diff is high or waiting too long
766 {
767 return false;
768 }
769 }
770
771 AuctionEntry* Aentry = itr->second;
772 if (!Aentry)
773 return false;
774
775 // Skip expired auctions
776 if (Aentry->expire_time < curTime.count())
777 {
778 continue;
779 }
780
781 Item* item = sAuctionMgr->GetAItem(Aentry->item_guid);
782 if (!item)
783 {
784 continue;
785 }
786
787 ItemTemplate const* proto = item->GetTemplate();
788 if (itemClass != 0xffffffff && proto->Class != itemClass)
789 {
790 continue;
791 }
792
793 if (itemSubClass != 0xffffffff && proto->SubClass != itemSubClass)
794 {
795 continue;
796 }
797
798 if (inventoryType != 0xffffffff && proto->InventoryType != inventoryType)
799 {
800 // xinef: exception, robes are counted as chests
801 if (inventoryType != INVTYPE_CHEST || proto->InventoryType != INVTYPE_ROBE)
802 {
803 continue;
804 }
805 }
806
807 if (quality != 0xffffffff && proto->Quality < quality)
808 {
809 continue;
810 }
811
812 if (levelmin != 0x00 && (proto->RequiredLevel < levelmin || (levelmax != 0x00 && proto->RequiredLevel > levelmax)))
813 {
814 continue;
815 }
816
817 if (usable != 0x00)
818 {
819 if (player->CanUseItem(item) != EQUIP_ERR_OK)
820 {
821 continue;
822 }
823
824 // xinef: check already learded recipes and pets
825 if (proto->Spells[1].SpellTrigger == ITEM_SPELLTRIGGER_LEARN_SPELL_ID && player->HasSpell(proto->Spells[1].SpellId))
826 {
827 continue;
828 }
829 }
830
831 // Allow search by suffix (ie: of the Monkey) or partial name (ie: Monkey)
832 // No need to do any of this if no search term was entered
833 if (!wsearchedname.empty())
834 {
835 std::string name = proto->Name1;
836 if (name.empty())
837 {
838 continue;
839 }
840
841 // local name
842 if (loc_idx >= 0)
843 if (ItemLocale const* il = sObjectMgr->GetItemLocale(proto->ItemId))
844 ObjectMgr::GetLocaleString(il->Name, loc_idx, name);
845
846 // DO NOT use GetItemEnchantMod(proto->RandomProperty) as it may return a result
847 // that matches the search but it may not equal item->GetItemRandomPropertyId()
848 // used in BuildAuctionInfo() which then causes wrong items to be listed
849 int32 propRefID = item->GetItemRandomPropertyId();
850
851 if (propRefID)
852 {
853 // Append the suffix to the name (ie: of the Monkey) if one exists
854 // These are found in ItemRandomSuffix.dbc and ItemRandomProperties.dbc
855 // even though the DBC name seems misleading
856 std::array<char const*, 16> const* suffix = nullptr;
857
858 if (propRefID < 0)
859 {
860 ItemRandomSuffixEntry const* itemRandEntry = sItemRandomSuffixStore.LookupEntry(-item->GetItemRandomPropertyId());
861 if (itemRandEntry)
862 suffix = &itemRandEntry->Name;
863 }
864 else
865 {
866 ItemRandomPropertiesEntry const* itemRandEntry = sItemRandomPropertiesStore.LookupEntry(item->GetItemRandomPropertyId());
867 if (itemRandEntry)
868 suffix = &itemRandEntry->Name;
869 }
870
871 // dbc local name
872 if (suffix)
873 {
874 // Append the suffix (ie: of the Monkey) to the name using localization
875 // or default enUS if localization is invalid
876 name += ' ';
877 name += (*suffix)[locdbc_idx >= 0 ? locdbc_idx : LOCALE_enUS];
878 }
879 }
880
881 // Perform the search (with or without suffix)
882 if (!Utf8FitTo(name, wsearchedname))
883 {
884 continue;
885 }
886 }
887
888 auctionShortlist.push_back(Aentry);
889 }
890 }
891
892 if (auctionShortlist.empty())
893 {
894 return true;
895 }
896
897 // Check if sort enabled, and first sort column is valid, if not don't sort
898 if (!sortOrder.empty())
899 {
900 AuctionSortInfo const& sortInfo = *sortOrder.begin();
901 if (sortInfo.sortOrder >= AUCTION_SORT_MINLEVEL && sortInfo.sortOrder < AUCTION_SORT_MAX && sortInfo.sortOrder != AUCTION_SORT_UNK4)
902 {
903 // Partial sort to improve performance a bit, but the last pages will burn
904 if (listfrom + 50 <= auctionShortlist.size())
905 {
906 std::partial_sort(auctionShortlist.begin(), auctionShortlist.begin() + listfrom + 50, auctionShortlist.end(),
907 std::bind(SortAuction, std::placeholders::_1, std::placeholders::_2, sortOrder, player, sortInfo.sortOrder == AUCTION_SORT_BID));
908 }
909 else
910 {
911 std::sort(auctionShortlist.begin(), auctionShortlist.end(), std::bind(SortAuction, std::placeholders::_1, std::placeholders::_2, sortOrder,
912 player, sortInfo.sortOrder == AUCTION_SORT_BID));
913 }
914 }
915 }
916
917 for (auto& auction : auctionShortlist)
918 {
919 // Add the item if no search term or if entered search term was found
920 if (count < 50 && totalcount >= listfrom)
921 {
922 Item* item = sAuctionMgr->GetAItem(auction->item_guid);
923 if (!item)
924 {
925 continue;
926 }
927
928 ++count;
929 auction->BuildAuctionInfo(data);
930 }
931 ++totalcount;
932 }
933
934 return true;
935}
@ LOCALE_enUS
Definition: Common.h:66
Milliseconds GetTimeMS()
Definition: Timer.h:84
Milliseconds GetMSTimeDiff(Milliseconds oldMSTime, Milliseconds newMSTime)
Definition: Timer.h:91
bool Utf8FitTo(std::string_view str, std::wstring_view search)
Definition: Util.cpp:481
std::int32_t int32
Definition: Define.h:103
std::uint32_t uint32
Definition: Define.h:107
#define sObjectMgr
Definition: ObjectMgr.h:1623
@ AUCTION_SORT_BID
Definition: AuctionHouseMgr.h:83
@ AUCTION_SORT_MINLEVEL
Definition: AuctionHouseMgr.h:75
@ AUCTION_SORT_UNK4
Definition: AuctionHouseMgr.h:79
@ AUCTION_SORT_MAX
Definition: AuctionHouseMgr.h:87
#define sAuctionMgr
Definition: AuctionHouseMgr.h:227
static bool SortAuction(AuctionEntry *left, AuctionEntry *right, AuctionSortOrderVector &sortOrder, Player *player, bool checkMinBidBuyout)
Definition: AuctionHouseMgr.cpp:36
DBCStorage< ItemRandomSuffixEntry > sItemRandomSuffixStore(ItemRandomSuffixfmt)
DBCStorage< ItemRandomPropertiesEntry > sItemRandomPropertiesStore(ItemRandomPropertiesfmt)
@ INVTYPE_ROBE
Definition: ItemTemplate.h:276
@ INVTYPE_CHEST
Definition: ItemTemplate.h:261
@ ITEM_SPELLTRIGGER_LEARN_SPELL_ID
Definition: ItemTemplate.h:88
@ EQUIP_ERR_OK
Definition: Item.h:47
Milliseconds GetGameTimeMS()
Definition: GameTime.cpp:43
Seconds GetGameTime()
Definition: GameTime.cpp:38
Definition: AuctionHouseMgr.h:91
AuctionSortOrder sortOrder
Definition: AuctionHouseMgr.h:94
Definition: AuctionHouseMgr.h:101
time_t expire_time
Definition: AuctionHouseMgr.h:111
ObjectGuid item_guid
Definition: AuctionHouseMgr.h:104
AuctionEntryMap::iterator GetAuctionsEnd()
Definition: AuctionHouseMgr.h:145
AuctionEntryMap const & GetAuctions()
Definition: AuctionHouseMgr.h:146
AuctionEntryMap::iterator GetAuctionsBegin()
Definition: AuctionHouseMgr.h:144
Definition: Item.h:220
int32 GetItemRandomPropertyId() const
Definition: Item.h:295
ItemTemplate const * GetTemplate() const
Definition: Item.cpp:545
uint32 SpellTrigger
Definition: ItemTemplate.h:592
int32 SpellId
Definition: ItemTemplate.h:591
Definition: ItemTemplate.h:619
uint32 Quality
Definition: ItemTemplate.h:626
_Spell Spells[MAX_ITEM_PROTO_SPELLS]
Definition: ItemTemplate.h:662
uint32 RequiredLevel
Definition: ItemTemplate.h:636
std::string Name1
Definition: ItemTemplate.h:624
uint32 Class
Definition: ItemTemplate.h:621
uint32 InventoryType
Definition: ItemTemplate.h:632
uint32 SubClass
Definition: ItemTemplate.h:622
uint32 ItemId
Definition: ItemTemplate.h:620
Definition: ItemTemplate.h:838
WorldSession * GetSession() const
Definition: Player.h:1978
bool HasSpell(uint32 spell) const override
Definition: Player.cpp:3859
InventoryResult CanUseItem(Item *pItem, bool not_loading=true) const
Definition: PlayerStorage.cpp:2225
static std::string_view GetLocaleString(std::vector< std::string > const &data, std::size_t locale)
Definition: ObjectMgr.h:1405
LocaleConstant GetSessionDbLocaleIndex() const
Definition: WorldSession.h:498
LocaleConstant GetSessionDbcLocale() const
Definition: WorldSession.h:497
Definition: DBCStructure.h:1207
std::array< char const *, 16 > Name
Definition: DBCStructure.h:1212
Definition: DBCStructure.h:1217
std::array< char const *, 16 > Name
Definition: DBCStructure.h:1219

References _auctionsMap, AUCTION_SORT_BID, AUCTION_SORT_MAX, AUCTION_SORT_MINLEVEL, AUCTION_SORT_UNK4, Player::CanUseItem(), ItemTemplate::Class, EQUIP_ERR_OK, AuctionEntry::expire_time, GetAuctions(), GetAuctionsBegin(), GetAuctionsEnd(), GameTime::GetGameTime(), GameTime::GetGameTimeMS(), Item::GetItemRandomPropertyId(), ObjectMgr::GetLocaleString(), GetMSTimeDiff(), Player::GetSession(), WorldSession::GetSessionDbcLocale(), WorldSession::GetSessionDbLocaleIndex(), Item::GetTemplate(), GetTimeMS(), Player::HasSpell(), ItemTemplate::InventoryType, INVTYPE_CHEST, INVTYPE_ROBE, AuctionEntry::item_guid, ITEM_SPELLTRIGGER_LEARN_SPELL_ID, ItemTemplate::ItemId, LOCALE_enUS, ItemRandomPropertiesEntry::Name, ItemRandomSuffixEntry::Name, ItemTemplate::Name1, ItemTemplate::Quality, ItemTemplate::RequiredLevel, sAuctionMgr, sItemRandomPropertiesStore, sItemRandomSuffixStore, sObjectMgr, SortAuction(), AuctionSortInfo::sortOrder, _Spell::SpellId, ItemTemplate::Spells, _Spell::SpellTrigger, ItemTemplate::SubClass, and Utf8FitTo().

Referenced by AuctionListItemsDelayEvent::Execute().

◆ BuildListBidderItems()

void AuctionHouseObject::BuildListBidderItems ( WorldPacket data,
Player player,
uint32 count,
uint32 totalcount 
)
704{
705 for (AuctionEntryMap::const_iterator itr = _auctionsMap.begin(); itr != _auctionsMap.end(); ++itr)
706 {
707 AuctionEntry* Aentry = itr->second;
708 if (Aentry && Aentry->bidder == player->GetGUID())
709 {
710 if (itr->second->BuildAuctionInfo(data))
711 ++count;
712
713 ++totalcount;
714 }
715 }
716}
ObjectGuid bidder
Definition: AuctionHouseMgr.h:112
static ObjectGuid GetGUID(Object const *o)
Definition: Object.h:109

References _auctionsMap, AuctionEntry::bidder, and Object::GetGUID().

Referenced by WorldSession::HandleAuctionListBidderItems().

◆ BuildListOwnerItems()

void AuctionHouseObject::BuildListOwnerItems ( WorldPacket data,
Player player,
uint32 count,
uint32 totalcount 
)
719{
720 for (AuctionEntryMap::const_iterator itr = _auctionsMap.begin(); itr != _auctionsMap.end(); ++itr)
721 {
722 AuctionEntry* Aentry = itr->second;
723 if (Aentry && Aentry->owner == player->GetGUID())
724 {
725 if (Aentry->BuildAuctionInfo(data))
726 ++count;
727
728 ++totalcount;
729 }
730 }
731}
bool BuildAuctionInfo(WorldPacket &data) const
Definition: AuctionHouseMgr.cpp:938
ObjectGuid owner
Definition: AuctionHouseMgr.h:107

References _auctionsMap, AuctionEntry::BuildAuctionInfo(), Object::GetGUID(), and AuctionEntry::owner.

Referenced by WorldSession::HandleAuctionListOwnerItemsEvent().

◆ GetAuction()

AuctionEntry * AuctionHouseObject::GetAuction ( uint32  id) const
inline
149 {
150 AuctionEntryMap::const_iterator itr = _auctionsMap.find(id);
151 return itr != _auctionsMap.end() ? itr->second : nullptr;
152 }

References _auctionsMap.

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

◆ GetAuctions()

AuctionEntryMap const & AuctionHouseObject::GetAuctions ( )
inline

◆ GetAuctionsBegin()

AuctionEntryMap::iterator AuctionHouseObject::GetAuctionsBegin ( )
inline
144{ return _auctionsMap.begin(); }

References _auctionsMap.

Referenced by BuildListAuctionItems().

◆ GetAuctionsEnd()

AuctionEntryMap::iterator AuctionHouseObject::GetAuctionsEnd ( )
inline
145{ return _auctionsMap.end(); }

References _auctionsMap.

Referenced by BuildListAuctionItems().

◆ Getcount()

uint32 AuctionHouseObject::Getcount ( ) const
inline
142{ return _auctionsMap.size(); }

References _auctionsMap.

◆ RemoveAuction()

bool AuctionHouseObject::RemoveAuction ( AuctionEntry auction)
646{
647 bool wasInMap = !!_auctionsMap.erase(auction->Id);
648
649 sScriptMgr->OnAuctionRemove(this, auction);
650
651 // we need to delete the entry, it is not referenced any more
652 delete auction;
653 auction = nullptr;
654
655 return wasInMap;
656}

References _auctionsMap, AuctionEntry::Id, and sScriptMgr.

Referenced by WorldSession::HandleAuctionPlaceBid(), WorldSession::HandleAuctionRemoveItem(), and Update().

◆ Update()

void AuctionHouseObject::Update ( )
  • Handle expired auctions
  • Either cancel the auction if there was no bidder
  • Or perform the transaction
  • In any case clear the auction
659{
660 time_t checkTime = GameTime::GetGameTime().count() + 60;
662
663 // If storage is empty, no need to update. next == nullptr in this case.
664 if (_auctionsMap.empty())
665 return;
666
667 CharacterDatabaseTransaction trans = CharacterDatabase.BeginTransaction();
668
669 for (AuctionEntryMap::iterator itr, iter = _auctionsMap.begin(); iter != _auctionsMap.end(); )
670 {
671 itr = iter++;
672 AuctionEntry* auction = (*itr).second;
673
674 if (auction->expire_time > checkTime)
675 continue;
676
678 if (!auction->bidder)
679 {
680 sAuctionMgr->SendAuctionExpiredMail(auction, trans);
681 sScriptMgr->OnAuctionExpire(this, auction);
682 }
684 else
685 {
686 //we should send an "item sold" message if the seller is online
687 //we send the item to the winner
688 //we send the money to the seller
689 sAuctionMgr->SendAuctionSuccessfulMail(auction, trans);
690 sAuctionMgr->SendAuctionWonMail(auction, trans);
691 sScriptMgr->OnAuctionSuccessful(this, auction);
692 }
693
695 auction->DeleteFromDB(trans);
696
697 sAuctionMgr->RemoveAItem(auction->item_guid);
698 RemoveAuction(auction);
699 }
700 CharacterDatabase.CommitTransaction(trans);
701}
SQLTransaction< CharacterDatabaseConnection > CharacterDatabaseTransaction
Definition: DatabaseEnvFwd.h:70
DatabaseWorkerPool< CharacterDatabaseConnection > CharacterDatabase
Accessor to the character database.
Definition: DatabaseEnv.cpp:21
void DeleteFromDB(CharacterDatabaseTransaction trans) const
Definition: AuctionHouseMgr.cpp:985
bool RemoveAuction(AuctionEntry *auction)
Definition: AuctionHouseMgr.cpp:645

References _auctionsMap, AuctionEntry::bidder, CharacterDatabase, AuctionEntry::DeleteFromDB(), AuctionEntry::expire_time, GameTime::GetGameTime(), AuctionEntry::item_guid, RemoveAuction(), sAuctionMgr, and sScriptMgr.

Referenced by AuctionHouseMgr::Update().

Member Data Documentation

◆ _auctionsMap

◆ _next

AuctionEntryMap::const_iterator AuctionHouseObject::_next
private

Referenced by AuctionHouseObject().