Project SkyFire Core
SkyFire 5.4.8 server core API documentation
Loading...
Searching...
No Matches
BlackMarketHandler.cpp
Go to the documentation of this file.
1/*
2* This file is part of Project SkyFire https://www.projectskyfire.org.
3* See LICENSE.md file for Copyright information
4*/
5
6#include "BlackMarketMgr.h"
7#include "ObjectMgr.h"
8#include "Opcodes.h"
9#include "Player.h"
10#include "Unit.h"
11#include "World.h"
12#include "WorldPacket.h"
13#include "WorldSession.h"
14
16{
17 ObjectGuid NpcGUID;
18 recvData.ReadGuidMask(NpcGUID, 4, 5, 2, 7, 0, 1, 3, 6);
19 recvData.ReadGuidBytes(NpcGUID, 4, 3, 0, 6, 2, 7, 5, 1);
20
21 if (GetPlayer()->HasUnitState(UNIT_STATE_DIED))
23
24 SendBlackMarketHello(NpcGUID, sBlackMarketMgr->isBlackMarketOpen());
25}
26
28{
30 data.WriteGuidMask(NpcGUID, 2, 0, 4, 1, 3, 6, 5, 7);
31 data.WriteBit(Open);
32 data.WriteGuidBytes(NpcGUID, 6, 1, 2, 5, 0, 7, 4, 3);
33 SendPacket(&data);
34}
35
37{
38 ObjectGuid NpcGUID;
39 uint32 Timestamp;
40 recvData >> Timestamp;
41 recvData.ReadGuidMask(NpcGUID, 2, 6, 0, 3, 4, 5, 1, 7);
42 recvData.ReadGuidBytes(NpcGUID, 6, 2, 3, 5, 7, 4, 1, 0);
44}
45
47{
49
50 sBlackMarketMgr->BuildBlackMarketRequestItemsResult(data, GetPlayer()->GetGUIDLow());
51
52 SendPacket(&data);
53}
54
56{
57 ObjectGuid NpcGUID;
58 uint32 ItemID, MarketID;
59 uint64 BidAmount;
60
61 recvData >> ItemID >> MarketID >> BidAmount;
62 recvData.ReadGuidMask(NpcGUID, 0, 5, 4, 3, 7, 6, 1, 2);
63 recvData.ReadGuidBytes(NpcGUID, 4, 3, 6, 5, 7, 1, 0, 2);
64
65 SF_LOG_DEBUG("blackMarket", ">> HandleBlackMarketBid >> MarketID : %u, BidAmount : " UI64FMTD ", ItemID : %u", MarketID, BidAmount, ItemID);
66
67 if (!BidAmount)
68 return;
69
70 BlackMarketAuction* auction = sBlackMarketMgr->GetAuction(MarketID);
71 if (!auction)
72 {
73 SF_LOG_DEBUG("blackMarket", "HandleBlackMarketBid - Auction (MarketID: %u) not found.", MarketID);
74 return;
75 }
76
77 if (auction->GetCurrentBidder() == GetPlayer()->GetGUIDLow())
78 {
79 SF_LOG_DEBUG("blackMarket", "HandleBlackMarketBid - Player (GUID: %u) is already the highest bidder.", GetPlayer()->GetGUIDLow());
80 return;
81 }
82
83 if (auction->GetCurrentBid() > BidAmount && BidAmount != auction->GetTemplate()->MinBid)
84 {
85 SF_LOG_DEBUG("blackMarket", "HandleBlackMarketBid - Player (GUID: %u) could not bid. The current bid (" UI64FMTD ") is higher than the given amount (" UI64FMTD ").", GetPlayer()->GetGUIDLow(), auction->GetCurrentBid(), BidAmount);
86 return;
87 }
88
89 uint64 currentRequiredIncrement = auction->GetCurrentBid() + auction->GetMinIncrement();
90 if (currentRequiredIncrement > BidAmount)
91 {
92 SF_LOG_DEBUG("blackMarket", "HandleBlackMarketBid - Player (GUID: %u) could not bid. The BidAmount (" UI64FMTD ") is lower than the current requiredIncrement (" UI64FMTD ").", GetPlayer()->GetGUIDLow(), BidAmount, currentRequiredIncrement);
93 return;
94 }
95
96 uint64 newIncrement = BidAmount - currentRequiredIncrement;
97
98 if (!GetPlayer()->ModifyMoney(-int64(BidAmount)))
99 {
100 SF_LOG_DEBUG("blackMarket", "HandleBlackMarketBid - Player (GUID: %u) has not enough money to bid.", GetPlayer()->GetGUIDLow());
101 return;
102 }
103
104 sBlackMarketMgr->UpdateAuction(auction, currentRequiredIncrement, newIncrement, GetPlayer());
105
106
109}
110
112{
114 data << uint32(2); // MarketID might be Result
115 data << uint32(ItemID); // ItemID
116 data << uint32(2); // Result might be MarketID
117 SendPacket(&data);
118}
#define sBlackMarketMgr
#define UI64FMTD
Definition Define.h:64
std::uint32_t uint32
Definition Define.h:77
std::uint64_t uint64
Definition Define.h:76
std::int64_t int64
Definition Define.h:72
#define SF_LOG_DEBUG(filterType__,...)
Definition Log.h:134
@ SPELL_AURA_FEIGN_DEATH
@ UNIT_STATE_DIED
Definition Unit.h:512
void WriteGuidBytes(const ObjectGuid &guid, Offsets... offsets)
Definition ByteBuffer.h:264
bool WriteBit(uint32 bit)
Definition ByteBuffer.h:164
void WriteGuidMask(const ObjectGuid &guid, Offsets... offsets)
Definition ByteBuffer.h:248
void ReadGuidBytes(ObjectGuid &guid, Offsets... offsets)
Definition ByteBuffer.h:256
void ReadGuidMask(ObjectGuid &guid, Offsets... offsets)
Definition ByteBuffer.h:240
void RemoveAurasByType(AuraType auraType, uint64 casterGUID=0, Aura *except=NULL, bool negative=true, bool positive=true)
void SendBlackMarketBidOnItemResult(uint32 ItemID)
void HandleBlackMarketRequestItemOpcode(WorldPacket &recvData)
Player * GetPlayer() const
void SendBlackMarketRequestItemsResult()
void SendPacket(WorldPacket const *packet, bool forced=false)
Send a packet to the client.
void HandleBlackMarketBidOnItem(WorldPacket &recvData)
void HandleBlackMarketHelloOpcode(WorldPacket &recvData)
void SendBlackMarketHello(ObjectGuid NpcGUID, bool Open)
@ SMSG_BLACKMARKET_REQUEST_ITEMS_RESULT
Definition Opcodes.h:568
@ SMSG_BLACKMARKET_HELLO
Definition Opcodes.h:566
@ SMSG_BLACKMARKET_BID_RESULT
Definition Opcodes.h:564
uint32 GetCurrentBidder() const
uint64 GetCurrentBid() const
BlackMarketAuctionTemplate * GetTemplate() const
uint64 GetMinIncrement() const