TrinityCore
BlackMarketMgr.h
Go to the documentation of this file.
1/*
2 * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#ifndef BLACK_MARKET_H
19#define BLACK_MARKET_H
20
21#include "SharedDefines.h"
22#include "DatabaseEnvFwd.h"
23#include "ObjectGuid.h"
24#include "ItemPacketsCommon.h"
25#include <unordered_map>
26
27class Player;
28
29namespace WorldPackets
30{
31 namespace BlackMarket
32 {
34 }
35}
36
37enum BlackMarketError : int32 // Extracted from client
38{
46};
47
49{
52};
53
54const static uint64 BMAH_MAX_BID = 1000000LL * GOLD;
55
57{
62 time_t Duration = time_t(0);
63 float Chance = 0.0f;
65
66 // Helpers
67 bool LoadFromDB(Field* fields);
68};
69
71{
72public:
73
74 void Update(time_t newTimeOfUpdate);
75 void Initialize(int32 marketId, uint32 duration)
76 {
77 _marketId = marketId;
78 _secondsRemaining = duration;
79 }
80
81 BlackMarketTemplate const* GetTemplate() const;
82 int32 GetMarketId() const { return _marketId; }
83
84 uint64 GetCurrentBid() const { return _currentBid; }
85 void SetCurrentBid(uint64 bid) { _currentBid = bid; }
86
87 int32 GetNumBids() const { return _numBids; }
88 void SetNumBids(int32 numBids) { _numBids = numBids; }
89
91 void SetBidder(ObjectGuid::LowType bidder) { _bidder = bidder; }
92
93 uint32 GetSecondsRemaining() const; // Get seconds remaining relative to now
94 time_t GetExpirationTime() const;
95 bool IsCompleted() const;
96
98 void SaveToDB(CharacterDatabaseTransaction trans) const;
99 bool LoadFromDB(Field* fields);
100
101 uint64 GetMinIncrement() const { return (_currentBid / 20) - ((_currentBid / 20) % GOLD); } //5% increase every bid (has to be round gold value)
102 bool ValidateBid(uint64 bid) const;
103 void PlaceBid(uint64 bid, Player* player, CharacterDatabaseTransaction trans);
104
105 std::string BuildAuctionMailSubject(BMAHMailAuctionAnswers response) const;
106 std::string BuildAuctionMailBody();
107
108 void MailSent() { _mailSent = true; } // Set when mail has been sent
109 bool GetMailSent() const { return _mailSent; }
110
111private:
117 bool _mailSent = false;
118};
119
121{
122 private:
125
126 public:
127 static BlackMarketMgr* Instance();
128
129 typedef std::unordered_map<int32, BlackMarketEntry*> BlackMarketEntryMap;
130 typedef std::unordered_map<int32, BlackMarketTemplate const*> BlackMarketTemplateMap;
131
132 // Load templates first
133 void LoadTemplates();
134 void LoadAuctions();
135
136 void Update(bool updateTime = false);
137 void RefreshAuctions();
138 time_t GetLastUpdate() const { return _lastUpdate; }
139
140 bool IsEnabled() const;
141
142 void BuildItemsResponse(WorldPackets::BlackMarket::BlackMarketRequestItemsResult& packet, Player* player);
143
144 BlackMarketEntry* GetAuctionByID(int32 marketId) const;
145 BlackMarketTemplate const* GetTemplateByID(int32 marketId) const;
146
147 void AddAuction(BlackMarketEntry* auction);
148 void AddTemplate(BlackMarketTemplate* templ);
149
150 void SendAuctionWonMail(BlackMarketEntry* entry, CharacterDatabaseTransaction trans);
151 void SendAuctionOutbidMail(BlackMarketEntry* entry, CharacterDatabaseTransaction trans); // Call before incrementing bid
152
153 private:
156 time_t _lastUpdate = time_t(0);
157};
158
159#define sBlackMarketMgr BlackMarketMgr::Instance()
160
161#endif
BlackMarketError
@ ERR_BMAH_HIGHER_BID
@ ERR_BMAH_RESTRICTED_ACCOUNT_TRIAL
@ ERR_BMAH_DATABASE_ERROR
@ ERR_BMAH_NOT_ENOUGH_MONEY
@ ERR_BMAH_OK
@ ERR_BMAH_ITEM_NOT_FOUND
@ ERR_BMAH_ALREADY_BID
static const uint64 BMAH_MAX_BID
BMAHMailAuctionAnswers
@ BMAH_AUCTION_WON
@ BMAH_AUCTION_OUTBID
SQLTransaction< CharacterDatabaseConnection > CharacterDatabaseTransaction
#define TC_GAME_API
Definition: Define.h:123
int32_t int32
Definition: Define.h:138
uint64_t uint64
Definition: Define.h:141
#define UI64LIT(N)
Definition: Define.h:127
uint32_t uint32
Definition: Define.h:142
@ GOLD
void DeleteFromDB(CharacterDatabaseTransaction trans) const
int32 GetMarketId() const
void SaveToDB(CharacterDatabaseTransaction trans) const
void Update(time_t newTimeOfUpdate)
bool IsCompleted() const
int32 GetNumBids() const
std::string BuildAuctionMailSubject(BMAHMailAuctionAnswers response) const
ObjectGuid::LowType _bidder
uint64 GetCurrentBid() const
BlackMarketTemplate const * GetTemplate() const
void SetBidder(ObjectGuid::LowType bidder)
bool GetMailSent() const
uint32 GetSecondsRemaining() const
time_t GetExpirationTime() const
std::string BuildAuctionMailBody()
bool ValidateBid(uint64 bid) const
bool LoadFromDB(Field *fields)
ObjectGuid::LowType GetBidder() const
void SetCurrentBid(uint64 bid)
void SetNumBids(int32 numBids)
void PlaceBid(uint64 bid, Player *player, CharacterDatabaseTransaction trans)
void Initialize(int32 marketId, uint32 duration)
uint64 GetMinIncrement() const
time_t GetLastUpdate() const
std::unordered_map< int32, BlackMarketEntry * > BlackMarketEntryMap
std::unordered_map< int32, BlackMarketTemplate const * > BlackMarketTemplateMap
BlackMarketEntryMap _auctions
BlackMarketTemplateMap _templates
Class used to access individual fields of database query result.
Definition: Field.h:90
uint64 LowType
Definition: ObjectGuid.h:278
void Update(VignetteData &vignette, WorldObject const *owner)
Definition: Vignette.cpp:90
WorldPackets::Item::ItemInstance Item
bool LoadFromDB(Field *fields)