Inventory.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #pragma once
  2. #include <Vec3.h>
  3. #include <ReferenceCounter.h>
  4. #include <HashMap.h>
  5. #include <Critical.h>
  6. #include "ItemSlot.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. Framework::Critical 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 ) const;
  41. virtual bool allowPushStack( ItemSlot* zSlot, Direction dir, const Item* zItem, int& count ) const;
  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. virtual void addItems( ItemStack* items, Direction dir );
  47. ItemStack* takeItemsOut( ItemSlot* zSlot, int count, Direction dir );
  48. public:
  49. Inventory( const Framework::Vec3<float> location, bool hasInventory );
  50. virtual ~Inventory();
  51. InventoryInteraction interactWith( Inventory* zInventory, Direction dir );
  52. void unsaveAddItem( ItemStack* zStack, Direction dir );
  53. int numberOfAddableItems( const ItemStack* zStack, Direction dir ) const;
  54. friend InventoryInteraction;
  55. };