1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- #include "Inventory.h"
- #include "Area.h"
- #include "Registries.h"
- using namespace Framework;
- Inventory::Inventory( const Framework::Vec3<float> location, bool hasInventory )
- : ReferenceCounter(),
- location( location )
- {
- if( hasInventory )
- {
- pullSlotsOrder = new Framework::RCArray<ItemSlot>();
- pushSlotsOrder = new Framework::RCArray<ItemSlot>();
- }
- else
- {
- pullSlotsOrder = 0;
- pushSlotsOrder = 0;
- }
- }
- Inventory::~Inventory()
- {
- if( pullSlotsOrder )
- pullSlotsOrder->release();
- if( pushSlotsOrder )
- pushSlotsOrder->release();
- }
- void Inventory::loadInventory( Framework::StreamReader* zReader )
- {
- if( pushSlotsOrder )
- {
- for( auto slot : *pushSlotsOrder )
- {
- int size = 0;
- zReader->lese( (char*)&size, 4 );
- if( size != 0 )
- {
- int id = 0;
- zReader->lese( (char*)&id, 4 );
- Item* item = STATIC_REGISTRY( ItemType ).zElement( id )->loadItem( zReader );
- slot->setItems( new ItemStack( item, size ) );
- }
- else
- slot->setItems( 0 );
- }
- }
- }
- void Inventory::addSlot( ItemSlot* slot )
- {
- int pullPrio = slot->getPullPriority();
- int pushPrio = slot->getPushPriority();
- int index = 0;
- for( auto stack : *pullSlotsOrder )
- {
- if( stack->getPullPriority() > pullPrio )
- break;
- index++;
- }
- pullSlotsOrder->add( dynamic_cast<ItemSlot*>(slot->getThis()), index );
- index = 0;
- for( auto stack : *pushSlotsOrder )
- {
- if( stack->getPushPriority() > pushPrio )
- break;
- index++;
- }
- pushSlotsOrder->add( slot, index );
- }
|