TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
AuctionHouseMgr.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2008-2016 TrinityCore <http://www.trinitycore.org/>
3  * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License as published by the
7  * Free Software Foundation; either version 2 of the License, or (at your
8  * option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13  * more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #ifndef _AUCTION_HOUSE_MGR_H
20 #define _AUCTION_HOUSE_MGR_H
21 
22 #include "Common.h"
23 #include "DatabaseEnv.h"
24 #include "DBCStructure.h"
25 #include "ObjectGuid.h"
26 #include "AuctionHousePackets.h"
27 #include <set>
28 
29 class Item;
30 class Player;
31 class WorldPacket;
32 
33 #define MIN_AUCTION_TIME (12*HOUR)
34 #define MAX_AUCTION_ITEMS 160
35 
37 {
47 };
48 
50 {
54 };
55 
57 {
65 };
66 
68 {
70  ObjectGuid::LowType auctioneer; // creature low guid
75  uint32 startbid; //maybe useless
78  time_t expire_time;
80  uint32 deposit; //deposit can be calculated only when creating auction
82  AuctionHouseEntry const* auctionHouseEntry; // in AuctionHouse.dbc
84 
85  // helpers
86  uint32 GetHouseId() const { return auctionHouseEntry->ID; }
87  uint32 GetHouseFaction() const { return auctionHouseEntry->FactionID; }
88  uint32 GetAuctionCut() const;
89  uint32 GetAuctionOutBid() const;
90  void BuildAuctionInfo(std::vector<WorldPackets::AuctionHouse::AuctionItem>& items, bool listAuctionItems) const;
91  void DeleteFromDB(SQLTransaction& trans) const;
92  void SaveToDB(SQLTransaction& trans) const;
93  bool LoadFromDB(Field* fields);
94  std::string BuildAuctionMailSubject(MailAuctionAnswers response) const;
95  static std::string BuildAuctionMailBody(uint64 lowGuid, uint32 bid, uint32 buyout, uint32 deposit, uint32 cut);
96 
97 };
98 
99 //this class is used as auctionhouse instance
101 {
102  public:
104  {
105  for (AuctionEntryMap::iterator itr = AuctionsMap.begin(); itr != AuctionsMap.end(); ++itr)
106  delete itr->second;
107  }
108 
109  typedef std::map<uint32, AuctionEntry*> AuctionEntryMap;
110 
111  uint32 Getcount() const { return uint32(AuctionsMap.size()); }
112 
113  AuctionEntryMap::iterator GetAuctionsBegin() {return AuctionsMap.begin();}
114  AuctionEntryMap::iterator GetAuctionsEnd() {return AuctionsMap.end();}
115 
117  {
118  AuctionEntryMap::const_iterator itr = AuctionsMap.find(id);
119  return itr != AuctionsMap.end() ? itr->second : NULL;
120  }
121 
122  void AddAuction(AuctionEntry* auction);
123 
124  bool RemoveAuction(AuctionEntry* auction);
125 
126  void Update();
127 
128  void BuildListBidderItems(WorldPackets::AuctionHouse::AuctionListBidderItemsResult& packet, Player* player, uint32& totalcount);
129  void BuildListOwnerItems(WorldPackets::AuctionHouse::AuctionListOwnerItemsResult& packet, Player* player, uint32& totalcount);
130  void BuildListAuctionItems(WorldPackets::AuctionHouse::AuctionListItemsResult& packet, Player* player,
131  std::wstring const& searchedname, uint32 listfrom, uint8 levelmin, uint8 levelmax, uint8 usable,
132  uint32 inventoryType, uint32 itemClass, uint32 itemSubClass, uint32 quality, uint32& totalcount);
133 
134  private:
135  AuctionEntryMap AuctionsMap;
136 };
137 
139 {
140  private:
141  AuctionHouseMgr();
142  ~AuctionHouseMgr();
143 
144  public:
145  static AuctionHouseMgr* instance();
146 
147  typedef std::unordered_map<ObjectGuid::LowType, Item*> ItemMap;
148  typedef std::vector<AuctionEntry*> PlayerAuctions;
149  typedef std::pair<PlayerAuctions*, uint32> AuctionPair;
150 
151  AuctionHouseObject* GetAuctionsMap(uint32 factionTemplateId);
152  AuctionHouseObject* GetBidsMap(uint32 factionTemplateId);
153 
155  {
156  ItemMap::const_iterator itr = mAitems.find(id);
157  if (itr != mAitems.end())
158  return itr->second;
159 
160  return NULL;
161  }
162 
163  //auction messages
164  void SendAuctionWonMail(AuctionEntry* auction, SQLTransaction& trans);
165  void SendAuctionSalePendingMail(AuctionEntry* auction, SQLTransaction& trans);
166  void SendAuctionSuccessfulMail(AuctionEntry* auction, SQLTransaction& trans);
167  void SendAuctionExpiredMail(AuctionEntry* auction, SQLTransaction& trans);
168  void SendAuctionOutbiddedMail(AuctionEntry* auction, uint32 newPrice, Player* newBidder, SQLTransaction& trans);
169  void SendAuctionCancelledToBidderMail(AuctionEntry* auction, SQLTransaction& trans);
170 
171  static uint32 GetAuctionDeposit(AuctionHouseEntry const* entry, uint32 time, Item* pItem, uint32 count);
172  static AuctionHouseEntry const* GetAuctionHouseEntry(uint32 factionTemplateId);
173 
174  public:
175 
176  //load first auction items, because of check if item exists, when loading
177  void LoadAuctionItems();
178  void LoadAuctions();
179 
180  void AddAItem(Item* it);
181  bool RemoveAItem(ObjectGuid::LowType id, bool deleteItem = false);
182  void PendingAuctionAdd(Player* player, AuctionEntry* aEntry);
183  uint32 PendingAuctionCount(const Player* player) const;
184  void PendingAuctionProcess(Player* player);
185  void UpdatePendingAuctions();
186  void Update();
187 
188  private:
189 
193 
194  std::map<ObjectGuid, AuctionPair> pendingAuctionMap;
195 
196  ItemMap mAitems;
197 };
198 
199 #define sAuctionMgr AuctionHouseMgr::instance()
200 
201 #endif
Definition: AuctionHouseMgr.h:39
Definition: AuctionHouseMgr.h:58
AuctionEntryMap::iterator GetAuctionsEnd()
Definition: AuctionHouseMgr.h:114
uint32 itemEntry
Definition: AuctionHouseMgr.h:72
Definition: AuctionHouseMgr.h:61
uint32 itemCount
Definition: AuctionHouseMgr.h:73
std::pair< PlayerAuctions *, uint32 > AuctionPair
Definition: AuctionHouseMgr.h:149
ItemMap mAitems
Definition: AuctionHouseMgr.h:196
AuctionHouseObject mNeutralAuctions
Definition: AuctionHouseMgr.h:192
AuctionEntry * GetAuction(uint32 id) const
Definition: AuctionHouseMgr.h:116
ObjectGuid::LowType itemGUIDLow
Definition: AuctionHouseMgr.h:71
Class used to access individual fields of database query result.
Definition: Field.h:56
uint32 ID
Definition: DB2Structure.h:55
void LoadFromDB()
Definition: AddonMgr.cpp:40
Definition: AuctionHouseMgr.h:42
Definition: AuctionHouseMgr.h:67
arena_t NULL
Definition: jemalloc_internal.h:624
~AuctionHouseObject()
Definition: AuctionHouseMgr.h:103
AuctionEntryMap::iterator GetAuctionsBegin()
Definition: AuctionHouseMgr.h:113
AuctionAction
Definition: AuctionHouseMgr.h:49
uint64 LowType
Definition: ObjectGuid.h:199
Definition: AuctionHousePackets.h:204
AuctionHouseEntry const * auctionHouseEntry
Definition: AuctionHouseMgr.h:82
Definition: AuctionHouseMgr.h:51
uint32 Id
Definition: AuctionHouseMgr.h:69
uint32 GetHouseFaction() const
Definition: AuctionHouseMgr.h:87
Definition: AuctionHouseMgr.h:41
Definition: AuctionHousePackets.h:217
uint32 FactionID
Definition: DB2Structure.h:56
Definition: AuctionHouseMgr.h:46
Definition: AuctionHouseMgr.h:40
AuctionEntryMap AuctionsMap
Definition: AuctionHouseMgr.h:135
Definition: AuctionHouseMgr.h:53
ObjectGuid::LowType owner
Definition: AuctionHouseMgr.h:74
Definition: AuctionHouseMgr.h:59
Definition: AuctionHouseMgr.h:62
Definition: Item.h:259
uint32 startbid
Definition: AuctionHouseMgr.h:75
uint32_t uint32
Definition: Define.h:150
std::unordered_map< ObjectGuid::LowType, Item * > ItemMap
Definition: AuctionHouseMgr.h:147
uint64_t uint64
Definition: Define.h:149
uint32 bid
Definition: AuctionHouseMgr.h:76
time_t expire_time
Definition: AuctionHouseMgr.h:78
AuctionHouseObject mAllianceAuctions
Definition: AuctionHouseMgr.h:191
uint32 Getcount() const
Definition: AuctionHouseMgr.h:111
Definition: AuctionHouseMgr.h:63
Definition: AuctionHouseMgr.h:138
std::map< uint32, AuctionEntry * > AuctionEntryMap
Definition: AuctionHouseMgr.h:109
ObjectGuid::LowType bidder
Definition: AuctionHouseMgr.h:79
Item * GetAItem(ObjectGuid::LowType id)
Definition: AuctionHouseMgr.h:154
uint32 buyout
Definition: AuctionHouseMgr.h:77
uint32 GetHouseId() const
Definition: AuctionHouseMgr.h:86
Definition: AuctionHouseMgr.h:44
MailAuctionAnswers
Definition: AuctionHouseMgr.h:56
ObjectGuid::LowType auctioneer
Definition: AuctionHouseMgr.h:70
std::map< ObjectGuid, AuctionPair > pendingAuctionMap
Definition: AuctionHouseMgr.h:194
uint32 factionTemplateId
Definition: AuctionHouseMgr.h:83
Definition: AuctionHouseMgr.h:43
Definition: AuctionHouseMgr.h:38
#define TC_GAME_API
Definition: Define.h:134
Definition: AuctionHouseMgr.h:52
uint8_t uint8
Definition: Define.h:152
uint32 etime
Definition: AuctionHouseMgr.h:81
Definition: AuctionHouseMgr.h:100
AuctionError
Definition: AuctionHouseMgr.h:36
uint32_t uint32
Definition: g3dmath.h:168
Definition: DB2Structure.h:53
std::vector< AuctionEntry * > PlayerAuctions
Definition: AuctionHouseMgr.h:148
Definition: AuctionHouseMgr.h:45
Definition: WorldPacket.h:26
AuctionHouseObject mHordeAuctions
Definition: AuctionHouseMgr.h:190
uint32 deposit
Definition: AuctionHouseMgr.h:80
void Update(uint32 diff)
Definition: WeatherMgr.cpp:150
Definition: AuctionHouseMgr.h:60
std::shared_ptr< Transaction > SQLTransaction
Definition: Transaction.h:58
Definition: AuctionHouseMgr.h:64