mirror of
https://github.com/SapphireServer/Sapphire.git
synced 2025-04-29 07:37:45 +00:00
fix loading of currency/crystal items
This commit is contained in:
parent
783bd655a8
commit
791f934a2d
2 changed files with 20 additions and 127 deletions
|
@ -58,10 +58,10 @@ void Core::Entity::Player::initInventory()
|
||||||
setupContainer( GearSet0, 13, "charaitemgearset", true );
|
setupContainer( GearSet0, 13, "charaitemgearset", true );
|
||||||
|
|
||||||
// gil contianer
|
// gil contianer
|
||||||
setupContainer( Currency, 11, "charaitemcurrency", false );
|
setupContainer( Currency, 11, "charaiteminventory", false );
|
||||||
|
|
||||||
// crystals??
|
// crystals??
|
||||||
setupContainer( Crystal, 11, "charaitemcrystal", false );
|
setupContainer( Crystal, 11, "charaiteminventory", false );
|
||||||
|
|
||||||
// armory weapons - 0
|
// armory weapons - 0
|
||||||
setupContainer( ArmoryMain, 34, "charaiteminventory", true );
|
setupContainer( ArmoryMain, 34, "charaiteminventory", true );
|
||||||
|
@ -219,20 +219,22 @@ void Core::Entity::Player::unequipItem( Common::EquipSlot equipSlotId, ItemPtr p
|
||||||
// TODO: these next functions are so similar that they could likely be simplified
|
// TODO: these next functions are so similar that they could likely be simplified
|
||||||
void Core::Entity::Player::addCurrency( CurrencyType type, uint32_t amount )
|
void Core::Entity::Player::addCurrency( CurrencyType type, uint32_t amount )
|
||||||
{
|
{
|
||||||
auto currItem = m_inventoryMap[Currency]->getItem( static_cast< uint8_t >( type ) - 1 );
|
auto slot = static_cast< uint8_t >( static_cast< uint8_t >( type ) - 1 );
|
||||||
|
auto currItem = m_inventoryMap[Currency]->getItem( slot );
|
||||||
|
|
||||||
if( !currItem )
|
if( !currItem )
|
||||||
{
|
{
|
||||||
// TODO: map currency type to itemid
|
// TODO: map currency type to itemid
|
||||||
currItem = createItem( 1 );
|
currItem = createItem( 1 );
|
||||||
m_inventoryMap[Currency]->setItem( static_cast< uint8_t >( type ) - 1, currItem );
|
m_inventoryMap[Currency]->setItem( slot, currItem );
|
||||||
updateCurrencyDb();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t currentAmount = currItem->getStackSize();
|
uint32_t currentAmount = currItem->getStackSize();
|
||||||
currItem->setStackSize( currentAmount + amount );
|
currItem->setStackSize( currentAmount + amount );
|
||||||
updateItemDb( currItem );
|
updateItemDb( currItem );
|
||||||
|
|
||||||
|
updateContainer( Currency, slot, currItem );
|
||||||
|
|
||||||
auto invUpdate = boost::make_shared< UpdateInventorySlotPacket >( getId(),
|
auto invUpdate = boost::make_shared< UpdateInventorySlotPacket >( getId(),
|
||||||
static_cast< uint8_t >( type ) - 1,
|
static_cast< uint8_t >( type ) - 1,
|
||||||
Common::InventoryType::Currency,
|
Common::InventoryType::Currency,
|
||||||
|
@ -272,7 +274,6 @@ void Core::Entity::Player::addCrystal( Common::CrystalType type, uint32_t amount
|
||||||
// TODO: map currency type to itemid
|
// TODO: map currency type to itemid
|
||||||
currItem = createItem( static_cast< uint8_t >( type ) + 1 );
|
currItem = createItem( static_cast< uint8_t >( type ) + 1 );
|
||||||
m_inventoryMap[Crystal]->setItem( static_cast< uint8_t >( type ) - 1, currItem );
|
m_inventoryMap[Crystal]->setItem( static_cast< uint8_t >( type ) - 1, currItem );
|
||||||
updateCrystalDb();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t currentAmount = currItem->getStackSize();
|
uint32_t currentAmount = currItem->getStackSize();
|
||||||
|
@ -281,6 +282,8 @@ void Core::Entity::Player::addCrystal( Common::CrystalType type, uint32_t amount
|
||||||
|
|
||||||
updateItemDb( currItem );
|
updateItemDb( currItem );
|
||||||
|
|
||||||
|
updateBagDb( Crystal );
|
||||||
|
|
||||||
|
|
||||||
auto invUpdate = boost::make_shared< UpdateInventorySlotPacket >( getId(),
|
auto invUpdate = boost::make_shared< UpdateInventorySlotPacket >( getId(),
|
||||||
static_cast< uint8_t >( type ) - 1,
|
static_cast< uint8_t >( type ) - 1,
|
||||||
|
@ -435,69 +438,16 @@ uint32_t Core::Entity::Player::getCrystal( CrystalType type )
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Core::Entity::Player::updateCurrencyDb()
|
|
||||||
{
|
|
||||||
auto pDb = g_fw.get< Db::DbWorkerPool< Db::CharaDbConnection > >();
|
|
||||||
int32_t firstItemPos = -1;
|
|
||||||
std::string query = "UPDATE charaitemcurrency SET ";
|
|
||||||
|
|
||||||
for( int32_t i = 0; i <= 11; i++ )
|
|
||||||
{
|
|
||||||
auto currItem = m_inventoryMap[Currency]->getItem( i );
|
|
||||||
|
|
||||||
if( currItem )
|
|
||||||
{
|
|
||||||
if( firstItemPos == -1 )
|
|
||||||
firstItemPos = i;
|
|
||||||
|
|
||||||
if( i > firstItemPos )
|
|
||||||
query += ", ";
|
|
||||||
|
|
||||||
query += "container_" + std::to_string( i ) + " = " + std::to_string( currItem->getUId() );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
query += " WHERE CharacterId = " + std::to_string( getId() );
|
|
||||||
|
|
||||||
pDb->execute( query );
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void Core::Entity::Player::updateCrystalDb()
|
|
||||||
{
|
|
||||||
auto pDb = g_fw.get< Db::DbWorkerPool< Db::CharaDbConnection > >();
|
|
||||||
int32_t firstItemPos = -1;
|
|
||||||
std::string query = "UPDATE charaitemcrystal SET ";
|
|
||||||
|
|
||||||
for( int32_t i = 0; i <= 11; i++ )
|
|
||||||
{
|
|
||||||
auto currItem = m_inventoryMap[Crystal]->getItem( i );
|
|
||||||
|
|
||||||
if( currItem )
|
|
||||||
{
|
|
||||||
if( firstItemPos == -1 )
|
|
||||||
firstItemPos = i;
|
|
||||||
|
|
||||||
if( i > firstItemPos )
|
|
||||||
query += ", ";
|
|
||||||
|
|
||||||
query += "container_" + std::to_string( i ) + " = " + std::to_string( currItem->getUId() );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
query += " WHERE CharacterId = " + std::to_string( getId() );
|
|
||||||
|
|
||||||
pDb->execute( query );
|
|
||||||
}
|
|
||||||
|
|
||||||
void Core::Entity::Player::updateBagDb( InventoryType type )
|
void Core::Entity::Player::updateBagDb( InventoryType type )
|
||||||
{
|
{
|
||||||
auto pDb = g_fw.get< Db::DbWorkerPool< Db::CharaDbConnection > >();
|
auto pDb = g_fw.get< Db::DbWorkerPool< Db::CharaDbConnection > >();
|
||||||
std::string query = "UPDATE charaiteminventory SET ";
|
std::string query = "UPDATE charaiteminventory SET ";
|
||||||
|
|
||||||
for( int32_t i = 0; i <= 34; i++ )
|
auto container = m_inventoryMap[type];
|
||||||
|
|
||||||
|
for( int32_t i = 0; i <= container->getMaxSize(); i++ )
|
||||||
{
|
{
|
||||||
auto currItem = m_inventoryMap[type]->getItem( i );
|
auto currItem = container->getItem( i );
|
||||||
|
|
||||||
if( i > 0 )
|
if( i > 0 )
|
||||||
query += ", ";
|
query += ", ";
|
||||||
|
@ -518,9 +468,11 @@ void Core::Entity::Player::updateMannequinDb( InventoryType type )
|
||||||
auto pDb = g_fw.get< Db::DbWorkerPool< Db::CharaDbConnection > >();
|
auto pDb = g_fw.get< Db::DbWorkerPool< Db::CharaDbConnection > >();
|
||||||
std::string query = "UPDATE charaitemgearset SET ";
|
std::string query = "UPDATE charaitemgearset SET ";
|
||||||
|
|
||||||
for( int32_t i = 0; i <= 13; i++ )
|
auto container = m_inventoryMap[type];
|
||||||
|
|
||||||
|
for( int32_t i = 0; i <= container->getMaxSize(); i++ )
|
||||||
{
|
{
|
||||||
auto currItem = m_inventoryMap[type]->getItem( i );
|
auto currItem = container->getItem( i );
|
||||||
|
|
||||||
if( i > 0 )
|
if( i > 0 )
|
||||||
query += ", ";
|
query += ", ";
|
||||||
|
@ -661,8 +613,8 @@ bool Core::Entity::Player::updateContainer( uint16_t containerId, uint8_t slotId
|
||||||
switch( containerType )
|
switch( containerType )
|
||||||
{
|
{
|
||||||
case Armory:
|
case Armory:
|
||||||
case CurrencyCrystal:
|
|
||||||
case Bag:
|
case Bag:
|
||||||
|
case CurrencyCrystal:
|
||||||
{
|
{
|
||||||
updateBagDb( static_cast< InventoryType >( containerId ) );
|
updateBagDb( static_cast< InventoryType >( containerId ) );
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -627,7 +627,7 @@ bool Core::Entity::Player::loadInventory()
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
// Load Bags
|
// Load everything
|
||||||
auto bagRes = pDb->query( "SELECT storageId, "
|
auto bagRes = pDb->query( "SELECT storageId, "
|
||||||
"container_0, container_1, container_2, container_3, container_4, "
|
"container_0, container_1, container_2, container_3, container_4, "
|
||||||
"container_5, container_6, container_7, container_8, container_9, "
|
"container_5, container_6, container_7, container_8, container_9, "
|
||||||
|
@ -643,7 +643,7 @@ bool Core::Entity::Player::loadInventory()
|
||||||
while( bagRes->next() )
|
while( bagRes->next() )
|
||||||
{
|
{
|
||||||
uint16_t storageId = bagRes->getUInt16( 1 );
|
uint16_t storageId = bagRes->getUInt16( 1 );
|
||||||
for( uint32_t i = 1; i <= 35; i++ )
|
for( uint32_t i = 1; i <= m_inventoryMap[storageId]->getMaxSize(); i++ )
|
||||||
{
|
{
|
||||||
uint64_t uItemId = bagRes->getUInt64( i + 1 );
|
uint64_t uItemId = bagRes->getUInt64( i + 1 );
|
||||||
if( uItemId == 0 )
|
if( uItemId == 0 )
|
||||||
|
@ -658,64 +658,5 @@ bool Core::Entity::Player::loadInventory()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
// Load Currency
|
|
||||||
auto curRes = pDb->query( "SELECT storageId, "
|
|
||||||
"container_0, container_1, container_2, container_3, container_4, "
|
|
||||||
"container_5, container_6, container_7, container_8, container_9, "
|
|
||||||
"container_10, container_11 "
|
|
||||||
"FROM charaitemcurrency " \
|
|
||||||
"WHERE CharacterId = " + std::to_string( getId() ) + " " \
|
|
||||||
"ORDER BY storageId ASC;" );
|
|
||||||
|
|
||||||
while( curRes->next() )
|
|
||||||
{
|
|
||||||
uint16_t storageId = curRes->getUInt16( 1 );
|
|
||||||
for( uint32_t i = 1; i <= 12; i++ )
|
|
||||||
{
|
|
||||||
uint64_t uItemId = curRes->getUInt64( i + 1 );
|
|
||||||
if( uItemId == 0 )
|
|
||||||
continue;
|
|
||||||
|
|
||||||
ItemPtr pItem = Items::Util::loadItem( uItemId );
|
|
||||||
|
|
||||||
if( pItem == nullptr )
|
|
||||||
continue;
|
|
||||||
|
|
||||||
m_inventoryMap[storageId]->getItemMap()[i - 1] = pItem;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
// Load Crystals
|
|
||||||
auto crystalRes = pDb->query( "SELECT storageId, "
|
|
||||||
"container_0, container_1, container_2, container_3, container_4, "
|
|
||||||
"container_5, container_6, container_7, container_8, container_9, "
|
|
||||||
"container_10, container_11, container_12, container_13, container_14, "
|
|
||||||
"container_15, container_16, container_17 "
|
|
||||||
"FROM charaitemcrystal " \
|
|
||||||
"WHERE CharacterId = " + std::to_string( getId() ) + " " \
|
|
||||||
"ORDER BY storageId ASC;" );
|
|
||||||
|
|
||||||
while( crystalRes->next() )
|
|
||||||
{
|
|
||||||
uint16_t storageId = crystalRes->getUInt16( 1 );
|
|
||||||
for( int32_t i = 1; i <= 17; i++ )
|
|
||||||
{
|
|
||||||
uint64_t uItemId = crystalRes->getUInt64( i + 1 );
|
|
||||||
if( uItemId == 0 )
|
|
||||||
continue;
|
|
||||||
|
|
||||||
ItemPtr pItem = Items::Util::loadItem( uItemId );
|
|
||||||
|
|
||||||
if( pItem == nullptr )
|
|
||||||
continue;
|
|
||||||
|
|
||||||
m_inventoryMap[storageId]->getItemMap()[i - 1] = pItem;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue