Just a few renames.
[AHbot.git] / src / game / AuctionHouseMgr.h
blob2775838d99bda65c213291758486f1edc757693e
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 void AddAuction(AuctionEntry *ah)
89 ASSERT( ah );
90 AuctionsMap[ah->Id] = ah;
93 AuctionEntry* GetAuction(uint32 id) const
95 AuctionEntryMap::const_iterator itr = AuctionsMap.find( id );
96 return itr != AuctionsMap.end() ? itr->second : NULL;
99 bool RemoveAuction(uint32 id)
101 return AuctionsMap.erase(id) ? true : false;
104 void Update();
106 void BuildListBidderItems(WorldPacket& data, Player* player, uint32& count, uint32& totalcount);
107 void BuildListOwnerItems(WorldPacket& data, Player* player, uint32& count, uint32& totalcount);
108 void BuildListAuctionItems(WorldPacket& data, Player* player,
109 std::wstring const& searchedname, uint32 listfrom, uint32 levelmin, uint32 levelmax, uint32 usable,
110 uint32 inventoryType, uint32 itemClass, uint32 itemSubClass, uint32 quality,
111 uint32& count, uint32& totalcount);
113 private:
114 AuctionEntryMap AuctionsMap;
117 class AuctionHouseMgr
119 public:
120 AuctionHouseMgr();
121 ~AuctionHouseMgr();
123 typedef UNORDERED_MAP<uint32, Item*> ItemMap;
125 AuctionHouseObject* GetAuctionsMap( uint32 factionTemplateId );
127 Item* GetAItem(uint32 id)
129 ItemMap::const_iterator itr = mAitems.find(id);
130 if (itr != mAitems.end())
132 return itr->second;
134 return NULL;
137 //auction messages
138 void SendAuctionWonMail( AuctionEntry * auction );
139 void SendAuctionSalePendingMail( AuctionEntry * auction );
140 void SendAuctionSuccessfulMail( AuctionEntry * auction );
141 void SendAuctionExpiredMail( AuctionEntry * auction );
142 static uint32 GetAuctionDeposit(AuctionHouseEntry const* entry, uint32 time, Item *pItem);
143 static AuctionHouseEntry const* GetAuctionHouseEntry(uint32 factionTemplateId);
145 public:
146 //load first auction items, because of check if item exists, when loading
147 void LoadAuctionItems();
148 void LoadAuctions();
150 void AddAItem(Item* it);
151 bool RemoveAItem(uint32 id);
153 void Update();
155 private:
156 AuctionHouseObject mHordeAuctions;
157 AuctionHouseObject mAllianceAuctions;
158 AuctionHouseObject mNeutralAuctions;
160 ItemMap mAitems;
163 #define auctionmgr MaNGOS::Singleton<AuctionHouseMgr>::Instance()
165 #endif