Editing Module:AbilityTable/ComplexRenderers

Warning: You are not logged in. Once you make an edit, a temporary account will be created for you. Learn more. Log in or create an account to continue receiving notifications after this account expires, and to access other features.
The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.
Latest revision Your text
Line 47: Line 47:
end
end


-- Sums the non-zero values of `fields` within a single record layer (the base
-- Returns true if prop exists with a non-zero value anywhere in the record
-- ability record, or one upgrade tier). Returns nil when none are present.
-- excluding the Upgrades key.
local function sum_fields(layer, fields)
local function is_base_property(record, prop)
    local total = nil
     for k, v in pairs(record) do
     for _, field in ipairs(fields) do
         if k == "Upgrades" then
         local v = unwrap_value(layer[field])
            -- skip
        if v and v ~= 0 then total = (total or 0) + math.abs(v) end
        elseif k == prop then
            if type(v) == "table" then v = v["Value"] end
            if v ~= nil and v ~= 0 and v ~= "" and v ~= "0" and v ~= "0m" then
                return true
            end
        elseif type(v) == "table" then
            if is_base_property(v, prop) then return true end
        elseif type(v) == "string" then
            if v == prop then return true end
        end
     end
     end
     return total
     return false
end
end


-- Sums the barrier value and Spirit scaling contributed by a single record
-- Finds the base-level melee scale value by scanning for Scale.Type == "melee".
-- layer (the base ability record, or one upgrade tier). Returns nil when the
local function find_base_melee_scale(ability)
-- layer grants no barrier at all; a tier that only raises the scaling still
     for _, v in pairs(ability) do
-- counts, so "+0 value, +1.0 scaling" upgrades are not lost.
         if type(v) == "table" then
local function sum_barrier(layer, fields)
             local scale = v["Scale"]
    local value, scale, found = 0, 0, false
             if type(scale) == "table"
     for _, field in ipairs(fields) do
                and scale["Type"] == "melee"
         local entry = layer[field]
                and type(scale["Value"]) == "number"
        if entry ~= nil then
                 and scale["Value"] > 0
             local v = unwrap_value(entry) or 0
            then
            local s = 0
                return scale["Value"]
             if type(entry) == "table" and type(entry["Scale"]) == "table" then
                 s = entry["Scale"]["Value"] or 0
             end
             end
            if v ~= 0 or s ~= 0 then found = true end
            value = value + v
            scale = scale + s
         end
         end
     end
     end
     if not found then return nil end
     return nil
    return value, scale
end
end


-- Pads a whole-number scaling out to one decimal, so a running total of 2
-- ============================================================
-- reads "2.0" next to its "1.5" neighbours instead of "2". Values that already
-- Debuff short names (used by RenderDebuff)
-- carry decimals are left alone, which keeps precision on things like 0.75.
-- ============================================================
local function format_scale(scale)
    local text = tostring(scale)
    if not text:find(".", 1, true) then text = text .. ".0" end
    return text
end


-- Formats one barrier step. Spirit scaling goes through the compact {{Ss}}
local debuff_short_name = {
-- form, expanded via the frame the surrounding #invoke is already running
    ["StunDuration"]              = "stun",
-- under: module return values are not re-expanded, so a literal "{{Ss|0.8}}"
    ["SleepDuration"]              = "sleep",
-- would reach the page as text. The plain fallback covers a nil frame
    ["SilenceDuration"]            = "silence",
-- (module console).
    ["SilenceDebuff"]              = "silence",
local function format_barrier(value, scale)
    ["PetrifyDuration"]            = "petrify",
     local out = tostring(value)
    ["HexDuration"]                = "hex",
     if scale and scale ~= 0 then
    ["ImmobilizeDuration"]        = "immobilize",
        local scale_text = format_scale(scale)
    ["LiftDuration"]              = "lift",
        local frame = mw.getCurrentFrame()
     ["HoldInPlaceDuration"]        = "immobilize",
        if frame then
     ["RestrictionDuration"]        = "immobilize",
            out = out .. " " .. frame:expandTemplate{
    ["SlowPercent"]                = "slow",
                title = "Ss",
    ["EnemySlowPct"]              = "slow",
                args  = { scale_text, compact = "1", show_value = "1" },
    ["MoveSlowPercent"]            = "slow",
            }
    ["GroundDashReductionPercent"] = "dash slow",
        else
    ["SlowDuration"]              = "slow",
            out = out .. " ×" .. scale_text
    ["MaxSlowDuration"]            = "slow",
        end
    ["BulletDamageAmpDuration"]    = "bullet amp",
     end
    ["BulletResistReduction"]      = "bullet resist reduction",
     return out
    ["TimeSlowDuration"]          = "time slow",
end
    ["LateCheckoutStun"]          = "stun",
    ["BurnDuration"]              = "burn",
    ["BleedDuration"]              = "bleed",
     ["VenomDuration"]              = "venom",
     ["TossDuration"]              = "knockback",
}


-- ============================================================
-- ============================================================
Line 168: Line 171:


local p = {}
local p = {}
-- Renders the barrier an ability grants, with its Spirit Power scaling.
-- Both the value and the scaling accumulate across upgrades, so every step
-- after the first shows the running total: "100 x0.8 → 180 x1.5 (T2)".
-- A tier that only improves the scaling still gets its own segment.
function p.RenderBarrier(ability)
    local fields  = Lists.lists["barrier"]
    local segments = {}
    local value, scale = sum_barrier(ability, fields)
    if value then
        table.insert(segments, format_barrier(value, scale))
    else
        value, scale = 0, 0
    end
    local upgrades = ability["Upgrades"]
    if type(upgrades) == "table" then
        for i, tier in ipairs(upgrades) do
            if type(tier) == "table" then
                local delta_value, delta_scale = sum_barrier(tier, fields)
                if delta_value then
                    value, scale = value + delta_value, scale + delta_scale
                    table.insert(segments,
                        format_barrier(value, scale) .. " (T" .. i .. ")")
                end
            end
        end
    end
    if #segments == 0 then return {} end
    return { ["Barrier"] = table.concat(segments, " → ") }
end


-- Renders charge count and time between charges.
-- Renders charge count and time between charges.
Line 206: Line 176:
function p.RenderCharges(ability)
function p.RenderCharges(ability)
     local base_charges  = unwrap_value(ability["AbilityCharges"])
     local base_charges  = unwrap_value(ability["AbilityCharges"])
     local base_cooldown = unwrap_value(ability["AbilityCooldownBetweenCharge"])
     local base_cooldown = ability["AbilityCooldownBetweenCharge"]
     local has_base      = base_charges ~= nil and base_charges > 0
     local has_base      = base_charges ~= nil and base_charges > 0
     local upgrade_info  = find_in_upgrades(ability, "AbilityCharges")
     local upgrade_info  = find_in_upgrades(ability, "AbilityCharges")
Line 393: Line 363:
                         cells["Base Damage"] = tostring(v["Value"] or 0)
                         cells["Base Damage"] = tostring(v["Value"] or 0)
                         cells["Heavy Melee Scaling"] = "×" .. scale["Value"]
                         cells["Heavy Melee Scaling"] = "×" .. scale["Value"]
                         cells["Notes"] = "Only becomes Heavy Melee on '''T" .. i .. "''' upgrade"
                         cells["Notes"] = "Only becomes 'eavy Melee on '''T" .. i .. "''' upgrade"
                         return cells
                         return cells
                     end
                     end
Line 404: Line 374:
end
end


-- Renders Spirit Power scaling.
-- Renders base damage and heavy melee scaling.
-- Shows the Scale.Value for abilities whose Scale.Type is "spirit".
-- Notes when heavy melee is only available via upgrade.
function p.RenderSpiritScaling(ability)
function p.RenderHeavyMelee(ability)
    local base_scale = nil
     -- Find base heavy_melee property
    local base_prop = nil
    local base_damage, base_scale
 
     -- Find base Spirit scaling
     for k, v in pairs(ability) do
     for k, v in pairs(ability) do
         if k ~= "Upgrades" and type(v) == "table" then
         if k ~= "Upgrades" and type(v) == "table" then
             local scale = v["Scale"]
             local scale = v["Scale"]
             if type(scale) == "table"
             if type(scale) == "table" and scale["Type"] == "heavy_melee"
              and scale["Type"] == "spirit"
               and type(scale["Value"]) == "number" then
               and type(scale["Value"]) == "number"
                base_damage = v["Value"] or 0
              and scale["Value"] ~= 0 then
                 base_scale = scale["Value"]
                 base_scale = scale["Value"]
                base_prop = k
                 break
                 break
             end
             end
Line 427: Line 393:
     local cells = {}
     local cells = {}


     if base_scale then
    -- Active at base
         cells["Spirit Scaling"] = "×" .. base_scale
     if base_scale and base_scale > 0 then
         cells["Base Damage"] = tostring(base_damage)
        cells["Heavy Melee Scaling"] = "×" .. base_scale
        return cells
     end
     end


    -- Not at base — find in upgrades
     local upgrades = ability["Upgrades"]
     local upgrades = ability["Upgrades"]
     if type(upgrades) ~= "table" then return cells end
     if type(upgrades) ~= "table" then return cells end
    local notes = {}


     for i, tier in ipairs(upgrades) do
     for i, tier in ipairs(upgrades) do
         if type(tier) == "table" then
         if type(tier) == "table" then
            local upgrade_scale = nil
             for k, v in pairs(tier) do
             for k, v in pairs(tier) do
                 if type(v) == "table" then
                 if type(v) == "table" then
                     local scale = v["Scale"]
                     local scale = v["Scale"]
                     if type(scale) == "table"
                     if type(scale) == "table" and scale["Type"] == "heavy_melee"
                      and scale["Type"] == "spirit"
                       and type(scale["Value"]) == "number" and scale["Value"] > 0 then
                       and type(scale["Value"]) == "number"
                        cells["Base Damage"] = tostring(v["Value"] or 0)
                      and scale["Value"] ~= 0 then
                         cells["Heavy Melee Scaling"] = "×" .. scale["Value"]
                         upgrade_scale = scale["Value"]
                         cells["Notes"] = "Only becomes '''Heavy Melee''' on T" .. i .. " upgrade"
                         break
                        return cells
                     end
                     end
                 end
                 end
            end
            if upgrade_scale then
                table.insert(notes,
                    "on T" .. i .. " gets +×" .. upgrade_scale .. " Spirit scaling")
             end
             end
         end
         end
    end
    if #notes > 0 then
        cells["Notes"] = table.concat(notes, ". ")
     end
     end


Line 486: Line 443:
     end
     end
     return render_upgradable_stat(ability, "Heal Reduction", filtered, "%")
     return render_upgradable_stat(ability, "Heal Reduction", filtered, "%")
end
-- Shows a note if an ability acquires a debuff via upgrades.
-- Shared by debuffresist and dispelmagic.
function p.RenderDebuff(ability, stat)
    local stat_props = Lists.lists[stat]
    local cells = {}
    -- If any prop exists in base, this is a base-level debuff — no note needed.
    for _, prop in ipairs(stat_props) do
        if is_base_property(ability, prop) then
            return cells
        end
    end
    local upgrades = ability["Upgrades"]
    if type(upgrades) ~= "table" then return cells end
    local tier_debuffs = {}
    local seen_names  = {}
    for i, tier in ipairs(upgrades) do
        if type(tier) == "table" then
            local names_this_tier = {}
            local seen_this_tier  = {}
            for _, prop in ipairs(stat_props) do
                local v = tier[prop]
                if v ~= nil then
                    if type(v) == "table" then v = v["Value"] end
                    if v ~= nil and v ~= 0 and v ~= "" and v ~= "0" and v ~= "0m" then
                        local short = debuff_short_name[prop] or "debuff"
                        if not seen_this_tier[short] then
                            seen_this_tier[short] = true
                            if not seen_names[short] then
                                seen_names[short] = true
                                table.insert(names_this_tier, short)
                            end
                        end
                    end
                end
            end
            if #names_this_tier > 0 then
                tier_debuffs[i] = names_this_tier
            end
        end
    end
    local tier_indices = {}
    for i in pairs(tier_debuffs) do table.insert(tier_indices, i) end
    table.sort(tier_indices)
    local parts = {}
    for _, i in ipairs(tier_indices) do
        table.insert(parts, "T" .. i .. " " .. table.concat(tier_debuffs[i], " + "))
    end
    if #parts > 0 then cells["Notes"] = table.concat(parts, ", ") end
    return cells
end
end


Line 556: Line 571:


     return cells
     return cells
end
-- Renders the amount of Debuff Resist an ability grants.
-- Upgrades stack additively onto the base value, so every step after the first
-- shows the running total: "20% (T3)" when granted only by an upgrade,
-- "10% → 25% (T2)" when a base value is later increased. Chains for any number
-- of steps. No ability currently has both a base and an upgrade value.
function p.RenderExtraDebuffResist(ability)
    local fields  = Lists.lists["extradebuffresist"]
    local segments = {}
    local running = sum_fields(ability, fields)
    if running then
        table.insert(segments, running .. "%")
    end
    local upgrades = ability["Upgrades"]
    if type(upgrades) == "table" then
        for i, tier in ipairs(upgrades) do
            if type(tier) == "table" then
                local delta = sum_fields(tier, fields)
                if delta then
                    running = (running or 0) + delta
                    table.insert(segments, running .. "% (T" .. i .. ")")
                end
            end
        end
    end
    if #segments == 0 then return {} end
    return { ["Debuff Resist"] = table.concat(segments, " → ") }
end
end


return p
return p
Please note that all contributions to The Deadlock Wiki are considered to be released under the Creative Commons Attribution-NonCommercial-ShareAlike (see Deadlock:Copyrights for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource. Do not submit copyrighted work without permission!
Cancel Editing help (opens in new window)
Preview page with this template