close trade window (#1457)

This commit is contained in:
David Markowitz 2024-02-11 19:00:39 -08:00 committed by GitHub
parent c3fbc87f9e
commit c7b3d9e817
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 11 additions and 9 deletions

View File

@ -104,7 +104,7 @@ void Trade::SetAccepted(LWOOBJID participant, bool value) {
} }
Complete(); Complete();
TradingManager::Instance()->CancelTrade(m_TradeId); TradingManager::Instance()->CancelTrade(LWOOBJID_EMPTY, m_TradeId, false);
} }
} }
@ -178,14 +178,14 @@ void Trade::Complete() {
return; return;
} }
void Trade::Cancel() { void Trade::Cancel(const LWOOBJID canceller) {
auto* entityA = GetParticipantAEntity(); auto* entityA = GetParticipantAEntity();
auto* entityB = GetParticipantBEntity(); auto* entityB = GetParticipantBEntity();
if (entityA == nullptr || entityB == nullptr) return; if (entityA == nullptr || entityB == nullptr) return;
GameMessages::SendServerTradeCancel(entityA->GetObjectID(), entityA->GetSystemAddress()); if (entityA->GetObjectID() != canceller || canceller == LWOOBJID_EMPTY) GameMessages::SendServerTradeCancel(entityA->GetObjectID(), entityA->GetSystemAddress());
GameMessages::SendServerTradeCancel(entityB->GetObjectID(), entityB->GetSystemAddress()); if (entityB->GetObjectID() != canceller || canceller == LWOOBJID_EMPTY) GameMessages::SendServerTradeCancel(entityB->GetObjectID(), entityB->GetSystemAddress());
} }
void Trade::SendUpdateToOther(LWOOBJID participant) { void Trade::SendUpdateToOther(LWOOBJID participant) {
@ -262,11 +262,13 @@ Trade* TradingManager::GetPlayerTrade(LWOOBJID playerId) const {
return nullptr; return nullptr;
} }
void TradingManager::CancelTrade(LWOOBJID tradeId) { void TradingManager::CancelTrade(const LWOOBJID canceller, LWOOBJID tradeId, const bool sendCancelMessage) {
auto* trade = GetTrade(tradeId); auto* trade = GetTrade(tradeId);
if (trade == nullptr) return; if (trade == nullptr) return;
if (sendCancelMessage) trade->Cancel(canceller);
delete trade; delete trade;
trades.erase(tradeId); trades.erase(tradeId);

View File

@ -30,7 +30,7 @@ public:
void SetAccepted(LWOOBJID participant, bool value); void SetAccepted(LWOOBJID participant, bool value);
void Complete(); void Complete();
void Cancel(); void Cancel(const LWOOBJID canceller);
void SendUpdateToOther(LWOOBJID participant); void SendUpdateToOther(LWOOBJID participant);
@ -66,7 +66,7 @@ public:
Trade* GetTrade(LWOOBJID tradeId) const; Trade* GetTrade(LWOOBJID tradeId) const;
Trade* GetPlayerTrade(LWOOBJID playerId) 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); Trade* NewTrade(LWOOBJID participantA, LWOOBJID participantB);
private: private:

View File

@ -3270,7 +3270,7 @@ void GameMessages::HandleClientTradeRequest(RakNet::BitStream* inStream, Entity*
if (trade != nullptr) { if (trade != nullptr) {
if (!trade->IsParticipant(i64Invitee)) { if (!trade->IsParticipant(i64Invitee)) {
TradingManager::Instance()->CancelTrade(trade->GetTradeId()); TradingManager::Instance()->CancelTrade(entity->GetObjectID(), trade->GetTradeId());
TradingManager::Instance()->NewTrade(entity->GetObjectID(), i64Invitee); TradingManager::Instance()->NewTrade(entity->GetObjectID(), i64Invitee);
} }
@ -3295,7 +3295,7 @@ void GameMessages::HandleClientTradeCancel(RakNet::BitStream* inStream, Entity*
LOG("Trade canceled from (%llu)", entity->GetObjectID()); 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) { void GameMessages::HandleClientTradeAccept(RakNet::BitStream* inStream, Entity* entity, const SystemAddress& sysAddr) {