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

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 
)
698{
699 for (AuctionEntryMap::const_iterator itr = _auctionsMap.begin(); itr != _auctionsMap.end(); ++itr)
700 {
701 AuctionEntry* Aentry = itr->second;
702 if (Aentry && Aentry->bidder == player->GetGUID())
703 {
704 if (itr->second->BuildAuctionInfo(data))
705 ++count;
706
707 ++totalcount;
708 }
709 }
710}
ObjectGuid bidder
Definition: AuctionHouseMgr.h:112
static ObjectGuid GetGUID(Object const *o)
Definition: Object.h:106

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

Referenced by WorldSession::HandleAuctionListBidderItems().

◆ BuildListOwnerItems()

void AuctionHouseObject::BuildListOwnerItems ( WorldPacket data,
Player player,
uint32 count,
uint32 totalcount 
)
713{
714 for (AuctionEntryMap::const_iterator itr = _auctionsMap.begin(); itr != _auctionsMap.end(); ++itr)
715 {
716 AuctionEntry* Aentry = itr->second;
717 if (Aentry && Aentry->owner == player->GetGUID())
718 {
719 if (Aentry->BuildAuctionInfo(data))
720 ++count;
721
722 ++totalcount;
723 }
724 }
725}
bool BuildAuctionInfo(WorldPacket &data) const
Definition: AuctionHouseMgr.cpp:929
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)
640{
641 bool wasInMap = !!_auctionsMap.erase(auction->Id);
642
643 sScriptMgr->OnAuctionRemove(this, auction);
644
645 // we need to delete the entry, it is not referenced any more
646 delete auction;
647 auction = nullptr;
648
649 return wasInMap;
650}

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
653{
654 time_t checkTime = GameTime::GetGameTime().count() + 60;
656
657 // If storage is empty, no need to update. next == nullptr in this case.
658 if (_auctionsMap.empty())
659 return;
660
661 CharacterDatabaseTransaction trans = CharacterDatabase.BeginTransaction();
662
663 for (AuctionEntryMap::iterator itr, iter = _auctionsMap.begin(); iter != _auctionsMap.end(); )
664 {
665 itr = iter++;
666 AuctionEntry* auction = (*itr).second;
667
668 if (auction->expire_time > checkTime)
669 continue;
670
672 if (!auction->bidder)
673 {
674 sAuctionMgr->SendAuctionExpiredMail(auction, trans);
675 sScriptMgr->OnAuctionExpire(this, auction);
676 }
678 else
679 {
680 //we should send an "item sold" message if the seller is online
681 //we send the item to the winner
682 //we send the money to the seller
683 sAuctionMgr->SendAuctionSuccessfulMail(auction, trans);
684 sAuctionMgr->SendAuctionWonMail(auction, trans);
685 sScriptMgr->OnAuctionSuccessful(this, auction);
686 }
687
689 auction->DeleteFromDB(trans);
690
691 sAuctionMgr->RemoveAItem(auction->item_guid);
692 RemoveAuction(auction);
693 }
694 CharacterDatabase.CommitTransaction(trans);
695}
DatabaseWorkerPool< CharacterDatabaseConnection > CharacterDatabase
Accessor to the character database.
Definition: DatabaseEnv.cpp:21
SQLTransaction< CharacterDatabaseConnection > CharacterDatabaseTransaction
Definition: DatabaseEnvFwd.h:74
void DeleteFromDB(CharacterDatabaseTransaction trans) const
Definition: AuctionHouseMgr.cpp:976
bool RemoveAuction(AuctionEntry *auction)
Definition: AuctionHouseMgr.cpp:639

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().