AMULET_ATTRIBUTE_INFO = 
{
    { ItemIndex = GET_ITEM(13, 300), BuffIndex = 73, Defense = 200, DefensePvP = 200, BlockSucess = 50, BlockSucessPvP = 30, AddLife = 250000, AddMana = 0, MinDmgLeft = 100, MaxDmgLeft = 150, MinDmgRight = 100, MaxDmgRight = 150, MagicMinDmg = 100, MagicMaxDmg = 150, AttackSpeed = 0, MagicSpeed = 0},
}

ItemAddEffect = {}    

function ItemAddEffect.Init()
    GameServerFunctions.CharacterSet(ItemAddEffect.CharacterSet)
    GameServerFunctions.CharacterSet(ItemAddEffect.AttributeElement)
end

function ItemAddEffect.AttributeElement(aIndex)    

    local pInv = Inventory.new(aIndex)

	local player = User.new(aIndex)
    
    if pInv:isItem(249) ~= 0 then
        for i = 1, #AMULET_ATTRIBUTE_INFO do
                
            local Amulet = AMULET_ATTRIBUTE_INFO[i]

            if Amulet.ItemIndex == pInv:getIndex(249)
            then
                if Amulet.Defense > 0
                then
                    player:setDefense((math.floor(player:getDefense() + Amulet.Defense)))
                end
                
                if Amulet.DefensePvP > 0
                then
                    player:setDefensePvP((math.floor(player:getDefensePvP() + Amulet.DefensePvP)))
                end
                
                if Amulet.BlockSucess > 0
                then
                    player:setSuccessBlock(math.floor(player:getSuccessBlock() + Amulet.BlockSucess))
                end
                
                if Amulet.BlockSucessPvP > 0
                then
                    player:setSuccessBlockPvP(math.floor(player:getSuccessBlockPvP() + Amulet.BlockSucessPvP))
                end
                
                if Amulet.AddLife > 0
                then
                    player:setAddLife((math.floor(player:getAddLife() + Amulet.AddLife)))
                end
                
                if Amulet.AddMana > 0
                then
                    player:setAddMana((math.floor(player:getAddMana() + Amulet.AddMana)))
                end
                
                if Amulet.MinDmgLeft > 0
                then
                    player:setAttackDamageMinLeft((math.floor(player:getAttackDamageMinLeft() + Amulet.MinDmgLeft)))
                end
                
                if Amulet.MaxDmgLeft > 0
                then
                    player:setAttackDamageMaxLeft((math.floor(player:getAttackDamageMaxLeft() + Amulet.MaxDmgLeft)))
                end
                
                if Amulet.MinDmgRight > 0
                then
                    player:setAttackDamageMinRight((math.floor(player:getAttackDamageMinRight() + Amulet.MinDmgRight)))
                end
                
                if Amulet.MaxDmgRight > 0
                then
                    player:setAttackDamageMaxRight((math.floor(player:getAttackDamageMaxRight() + Amulet.MaxDmgRight)))
                end
                
                if Amulet.MagicMinDmg > 0
                then
                    player:setMagicDamageMin((math.floor(player:getMagicDamageMin() + Amulet.MagicMinDmg)))
                end
                
                if Amulet.MagicMaxDmg > 0
                then
                    player:setMagicDamageMax((math.floor(player:getMagicDamageMax() + Amulet.MagicMaxDmg)))
                end
                
                if Amulet.AttackSpeed > 0
                then
                    player:setAttackSpeed((math.floor(player:getAttackSpeed() + Amulet.AttackSpeed)))
                end
                
                if Amulet.MagicSpeed > 0
                then
                    player:setMagicSpeed((math.floor(player:getMagicSpeed() + Amulet.MagicSpeed)))
                end
            end
        end
    end
    
	pInv = nil
	player = nil
end

function ItemAddEffect.CharacterSet(aIndex)
    local pInv = Inventory.new(aIndex)

    if pInv:isItem(249) ~= 0 then
        for i = 1, #AMULET_ATTRIBUTE_INFO do
            
            local AmuletBuff = AMULET_ATTRIBUTE_INFO[i]

            if AmuletBuff.ItemIndex == pInv:getIndex(249) then
                if CheckBuffPlayer(aIndex, AmuletBuff.BuffIndex) == 0 then

                    Timer.TimeOut(2, AddEffect, aIndex, 0, AmuletBuff.BuffIndex, 0, 0, 0, 0, 0 )

                end
            else
                if CheckBuffPlayer(aIndex, AmuletBuff.BuffIndex) == 1 then

                    Timer.TimeOut(2, RemoveEffect, aIndex, AmuletBuff.BuffIndex)
                end
            end
            
        end
    else
        for n = 1, #AMULET_ATTRIBUTE_INFO do

            local AmuletBuff = AMULET_ATTRIBUTE_INFO[n]

            if CheckBuffPlayer(aIndex, AmuletBuff.BuffIndex) == 1 then

                Timer.TimeOut(2, RemoveEffect, aIndex, AmuletBuff.BuffIndex)

            end
        end
    end
end

ItemAddEffect.Init()

return ItemAddEffect