Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: close trade window when one player ends the trade #1457

Merged
merged 1 commit into from
Feb 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading