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

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

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