Skip to content

Commit

Permalink
close trade window (#1457)
Browse files Browse the repository at this point in the history
  • Loading branch information
EmosewaMC authored Feb 12, 2024
1 parent c3fbc87 commit c7b3d9e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
12 changes: 7 additions & 5 deletions dGame/TradingManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ void Trade::SetAccepted(LWOOBJID participant, bool value) {
}

Complete();
TradingManager::Instance()->CancelTrade(m_TradeId);
TradingManager::Instance()->CancelTrade(LWOOBJID_EMPTY, m_TradeId, false);
}
}

Expand Down Expand Up @@ -178,14 +178,14 @@ void Trade::Complete() {
return;
}

void Trade::Cancel() {
void Trade::Cancel(const LWOOBJID canceller) {
auto* entityA = GetParticipantAEntity();
auto* entityB = GetParticipantBEntity();

if (entityA == nullptr || entityB == nullptr) return;

GameMessages::SendServerTradeCancel(entityA->GetObjectID(), entityA->GetSystemAddress());
GameMessages::SendServerTradeCancel(entityB->GetObjectID(), entityB->GetSystemAddress());
if (entityA->GetObjectID() != canceller || canceller == LWOOBJID_EMPTY) GameMessages::SendServerTradeCancel(entityA->GetObjectID(), entityA->GetSystemAddress());
if (entityB->GetObjectID() != canceller || canceller == LWOOBJID_EMPTY) GameMessages::SendServerTradeCancel(entityB->GetObjectID(), entityB->GetSystemAddress());
}

void Trade::SendUpdateToOther(LWOOBJID participant) {
Expand Down Expand Up @@ -262,11 +262,13 @@ Trade* TradingManager::GetPlayerTrade(LWOOBJID playerId) const {
return nullptr;
}

void TradingManager::CancelTrade(LWOOBJID tradeId) {
void TradingManager::CancelTrade(const LWOOBJID canceller, LWOOBJID tradeId, const bool sendCancelMessage) {
auto* trade = GetTrade(tradeId);

if (trade == nullptr) return;

if (sendCancelMessage) trade->Cancel(canceller);

delete trade;

trades.erase(tradeId);
Expand Down
4 changes: 2 additions & 2 deletions dGame/TradingManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class Trade
void SetAccepted(LWOOBJID participant, bool value);

void Complete();
void Cancel();
void Cancel(const LWOOBJID canceller);

void SendUpdateToOther(LWOOBJID participant);

Expand Down Expand Up @@ -66,7 +66,7 @@ class TradingManager

Trade* GetTrade(LWOOBJID tradeId) const;
Trade* GetPlayerTrade(LWOOBJID playerId) const;
void CancelTrade(LWOOBJID tradeId);
void CancelTrade(const LWOOBJID canceller, LWOOBJID tradeId, const bool sendCancelMessage = true);
Trade* NewTrade(LWOOBJID participantA, LWOOBJID participantB);

private:
Expand Down
4 changes: 2 additions & 2 deletions dGame/dGameMessages/GameMessages.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3270,7 +3270,7 @@ void GameMessages::HandleClientTradeRequest(RakNet::BitStream* inStream, Entity*

if (trade != nullptr) {
if (!trade->IsParticipant(i64Invitee)) {
TradingManager::Instance()->CancelTrade(trade->GetTradeId());
TradingManager::Instance()->CancelTrade(entity->GetObjectID(), trade->GetTradeId());

TradingManager::Instance()->NewTrade(entity->GetObjectID(), i64Invitee);
}
Expand All @@ -3295,7 +3295,7 @@ void GameMessages::HandleClientTradeCancel(RakNet::BitStream* inStream, Entity*

LOG("Trade canceled from (%llu)", entity->GetObjectID());

TradingManager::Instance()->CancelTrade(trade->GetTradeId());
TradingManager::Instance()->CancelTrade(entity->GetObjectID(), trade->GetTradeId());
}

void GameMessages::HandleClientTradeAccept(RakNet::BitStream* inStream, Entity* entity, const SystemAddress& sysAddr) {
Expand Down

0 comments on commit c7b3d9e

Please sign in to comment.