#pragma once #include #include #include #include "ItemSlot.h" #include "Area.h" class ItemFilter; class Inventory; class InventoryInteraction { private: Inventory* current; Inventory* other; Direction dir; void lock(); void unlock(); void transaction( Inventory* zSource, Inventory* zTarget, ItemFilter* zFilter, Direction sourceView, Direction targetView, int count ); public: InventoryInteraction( Inventory* zCurrent, Inventory* zOther, Direction dir ); InventoryInteraction( const InventoryInteraction& interaction ); ~InventoryInteraction(); InventoryInteraction& operator=( const InventoryInteraction& data ); void endInteraction(); void pullItems( int count, ItemFilter* zFilter ); void pushItems( int count, ItemFilter* zFilter ); }; class Inventory : public virtual Framework::ReferenceCounter { private: Framework::RCArray* pullSlotsOrder; Framework::RCArray* pushSlotsOrder; Framework::HashMap*>* itemCache; CriticalSection cs; void updateCache( ItemSlot* zSlot, int beforeKey ); protected: Framework::Vec3 location; void addSlot( ItemSlot* slot ); void localTransaction( Framework::Array< ItemSlot* >* zSourceSlots, Framework::Array< ItemSlot* >* zTargetSlots, ItemFilter* zFilter, int count ); virtual bool allowPullStack( ItemSlot* zSlot, Direction dir ); virtual bool allowPushStack( ItemSlot* zSlot, Direction dir, const Item* zItem, int& count ); virtual void afterPullStack( ItemSlot* zSlot, Direction dir, const Item* zItem, int count ); virtual void afterPushStack( ItemSlot* zSlot, Direction dir, const Item* zItem, int count ); virtual void loadInventory( Framework::StreamReader* zReader ); virtual void saveInventory( Framework::StreamWriter* zWriter ); public: Inventory( const Framework::Vec3 location, bool hasInventory ); virtual ~Inventory(); InventoryInteraction interactWith( Inventory* zInventory, Direction dir ); friend InventoryInteraction; };