Esempio n. 1
0
void Item::ApplyRandomProperties( bool apply )
{
    // apply random properties
    if( m_uint32Values[ITEM_FIELD_RANDOM_PROPERTIES_ID] != 0 )
    {
        if( int32( m_uint32Values[ITEM_FIELD_RANDOM_PROPERTIES_ID] ) > 0 )      // Random Property
        {
            ItemRandomPropertiesEntry* rp= dbcItemRandomProperties.LookupEntry( m_uint32Values[ITEM_FIELD_RANDOM_PROPERTIES_ID] );
            if(rp == NULL)
                return;

            int32 Slot;
            for( int k = 0; k < 3; k++ )
            {
                if( rp->spells[k] != 0 )
                {
                    EnchantEntry* ee = dbcEnchant.LookupEntry( rp->spells[k] );
                    Slot = HasEnchantment( ee->Id );
                    if( Slot < 0 )
                    {
                        Slot = FindFreeEnchantSlot( ee, 1 );
                        AddEnchantment( ee, 0, false, apply, true, Slot );
                    }
                    else
                        if( apply )
                            ApplyEnchantmentBonus( Slot, true );
                }
            }
        }
        else
        {
            ItemRandomSuffixEntry* rs = dbcItemRandomSuffix.LookupEntry( abs( int( m_uint32Values[ITEM_FIELD_RANDOM_PROPERTIES_ID] ) ) );
            if(rs == NULL)
                return;
            int32 Slot;
            for( uint32 k = 0; k < 3; ++k )
            {
                if( rs->enchantments[k] != 0 )
                {
                    EnchantEntry* ee = dbcEnchant.LookupEntry( rs->enchantments[k] );
                    Slot = HasEnchantment( ee->Id );
                    if( Slot < 0 )
                    {
                        Slot = FindFreeEnchantSlot( ee, 2 );
                        AddEnchantment( ee, 0, false, apply, true, Slot, rs->prefixes[k] );
                    }
                    else
                        if( apply )
                            ApplyEnchantmentBonus( Slot, true );
                }
            }
        }
    }
}
Esempio n. 2
0
void Item::RemoveEnchantmentBonuses()
{
    EnchantmentMap::iterator itr, itr2;
    for( itr = Enchantments.begin(); itr != Enchantments.end(); )
    {
        itr2 = itr++;
        if(!itr2->second.Dummy)
            ApplyEnchantmentBonus( itr2->first, REMOVE );
    }

    int32 value = 0;
    ItemPrototype* proto = NULL;
    for(uint32 gem = 0; gem < 3; gem++)
    {
        if(!Gems[gem])
            continue;

        proto = ItemPrototypeStorage.LookupEntry(Gems[gem]);
        if(proto == NULL)
            continue;

        if(proto->Armor)
        {
            m_owner->BaseResistance[RESISTANCE_ARMOR] -= proto->Armor;
            m_owner->CalcResistance(RESISTANCE_ARMOR);
        }

        for(uint32 i = 0; i < 10; i++)
        {
            if(value = proto->Stats[i].Value)
                m_owner->ModifyBonuses( proto->Stats[i].Type, -value );
        }
        proto = NULL;
    }
}
Esempio n. 3
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;
}
Esempio n. 4
0
void Item::ApplyRandomProperties(bool apply)
{
    // apply random properties
    if (GetItemRandomPropertyId() != 0)
    {
        if (int32(GetItemRandomPropertyId()) > 0)
        {
            RandomProps* rp = dbcRandomProps.LookupEntry(GetItemRandomPropertyId());
            int32 Slot;
            for (int k = 0; k < 3; k++)
            {
                if (rp->spells[k] != 0)
                {
                    EnchantEntry* ee = dbcEnchant.LookupEntry(rp->spells[k]);
                    Slot = HasEnchantment(ee->Id);
                    if (Slot < 0)
                    {
                        Slot = FindFreeEnchantSlot(ee, 1);
                        AddEnchantment(ee, 0, false, apply, true, Slot);
                    }
                    else if (apply)
                        ApplyEnchantmentBonus(Slot, true);
                }
            }
        }
        else
        {
            ItemRandomSuffixEntry* rs = dbcItemRandomSuffix.LookupEntry(abs(int(GetItemRandomPropertyId())));
            int32 Slot;
            for (uint32 k = 0; k < 3; ++k)
            {
                if (rs->enchantments[k] != 0)
                {
                    EnchantEntry* ee = dbcEnchant.LookupEntry(rs->enchantments[k]);
                    Slot = HasEnchantment(ee->Id);
                    if (Slot < 0)
                    {
                        Slot = FindFreeEnchantSlot(ee, 2);
                        AddEnchantment(ee, 0, false, apply, true, Slot, rs->prefixes[k]);
                    }
                    else if (apply)
                        ApplyEnchantmentBonus(Slot, true);
                }
            }
        }
    }
}
Esempio n. 5
0
void Item::RemoveEnchantmentBonuses()
{
	EnchantmentMap::iterator itr, itr2;
	for( itr = Enchantments.begin(); itr != Enchantments.end(); )
	{
		itr2 = itr++;
		ApplyEnchantmentBonus( itr2->first, REMOVE );
	}
}
Esempio n. 6
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);
}
Esempio n. 7
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.
	uint32 EnchantBase = Slot * 3 + ITEM_FIELD_ENCHANTMENT;
	SetUInt32Value( EnchantBase + 0, 0 );
	SetUInt32Value( EnchantBase + 1, 0 );
	SetUInt32Value( EnchantBase + 2, 0 );

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

	// Remove the enchantment instance.
	Enchantments.erase( itr );
}
Esempio n. 8
0
int32 Item::AddEnchantment( EnchantEntry* Enchantment, uint32 Duration, bool Perm /* = false */, bool apply /* = true */, bool RemoveAtLogout /* = false */, uint32 Slot_, uint32 RandomSuffix )
{
	int32 Slot = Slot_;
	m_isDirty = true;

/*
	if(Perm)
	{
		if(Slot_)
		{
			Slot=Slot_;
		}
		else
        {
			Slot = FindFreeEnchantSlot(Enchantment);
        }
	}
	else
	{
		if(Enchantment->EnchantGroups > 1) // replaceable temp enchants
		{
			Slot = 1;
			RemoveEnchantment(1);
		}
		else
		{
			Slot = FindFreeEnchantSlot(Enchantment);*/
			/*
			Slot = Enchantment->type ? 3 : 0;
			 //that's 's code
			for(uint32 Index = ITEM_FIELD_ENCHANTMENT_09; Index < ITEM_FIELD_ENCHANTMENT_32; Index += 3)
			{
				if(m_uint32Values[Index] == 0) break;;	
				++Slot;
			}

			//Slot = FindFreeEnchantSlot(Enchantment);
			// reach max of temp enchants
			if(Slot >= 11) return -1;
			*/
		/*}
	}   
*/

	// 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;

	// Set the enchantment in the item fields.
	uint32 EnchantBase = Slot * 3 + ITEM_FIELD_ENCHANTMENT;
	SetUInt32Value( EnchantBase, Enchantment->Id );
	SetUInt32Value( EnchantBase + 1, (uint32)Instance.ApplyTime );
	SetUInt32Value( EnchantBase + 2, 0 ); // charges

	// 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, 0 );
	}

	// 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();
		}
	
		/* 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 );
	}

	return Slot;
}
Esempio n. 9
0
void Item::RemoveEnchantmentBonuses()
{
    EnchantmentMap::iterator itr, itr2;
    for( itr = Enchantments.begin(); itr != Enchantments.end(); )
    {
        itr2 = itr++;
        if(!itr2->second.Dummy)
            ApplyEnchantmentBonus( itr2->first, REMOVE );
    }

    int32 value = 0;
    ItemPrototype* proto = NULL;
    for(uint32 gem = 0; gem < 3; gem++)
    {
        if(!Gems[gem])
            continue;

        proto = ItemPrototypeStorage.LookupEntry(Gems[gem]);
        if(proto == NULL)
            continue;

        if(proto->Armor)
        {
            m_owner->BaseResistance[RESISTANCE_ARMOR] -= proto->Armor;
            m_owner->CalcResistance(RESISTANCE_ARMOR);
        }

        if( proto->HolyRes )
        {
            m_owner->FlatResistanceModifierPos[RESISTANCE_HOLY] -= proto->HolyRes;
            m_owner->CalcResistance(RESISTANCE_HOLY);
        }

        if( proto->FireRes )
        {
            m_owner->FlatResistanceModifierPos[RESISTANCE_FIRE] -= proto->FireRes;
            m_owner->CalcResistance(RESISTANCE_FIRE);
        }

        if( proto->NatureRes )
        {
            m_owner->FlatResistanceModifierPos[RESISTANCE_NATURE] -= proto->NatureRes;
            m_owner->CalcResistance(RESISTANCE_NATURE);
        }

        if( proto->FrostRes )
        {
            m_owner->FlatResistanceModifierPos[RESISTANCE_FROST] -= proto->FrostRes;
            m_owner->CalcResistance(RESISTANCE_FROST);
        }

        if( proto->ShadowRes )
        {
            m_owner->FlatResistanceModifierPos[RESISTANCE_SHADOW] -= proto->ShadowRes;
            m_owner->CalcResistance(RESISTANCE_SHADOW);
        }

        if( proto->ArcaneRes )
        {
            m_owner->FlatResistanceModifierPos[RESISTANCE_ARCANE] -= proto->ArcaneRes;
            m_owner->CalcResistance(RESISTANCE_ARCANE);
        }

        for(uint32 i = 0; i < 10; i++)
        {
            if(value = proto->Stats[i].Value)
                m_owner->ModifyBonuses( proto->Stats[i].Type, -value );
        }
        proto = NULL;
    }
}
Esempio n. 10
0
void Item::RemoveEnchantmentBonuses()
{
    for (EnchantmentMap::iterator itr = Enchantments.begin(); itr != Enchantments.end(); ++itr)
        ApplyEnchantmentBonus(itr->first, REMOVE);
}
Esempio n. 11
0
void Item::ApplyEnchantmentBonuses()
{
    for (EnchantmentMap::iterator itr = Enchantments.begin(); itr != Enchantments.end(); ++itr)
        ApplyEnchantmentBonus(itr->first, APPLY);
}