OregonCore  revision fb2a440-git
Your Favourite TBC server
AuctionHouseMgr.h
Go to the documentation of this file.
1 /*
2  * This file is part of the OregonCore Project. See AUTHORS file for Copyright information
3  *
4  * This program is free software; you can redistribute it and/or modify it
5  * under the terms of the GNU General Public License as published by the
6  * Free Software Foundation; either version 2 of the License, or (at your
7  * option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12  * more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef _AUCTION_HOUSE_MGR_H
19 #define _AUCTION_HOUSE_MGR_H
20 
21 #include "ace/Singleton.h"
22 #include "SharedDefines.h"
23 #include "AuctionHouseBot.h"
24 
25 class Item;
26 class Player;
27 class WorldPacket;
28 
29 #define MIN_AUCTION_TIME (12*HOUR)
30 
32 {
38 };
39 
41 {
45 };
46 
48 {
50  uint32 auctioneer; // creature low guid
54  uint32 startbid; // maybe useless
57  time_t expire_time;
59  uint32 deposit; // deposit can be calculated only when creating auction
60  AuctionHouseEntry const* auctionHouseEntry; // in AuctionHouse.dbc
61 
62  // helpers
64  {
65  return auctionHouseEntry->houseId;
66  }
68  {
69  return auctionHouseEntry->faction;
70  }
71  uint32 GetAuctionCut() const;
72  uint32 GetAuctionOutBid() const;
73  bool BuildAuctionInfo(WorldPacket& data) const;
74  void DeleteFromDB() const;
75  void SaveToDB() const;
76 };
77 
78 // this class is used as auctionhouse instance
80 {
81  public:
82  // Initialize storage
84  {
85  next = AuctionsMap.begin();
86  }
88  {
89  for (AuctionEntryMap::iterator itr = AuctionsMap.begin(); itr != AuctionsMap.end(); ++itr)
90  delete itr->second;
91  }
92 
93  typedef std::map<uint32, AuctionEntry*> AuctionEntryMap;
94 
96  {
97  return AuctionsMap.size();
98  }
99 
100  AuctionEntryMap::iterator GetAuctionsBegin()
101  {
102  return AuctionsMap.begin();
103  }
104  AuctionEntryMap::iterator GetAuctionsEnd()
105  {
106  return AuctionsMap.end();
107  }
108 
110  {
111  AuctionEntryMap::const_iterator itr = AuctionsMap.find(id);
112  return itr != AuctionsMap.end() ? itr->second : NULL;
113  }
114 
115  void AddAuction(AuctionEntry* ah);
116 
117  bool RemoveAuction(AuctionEntry* auction, uint32 item_template);
118 
119  void Update();
120 
121  void BuildListBidderItems(WorldPacket& data, Player* player, uint32& count, uint32& totalcount);
122  void BuildListOwnerItems(WorldPacket& data, Player* player, uint32& count, uint32& totalcount);
123  void BuildListAuctionItems(WorldPacket& data, Player* player,
124  std::wstring const& searchedname, uint32 listfrom, uint32 levelmin, uint32 levelmax, uint32 usable,
125  uint32 inventoryType, uint32 itemClass, uint32 itemSubClass, uint32 quality,
126  uint32& count, uint32& totalcount);
127 
128  private:
129  AuctionEntryMap AuctionsMap;
130 
131  // storage for "next" auction item for next Update()
132  AuctionEntryMap::const_iterator next;
133 };
134 
136 {
137  public:
138  AuctionHouseMgr();
139  ~AuctionHouseMgr();
140 
141  typedef UNORDERED_MAP<uint32, Item*> ItemMap;
142 
143  AuctionHouseObject* GetAuctionsMap(uint32 factionTemplateId);
144  AuctionHouseObject* GetBidsMap(uint32 factionTemplateId);
145 
147  {
148  ItemMap::const_iterator itr = mAitems.find(id);
149  if (itr != mAitems.end())
150  return itr->second;
151  return NULL;
152  }
153 
154  // auction messages
155  void SendAuctionWonMail(AuctionEntry* auction);
156  void SendAuctionSalePendingMail(AuctionEntry* auction);
157  void SendAuctionSuccessfulMail(AuctionEntry* auction);
158  void SendAuctionExpiredMail(AuctionEntry* auction);
159  static uint32 GetAuctionDeposit(AuctionHouseEntry const* entry, uint32 time, Item* pItem);
160  static AuctionHouseEntry const* GetAuctionHouseEntry(uint32 factionTemplateId);
161 
162  public:
163  // load first auction items, because of check if item exists, when loading
164  void LoadAuctionItems();
165  void LoadAuctions();
166 
167  void AddAItem(Item* it);
168  bool RemoveAItem(uint32 id);
169 
170  void Update();
171 
172  private:
176 
177  ItemMap mAitems;
178 };
179 
180 #define sAuctionMgr ACE_Singleton<AuctionHouseMgr, ACE_Null_Mutex>::instance()
181 
182 #endif
183 
void SaveToDB() const
AuctionEntryMap::iterator GetAuctionsEnd()
bool BuildAuctionInfo(WorldPacket &data) const
uint32 item_guidlow
AuctionHouseObject mNeutralAuctions
AuctionEntry * GetAuction(uint32 id) const
void DeleteFromDB() const
AuctionEntryMap::iterator GetAuctionsBegin()
AuctionAction
AuctionHouseEntry const * auctionHouseEntry
uint32 GetHouseFaction() const
UNORDERED_MAP< uint32, Item * > ItemMap
AuctionEntryMap AuctionsMap
AuctionEntryMap::const_iterator next
Definition: Item.h:196
time_t expire_time
AuctionHouseObject mAllianceAuctions
std::map< uint32, AuctionEntry * > AuctionEntryMap
uint32 GetAuctionCut() const
uint32 item_template
uint32 GetHouseId() const
Item * GetAItem(uint32 id)
AuctionError
ACE_UINT32 uint32
Definition: Define.h:71
Definition: Player.h:922
AuctionHouseObject mHordeAuctions
uint32 GetAuctionOutBid() const