|
6 | 6 | #include <Services/OverlayClient.h> |
7 | 7 | #include <Services/TransportService.h> |
8 | 8 | #include <Services/PlayerService.h> |
| 9 | +#include <Services/TradeService.h> |
| 10 | + |
| 11 | +#include <Structs/Inventory.h> |
9 | 12 |
|
10 | 13 | #include <Messages/SendChatMessageRequest.h> |
11 | 14 | #include <Messages/TeleportRequest.h> |
@@ -86,6 +89,65 @@ bool OverlayClient::OnProcessMessageReceived(CefRefPtr<CefBrowser> browser, CefR |
86 | 89 | ProcessToggleDebugUI(); |
87 | 90 | else if (eventName == "respawnButtonClicked") |
88 | 91 | 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 | + } |
89 | 151 |
|
90 | 152 | return true; |
91 | 153 | } |
|
0 commit comments