local config = {
[2193] = {
manaLeech = {
text = "Mana leech",
param = CONDITION_PARAM_SPECIALSKILL_MANALEECHAMOUNT,
offset = 50,
upgradeValue = 1,
maxUpgrade = 20,
},
lifeLeech = {
text = "Life leech",
offset = 51,
param = CONDITION_PARAM_SPECIALSKILL_LIFELEECHAMOUNT,
upgradeValue = 1,
maxUpgrade = 20,
},
},
}
local wandUpgrade = Action()
function wandUpgrade.onUse(player, item, fromPosition, target, toPosition, isHotkey)
local itemId = item:getId()
local itemConfig = config[itemId]
if not itemConfig then
return false
end
local wandId = ItemType(target:getId())
local wandType = wandId:getWeaponType()
for attributeName, data in pairs(itemConfig) do
if wandType == WEAPON_WAND then
local wandDescription = target:getAttribute(ITEM_ATTRIBUTE_DESCRIPTION)
local searchText = "%("..data.text..": %+(%d+)%%%)"
local value = data.upgradeValue
local matchValue = string.match(wandDescription, searchText)
if not matchValue then
local newAttribute = "(" .. data.text .. ": +" .. data.upgradeValue .. "%)"
local newDescription = wandDescription .. "\n" .. newAttribute
target:setAttribute(ITEM_ATTRIBUTE_DESCRIPTION, newDescription)
-- SetCondition to player
local condition = player:getCondition(CONDITION_ATTRIBUTES, CONDITIONID_COMBAT, data.offset)
if not condition then
condition = Condition(CONDITION_ATTRIBUTES)
condition:setParameter(CONDITION_PARAM_SUBID, data.offset)
condition:setParameter(CONDITION_PARAM_TICKS, -1)
end
condition:setParameter(data.param, data.upgradeValue)
if value > 0 then
player:addCondition(condition)
else
player:removeCondition(CONDITION_ATTRIBUTES, CONDITIONID_COMBAT, data.offset)
end
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You have upgraded your " .. data.text .. " with " .. data.upgradeValue .. "%.")
return true
else
value = tonumber(matchValue) + data.upgradeValue
local newDescription = string.gsub(wandDescription, searchText, "(" .. data.text .. ": +" .. value .. "%%)")
target:setAttribute(ITEM_ATTRIBUTE_DESCRIPTION, newDescription)
-- Update the condition value
local condition = player:getCondition(CONDITION_ATTRIBUTES, CONDITIONID_COMBAT, data.offset)
if condition then
condition:setParameter(data.param, value)
end
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You have upgraded your " .. data.text .. " with " .. data.upgradeValue .. "%.")
return true
end
end
end
return false
end
for itemId, _ in pairs(config) do
wandUpgrade:id(itemId)
end
wandUpgrade:register()