Skip to content

Commit ec428d7

Browse files
committed
feat: trading system
1 parent 7d36192 commit ec428d7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+3634
-17
lines changed

Code/client/Services/Generic/OverlayClient.cpp

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
#include <Services/OverlayClient.h>
77
#include <Services/TransportService.h>
88
#include <Services/PlayerService.h>
9+
#include <Services/TradeService.h>
10+
11+
#include <Structs/Inventory.h>
912

1013
#include <Messages/SendChatMessageRequest.h>
1114
#include <Messages/TeleportRequest.h>
@@ -86,6 +89,65 @@ bool OverlayClient::OnProcessMessageReceived(CefRefPtr<CefBrowser> browser, CefR
8689
ProcessToggleDebugUI();
8790
else if (eventName == "respawnButtonClicked")
8891
World::Get().GetRunner().Queue([]() { World::Get().ctx().at<PlayerService>().RequestManualRespawn(); });
92+
else if (eventName == "sendTradeInvite")
93+
{
94+
uint32_t aPlayerId = eventArgs->GetInt(0);
95+
World::Get().GetTradeService().SendInvite(aPlayerId);
96+
}
97+
else if (eventName == "respondTradeInvite")
98+
{
99+
uint32_t inviterId = eventArgs->GetInt(0);
100+
bool accept = eventArgs->GetBool(1);
101+
World::Get().GetTradeService().RespondToInvite(inviterId, accept);
102+
}
103+
else if (eventName == "cancelTrade")
104+
{
105+
World::Get().GetTradeService().CancelTrade();
106+
}
107+
else if (eventName == "setTradeReady")
108+
{
109+
bool ready = eventArgs->GetBool(0);
110+
World::Get().GetTradeService().SetReady(ready);
111+
}
112+
else if (eventName == "updateTradeOffer")
113+
{
114+
TiltedPhoques::Vector<TradeService::OfferSelection> selections;
115+
auto pList = eventArgs->GetList(0);
116+
if (pList)
117+
{
118+
const auto cCount = pList->GetSize();
119+
selections.reserve(cCount);
120+
for (size_t i = 0; i < cCount; ++i)
121+
{
122+
TradeService::OfferSelection selection{};
123+
124+
if (pList->GetType(static_cast<int>(i)) == VTYPE_DICTIONARY)
125+
{
126+
auto pEntry = pList->GetDictionary(static_cast<int>(i));
127+
if (!pEntry)
128+
continue;
129+
130+
selection.Index = static_cast<uint32_t>(pEntry->GetInt("index"));
131+
selection.Count = pEntry->GetInt("count");
132+
}
133+
else
134+
{
135+
auto pEntry = pList->GetList(static_cast<int>(i));
136+
if (!pEntry || pEntry->GetSize() < 2)
137+
continue;
138+
139+
selection.Index = static_cast<uint32_t>(pEntry->GetInt(0));
140+
selection.Count = pEntry->GetInt(1);
141+
}
142+
143+
if (selection.Count <= 0)
144+
continue;
145+
146+
selections.push_back(selection);
147+
}
148+
}
149+
World::Get().GetTradeService().UpdateOffer(selections);
150+
}
89151

90152
return true;
91153
}

0 commit comments

Comments
 (0)