AHBot for 3.1.x
[AHbot.git] / src / game / AuctionHouseMgr.h
blob2eef5965f48fc210802b7cbbb09ebb2f36c1f5db
1 /*
2 * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #ifndef _AUCTION_HOUSE_MGR_H
20 #define _AUCTION_HOUSE_MGR_H
22 #include "SharedDefines.h"
23 #include "Policies/Singleton.h"
25 class Item;
26 class Player;
27 class WorldPacket;
29 #define MIN_AUCTION_TIME (12*HOUR)
31 enum AuctionError
33 AUCTION_OK = 0,
34 AUCTION_INTERNAL_ERROR = 2,
35 AUCTION_NOT_ENOUGHT_MONEY = 3,
36 AUCTION_ITEM_NOT_FOUND = 4,
37 CANNOT_BID_YOUR_AUCTION_ERROR = 10
40 enum AuctionAction
42 AUCTION_SELL_ITEM = 0,
43 AUCTION_CANCEL = 1,
44 AUCTION_PLACE_BID = 2
47 struct AuctionEntry
49 uint32 Id;
50 uint32 auctioneer; // creature low guid
51 uint32 item_guidlow;
52 uint32 item_template;
53 uint32 owner;
54 uint32 startbid; //maybe useless
55 uint32 bid;
56 uint32 buyout;
57 time_t expire_time;
58 uint32 bidder;
59 uint32 deposit; //deposit can be calculated only when creating auction
60 AuctionHouseEntry const* auctionHouseEntry; // in AuctionHouse.dbc
62 // helpers
63 uint32 GetHouseId() const { return auctionHouseEntry->houseId; }
64 uint32 GetHouseFaction() const { return auctionHouseEntry->faction; }
65 uint32 GetAuctionCut() const;
66 uint32 GetAuctionOutBid() const;
67 bool BuildAuctionInfo(WorldPacket & data) const;
68 void DeleteFromDB() const;
69 void SaveToDB() const;
72 //this class is used as auctionhouse instance
73 class AuctionHouseObject
75 public:
76 AuctionHouseObject() {}
77 ~AuctionHouseObject()
79 for (AuctionEntryMap::const_iterator itr = AuctionsMap.begin(); itr != AuctionsMap.end(); ++itr)
80 delete itr->second;
83 typedef std::map<uint32, AuctionEntry*> AuctionEntryMap;
85 uint32 Getcount() { return AuctionsMap.size(); }
87 AuctionEntryMap::iterator GetAuctionsBegin() {return AuctionsMap.begin();}
88 AuctionEntryMap::iterator GetAuctionsEnd() {return AuctionsMap.end();}
90 void AddAuction(AuctionEntry *ah)
92 ASSERT( ah );
93 AuctionsMap[ah->Id] = ah;
96 AuctionEntry* GetAuction(uint32 id) const
98 AuctionEntryMap::const_iterator itr = AuctionsMap.find( id );
99 return itr != AuctionsMap.end() ? itr->second : NULL;
102 bool RemoveAuction(uint32 id)
104 return AuctionsMap.erase(id) ? true : false;
107 void Update();
109 void BuildListBidderItems(WorldPacket& data, Player* player, uint32& count, uint32& totalcount);
110 void BuildListOwnerItems(WorldPacket& data, Player* player, uint32& count, uint32& totalcount);
111 void BuildListAuctionItems(WorldPacket& data, Player* player,
112 std::wstring const& searchedname, uint32 listfrom, uint32 levelmin, uint32 levelmax, uint32 usable,
113 uint32 inventoryType, uint32 itemClass, uint32 itemSubClass, uint32 quality,
114 uint32& count, uint32& totalcount);
116 private:
117 AuctionEntryMap AuctionsMap;
120 class AuctionHouseMgr
122 public:
123 AuctionHouseMgr();
124 ~AuctionHouseMgr();
126 typedef UNORDERED_MAP<uint32, Item*> ItemMap;
128 AuctionHouseObject* GetAuctionsMap( uint32 factionTemplateId );
130 Item* GetAItem(uint32 id)
132 ItemMap::const_iterator itr = mAitems.find(id);
133 if (itr != mAitems.end())
135 return itr->second;
137 return NULL;
140 //auction messages
141 void SendAuctionWonMail( AuctionEntry * auction );
142 void SendAuctionSalePendingMail( AuctionEntry * auction );
143 void SendAuctionSuccessfulMail( AuctionEntry * auction );
144 void SendAuctionExpiredMail( AuctionEntry * auction );
145 static uint32 GetAuctionDeposit(AuctionHouseEntry const* entry, uint32 time, Item *pItem);
146 static AuctionHouseEntry const* GetAuctionHouseEntry(uint32 factionTemplateId);
148 public:
149 //load first auction items, because of check if item exists, when loading
150 void LoadAuctionItems();
151 void LoadAuctions();
153 void AddAItem(Item* it);
154 bool RemoveAItem(uint32 id);
156 void Update();
158 private:
159 AuctionHouseObject mHordeAuctions;
160 AuctionHouseObject mAllianceAuctions;
161 AuctionHouseObject mNeutralAuctions;
163 ItemMap mAitems;
166 #define auctionmgr MaNGOS::Singleton<AuctionHouseMgr>::Instance()
168 #endif