1
Fork 0
mirror of https://github.com/SapphireServer/Sapphire.git synced 2025-05-01 16:37:45 +00:00

store item hq state in flags field

This commit is contained in:
collett 2023-03-11 18:44:37 +09:00
parent f608e1e8cf
commit 4411f22123
5 changed files with 54 additions and 36 deletions

View file

@ -1306,6 +1306,12 @@ namespace Sapphire::Common
GetGil = 9, // p1: gil GetGil = 9, // p1: gil
EmptyCoffer = 11, // seems like no param EmptyCoffer = 11, // seems like no param
}; };
enum ItemFlag
{
FlagNone = 0,
FlagHq = 1,
};
} }
#endif #endif

View file

@ -241,7 +241,7 @@ void Sapphire::Db::ZoneDbConnection::doPrepareStatements()
CONNECTION_BOTH ); CONNECTION_BOTH );
prepareStatement( CHARA_ITEMGLOBAL_UP, prepareStatement( CHARA_ITEMGLOBAL_UP,
"UPDATE charaglobalitem SET stack = ?, durability = ?, stain = ? WHERE ItemId = ?;", "UPDATE charaglobalitem SET stack = ?, durability = ?, flags = ?, reservedFlag = ?, stain = ? WHERE ItemId = ?;",
CONNECTION_BOTH ); CONNECTION_BOTH );
prepareStatement( CHARA_ITEMGLOBAL_DELETE, prepareStatement( CHARA_ITEMGLOBAL_DELETE,

View file

@ -547,38 +547,6 @@ void Sapphire::Entity::Player::writeInventory( InventoryType type )
db.execute( query ); 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 ) bool Sapphire::Entity::Player::isObtainable( uint32_t catalogId, uint8_t quantity )
{ {
return true; return true;

View file

@ -650,10 +650,13 @@ void Sapphire::Entity::Player::writeItemDb( Sapphire::ItemPtr pItem ) const
auto& itemMgr = Common::Service< World::Manager::ItemMgr >::ref(); auto& itemMgr = Common::Service< World::Manager::ItemMgr >::ref();
uint8_t flags = 0; uint8_t flags = 0;
if( pItem->isHq() )
flags |= Common::ItemFlag::FlagHq;
pItem->setUId( itemMgr.getNextUId() ); 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( getId() ) + ", " +
std::to_string( pItem->getUId() ) + ", " + std::to_string( pItem->getUId() ) + ", " +
std::to_string( pItem->getReservedFlag() ) + ", " +
std::to_string( pItem->getId() ) + ", " + std::to_string( pItem->getId() ) + ", " +
std::to_string( pItem->getStackSize() ) + ", " + std::to_string( pItem->getStackSize() ) + ", " +
std::to_string( flags ) + ");"; 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() bool Sapphire::Entity::Player::loadInventory()
{ {
auto& itemMgr = Common::Service< World::Manager::ItemMgr >::ref(); auto& itemMgr = Common::Service< World::Manager::ItemMgr >::ref();

View file

@ -132,15 +132,16 @@ Sapphire::ItemPtr Sapphire::World::Manager::ItemMgr::loadItem( uint64_t uId )
try try
{ {
auto itemInfo = exdData.get< Sapphire::Data::Item >( itemRes->getUInt( 1 ) ); 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, ItemPtr pItem = make_Item( uId,
itemRes->getUInt( 1 ), itemRes->getUInt( 1 ),
isHq ); isHq );
pItem->setStackSize( itemRes->getUInt( 2 ) ); pItem->setStackSize( itemRes->getUInt( 2 ) );
pItem->setStain( itemRes->getUInt16( 13 ) ); pItem->setReservedFlag( itemRes->getUInt( 3 ) );
pItem->setDurability( itemRes->getInt16( 6 ) ); pItem->setDurability( itemRes->getInt16( 6 ) );
pItem->setStain( itemRes->getUInt16( 13 ) );
return pItem; return pItem;
} }