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 255: Line 255:
end
end


-- Renders base damage and melee scaling.
-- Renders light melee scaling.
-- Special case for upgrades that switch from Light to Heavy Melee scaling.
-- Special case for upgrades that change to heavy melee scaling.
function p.RenderMelee(ability)
function p.RenderMelee(ability)
    local melee_types = {}
    for _, t in ipairs(Lists.lists["melee"]) do melee_types[t] = true end
    -- Find the base property with active melee/heavy_melee scaling (Scale.Value > 0)
    local base_prop, base_damage, base_scale, base_type
    for k, v in pairs(ability) do
        if k ~= "Upgrades" and type(v) == "table" then
            local scale = v["Scale"]
            if type(scale) == "table" and melee_types[scale["Type"]]
              and type(scale["Value"]) == "number" and scale["Value"] > 0 then
                base_prop = k
                base_damage = v["Value"] or 0
                base_scale = scale["Value"]
                base_type = scale["Type"]
                break
            end
        end
    end
     local cells = {}
     local cells = {}
     cells["Base Damage"] = tostring(base_damage or 0)
     local base_scale = find_base_melee_scale(ability)
     if base_scale then
     if base_scale then cells["Light Melee Scaling"] = "×" .. base_scale end
        cells["Light Melee Scaling"] = "×" .. base_scale
    end


     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 = {}
     local notes = {}
    local running_damage = base_damage or 0
    local running_scale = base_scale or 0
    local running_type = base_type
     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 damage_delta = 0
             for _, v in pairs(tier) do
            local new_scale = nil
            local new_type = nil
 
             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" and melee_types[scale["Type"]] then
                     if type(scale) == "table" and type(scale["Value"]) == "number" then
                         damage_delta = damage_delta + (v["Value"] or 0)
                         local stype = scale["Type"]
                         if scale["Value"] > 0 then
                         local delta = scale["Value"]
                             new_scale = scale["Value"]
                        if stype == "heavy_melee" and delta > 0 then
                             new_type = scale["Type"]
                             table.insert(notes, "T" .. i .. " upgrade changes scaling to ×"
                                .. delta .. " of Heavy Melee damage")
                        elseif stype == "melee" and delta ~= 0 and base_scale then
                             local final = math.floor((base_scale + delta) * 1000 + 0.5) / 1000
                            table.insert(notes, "T" .. i .. " upgrade adds ×"
                                .. delta .. " scaling (total ×" .. final .. ")")
                         end
                         end
                     end
                     end
                 end
                 end
            end
            local flat_delta = 0
            if base_prop and type(tier[base_prop]) == "number" then
                flat_delta = tier[base_prop]
            end
            local tier_parts = {}
            if new_type and new_type ~= running_type then
                running_damage = running_damage + damage_delta
                running_scale = new_scale
                running_type = new_type
                local type_label = new_type == "heavy_melee" and "'''Heavy Melee'''" or "Light Melee"
                local parts = {}
                if running_damage > 0 then
                    table.insert(parts, running_damage .. " base damage")
                end
                table.insert(parts, "×" .. new_scale .. " " .. type_label .. " scaling")
                table.insert(tier_parts, "on T" .. i .. " becomes " .. table.concat(parts, " with "))
            elseif new_scale then
                running_damage = running_damage + damage_delta
                running_scale = running_scale + new_scale
                local parts = {}
                if damage_delta ~= 0 then
                    table.insert(parts, "+" .. damage_delta .. " base damage")
                end
                table.insert(parts, "+×" .. new_scale .. " scaling (total ×" .. running_scale .. ")")
                table.insert(tier_parts, "on T" .. i .. " gets " .. table.concat(parts, ", "))
            end
            if flat_delta ~= 0 and not new_scale then
                running_damage = running_damage + flat_delta
                table.insert(tier_parts, "on T" .. i .. " gets +" .. flat_delta .. " base damage (total " .. running_damage .. ")")
            end
            if #tier_parts > 0 then
                table.insert(notes, table.concat(tier_parts, ", "))
             end
             end
         end
         end
     end
     end
 
     if #notes > 0 then cells["Notes"] = table.concat(notes, " ") end
     if #notes > 0 then cells["Notes"] = table.concat(notes, ". ") end
     return cells
     return cells
end
end
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