Inventory.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #pragma once
  2. #include <Vec3.h>
  3. #include <ReferenceCounter.h>
  4. #include <HashMap.h>
  5. #include "ItemSlot.h"
  6. #include "EventThrower.h"
  7. #include "Area.h"
  8. class ItemFilter;
  9. class Inventory;
  10. class InventoryInteraction
  11. {
  12. private:
  13. Inventory *current;
  14. Inventory *other;
  15. Direction dir;
  16. void lock();
  17. void unlock();
  18. void transaction( Inventory *zSource, Inventory *zTarget, ItemFilter *zFilter, Direction sourceView, Direction targetView, int count );
  19. public:
  20. InventoryInteraction( Inventory *zCurrent, Inventory *zOther, Direction dir );
  21. InventoryInteraction( const InventoryInteraction &interaction );
  22. ~InventoryInteraction();
  23. InventoryInteraction &operator=( const InventoryInteraction &data );
  24. void endInteraction();
  25. void pullItems( int count, ItemFilter *zFilter );
  26. void pushItems( int count, ItemFilter *zFilter );
  27. };
  28. class Inventory : public virtual Framework::ReferenceCounter
  29. {
  30. private:
  31. Framework::RCArray<ItemSlot> *pullSlotsOrder;
  32. Framework::RCArray<ItemSlot> *pushSlotsOrder;
  33. Framework::HashMap<int, Framework::Array<ItemSlot *> *> *itemCache;
  34. CriticalSection cs;
  35. void updateCache( ItemSlot *zSlot, int beforeKey );
  36. protected:
  37. Framework::Vec3<float> location;
  38. void addSlot( ItemSlot *slot );
  39. void localTransaction( Framework::Array< ItemSlot * > *zSourceSlots, Framework::Array< ItemSlot * > *zTargetSlots, ItemFilter *zFilter, int count );
  40. virtual bool allowPullStack( ItemSlot *zSlot, Direction dir );
  41. virtual bool allowPushStack( ItemSlot *zSlot, Direction dir, const Item *zItem, int &count );
  42. virtual void afterPullStack( ItemSlot *zSlot, Direction dir, const Item *zItem, int count );
  43. virtual void afterPushStack( ItemSlot *zSlot, Direction dir, const Item *zItem, int count );
  44. virtual void loadInventory( Framework::StreamReader *zReader );
  45. virtual void saveInventory( Framework::StreamWriter *zWriter );
  46. public:
  47. Inventory( const Framework::Vec3<float> location );
  48. virtual ~Inventory();
  49. InventoryInteraction interactWith( Inventory *zInventory, Direction dir );
  50. friend InventoryInteraction;
  51. };