diff --git a/src/common/Common.h b/src/common/Common.h index c9928c06..e095a77d 100644 --- a/src/common/Common.h +++ b/src/common/Common.h @@ -1306,6 +1306,12 @@ namespace Sapphire::Common GetGil = 9, // p1: gil EmptyCoffer = 11, // seems like no param }; + + enum ItemFlag + { + FlagNone = 0, + FlagHq = 1, + }; } #endif diff --git a/src/common/Database/ZoneDbConnection.cpp b/src/common/Database/ZoneDbConnection.cpp index 773f8cef..a23a1a72 100644 --- a/src/common/Database/ZoneDbConnection.cpp +++ b/src/common/Database/ZoneDbConnection.cpp @@ -241,7 +241,7 @@ void Sapphire::Db::ZoneDbConnection::doPrepareStatements() CONNECTION_BOTH ); prepareStatement( CHARA_ITEMGLOBAL_UP, - "UPDATE charaglobalitem SET stack = ?, durability = ?, stain = ? WHERE ItemId = ?;", + "UPDATE charaglobalitem SET stack = ?, durability = ?, flags = ?, reservedFlag = ?, stain = ? WHERE ItemId = ?;", CONNECTION_BOTH ); prepareStatement( CHARA_ITEMGLOBAL_DELETE, diff --git a/src/world/Actor/PlayerInventory.cpp b/src/world/Actor/PlayerInventory.cpp index cd752de3..af664a1f 100644 --- a/src/world/Actor/PlayerInventory.cpp +++ b/src/world/Actor/PlayerInventory.cpp @@ -547,38 +547,6 @@ void Sapphire::Entity::Player::writeInventory( InventoryType type ) db.execute( query ); } -void Sapphire::Entity::Player::updateItemDb( Sapphire::ItemPtr pItem ) const -{ - if( pItem->getUId() == 0 ) - writeItemDb( pItem ); - - auto& db = Common::Service< Db::DbWorkerPool< Db::ZoneDbConnection > >::ref(); - auto stmt = db.getPreparedStatement( Db::CHARA_ITEMGLOBAL_UP ); - - // todo: add more fields - stmt->setInt( 1, pItem->getStackSize() ); - stmt->setInt( 2, pItem->getDurability() ); - stmt->setInt( 3, pItem->getStain() ); - - stmt->setInt64( 4, pItem->getUId() ); - - db.directExecute( stmt ); -} - -void Sapphire::Entity::Player::deleteItemDb( Sapphire::ItemPtr item ) const -{ - if( item->getUId() == 0 ) - return; - - auto& db = Common::Service< Db::DbWorkerPool< Db::ZoneDbConnection > >::ref(); - auto stmt = db.getPreparedStatement( Db::CHARA_ITEMGLOBAL_DELETE ); - - stmt->setInt64( 1, item->getUId() ); - - db.directExecute( stmt ); -} - - bool Sapphire::Entity::Player::isObtainable( uint32_t catalogId, uint8_t quantity ) { return true; diff --git a/src/world/Actor/PlayerSql.cpp b/src/world/Actor/PlayerSql.cpp index bd3fe3d3..4b0bb68b 100644 --- a/src/world/Actor/PlayerSql.cpp +++ b/src/world/Actor/PlayerSql.cpp @@ -650,10 +650,13 @@ void Sapphire::Entity::Player::writeItemDb( Sapphire::ItemPtr pItem ) const auto& itemMgr = Common::Service< World::Manager::ItemMgr >::ref(); uint8_t flags = 0; + if( pItem->isHq() ) + flags |= Common::ItemFlag::FlagHq; pItem->setUId( itemMgr.getNextUId() ); - std::string sql = "INSERT INTO charaglobalitem ( CharacterId, itemId, catalogId, stack, flags ) VALUES ( " + + std::string sql = "INSERT INTO charaglobalitem ( CharacterId, itemId, reservedFlag, catalogId, stack, flags ) VALUES ( " + std::to_string( getId() ) + ", " + std::to_string( pItem->getUId() ) + ", " + + std::to_string( pItem->getReservedFlag() ) + ", " + std::to_string( pItem->getId() ) + ", " + std::to_string( pItem->getStackSize() ) + ", " + std::to_string( flags ) + ");"; @@ -661,6 +664,46 @@ void Sapphire::Entity::Player::writeItemDb( Sapphire::ItemPtr pItem ) const } } +void Sapphire::Entity::Player::updateItemDb( Sapphire::ItemPtr pItem ) const +{ + if( pItem->getUId() == 0 ) + { + writeItemDb( pItem ); + return; + } + + uint8_t flags = 0; + if( pItem->isHq() ) + flags |= Common::ItemFlag::FlagHq; + + auto& db = Common::Service< Db::DbWorkerPool< Db::ZoneDbConnection > >::ref(); + auto stmt = db.getPreparedStatement( Db::CHARA_ITEMGLOBAL_UP ); + + // todo: add more fields + stmt->setInt( 1, pItem->getStackSize() ); + stmt->setInt( 2, pItem->getDurability() ); + stmt->setInt( 3, flags ); + stmt->setInt( 4, pItem->getReservedFlag() ); + stmt->setInt( 5, pItem->getStain() ); + + stmt->setInt64( 6, pItem->getUId() ); + + db.directExecute( stmt ); +} + +void Sapphire::Entity::Player::deleteItemDb( Sapphire::ItemPtr item ) const +{ + if( item->getUId() == 0 ) + return; + + auto& db = Common::Service< Db::DbWorkerPool< Db::ZoneDbConnection > >::ref(); + auto stmt = db.getPreparedStatement( Db::CHARA_ITEMGLOBAL_DELETE ); + + stmt->setInt64( 1, item->getUId() ); + + db.directExecute( stmt ); +} + bool Sapphire::Entity::Player::loadInventory() { auto& itemMgr = Common::Service< World::Manager::ItemMgr >::ref(); diff --git a/src/world/Manager/ItemMgr.cpp b/src/world/Manager/ItemMgr.cpp index c8331dac..01d2b03c 100644 --- a/src/world/Manager/ItemMgr.cpp +++ b/src/world/Manager/ItemMgr.cpp @@ -132,15 +132,16 @@ Sapphire::ItemPtr Sapphire::World::Manager::ItemMgr::loadItem( uint64_t uId ) try { auto itemInfo = exdData.get< Sapphire::Data::Item >( itemRes->getUInt( 1 ) ); - bool isHq = itemRes->getUInt( 3 ) == 1; + bool isHq = itemRes->getUInt( 5 ) & Common::ItemFlag::FlagHq; ItemPtr pItem = make_Item( uId, itemRes->getUInt( 1 ), isHq ); pItem->setStackSize( itemRes->getUInt( 2 ) ); - pItem->setStain( itemRes->getUInt16( 13 ) ); + pItem->setReservedFlag( itemRes->getUInt( 3 ) ); pItem->setDurability( itemRes->getInt16( 6 ) ); + pItem->setStain( itemRes->getUInt16( 13 ) ); return pItem; }