mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2024-12-22 13:33:35 +00:00
close trade window (#1457)
This commit is contained in:
parent
c3fbc87f9e
commit
c7b3d9e817
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@ -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) {
|
||||
@ -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);
|
||||
|
@ -30,7 +30,7 @@ public:
|
||||
void SetAccepted(LWOOBJID participant, bool value);
|
||||
|
||||
void Complete();
|
||||
void Cancel();
|
||||
void Cancel(const LWOOBJID canceller);
|
||||
|
||||
void SendUpdateToOther(LWOOBJID participant);
|
||||
|
||||
@ -66,7 +66,7 @@ public:
|
||||
|
||||
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:
|
||||
|
@ -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);
|
||||
}
|
||||
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user