From abbe35196bbb224c33b53fc39d377ea5d6497a05 Mon Sep 17 00:00:00 2001 From: ErikasKontenis Date: Wed, 21 Apr 2021 19:30:15 +0300 Subject: [PATCH] refactor chests rewards description to show enchant value --- data/actions/scripts/misc/chests.lua | 49 ++++++++++++++++++++-------- 1 file changed, 35 insertions(+), 14 deletions(-) diff --git a/data/actions/scripts/misc/chests.lua b/data/actions/scripts/misc/chests.lua index b94751a..b119b1b 100644 --- a/data/actions/scripts/misc/chests.lua +++ b/data/actions/scripts/misc/chests.lua @@ -51,39 +51,60 @@ function onUse(player, item, fromPosition, target, toPosition) if rewardClone:getType():getAttack() > 0 then rewardClone:setAttribute(ITEM_ATTRIBUTE_ATTACK, rewardClone:getType():getAttack() + attackAttribute) local description = rewardClone:hasAttribute(ITEM_ATTRIBUTE_DESCRIPTION) and rewardClone:getAttribute(ITEM_ATTRIBUTE_DESCRIPTION) or rewardClone:getType():getDescription() + if description ~= nil and description ~= '' then + description = description .. ". " + end + if attackAttribute == 5 then - if description == nil or description == '' then - rewardClone:setAttribute(ITEM_ATTRIBUTE_DESCRIPTION, description .. "Enchanted with perfect attack.") - else - rewardClone:setAttribute(ITEM_ATTRIBUTE_DESCRIPTION, description .. ". Enchanted with perfect attack.") + rewardClone:setAttribute(ITEM_ATTRIBUTE_DESCRIPTION, description .. "Enchanted with perfect attack.") + else + if attackAttribute ~= 0 then + rewardClone:setAttribute(ITEM_ATTRIBUTE_DESCRIPTION, description .. "Enchanted with " .. attackAttribute .. " attack.") end end end + local defenseAttribute = math.random(-2, 5) if rewardClone:getType():getDefense() > 0 then rewardClone:setAttribute(ITEM_ATTRIBUTE_DEFENSE, rewardClone:getType():getDefense() + defenseAttribute) local description = rewardClone:hasAttribute(ITEM_ATTRIBUTE_DESCRIPTION) and rewardClone:getAttribute(ITEM_ATTRIBUTE_DESCRIPTION) or rewardClone:getType():getDescription() - if defenseAttribute == 5 then - if attackAttribute == 5 and rewardClone:getType():getAttack() > 0 then + + if rewardClone:getType():getAttack() > 0 and attackAttribute ~= 0 then + if defenseAttribute == 5 then rewardClone:setAttribute(ITEM_ATTRIBUTE_DESCRIPTION, description .. " Enchanted with perfect defense.") else - if description == nil or description == '' then - rewardClone:setAttribute(ITEM_ATTRIBUTE_DESCRIPTION, description .. "Enchanted with perfect defense.") - else - rewardClone:setAttribute(ITEM_ATTRIBUTE_DESCRIPTION, description .. ". Enchanted with perfect defense.") + if defenseAttribute ~= 0 then + rewardClone:setAttribute(ITEM_ATTRIBUTE_DESCRIPTION, description .. " Enchanted with " .. defenseAttribute .. " defense.") + end + end + else + if description ~= nil and description ~= '' then + description = description .. ". " + end + + if defenseAttribute == 5 then + rewardClone:setAttribute(ITEM_ATTRIBUTE_DESCRIPTION, description .. "Enchanted with perfect defense.") + else + if defenseAttribute ~= 0 then + rewardClone:setAttribute(ITEM_ATTRIBUTE_DESCRIPTION, description .. "Enchanted with " .. defenseAttribute .. " defense.") end end end end + local armorAttribute = math.random(-1, 2) if rewardClone:getType():getArmor() > 0 then rewardClone:setAttribute(ITEM_ATTRIBUTE_ARMOR, rewardClone:getType():getArmor() + armorAttribute) local description = rewardClone:hasAttribute(ITEM_ATTRIBUTE_DESCRIPTION) and rewardClone:getAttribute(ITEM_ATTRIBUTE_DESCRIPTION) or rewardClone:getType():getDescription() + if description ~= nil and description ~= '' then + description = description .. ". " + end + if armorAttribute == 2 then - if description == nil or description == '' then - rewardClone:setAttribute(ITEM_ATTRIBUTE_DESCRIPTION, description .. "Enchanted with perfect armor protection.") - else - rewardClone:setAttribute(ITEM_ATTRIBUTE_DESCRIPTION, description .. ". Enchanted with perfect armor protection.") + rewardClone:setAttribute(ITEM_ATTRIBUTE_DESCRIPTION, description .. "Enchanted with perfect armor protection.") + else + if armorAttribute ~= 0 then + rewardClone:setAttribute(ITEM_ATTRIBUTE_DESCRIPTION, description .. "Enchanted with " .. armorAttribute .. " armor protection.") end end end