Inventory.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. public:
  48. Inventory( const Framework::Vec3<float> location, bool hasInventory );
  49. virtual ~Inventory();
  50. InventoryInteraction interactWith( Inventory* zInventory, Direction dir );
  51. void unsaveAddItem( ItemStack* zStack, Direction dir );
  52. int numberOfAddableItems( const ItemStack* zStack, Direction dir ) const;
  53. friend InventoryInteraction;
  54. };