1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
|
/*
* This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
*
* 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 MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the 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, see <http://www.gnu.org/licenses/>.
*/
#include "WorldSession.h"
#include "BlackMarketMgr.h"
#include "BlackMarketPackets.h"
#include "DatabaseEnv.h"
#include "Item.h"
#include "Log.h"
#include "NPCPackets.h"
#include "Player.h"
void WorldSession::HandleBlackMarketOpen(WorldPackets::BlackMarket::BlackMarketOpen& blackMarketOpen)
{
Creature* unit = GetPlayer()->GetNPCIfCanInteractWith(blackMarketOpen.Guid, UNIT_NPC_FLAG_BLACK_MARKET, UNIT_NPC_FLAG_2_BLACK_MARKET_VIEW);
if (!unit)
{
TC_LOG_DEBUG("network", "WORLD: HandleBlackMarketHello - Unit (GUID: {}) not found or you can't interact with him.", blackMarketOpen.Guid.ToString());
return;
}
// remove fake death
if (GetPlayer()->HasUnitState(UNIT_STATE_DIED))
GetPlayer()->RemoveAurasByType(SPELL_AURA_FEIGN_DEATH);
SendBlackMarketOpenResult(blackMarketOpen.Guid, unit);
}
void WorldSession::SendBlackMarketOpenResult(ObjectGuid guid, Creature* /*auctioneer*/)
{
WorldPackets::NPC::NPCInteractionOpenResult npcInteraction;
npcInteraction.Npc = guid;
npcInteraction.InteractionType = PlayerInteractionType::BlackMarketAuctioneer;
npcInteraction.Success = sBlackMarketMgr->IsEnabled();
SendPacket(npcInteraction.Write());
}
void WorldSession::HandleBlackMarketRequestItems(WorldPackets::BlackMarket::BlackMarketRequestItems& blackMarketRequestItems)
{
if (!sBlackMarketMgr->IsEnabled())
return;
Creature* unit = GetPlayer()->GetNPCIfCanInteractWith(blackMarketRequestItems.Guid, UNIT_NPC_FLAG_BLACK_MARKET, UNIT_NPC_FLAG_2_BLACK_MARKET_VIEW);
if (!unit)
{
TC_LOG_DEBUG("network", "WORLD: HandleBlackMarketRequestItems - Unit (GUID: {}) not found or you can't interact with him.", blackMarketRequestItems.Guid.ToString());
return;
}
WorldPackets::BlackMarket::BlackMarketRequestItemsResult result;
sBlackMarketMgr->BuildItemsResponse(result, GetPlayer());
SendPacket(result.Write());
}
void WorldSession::HandleBlackMarketBidOnItem(WorldPackets::BlackMarket::BlackMarketBidOnItem& blackMarketBidOnItem)
{
if (!sBlackMarketMgr->IsEnabled())
return;
Player* player = GetPlayer();
Creature* unit = player->GetNPCIfCanInteractWith(blackMarketBidOnItem.Guid, UNIT_NPC_FLAG_BLACK_MARKET, UNIT_NPC_FLAG_2_NONE);
if (!unit)
{
TC_LOG_DEBUG("network", "WORLD: HandleBlackMarketBidOnItem - Unit (GUID: {}) not found or you can't interact with him.", blackMarketBidOnItem.Guid.ToString());
return;
}
BlackMarketEntry* entry = sBlackMarketMgr->GetAuctionByID(blackMarketBidOnItem.MarketID);
if (!entry)
{
TC_LOG_DEBUG("network", "WORLD: HandleBlackMarketBidOnItem - Player ({}, name: {}) tried to bid on a nonexistent auction (MarketId: {}).", player->GetGUID().ToString(), player->GetName(), blackMarketBidOnItem.MarketID);
SendBlackMarketBidOnItemResult(ERR_BMAH_ITEM_NOT_FOUND, blackMarketBidOnItem.MarketID, blackMarketBidOnItem.Item);
return;
}
if (entry->GetBidder() == player->GetGUID().GetCounter())
{
TC_LOG_DEBUG("network", "WORLD: HandleBlackMarketBidOnItem - Player ({}, name: {}) tried to place a bid on an item he already bid on. (MarketId: {}).", player->GetGUID().ToString(), player->GetName(), blackMarketBidOnItem.MarketID);
SendBlackMarketBidOnItemResult(ERR_BMAH_ALREADY_BID, blackMarketBidOnItem.MarketID, blackMarketBidOnItem.Item);
return;
}
if (!entry->ValidateBid(blackMarketBidOnItem.BidAmount))
{
TC_LOG_DEBUG("network", "WORLD: HandleBlackMarketBidOnItem - Player ({}, name: {}) tried to place an invalid bid. Amount: {} (MarketId: {}).", player->GetGUID().ToString(), player->GetName(), blackMarketBidOnItem.BidAmount, blackMarketBidOnItem.MarketID);
SendBlackMarketBidOnItemResult(ERR_BMAH_HIGHER_BID, blackMarketBidOnItem.MarketID, blackMarketBidOnItem.Item);
return;
}
if (!player->HasEnoughMoney(blackMarketBidOnItem.BidAmount))
{
TC_LOG_DEBUG("network", "WORLD: HandleBlackMarketBidOnItem - Player ({}, name: {}) does not have enough money to place bid. (MarketId: {}).", player->GetGUID().ToString(), player->GetName(), blackMarketBidOnItem.MarketID);
SendBlackMarketBidOnItemResult(ERR_BMAH_NOT_ENOUGH_MONEY, blackMarketBidOnItem.MarketID, blackMarketBidOnItem.Item);
return;
}
if (entry->GetSecondsRemaining() <= 0)
{
TC_LOG_DEBUG("network", "WORLD: HandleBlackMarketBidOnItem - Player ({}, name: {}) tried to bid on a completed auction. (MarketId: {}).", player->GetGUID().ToString(), player->GetName(), blackMarketBidOnItem.MarketID);
SendBlackMarketBidOnItemResult(ERR_BMAH_DATABASE_ERROR, blackMarketBidOnItem.MarketID, blackMarketBidOnItem.Item);
return;
}
CharacterDatabaseTransaction trans = CharacterDatabase.BeginTransaction();
sBlackMarketMgr->SendAuctionOutbidMail(entry, trans);
entry->PlaceBid(blackMarketBidOnItem.BidAmount, player, trans);
CharacterDatabase.CommitTransaction(trans);
SendBlackMarketBidOnItemResult(ERR_BMAH_OK, blackMarketBidOnItem.MarketID, blackMarketBidOnItem.Item);
}
void WorldSession::SendBlackMarketBidOnItemResult(int32 result, int32 marketId, WorldPackets::Item::ItemInstance& item)
{
WorldPackets::BlackMarket::BlackMarketBidOnItemResult packet;
packet.MarketID = marketId;
packet.Item = item;
packet.Result = result;
SendPacket(packet.Write());
}
void WorldSession::SendBlackMarketWonNotification(BlackMarketEntry const* entry, Item const* item)
{
WorldPackets::BlackMarket::BlackMarketWon packet;
packet.MarketID = entry->GetMarketId();
packet.Item.Initialize(item);
SendPacket(packet.Write());
}
void WorldSession::SendBlackMarketOutbidNotification(BlackMarketTemplate const* templ)
{
WorldPackets::BlackMarket::BlackMarketOutbid packet;
packet.MarketID = templ->MarketID;
packet.Item = templ->Item;
packet.RandomPropertiesID = 0;
SendPacket(packet.Write());
}
|