| 1 | /* |
|---|
| 2 | * Copyright (C) 2008 Trinity <http://www.trinitycore.org/> |
|---|
| 3 | * |
|---|
| 4 | * Thanks to the original authors: MaNGOS <http://www.mangosproject.org/> |
|---|
| 5 | * |
|---|
| 6 | * This program is free software; you can redistribute it and/or modify |
|---|
| 7 | * it under the terms of the GNU General Public License as published by |
|---|
| 8 | * the Free Software Foundation; either version 2 of the License, or |
|---|
| 9 | * (at your option) any later version. |
|---|
| 10 | * |
|---|
| 11 | * This program is distributed in the hope that it will be useful, |
|---|
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 14 | * GNU General Public License for more details. |
|---|
| 15 | * |
|---|
| 16 | * You should have received a copy of the GNU General Public License |
|---|
| 17 | * along with this program; if not, write to the Free Software |
|---|
| 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|---|
| 19 | */ |
|---|
| 20 | |
|---|
| 21 | #ifndef _AUCTION_HOUSE_H |
|---|
| 22 | #define _AUCTION_HOUSE_H |
|---|
| 23 | |
|---|
| 24 | #include "SharedDefines.h" |
|---|
| 25 | |
|---|
| 26 | #define MIN_AUCTION_TIME (12*HOUR) |
|---|
| 27 | |
|---|
| 28 | enum AuctionError |
|---|
| 29 | { |
|---|
| 30 | AUCTION_OK = 0, |
|---|
| 31 | AUCTION_INTERNAL_ERROR = 2, |
|---|
| 32 | AUCTION_NOT_ENOUGHT_MONEY = 3, |
|---|
| 33 | AUCTION_ITEM_NOT_FOUND = 4, |
|---|
| 34 | CANNOT_BID_YOUR_AUCTION_ERROR = 10 |
|---|
| 35 | }; |
|---|
| 36 | |
|---|
| 37 | enum AuctionAction |
|---|
| 38 | { |
|---|
| 39 | AUCTION_SELL_ITEM = 0, |
|---|
| 40 | AUCTION_CANCEL = 1, |
|---|
| 41 | AUCTION_PLACE_BID = 2 |
|---|
| 42 | }; |
|---|
| 43 | |
|---|
| 44 | struct AuctionEntry |
|---|
| 45 | { |
|---|
| 46 | uint32 Id; |
|---|
| 47 | uint32 auctioneer; |
|---|
| 48 | uint32 item_guidlow; |
|---|
| 49 | uint32 item_template; |
|---|
| 50 | uint32 owner; |
|---|
| 51 | uint32 startbid; //maybe useless |
|---|
| 52 | uint32 bid; |
|---|
| 53 | uint32 buyout; |
|---|
| 54 | time_t time; |
|---|
| 55 | uint32 bidder; |
|---|
| 56 | uint32 deposit; //deposit can be calculated only when creating auction |
|---|
| 57 | uint32 location; |
|---|
| 58 | }; |
|---|
| 59 | |
|---|
| 60 | //this class is used as auctionhouse instance |
|---|
| 61 | class AuctionHouseObject |
|---|
| 62 | { |
|---|
| 63 | public: |
|---|
| 64 | AuctionHouseObject() {} |
|---|
| 65 | ~AuctionHouseObject() |
|---|
| 66 | { |
|---|
| 67 | for (AuctionEntryMap::iterator itr = AuctionsMap.begin(); itr != AuctionsMap.end(); ++itr) |
|---|
| 68 | delete itr->second; |
|---|
| 69 | } |
|---|
| 70 | |
|---|
| 71 | typedef std::map<uint32, AuctionEntry*> AuctionEntryMap; |
|---|
| 72 | |
|---|
| 73 | uint32 Getcount() { return AuctionsMap.size(); } |
|---|
| 74 | |
|---|
| 75 | AuctionEntryMap::iterator GetAuctionsBegin() {return AuctionsMap.begin();} |
|---|
| 76 | AuctionEntryMap::iterator GetAuctionsEnd() {return AuctionsMap.end();} |
|---|
| 77 | |
|---|
| 78 | void AddAuction(AuctionEntry *ah) |
|---|
| 79 | { |
|---|
| 80 | ASSERT( ah ); |
|---|
| 81 | AuctionsMap[ah->Id] = ah; |
|---|
| 82 | } |
|---|
| 83 | |
|---|
| 84 | AuctionEntry* GetAuction(uint32 id) const |
|---|
| 85 | { |
|---|
| 86 | AuctionEntryMap::const_iterator itr = AuctionsMap.find( id ); |
|---|
| 87 | if( itr != AuctionsMap.end() ) |
|---|
| 88 | return itr->second; |
|---|
| 89 | return NULL; |
|---|
| 90 | } |
|---|
| 91 | |
|---|
| 92 | bool RemoveAuction(uint32 id) |
|---|
| 93 | { |
|---|
| 94 | AuctionEntryMap::iterator i = AuctionsMap.find(id); |
|---|
| 95 | if (i == AuctionsMap.end()) |
|---|
| 96 | { |
|---|
| 97 | return false; |
|---|
| 98 | } |
|---|
| 99 | AuctionsMap.erase(i); |
|---|
| 100 | return true; |
|---|
| 101 | } |
|---|
| 102 | |
|---|
| 103 | private: |
|---|
| 104 | AuctionEntryMap AuctionsMap; |
|---|
| 105 | }; |
|---|
| 106 | #endif |
|---|