DarkflameServer/dGame/TradingManager.h

77 lines
1.5 KiB
C
Raw Permalink Normal View History

#pragma once
#include "Entity.h"
struct TradeItem
{
2022-07-28 13:39:57 +00:00
LWOOBJID itemId;
LOT itemLot;
uint32_t itemCount;
};
class Trade
{
public:
2022-07-28 13:39:57 +00:00
explicit Trade(LWOOBJID tradeId, LWOOBJID participantA, LWOOBJID participantB);
~Trade();
2022-07-28 13:39:57 +00:00
LWOOBJID GetTradeId() const;
2022-07-28 13:39:57 +00:00
bool IsParticipant(LWOOBJID playerId) const;
2022-07-28 13:39:57 +00:00
LWOOBJID GetParticipantA() const;
LWOOBJID GetParticipantB() const;
2022-07-28 13:39:57 +00:00
Entity* GetParticipantAEntity() const;
Entity* GetParticipantBEntity() const;
2022-07-28 13:39:57 +00:00
void SetCoins(LWOOBJID participant, uint64_t coins);
void SetItems(LWOOBJID participant, std::vector<TradeItem> items);
void SetAccepted(LWOOBJID participant, bool value);
2022-07-28 13:39:57 +00:00
void Complete();
void Cancel();
2022-07-28 13:39:57 +00:00
void SendUpdateToOther(LWOOBJID participant);
private:
2022-07-28 13:39:57 +00:00
LWOOBJID m_TradeId = LWOOBJID_EMPTY;
LWOOBJID m_ParticipantA = LWOOBJID_EMPTY;
LWOOBJID m_ParticipantB = LWOOBJID_EMPTY;
2022-07-28 13:39:57 +00:00
uint64_t m_CoinsA = 0;
uint64_t m_CoinsB = 0;
2022-07-28 13:39:57 +00:00
std::vector<TradeItem> m_ItemsA{};
std::vector<TradeItem> m_ItemsB{};
2022-07-28 13:39:57 +00:00
bool m_AcceptedA = false;
bool m_AcceptedB = false;
};
class TradingManager
{
public:
2022-07-28 13:39:57 +00:00
static TradingManager* Instance() {
if (!m_Address) {
m_Address = new TradingManager();
}
2022-07-28 13:39:57 +00:00
return m_Address;
}
2022-07-28 13:39:57 +00:00
explicit TradingManager();
~TradingManager();
2022-07-28 13:39:57 +00:00
Trade* GetTrade(LWOOBJID tradeId) const;
Trade* GetPlayerTrade(LWOOBJID playerId) const;
void CancelTrade(LWOOBJID tradeId);
Trade* NewTrade(LWOOBJID participantA, LWOOBJID participantB);
private:
2022-07-28 13:39:57 +00:00
static TradingManager* m_Address; //For singleton method
2022-07-28 13:39:57 +00:00
std::unordered_map<LWOOBJID, Trade*> trades;
};