Trade.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #pragma once
  2. #include "../common/types.h"
  3. #include <map>
  4. class Item;
  5. class Entity;
  6. struct TradeItemInfo {
  7. Item* item;
  8. int32 quantity;
  9. };
  10. class Trade {
  11. public:
  12. Trade(Entity* trader1, Entity* trader2);
  13. ~Trade();
  14. int8 AddItemToTrade(Entity* character, Item* item, int8 quantity, int8 slot);
  15. void RemoveItemFromTrade(Entity* character, int8 slot);
  16. void AddCoinToTrade(Entity* character, int64 amount);
  17. void RemoveCoinFromTrade(Entity* character, int64 amount);
  18. Entity* GetTradee(Entity* character);
  19. bool SetTradeAccepted(Entity* character);
  20. bool HasAcceptedTrade(Entity* character);
  21. void CancelTrade(Entity* character);
  22. int8 CheckItem(Entity* trader, Item* item, Entity* other);
  23. Item* GetTraderSlot(Entity* trader, int8 slot);
  24. Entity* GetTrader1() { return trader1; }
  25. Entity* GetTrader2() { return trader2; }
  26. int8 MaxSlots() { return trade_max_slots; }
  27. private:
  28. void Trader1ItemAdd(Item* item, int8 quantity, int8 slot);
  29. void Trader2ItemAdd(Item* item, int8 quantity, int8 slot);
  30. void CompleteTrade();
  31. void OpenTradeWindow();
  32. void SendTradePacket();
  33. void CalculateCoins(int64 val, int32& plat, int32& gold, int32& silver, int32& copper);
  34. int8 GetNextFreeSlot(Entity* character);
  35. Entity* trader1;
  36. map<int8, TradeItemInfo> trader1_items;
  37. int64 trader1_coins;
  38. bool trader1_accepted;
  39. Entity* trader2;
  40. map<int8, TradeItemInfo> trader2_items;
  41. int64 trader2_coins;
  42. bool trader2_accepted;
  43. int32 trade_max_slots;
  44. };