From 8b00fe6012f8e83050350e1d1b1897706ad9e768 Mon Sep 17 00:00:00 2001 From: NotAdam Date: Fri, 31 Aug 2018 23:25:53 +1000 Subject: [PATCH] sql cleanup/improvements, add some fields for durability/stain --- src/common/Database/CharaDbConnection.cpp | 8 +++++++ src/common/Database/CharaDbConnection.h | 2 ++ .../sapphire_zone/Actor/PlayerInventory.cpp | 21 +++++++++++++------ src/servers/sapphire_zone/Inventory/Item.cpp | 20 ++++++++++++++++++ src/servers/sapphire_zone/Inventory/Item.h | 8 +++++++ 5 files changed, 53 insertions(+), 6 deletions(-) diff --git a/src/common/Database/CharaDbConnection.cpp b/src/common/Database/CharaDbConnection.cpp index c8076af1..f89c61df 100644 --- a/src/common/Database/CharaDbConnection.cpp +++ b/src/common/Database/CharaDbConnection.cpp @@ -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 ); + } diff --git a/src/common/Database/CharaDbConnection.h b/src/common/Database/CharaDbConnection.h index d595158d..5a6a1f94 100644 --- a/src/common/Database/CharaDbConnection.h +++ b/src/common/Database/CharaDbConnection.h @@ -74,6 +74,8 @@ enum CharaDbStatements : CHARA_ITEMINV_INS, CHARA_ITEMGLOBAL_INS, + CHARA_ITEMGLOBAL_UP, + CHARA_ITEMGLOBAL_DELETE, MAX_STATEMENTS }; diff --git a/src/servers/sapphire_zone/Actor/PlayerInventory.cpp b/src/servers/sapphire_zone/Actor/PlayerInventory.cpp index 07a95123..09430f79 100644 --- a/src/servers/sapphire_zone/Actor/PlayerInventory.cpp +++ b/src/servers/sapphire_zone/Actor/PlayerInventory.cpp @@ -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; diff --git a/src/servers/sapphire_zone/Inventory/Item.cpp b/src/servers/sapphire_zone/Inventory/Item.cpp index 08601604..97802d6f 100644 --- a/src/servers/sapphire_zone/Inventory/Item.cpp +++ b/src/servers/sapphire_zone/Inventory/Item.cpp @@ -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; +} diff --git a/src/servers/sapphire_zone/Inventory/Item.h b/src/servers/sapphire_zone/Inventory/Item.h index 1f30fbf0..ba6c56c5 100644 --- a/src/servers/sapphire_zone/Inventory/Item.h +++ b/src/servers/sapphire_zone/Inventory/Item.h @@ -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; };