From 7ac611fabbb4a31fa8b2322b56fdeaf72b074370 Mon Sep 17 00:00:00 2001 From: DarkGod <darkgod@net-core.org> Date: Mon, 3 Aug 2020 17:30:17 +0200 Subject: [PATCH] Fix absolute resistance display in tooltips --- game/engines/default/engine/utils.lua | 4 ++-- game/modules/tome/class/Actor.lua | 18 ++++++++++++------ 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/game/engines/default/engine/utils.lua b/game/engines/default/engine/utils.lua index 3d720cc540..1aa08e64ce 100644 --- a/game/engines/default/engine/utils.lua +++ b/game/engines/default/engine/utils.lua @@ -704,7 +704,7 @@ function table.orderedPairs(t) return function () if i < n then i = i + 1 - return sorted_keys[i], t[sorted_keys[i]] + return sorted_keys[i], t[sorted_keys[i]], i == n end end end @@ -720,7 +720,7 @@ function table.orderedPairs2(t, ordering) if index <= #t then value = t[index] index = index + 1 - return value[1], value[2] + return value[1], value[2], index == #t + 1 end end end diff --git a/game/modules/tome/class/Actor.lua b/game/modules/tome/class/Actor.lua index a67a89d593..b024318e10 100644 --- a/game/modules/tome/class/Actor.lua +++ b/game/modules/tome/class/Actor.lua @@ -2055,18 +2055,24 @@ function _M:tooltip(x, y, seen_by) --if #resists > 0 then ts:add("Resists: ", table.concat(resists, ','), true) end local dt_order = function(a, b) - if a[1] == "all" then return true - elseif b[1] == "all" then return false - else return a[2] > b[2] end + if a[1] == "absolute" then return true + elseif b[1] == "absolute" then return false + else + if a[1] == "all" then return true + elseif b[1] == "all" then return false + else return a[2] > b[2] end + end end local resists = tstring{} local first = true ts:add({"color", "ANTIQUE_WHITE"}, _t"Resists: ") - for t, _ in table.orderedPairs2(self.resists or {}, dt_order) do + for t, ov, is_last in table.orderedPairs2(self.resists or {}, dt_order) do local v = self:combatGetResist(t) - if t == "all" or t == "absolute" then - ts:add({"color", "LIGHT_BLUE"}, tostring(math.floor(v)) .. "%", " ", {"color", "LAST"}, _t(t)..", ") + if t == "all" then + ts:add({"color", "LIGHT_BLUE"}, tostring(math.floor(v)) .. "%", " ", {"color", "LAST"}, _t(t)) if not is_last then ts:add(", ") end + elseif t == "absolute" then + ts:add({"color", "LIGHT_BLUE"}, tostring(math.floor(ov)) .. "%", " ", {"color", "LAST"}, _t(t)) if not is_last then ts:add(", ") end elseif type(t) == "string" and math.abs(v) >= 20 then local res = tostring(math.floor(v)) .. "%" if first then first = false else ts:add(", ") end -- GitLab