1
Fork 0
mirror of https://github.com/SapphireServer/Sapphire.git synced 2025-05-08 19:57:46 +00:00

sql cleanup/improvements, add some fields for durability/stain

This commit is contained in:
NotAdam 2018-08-31 23:25:53 +10:00
parent 23344c02e6
commit 8b00fe6012
5 changed files with 53 additions and 6 deletions

View file

@ -175,5 +175,13 @@ void Core::Db::CharaDbConnection::doPrepareStatements()
"INSERT INTO charaglobalitem ( CharacterId, ItemId, catalogId, UPDATE_DATE ) VALUES ( ?, ?, ?, NOW() );",
CONNECTION_BOTH );
prepareStatement( CHARA_ITEMGLOBAL_UP,
"UPDATE charaglobalitem SET stack = ?, durability = ?, stain = ? WHERE ItemId = ?;",
CONNECTION_BOTH );
prepareStatement( CHARA_ITEMGLOBAL_DELETE,
"UPDATE charaglobalitem SET IS_DELETE = 1 WHERE ItemId = ?;",
CONNECTION_BOTH );
}

View file

@ -74,6 +74,8 @@ enum CharaDbStatements :
CHARA_ITEMINV_INS,
CHARA_ITEMGLOBAL_INS,
CHARA_ITEMGLOBAL_UP,
CHARA_ITEMGLOBAL_DELETE,
MAX_STATEMENTS
};

View file

@ -428,15 +428,26 @@ void Core::Entity::Player::writeInventory( InventoryType type )
void Core::Entity::Player::writeItem( Core::ItemPtr pItem ) const
{
auto pDb = g_fw.get< Db::DbWorkerPool< Db::CharaDbConnection > >();
pDb->execute( "UPDATE charaglobalitem SET stack = " + std::to_string( pItem->getStackSize() ) + " " +
// TODO: add other attributes
" WHERE itemId = " + std::to_string( pItem->getUId() ) );
auto stmt = pDb->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() );
pDb->directExecute( stmt );
}
void Core::Entity::Player::deleteItemDb( Core::ItemPtr item ) const
{
auto pDb = g_fw.get< Db::DbWorkerPool< Db::CharaDbConnection > >();
pDb->execute( "UPDATE charaglobalitem SET IS_DELETE = 1 WHERE itemId = " + std::to_string( item->getUId() ) );
auto stmt = pDb->getPreparedStatement( Db::CHARA_ITEMGLOBAL_DELETE );
stmt->setInt64( 1, item->getUId() );
pDb->directExecute( stmt );
}
@ -464,8 +475,6 @@ Core::ItemPtr Core::Entity::Player::addItem( uint32_t catalogId, uint32_t quanti
// used for item obtain notification
uint32_t originalQuantity = quantity;
// todo: for now we're just going to add any items to main inv
std::pair< uint16_t, uint8_t > freeBagSlot;
bool foundFreeSlot = false;

View file

@ -132,3 +132,23 @@ uint32_t Core::Item::getMaxStackSize() const
{
return m_maxStackSize;
}
uint16_t Core::Item::getDurability() const
{
return m_durability;
}
void Core::Item::setDurability( uint16_t durability )
{
m_durability = durability;
}
uint16_t Core::Item::getStain() const
{
return m_stain;
}
void Core::Item::setStain( uint16_t stain )
{
m_stain = stain;
}

View file

@ -55,6 +55,12 @@ public:
uint32_t getMaxStackSize() const;
uint16_t getDurability() const;
void setDurability( uint16_t durability );
uint16_t getStain() const;
void setStain( uint16_t stain );
protected:
uint32_t m_id;
@ -78,6 +84,8 @@ protected:
uint16_t m_weaponDmg;
float m_autoAttackDmg;
uint16_t m_itemLevel;
uint16_t m_durability;
uint16_t m_stain;
};