Exemple #1
0
int32 Item::AddEnchantment(EnchantEntry* Enchantment, uint32 Duration, bool Perm /* = false */, bool apply /* = true */, bool RemoveAtLogout /* = false */, uint32 Slot_, uint32 RandomSuffix, bool dummy /* = false */ )
{
    int32 Slot = Slot_;
    m_isDirty = true;

    // Create the enchantment struct.
    EnchantmentInstance Instance;
    Instance.ApplyTime = UNIXTIME;
    Instance.BonusApplied = false;
    Instance.Slot = Slot;
    Instance.Enchantment = Enchantment;
    Instance.Duration = Duration;
    Instance.RemoveAtLogout = RemoveAtLogout;
    Instance.RandomSuffix = RandomSuffix;
    Instance.Dummy = dummy;

    // Set the enchantment in the item fields.
    SetEnchantmentId(Slot, Enchantment->Id);
    SetEnchantmentDuration(Slot, (uint32)Instance.ApplyTime);
    SetEnchantmentCharges(Slot, 0);

    // Add it to our map.
    Enchantments.insert(make_pair((uint32)Slot, Instance));

    if( m_owner == NULL )
        return Slot;

    // Add the removal event.
    if( Duration )
        sEventMgr.AddEvent( this, &Item::RemoveEnchantment, uint32(Slot), EVENT_REMOVE_ENCHANTMENT1 + Slot, Duration * 1000, 1, EVENT_FLAG_DO_NOT_EXECUTE_IN_WORLD_CONTEXT );

    // No need to send the log packet, if the owner isn't in world (we're still loading)
    if( !m_owner->IsInWorld() )
        return Slot;

    if( apply )
    {
/*      WorldPacket EnchantLog( SMSG_ENCHANTMENTLOG, 25 );
        EnchantLog << m_owner->GetGUID();
        EnchantLog << m_owner->GetGUID();
        EnchantLog << m_uint32Values[OBJECT_FIELD_ENTRY];
        EnchantLog << Enchantment->Id;
        EnchantLog << uint8(0);
        m_owner->GetSession()->SendPacket( &EnchantLog );*/

        if( m_owner->GetTradeTarget() )
            m_owner->SendTradeUpdate();

        if(Instance.Dummy)
            return Slot;

        /* Only apply the enchantment bonus if we're equipped */
        uint8 slot = m_owner->GetItemInterface()->GetInventorySlotByGuid( GetGUID() );
        if( slot > EQUIPMENT_SLOT_START && slot < EQUIPMENT_SLOT_END )
            ApplyEnchantmentBonus( Slot, APPLY );
    }

    m_owner->SaveToDB(false);
    return Slot;
}
Exemple #2
0
void Item::RemoveEnchantment(uint32 EnchantmentSlot)
{
    // Make sure we actually exist.
    EnchantmentMap::iterator itr = Enchantments.find(EnchantmentSlot);
    if (itr == Enchantments.end())
        return;

    m_isDirty = true;
    uint32 Slot = itr->first;
    if (itr->second.BonusApplied)
        ApplyEnchantmentBonus(EnchantmentSlot, REMOVE);

    // Unset the item fields.
    SetEnchantmentId(Slot, 0);
    SetEnchantmentDuration(Slot, 0);
    SetEnchantmentCharges(Slot, 0);

    // Remove the enchantment event for removal.
    event_RemoveEvents(EVENT_REMOVE_ENCHANTMENT1 + Slot);

    // Remove the enchantment instance.
    Enchantments.erase(itr);
}