2017-08-18 17:16:15 +02:00
|
|
|
#include "src/servers/Server_Zone/Forwards.h"
|
2017-08-08 13:53:47 +02:00
|
|
|
#include "ItemContainer.h"
|
|
|
|
|
2017-08-19 00:18:40 +02:00
|
|
|
#include <src/servers/Server_Common/Common.h>
|
|
|
|
#include <src/servers/Server_Common/Logging/Logger.h>
|
2017-08-08 13:53:47 +02:00
|
|
|
|
2017-08-18 17:16:15 +02:00
|
|
|
#include "src/servers/Server_Zone/Actor/Player.h"
|
2017-08-08 13:53:47 +02:00
|
|
|
|
|
|
|
#include "Item.h"
|
|
|
|
|
2017-10-27 14:01:50 +02:00
|
|
|
#include <Server_Common/Database/DatabaseDef.h>
|
2017-10-27 00:10:13 +02:00
|
|
|
|
2017-08-08 13:53:47 +02:00
|
|
|
extern Core::Logger g_log;
|
|
|
|
|
|
|
|
Core::ItemContainer::ItemContainer( uint16_t locationId ) :
|
|
|
|
m_id( locationId ),
|
|
|
|
m_size( 25 )
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Core::ItemContainer::~ItemContainer()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
uint16_t Core::ItemContainer::getId() const
|
|
|
|
{
|
|
|
|
return m_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t Core::ItemContainer::getEntryCount() const
|
|
|
|
{
|
|
|
|
return static_cast< uint8_t >( m_itemMap.size() );
|
|
|
|
}
|
|
|
|
|
|
|
|
void Core::ItemContainer::removeItem( uint8_t slotId )
|
|
|
|
{
|
|
|
|
ItemMap::iterator it = m_itemMap.find( slotId );
|
|
|
|
|
|
|
|
if( it != m_itemMap.end() )
|
|
|
|
{
|
2017-10-27 00:10:13 +02:00
|
|
|
g_charaDb.execute( "DELETE FROM charaglobalitem WHERE itemId = " + std::to_string( it->second->getUId() ) );
|
2017-08-08 13:53:47 +02:00
|
|
|
|
|
|
|
m_itemMap.erase( it );
|
|
|
|
|
|
|
|
g_log.debug( "Dropped item from slot " + std::to_string( slotId ) );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_log.debug( "Item could not be dropped from slot " + std::to_string( slotId ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Core::ItemMap & Core::ItemContainer::getItemMap()
|
|
|
|
{
|
|
|
|
return m_itemMap;
|
|
|
|
}
|
|
|
|
|
|
|
|
const Core::ItemMap & Core::ItemContainer::getItemMap() const
|
|
|
|
{
|
|
|
|
return m_itemMap;
|
|
|
|
}
|
|
|
|
|
|
|
|
int16_t Core::ItemContainer::getFreeSlot()
|
|
|
|
{
|
2017-08-11 22:56:30 +01:00
|
|
|
for( uint8_t slotId = 0; slotId < m_size; slotId++ )
|
2017-08-08 13:53:47 +02:00
|
|
|
{
|
|
|
|
ItemMap::iterator it = m_itemMap.find( slotId );
|
|
|
|
if( it == m_itemMap.end() ||
|
|
|
|
it->second == nullptr )
|
|
|
|
return slotId;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
Core::ItemPtr Core::ItemContainer::getItem( uint8_t slotId )
|
|
|
|
{
|
|
|
|
|
|
|
|
if( ( slotId > m_size ) || ( slotId == -1 ) )
|
|
|
|
{
|
|
|
|
g_log.error( "Slot out of range " + std::to_string( slotId ) );
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return m_itemMap[slotId];
|
|
|
|
}
|
|
|
|
|
|
|
|
void Core::ItemContainer::setItem( uint8_t slotId, Core::ItemPtr pItem )
|
|
|
|
{
|
|
|
|
if( ( slotId > m_size ) )
|
|
|
|
return;
|
|
|
|
|
|
|
|
m_itemMap[slotId] = pItem;
|
|
|
|
}
|