Inventory.h 2.1 KB

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