All pastes #839871 Raw Edit

Unnamed

public cpp v1 · immutable
#839871 ·published 2007-12-31 08:16 UTC
rendered paste body
uint8 Player::CanEquipItem( uint8 slot, uint16 &dest, Item *pItem, bool swap, bool not_loading ) const{    dest = 0;    if( pItem )    {        sLog.outDebug( "STORAGE: CanEquipItem slot = %u, item = %u, count = %u", slot, pItem->GetEntry(), pItem->GetCount());        ItemPrototype const *pProto = pItem->GetProto();        if( pProto )        {            if(pItem->IsBindedNotWith(GetGUID()))                return EQUIP_ERR_DONT_OWN_THAT_ITEM;            // check count of items (skip for auto move for same player from bank)            uint8 res = CanTakeMoreSimilarItems(pItem);            if(res != EQUIP_ERR_OK)                return res;            // check unique-equipped on item            if (pProto->Flags & ITEM_FLAGS_UNIQUE_EQUIPPED) {                // there is an equip limit on this item                if (HasItemEquipped(pProto->ItemId))                    return EQUIP_ERR_ITEM_UNIQUE_EQUIPABLE;            }            // check unique-equipped on gems            for(uint32 enchant_slot = SOCK_ENCHANTMENT_SLOT; enchant_slot < SOCK_ENCHANTMENT_SLOT+3; ++enchant_slot)            {                uint32 enchant_id = pItem->GetEnchantmentId(EnchantmentSlot(enchant_slot));                if(!enchant_id)                    continue;                SpellItemEnchantmentEntry const* enchantEntry = sSpellItemEnchantmentStore.LookupEntry(enchant_id);                if(!enchantEntry)                    continue;                                ItemPrototype const* pGem = objmgr.GetItemPrototype(enchantEntry->GemID);                if(pGem && (pGem->Flags & ITEM_FLAGS_UNIQUE_EQUIPPED) && HasItemEquipped(enchantEntry->GemID))                    return EQUIP_ERR_ITEM_UNIQUE_EQUIPABLE;            }            if( isInCombat()&& pProto->Class != ITEM_CLASS_WEAPON && pProto->Class != ITEM_CLASS_PROJECTILE &&                pProto->SubClass != ITEM_SUBCLASS_ARMOR_SHIELD && pProto->InventoryType != INVTYPE_RELIC)                return EQUIP_ERR_NOT_IN_COMBAT;            if(isInCombat()&& pProto->Class == ITEM_CLASS_WEAPON && m_weaponChangeTimer != 0)                return EQUIP_ERR_CANT_DO_RIGHT_NOW;         // maybe exist better err            uint8 eslot = FindEquipSlot( pProto, slot, swap );            if( eslot == NULL_SLOT )                return EQUIP_ERR_ITEM_CANT_BE_EQUIPPED;            uint8 msg = CanUseItem( pItem , not_loading );            if( msg != EQUIP_ERR_OK )                return msg;            if( !swap && GetItemByPos( INVENTORY_SLOT_BAG_0, eslot ) )                return EQUIP_ERR_NO_EQUIPMENT_SLOT_AVAILABLE;            uint32 type = pProto->InventoryType;            if(eslot == EQUIPMENT_SLOT_OFFHAND)            {                if( type == INVTYPE_WEAPON || type == INVTYPE_WEAPONOFFHAND )                {                    if(!CanDualWield())                        return EQUIP_ERR_CANT_DUAL_WIELD;                }                Item *mainItem = GetItemByPos( INVENTORY_SLOT_BAG_0, EQUIPMENT_SLOT_MAINHAND );                if(mainItem)                {                    if(mainItem->GetProto()->InventoryType == INVTYPE_2HWEAPON)                        return EQUIP_ERR_CANT_EQUIP_WITH_TWOHANDED;                }                else if(type != INVTYPE_HOLDABLE)                {                    // not let equip offhand non-holdable item if mainhand not equipped                    return EQUIP_ERR_ITEM_CANT_BE_EQUIPPED;                }            }            if( type == INVTYPE_2HWEAPON )            {                uint8 twinslot = ( eslot == EQUIPMENT_SLOT_MAINHAND ? EQUIPMENT_SLOT_OFFHAND : EQUIPMENT_SLOT_MAINHAND );                Item *twinItem = GetItemByPos( INVENTORY_SLOT_BAG_0, twinslot );                if( twinItem )                    return EQUIP_ERR_ITEM_CANT_BE_EQUIPPED;            }            dest = ((INVENTORY_SLOT_BAG_0 << 8) | eslot);            return EQUIP_ERR_OK;        }    }    if( !swap )        return EQUIP_ERR_ITEM_NOT_FOUND;    else        return EQUIP_ERR_ITEMS_CANT_BE_SWAPPED;}