Files
TCPlayerbotCore/src/game/AuctionHouseMgr.h
T

172 lines
5.1 KiB
C++
Raw Normal View History

2008-10-02 16:23:55 -05:00
/*
* Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
2008-10-14 11:57:03 -05:00
*
* Copyright (C) 2008-2009 Trinity <http://www.trinitycore.org/>
2008-10-02 16:23:55 -05:00
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
2008-10-14 11:57:03 -05:00
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2008-10-02 16:23:55 -05:00
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
2008-10-14 11:57:03 -05:00
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
2008-10-02 16:23:55 -05:00
*/
2009-10-17 15:51:44 -07:00
#ifndef _AUCTION_HOUSE_MGR_H
#define _AUCTION_HOUSE_MGR_H
2009-10-17 15:51:44 -07:00
#include "Policies/Singleton.h"
2009-10-17 15:51:44 -07:00
2009-06-04 21:41:07 +02:00
#include "SharedDefines.h"
2009-10-17 15:51:44 -07:00
#include "AuctionHouseBot.h"
2009-10-17 15:51:44 -07:00
class Item;
class Player;
class WorldPacket;
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
#define MIN_AUCTION_TIME (12*HOUR)
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
enum AuctionError
{
AUCTION_OK = 0,
AUCTION_INTERNAL_ERROR = 2,
AUCTION_NOT_ENOUGHT_MONEY = 3,
AUCTION_ITEM_NOT_FOUND = 4,
CANNOT_BID_YOUR_AUCTION_ERROR = 10
};
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
enum AuctionAction
{
AUCTION_SELL_ITEM = 0,
AUCTION_CANCEL = 1,
AUCTION_PLACE_BID = 2
};
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
struct AuctionEntry
{
uint32 Id;
uint32 auctioneer; // creature low guid
2008-10-02 16:23:55 -05:00
uint32 item_guidlow;
uint32 item_template;
uint32 owner;
uint32 startbid; //maybe useless
uint32 bid;
uint32 buyout;
time_t expire_time;
2008-10-02 16:23:55 -05:00
uint32 bidder;
uint32 deposit; //deposit can be calculated only when creating auction
AuctionHouseEntry const* auctionHouseEntry; // in AuctionHouse.dbc
2009-10-17 15:51:44 -07:00
// helpers
uint32 GetHouseId() const { return auctionHouseEntry->houseId; }
uint32 GetHouseFaction() const { return auctionHouseEntry->faction; }
uint32 GetAuctionCut() const;
uint32 GetAuctionOutBid() const;
bool BuildAuctionInfo(WorldPacket & data) const;
void DeleteFromDB() const;
void SaveToDB() const;
2008-10-02 16:23:55 -05:00
};
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
//this class is used as auctionhouse instance
class AuctionHouseObject
{
2009-02-28 17:42:29 -05:00
public:
// Initialize storage
AuctionHouseObject() { next = AuctionsMap.begin(); }
2009-02-28 17:42:29 -05:00
~AuctionHouseObject()
{
for (AuctionEntryMap::iterator itr = AuctionsMap.begin(); itr != AuctionsMap.end(); ++itr)
delete itr->second;
}
2009-10-17 15:51:44 -07:00
2009-02-28 17:42:29 -05:00
typedef std::map<uint32, AuctionEntry*> AuctionEntryMap;
2009-10-17 15:51:44 -07:00
2009-02-28 17:42:29 -05:00
uint32 Getcount() { return AuctionsMap.size(); }
2009-10-17 15:51:44 -07:00
2009-02-28 17:42:29 -05:00
AuctionEntryMap::iterator GetAuctionsBegin() {return AuctionsMap.begin();}
AuctionEntryMap::iterator GetAuctionsEnd() {return AuctionsMap.end();}
2009-10-17 15:51:44 -07:00
2009-02-28 17:42:29 -05:00
AuctionEntry* GetAuction(uint32 id) const
{
AuctionEntryMap::const_iterator itr = AuctionsMap.find(id);
2009-02-28 17:42:29 -05:00
return itr != AuctionsMap.end() ? itr->second : NULL;
}
2009-10-17 15:51:44 -07:00
2009-09-23 00:05:52 -04:00
void AddAuction(AuctionEntry *ah);
2009-10-17 15:51:44 -07:00
2009-09-23 00:05:52 -04:00
bool RemoveAuction(AuctionEntry *auction, uint32 item_template);
2009-10-17 15:51:44 -07:00
2009-02-28 17:42:29 -05:00
void Update();
2009-10-17 15:51:44 -07:00
2009-02-28 17:42:29 -05:00
void BuildListBidderItems(WorldPacket& data, Player* player, uint32& count, uint32& totalcount);
void BuildListOwnerItems(WorldPacket& data, Player* player, uint32& count, uint32& totalcount);
void BuildListAuctionItems(WorldPacket& data, Player* player,
std::wstring const& searchedname, uint32 listfrom, uint8 levelmin, uint8 levelmax, uint8 usable,
2009-02-28 17:42:29 -05:00
uint32 inventoryType, uint32 itemClass, uint32 itemSubClass, uint32 quality,
uint32& count, uint32& totalcount);
2009-10-17 15:51:44 -07:00
2009-02-28 17:42:29 -05:00
private:
AuctionEntryMap AuctionsMap;
2009-10-17 15:51:44 -07:00
// storage for "next" auction item for next Update()
AuctionEntryMap::const_iterator next;
2008-10-02 16:23:55 -05:00
};
2009-10-17 15:51:44 -07:00
class AuctionHouseMgr
{
2009-02-28 17:42:29 -05:00
public:
AuctionHouseMgr();
~AuctionHouseMgr();
2009-10-17 15:51:44 -07:00
2009-02-28 17:42:29 -05:00
typedef UNORDERED_MAP<uint32, Item*> ItemMap;
2009-10-17 15:51:44 -07:00
AuctionHouseObject* GetAuctionsMap(uint32 factionTemplateId);
AuctionHouseObject* GetBidsMap(uint32 factionTemplateId);
2009-10-17 15:51:44 -07:00
2009-02-28 17:42:29 -05:00
Item* GetAItem(uint32 id)
{
ItemMap::const_iterator itr = mAitems.find(id);
if (itr != mAitems.end())
{
2009-02-28 17:42:29 -05:00
return itr->second;
}
2009-02-28 17:42:29 -05:00
return NULL;
}
2009-10-17 15:51:44 -07:00
2009-02-28 17:42:29 -05:00
//auction messages
void SendAuctionWonMail(AuctionEntry * auction);
void SendAuctionSalePendingMail(AuctionEntry * auction);
void SendAuctionSuccessfulMail(AuctionEntry * auction);
void SendAuctionExpiredMail(AuctionEntry * auction);
2009-02-28 17:42:29 -05:00
static uint32 GetAuctionDeposit(AuctionHouseEntry const* entry, uint32 time, Item *pItem);
static AuctionHouseEntry const* GetAuctionHouseEntry(uint32 factionTemplateId);
2009-10-17 15:51:44 -07:00
2009-02-28 17:42:29 -05:00
public:
//load first auction items, because of check if item exists, when loading
void LoadAuctionItems();
void LoadAuctions();
2009-10-17 15:51:44 -07:00
2009-02-28 17:42:29 -05:00
void AddAItem(Item* it);
bool RemoveAItem(uint32 id);
2009-10-17 15:51:44 -07:00
2009-02-28 17:42:29 -05:00
void Update();
2009-10-17 15:51:44 -07:00
2009-02-28 17:42:29 -05:00
private:
AuctionHouseObject mHordeAuctions;
AuctionHouseObject mAllianceAuctions;
AuctionHouseObject mNeutralAuctions;
2009-10-17 15:51:44 -07:00
2009-02-28 17:42:29 -05:00
ItemMap mAitems;
};
2009-10-17 15:51:44 -07:00
2009-02-28 17:42:29 -05:00
#define auctionmgr Trinity::Singleton<AuctionHouseMgr>::Instance()
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
#endif