mirror of
https://github.com/mangosfour/server.git
synced 2025-12-14 16:37:01 +00:00
Code style and cleanups in item equip checks.
This commit is contained in:
parent
bfe2e187a6
commit
167e8c86f6
1 changed files with 46 additions and 40 deletions
|
|
@ -9592,17 +9592,17 @@ uint8 Player::CanEquipItem( uint8 slot, uint16 &dest, Item *pItem, bool swap, bo
|
||||||
return EQUIP_ERR_ITEM_CANT_BE_EQUIPPED;
|
return EQUIP_ERR_ITEM_CANT_BE_EQUIPPED;
|
||||||
|
|
||||||
uint8 eslot = FindEquipSlot( pProto, slot, swap );
|
uint8 eslot = FindEquipSlot( pProto, slot, swap );
|
||||||
if( eslot == NULL_SLOT )
|
if (eslot == NULL_SLOT)
|
||||||
return EQUIP_ERR_ITEM_CANT_BE_EQUIPPED;
|
return EQUIP_ERR_ITEM_CANT_BE_EQUIPPED;
|
||||||
|
|
||||||
uint8 msg = CanUseItem( pItem , not_loading );
|
uint8 msg = CanUseItem(pItem , not_loading);
|
||||||
if( msg != EQUIP_ERR_OK )
|
if (msg != EQUIP_ERR_OK)
|
||||||
return msg;
|
return msg;
|
||||||
if( !swap && GetItemByPos( INVENTORY_SLOT_BAG_0, eslot ) )
|
if (!swap && GetItemByPos(INVENTORY_SLOT_BAG_0, eslot))
|
||||||
return EQUIP_ERR_NO_EQUIPMENT_SLOT_AVAILABLE;
|
return EQUIP_ERR_NO_EQUIPMENT_SLOT_AVAILABLE;
|
||||||
|
|
||||||
// if swap ignore item (equipped also)
|
// if swap ignore item (equipped also)
|
||||||
if(uint8 res2 = CanEquipUniqueItem(pItem, swap ? eslot : NULL_SLOT))
|
if (uint8 res2 = CanEquipUniqueItem(pItem, swap ? eslot : NULL_SLOT))
|
||||||
return res2;
|
return res2;
|
||||||
|
|
||||||
// check unique-equipped special item classes
|
// check unique-equipped special item classes
|
||||||
|
|
@ -9610,19 +9610,16 @@ uint8 Player::CanEquipItem( uint8 slot, uint16 &dest, Item *pItem, bool swap, bo
|
||||||
{
|
{
|
||||||
for(int i = INVENTORY_SLOT_BAG_START; i < INVENTORY_SLOT_BAG_END; ++i)
|
for(int i = INVENTORY_SLOT_BAG_START; i < INVENTORY_SLOT_BAG_END; ++i)
|
||||||
{
|
{
|
||||||
if( Item* pBag = GetItemByPos( INVENTORY_SLOT_BAG_0, i ) )
|
if (Item* pBag = GetItemByPos(INVENTORY_SLOT_BAG_0, i))
|
||||||
{
|
{
|
||||||
if( pBag != pItem )
|
if (pBag != pItem)
|
||||||
{
|
{
|
||||||
if( ItemPrototype const* pBagProto = pBag->GetProto() )
|
if (ItemPrototype const* pBagProto = pBag->GetProto())
|
||||||
{
|
{
|
||||||
if( pBagProto->Class==pProto->Class && (!swap || pBag->GetSlot() != eslot ) )
|
if (pBagProto->Class==pProto->Class && (!swap || pBag->GetSlot() != eslot))
|
||||||
{
|
return (pBagProto->SubClass == ITEM_SUBCLASS_AMMO_POUCH)
|
||||||
if(pBagProto->SubClass == ITEM_SUBCLASS_AMMO_POUCH)
|
? EQUIP_ERR_CAN_EQUIP_ONLY1_AMMOPOUCH
|
||||||
return EQUIP_ERR_CAN_EQUIP_ONLY1_AMMOPOUCH;
|
: EQUIP_ERR_CAN_EQUIP_ONLY1_QUIVER;
|
||||||
else
|
|
||||||
return EQUIP_ERR_CAN_EQUIP_ONLY1_QUIVER;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -9631,25 +9628,25 @@ uint8 Player::CanEquipItem( uint8 slot, uint16 &dest, Item *pItem, bool swap, bo
|
||||||
|
|
||||||
uint32 type = pProto->InventoryType;
|
uint32 type = pProto->InventoryType;
|
||||||
|
|
||||||
if(eslot == EQUIPMENT_SLOT_OFFHAND)
|
if (eslot == EQUIPMENT_SLOT_OFFHAND)
|
||||||
{
|
{
|
||||||
if (type == INVTYPE_WEAPON || type == INVTYPE_WEAPONOFFHAND)
|
if (type == INVTYPE_WEAPON || type == INVTYPE_WEAPONOFFHAND)
|
||||||
{
|
{
|
||||||
if(!CanDualWield())
|
if (!CanDualWield())
|
||||||
return EQUIP_ERR_CANT_DUAL_WIELD;
|
return EQUIP_ERR_CANT_DUAL_WIELD;
|
||||||
}
|
}
|
||||||
else if (type == INVTYPE_2HWEAPON)
|
else if (type == INVTYPE_2HWEAPON)
|
||||||
{
|
{
|
||||||
if(!CanDualWield() || !CanTitanGrip())
|
if (!CanDualWield() || !CanTitanGrip())
|
||||||
return EQUIP_ERR_CANT_DUAL_WIELD;
|
return EQUIP_ERR_CANT_DUAL_WIELD;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(IsTwoHandUsed())
|
if (IsTwoHandUsed())
|
||||||
return EQUIP_ERR_CANT_EQUIP_WITH_TWOHANDED;
|
return EQUIP_ERR_CANT_EQUIP_WITH_TWOHANDED;
|
||||||
}
|
}
|
||||||
|
|
||||||
// equip two-hand weapon case (with possible unequip 2 items)
|
// equip two-hand weapon case (with possible unequip 2 items)
|
||||||
if( type == INVTYPE_2HWEAPON )
|
if (type == INVTYPE_2HWEAPON)
|
||||||
{
|
{
|
||||||
if (eslot == EQUIPMENT_SLOT_OFFHAND)
|
if (eslot == EQUIPMENT_SLOT_OFFHAND)
|
||||||
{
|
{
|
||||||
|
|
@ -9664,9 +9661,9 @@ uint8 Player::CanEquipItem( uint8 slot, uint16 &dest, Item *pItem, bool swap, bo
|
||||||
// offhand item must can be stored in inventory for offhand item and it also must be unequipped
|
// offhand item must can be stored in inventory for offhand item and it also must be unequipped
|
||||||
Item *offItem = GetItemByPos( INVENTORY_SLOT_BAG_0, EQUIPMENT_SLOT_OFFHAND );
|
Item *offItem = GetItemByPos( INVENTORY_SLOT_BAG_0, EQUIPMENT_SLOT_OFFHAND );
|
||||||
ItemPosCountVec off_dest;
|
ItemPosCountVec off_dest;
|
||||||
if( offItem && (!not_loading ||
|
if (offItem && (!not_loading ||
|
||||||
CanUnequipItem(uint16(INVENTORY_SLOT_BAG_0) << 8 | EQUIPMENT_SLOT_OFFHAND,false) != EQUIP_ERR_OK ||
|
CanUnequipItem(uint16(INVENTORY_SLOT_BAG_0) << 8 | EQUIPMENT_SLOT_OFFHAND,false) != EQUIP_ERR_OK ||
|
||||||
CanStoreItem( NULL_BAG, NULL_SLOT, off_dest, offItem, false ) != EQUIP_ERR_OK ) )
|
CanStoreItem( NULL_BAG, NULL_SLOT, off_dest, offItem, false ) != EQUIP_ERR_OK ))
|
||||||
return swap ? EQUIP_ERR_ITEMS_CANT_BE_SWAPPED : EQUIP_ERR_INVENTORY_FULL;
|
return swap ? EQUIP_ERR_ITEMS_CANT_BE_SWAPPED : EQUIP_ERR_INVENTORY_FULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -9674,10 +9671,8 @@ uint8 Player::CanEquipItem( uint8 slot, uint16 &dest, Item *pItem, bool swap, bo
|
||||||
return EQUIP_ERR_OK;
|
return EQUIP_ERR_OK;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if( !swap )
|
|
||||||
return EQUIP_ERR_ITEM_NOT_FOUND;
|
return !swap ? EQUIP_ERR_ITEM_NOT_FOUND : EQUIP_ERR_ITEMS_CANT_BE_SWAPPED;
|
||||||
else
|
|
||||||
return EQUIP_ERR_ITEMS_CANT_BE_SWAPPED;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8 Player::CanUnequipItem( uint16 pos, bool swap ) const
|
uint8 Player::CanUnequipItem( uint16 pos, bool swap ) const
|
||||||
|
|
@ -9896,38 +9891,49 @@ uint8 Player::CanBankItem( uint8 bag, uint8 slot, ItemPosCountVec &dest, Item *p
|
||||||
|
|
||||||
uint8 Player::CanUseItem( Item *pItem, bool not_loading ) const
|
uint8 Player::CanUseItem( Item *pItem, bool not_loading ) const
|
||||||
{
|
{
|
||||||
if( pItem )
|
if (pItem)
|
||||||
{
|
{
|
||||||
sLog.outDebug( "STORAGE: CanUseItem item = %u", pItem->GetEntry());
|
sLog.outDebug( "STORAGE: CanUseItem item = %u", pItem->GetEntry());
|
||||||
if( !isAlive() && not_loading )
|
|
||||||
|
if (!isAlive() && not_loading)
|
||||||
return EQUIP_ERR_YOU_ARE_DEAD;
|
return EQUIP_ERR_YOU_ARE_DEAD;
|
||||||
//if( isStunned() )
|
|
||||||
|
//if (isStunned())
|
||||||
// return EQUIP_ERR_YOU_ARE_STUNNED;
|
// return EQUIP_ERR_YOU_ARE_STUNNED;
|
||||||
|
|
||||||
ItemPrototype const *pProto = pItem->GetProto();
|
ItemPrototype const *pProto = pItem->GetProto();
|
||||||
if( pProto )
|
if (pProto)
|
||||||
{
|
{
|
||||||
if( pItem->IsBindedNotWith(GetGUID()) )
|
if (pItem->IsBindedNotWith(GetGUID()))
|
||||||
return EQUIP_ERR_DONT_OWN_THAT_ITEM;
|
return EQUIP_ERR_DONT_OWN_THAT_ITEM;
|
||||||
if( (pProto->AllowableClass & getClassMask()) == 0 || (pProto->AllowableRace & getRaceMask()) == 0 )
|
|
||||||
|
if ((pProto->AllowableClass & getClassMask()) == 0 || (pProto->AllowableRace & getRaceMask()) == 0)
|
||||||
return EQUIP_ERR_YOU_CAN_NEVER_USE_THAT_ITEM;
|
return EQUIP_ERR_YOU_CAN_NEVER_USE_THAT_ITEM;
|
||||||
if( pItem->GetSkill() != 0 )
|
|
||||||
|
if (pItem->GetSkill() != 0)
|
||||||
{
|
{
|
||||||
if( GetSkillValue( pItem->GetSkill() ) == 0 )
|
if (GetSkillValue( pItem->GetSkill() ) == 0)
|
||||||
return EQUIP_ERR_NO_REQUIRED_PROFICIENCY;
|
return EQUIP_ERR_NO_REQUIRED_PROFICIENCY;
|
||||||
}
|
}
|
||||||
if( pProto->RequiredSkill != 0 )
|
|
||||||
|
if (pProto->RequiredSkill != 0)
|
||||||
{
|
{
|
||||||
if( GetSkillValue( pProto->RequiredSkill ) == 0 )
|
if (GetSkillValue( pProto->RequiredSkill ) == 0)
|
||||||
return EQUIP_ERR_NO_REQUIRED_PROFICIENCY;
|
return EQUIP_ERR_NO_REQUIRED_PROFICIENCY;
|
||||||
else if( GetSkillValue( pProto->RequiredSkill ) < pProto->RequiredSkillRank )
|
|
||||||
|
if (GetSkillValue( pProto->RequiredSkill ) < pProto->RequiredSkillRank)
|
||||||
return EQUIP_ERR_ERR_CANT_EQUIP_SKILL;
|
return EQUIP_ERR_ERR_CANT_EQUIP_SKILL;
|
||||||
}
|
}
|
||||||
if( pProto->RequiredSpell != 0 && !HasSpell( pProto->RequiredSpell ) )
|
|
||||||
|
if (pProto->RequiredSpell != 0 && !HasSpell(pProto->RequiredSpell))
|
||||||
return EQUIP_ERR_NO_REQUIRED_PROFICIENCY;
|
return EQUIP_ERR_NO_REQUIRED_PROFICIENCY;
|
||||||
if( pProto->RequiredReputationFaction && uint32(GetReputationRank(pProto->RequiredReputationFaction)) < pProto->RequiredReputationRank )
|
|
||||||
|
if (pProto->RequiredReputationFaction && uint32(GetReputationRank(pProto->RequiredReputationFaction)) < pProto->RequiredReputationRank)
|
||||||
return EQUIP_ERR_CANT_EQUIP_REPUTATION;
|
return EQUIP_ERR_CANT_EQUIP_REPUTATION;
|
||||||
if( getLevel() < pProto->RequiredLevel )
|
|
||||||
|
if (getLevel() < pProto->RequiredLevel)
|
||||||
return EQUIP_ERR_CANT_EQUIP_LEVEL_I;
|
return EQUIP_ERR_CANT_EQUIP_LEVEL_I;
|
||||||
|
|
||||||
return EQUIP_ERR_OK;
|
return EQUIP_ERR_OK;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue