mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2026-10-02 19:03:43 +00:00
Converts the vendor, donation vendor and trade game messages to
NetGameMsgs in VendorMessages.{h,cpp} and TradeMessages.{h,cpp}:
VendorOpenWindow and VendorTransactionResult (SendToClient: the old
functions never broadcast), VendorStatusUpdate, ServerTradeInvite,
ServerTradeInitialReply, ServerTradeFinalReply, ServerTradeAccept,
ServerTradeCancel and ServerTradeUpdate, and the received
RequestVendorStatusUpdate, BuyFromVendor, SellToVendor,
BuybackFromVendor, AddDonationItem, RemoveDonationItem,
ConfirmDonationOnPlayer, CancelDonationOnPlayer, ClientTradeRequest,
ClientTradeCancel, ClientTradeAccept and ClientTradeUpdate. A trade
offer entry (the client's inventory item layout, optional fields and
config block included) is TradeItemEntry, shared by both trade updates.
Selling and buying back move into VendorComponent (SellToVendor,
BuybackFromVendor), adding and confirming donations into
DonationVendorComponent, and VendorComponent builds its own status
update and transaction results. Only the VENDOR component sends its
stock, as before. The received messages are registered in
GameMessageHandler's map, the switch cases and the old functions are
deleted. Handler logic is unchanged.
No wire change and no change in recipients. Verified byte for byte
against a frozen verbatim copy of the old functions over an input grid
(to one client and broadcast), received messages compared with the old
handlers' read sequences (every optional field of a trade entry,
raw and compressed config blocks) and truncated payloads rejected, hand
computed golden bytes, round trips, and a deliberate width mutation made
the tests fail. ConfirmDonationOnPlayer still accepts a message without
its vendor ID, since the old handler read nothing.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
81 lines
3.5 KiB
C++
81 lines
3.5 KiB
C++
#include "AchievementVendorComponent.h"
|
|
#include "MissionComponent.h"
|
|
#include "InventoryComponent.h"
|
|
#include "eMissionState.h"
|
|
#include "CDComponentsRegistryTable.h"
|
|
#include "CDItemComponentTable.h"
|
|
#include "eVendorTransactionResult.h"
|
|
#include "CheatDetection.h"
|
|
#include "UserManager.h"
|
|
#include "CDMissionsTable.h"
|
|
|
|
AchievementVendorComponent::AchievementVendorComponent(Entity* parent, const int32_t componentID) : VendorComponent(parent, componentID) {
|
|
RefreshInventory(true);
|
|
};
|
|
|
|
bool AchievementVendorComponent::SellsItem(Entity* buyer, const LOT lot) {
|
|
auto* missionComponent = buyer->GetComponent<MissionComponent>();
|
|
if (!missionComponent) return false;
|
|
|
|
if (m_PlayerPurchasableItems[buyer->GetObjectID()].contains(lot)) {
|
|
return true;
|
|
}
|
|
|
|
CDMissionsTable* missionsTable = CDClientManager::GetTable<CDMissionsTable>();
|
|
const auto missions = missionsTable->GetMissionsForReward(lot);
|
|
for (const auto mission : missions) {
|
|
if (missionComponent->GetMissionState(mission) == eMissionState::COMPLETE) {
|
|
m_PlayerPurchasableItems[buyer->GetObjectID()].insert(lot);
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
void AchievementVendorComponent::Buy(Entity* buyer, LOT lot, uint32_t count) {
|
|
// get the item Comp from the item LOT
|
|
CDComponentsRegistryTable* compRegistryTable = CDClientManager::GetTable<CDComponentsRegistryTable>();
|
|
CDItemComponentTable* itemComponentTable = CDClientManager::GetTable<CDItemComponentTable>();
|
|
int itemCompID = compRegistryTable->GetByIDAndType(lot, eReplicaComponentType::ITEM);
|
|
CDItemComponent itemComp = itemComponentTable->GetItemComponentByID(itemCompID);
|
|
uint32_t costLOT = itemComp.commendationLOT;
|
|
|
|
if (costLOT == -1 || !SellsItem(buyer, lot)) {
|
|
auto* user = UserManager::Instance()->GetUser(buyer->GetSystemAddress());
|
|
CheatDetection::ReportCheat(user, buyer->GetSystemAddress(), "Attempted to buy item %i from achievement vendor %i that is not purchasable", lot, m_Parent->GetLOT());
|
|
SendTransactionResult(buyer->GetObjectID(), buyer->GetSystemAddress(), eVendorTransactionResult::PURCHASE_FAIL);
|
|
return;
|
|
}
|
|
|
|
auto* inventoryComponent = buyer->GetComponent<InventoryComponent>();
|
|
if (!inventoryComponent) {
|
|
SendTransactionResult(buyer->GetObjectID(), buyer->GetSystemAddress(), eVendorTransactionResult::PURCHASE_FAIL);
|
|
return;
|
|
}
|
|
|
|
if (costLOT == 13763) { // Faction Token Proxy
|
|
auto* missionComponent = buyer->GetComponent<MissionComponent>();
|
|
if (!missionComponent) return;
|
|
|
|
if (missionComponent->GetMissionState(545) == eMissionState::COMPLETE) costLOT = 8318; // "Assembly Token"
|
|
if (missionComponent->GetMissionState(556) == eMissionState::COMPLETE) costLOT = 8321; // "Venture League Token"
|
|
if (missionComponent->GetMissionState(567) == eMissionState::COMPLETE) costLOT = 8319; // "Sentinels Token"
|
|
if (missionComponent->GetMissionState(578) == eMissionState::COMPLETE) costLOT = 8320; // "Paradox Token"
|
|
}
|
|
|
|
const uint32_t altCurrencyCost = itemComp.commendationCost * count;
|
|
if (inventoryComponent->GetLotCount(costLOT) < altCurrencyCost || !inventoryComponent->RemoveItem(costLOT, altCurrencyCost, eInventoryType::ALL)) {
|
|
SendTransactionResult(buyer->GetObjectID(), buyer->GetSystemAddress(), eVendorTransactionResult::PURCHASE_FAIL);
|
|
return;
|
|
}
|
|
|
|
inventoryComponent->AddItem(lot, count, eLootSourceType::VENDOR);
|
|
SendTransactionResult(buyer->GetObjectID(), buyer->GetSystemAddress(), eVendorTransactionResult::PURCHASE_SUCCESS);
|
|
|
|
}
|
|
|
|
void AchievementVendorComponent::RefreshInventory(bool isCreation) {
|
|
SetHasStandardCostItems(true);
|
|
Game::entityManager->SerializeEntity(m_Parent);
|
|
}
|