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)
 

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:2702
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 
)
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 (!AsyncAuctionListingMgr::IsAuctionListingAllowed()) // pussywizard: World::Update is waiting for us...
758 {
759 if ((itrcounter++) % 100 == 0) // check condition every 100 iterations
760 {
761 if (sWorldUpdateTime.GetAverageUpdateTime() >= 30 || GetMSTimeDiff(GameTime::GetGameTimeMS(), GetTimeMS()) >= 10ms) // pussywizard: stop immediately if diff is high or waiting too long
762 {
763 return false;
764 }
765 }
766 }
767
768 AuctionEntry* Aentry = itr->second;
769 // Skip expired auctions
770 if (Aentry->expire_time < curTime.count())
771 {
772 continue;
773 }
774
775 Item* item = sAuctionMgr->GetAItem(Aentry->item_guid);
776 if (!item)
777 {
778 continue;
779 }
780
781 ItemTemplate const* proto = item->GetTemplate();
782 if (itemClass != 0xffffffff && proto->Class != itemClass)
783 {
784 continue;
785 }
786
787 if (itemSubClass != 0xffffffff && proto->SubClass != itemSubClass)
788 {
789 continue;
790 }
791
792 if (inventoryType != 0xffffffff && proto->InventoryType != inventoryType)
793 {
794 // xinef: exception, robes are counted as chests
795 if (inventoryType != INVTYPE_CHEST || proto->InventoryType != INVTYPE_ROBE)
796 {
797 continue;
798 }
799 }
800
801 if (quality != 0xffffffff && proto->Quality < quality)
802 {
803 continue;
804 }
805
806 if (levelmin != 0x00 && (proto->RequiredLevel < levelmin || (levelmax != 0x00 && proto->RequiredLevel > levelmax)))
807 {
808 continue;
809 }
810
811 if (usable != 0x00)
812 {
813 if (player->CanUseItem(item) != EQUIP_ERR_OK)
814 {
815 continue;
816 }
817
818 // xinef: check already learded recipes and pets
819 if (proto->Spells[1].SpellTrigger == ITEM_SPELLTRIGGER_LEARN_SPELL_ID && player->HasSpell(proto->Spells[1].SpellId))
820 {
821 continue;
822 }
823 }
824
825 // Allow search by suffix (ie: of the Monkey) or partial name (ie: Monkey)
826 // No need to do any of this if no search term was entered
827 if (!wsearchedname.empty())
828 {
829 std::string name = proto->Name1;
830 if (name.empty())
831 {
832 continue;
833 }
834
835 // local name
836 if (loc_idx >= 0)
837 if (ItemLocale const* il = sObjectMgr->GetItemLocale(proto->ItemId))
838 ObjectMgr::GetLocaleString(il->Name, loc_idx, name);
839
840 // DO NOT use GetItemEnchantMod(proto->RandomProperty) as it may return a result
841 // that matches the search but it may not equal item->GetItemRandomPropertyId()
842 // used in BuildAuctionInfo() which then causes wrong items to be listed
843 int32 propRefID = item->GetItemRandomPropertyId();
844
845 if (propRefID)
846 {
847 // Append the suffix to the name (ie: of the Monkey) if one exists
848 // These are found in ItemRandomSuffix.dbc and ItemRandomProperties.dbc
849 // even though the DBC name seems misleading
850 std::array<char const*, 16> const* suffix = nullptr;
851
852 if (propRefID < 0)
853 {
854 ItemRandomSuffixEntry const* itemRandEntry = sItemRandomSuffixStore.LookupEntry(-item->GetItemRandomPropertyId());
855 if (itemRandEntry)
856 suffix = &itemRandEntry->Name;
857 }
858 else
859 {
860 ItemRandomPropertiesEntry const* itemRandEntry = sItemRandomPropertiesStore.LookupEntry(item->GetItemRandomPropertyId());
861 if (itemRandEntry)
862 suffix = &itemRandEntry->Name;
863 }
864
865 // dbc local name
866 if (suffix)
867 {
868 // Append the suffix (ie: of the Monkey) to the name using localization
869 // or default enUS if localization is invalid
870 name += ' ';
871 name += (*suffix)[locdbc_idx >= 0 ? locdbc_idx : LOCALE_enUS];
872 }
873 }
874
875 // Perform the search (with or without suffix)
876 if (!Utf8FitTo(name, wsearchedname))
877 {
878 continue;
879 }
880 }
881
882 auctionShortlist.push_back(Aentry);
883 }
884 }
885
886 if (auctionShortlist.empty())
887 {
888 return true;
889 }
890
891 // Check if sort enabled, and first sort column is valid, if not don't sort
892 if (!sortOrder.empty())
893 {
894 AuctionSortInfo const& sortInfo = *sortOrder.begin();
895 if (sortInfo.sortOrder >= AUCTION_SORT_MINLEVEL && sortInfo.sortOrder < AUCTION_SORT_MAX && sortInfo.sortOrder != AUCTION_SORT_UNK4)
896 {
897 // Partial sort to improve performance a bit, but the last pages will burn
898 if (listfrom + 50 <= auctionShortlist.size())
899 {
900 std::partial_sort(auctionShortlist.begin(), auctionShortlist.begin() + listfrom + 50, auctionShortlist.end(),
901 std::bind(SortAuction, std::placeholders::_1, std::placeholders::_2, sortOrder, player, sortInfo.sortOrder == AUCTION_SORT_BID));
902 }
903 else
904 {
905 std::sort(auctionShortlist.begin(), auctionShortlist.end(), std::bind(SortAuction, std::placeholders::_1, std::placeholders::_2, sortOrder,
906 player, sortInfo.sortOrder == AUCTION_SORT_BID));
907 }
908 }
909 }
910
911 for (auto auction : auctionShortlist)
912 {
913 // Add the item if no search term or if entered search term was found
914 if (count < 50 && totalcount >= listfrom)
915 {
916 Item* item = sAuctionMgr->GetAItem(auction->item_guid);
917 if (!item)
918 {
919 continue;
920 }
921
922 ++count;
923 auction->BuildAuctionInfo(data);
924 }
925 ++totalcount;
926 }
927
928 return true;
929}
@ 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:228
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
WorldUpdateTime sWorldUpdateTime
Definition: UpdateTime.cpp:24
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:841
WorldSession * GetSession() const
Definition: Player.h:1948
bool HasSpell(uint32 spell) const override
Definition: Player.cpp:3818
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
static bool IsAuctionListingAllowed()
Definition: AsyncAuctionListing.h:73
LocaleConstant GetSessionDbLocaleIndex() const
Definition: WorldSession.h:497
LocaleConstant GetSessionDbcLocale() const
Definition: WorldSession.h:496
uint32 GetAverageUpdateTime() const
Definition: UpdateTime.cpp:38
Definition: DBCStructure.h:1186
std::array< char const *, 16 > Name
Definition: DBCStructure.h:1191
Definition: DBCStructure.h:1196
std::array< char const *, 16 > Name
Definition: DBCStructure.h:1198

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(), UpdateTime::GetAverageUpdateTime(), 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, AsyncAuctionListingMgr::IsAuctionListingAllowed(), 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, sWorldUpdateTime, 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:932
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:70
void DeleteFromDB(CharacterDatabaseTransaction trans) const
Definition: AuctionHouseMgr.cpp:979
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().