1
Fork 0
mirror of https://github.com/SapphireServer/Sapphire.git synced 2025-05-02 16:57:47 +00:00

Fix and optimize itemlevel; IsWeapon Item Property;

This commit is contained in:
Maru 2017-11-16 20:44:37 -02:00
parent 6bf2fc2016
commit 31df365a09
4 changed files with 25 additions and 11 deletions

View file

@ -86,7 +86,7 @@ void Core::Entity::Player::equipWeapon( Core::ItemPtr pItem )
} }
// equip an item // equip an item
void Core::Entity::Player::equipItem( Inventory::EquipSlot equipSlotId, Core::ItemPtr pItem, bool sendModel ) void Core::Entity::Player::equipItem( Inventory::EquipSlot equipSlotId, Core::ItemPtr pItem, bool sendUpdate )
{ {
//g_log.debug( "Equipping into slot " + std::to_string( equipSlotId ) ); //g_log.debug( "Equipping into slot " + std::to_string( equipSlotId ) );
@ -118,11 +118,12 @@ void Core::Entity::Player::equipItem( Inventory::EquipSlot equipSlotId, Core::It
} }
if( sendModel ) if( sendUpdate )
{
this->sendModel(); this->sendModel();
m_itemLevel = getInventory()->calculateEquippedGearItemLevel(); m_itemLevel = getInventory()->calculateEquippedGearItemLevel();
sendItemLevel(); sendItemLevel();
}
} }
void Core::Entity::Player::unequipItem( Inventory::EquipSlot equipSlotId, ItemPtr pItem ) void Core::Entity::Player::unequipItem( Inventory::EquipSlot equipSlotId, ItemPtr pItem )

View file

@ -833,20 +833,26 @@ uint16_t Core::Inventory::calculateEquippedGearItemLevel()
{ {
uint32_t iLvlResult = 0; uint32_t iLvlResult = 0;
for ( uint16_t i = 0; i < sizeof( m_inventoryMap[GearSet0] ); i++ ) auto gearSetMap = m_inventoryMap[GearSet0]->getItemMap();
auto it = gearSetMap.begin();
while ( it != gearSetMap.end() )
{ {
auto currItem = m_inventoryMap[GearSet0]->getItem( i ); auto currItem = it->second;
if ( currItem ) if ( currItem )
{ {
g_log.debug( std::to_string( currItem->getId() ) + " ilvl: " + std::to_string( currItem->getItemLevel() ) );
iLvlResult += currItem->getItemLevel(); iLvlResult += currItem->getItemLevel();
// If weapon isn't one-handed // If item is weapon and isn't one-handed
if ( currItem->getCategory() != ItemCategory::CnjWep || if ( currItem->isWeapon() &&
currItem->getCategory() != ItemCategory::ThmWep ) ( currItem->getCategory() != ItemCategory::CnjWep ||
currItem->getCategory() != ItemCategory::ThmWep ) )
iLvlResult += currItem->getItemLevel(); iLvlResult += currItem->getItemLevel();
} }
it++;
} }
return boost::algorithm::clamp( iLvlResult / 12, 0, 9999 ); return boost::algorithm::clamp( iLvlResult / 12, 0, 9999 );

View file

@ -68,6 +68,11 @@ uint16_t Core::Item::getWeaponDmg() const
return m_weaponDmg; return m_weaponDmg;
} }
bool Core::Item::isWeapon() const
{
return (m_weaponDmg != 0);
}
uint32_t Core::Item::getId() const uint32_t Core::Item::getId() const
{ {
return m_id; return m_id;

View file

@ -48,6 +48,8 @@ public:
uint16_t getWeaponDmg() const; uint16_t getWeaponDmg() const;
bool isWeapon() const;
float getAutoAttackDmg() const; float getAutoAttackDmg() const;
uint16_t getItemLevel() const; uint16_t getItemLevel() const;