Module:AbilityTable/ComplexRenderers: Difference between revisions

Jump to navigation Jump to search
Vergir (talk | contribs)
strip trailing periods from auto-generated notes, period is now handled by main module ensure_period (with help from vergir-bot LLM)
Vergir (talk | contribs)
add base damage column to melee list
Line 225: Line 225:
end
end


-- Renders light melee scaling.
-- Renders base damage and melee scaling.
-- Special case for upgrades that change to heavy melee scaling.
-- Special case for upgrades that switch from Light 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 = {}
     local base_scale = find_base_melee_scale(ability)
     cells["Base Damage"] = tostring(base_damage or 0)
     if base_scale then cells["Light Melee Scaling"] = "×" .. base_scale end
     if base_scale then
        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
             for _, v in pairs(tier) do
            local damage_delta = 0
            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 type(scale["Value"]) == "number" then
                     if type(scale) == "table" and melee_types[scale["Type"]] then
                         local stype = scale["Type"]
                         damage_delta = damage_delta + (v["Value"] or 0)
                         local delta = scale["Value"]
                         if scale["Value"] > 0 then
                        if stype == "heavy_melee" and delta > 0 then
                             new_scale = scale["Value"]
                             table.insert(notes, "T" .. i .. " upgrade changes scaling to ×"
                             new_type = scale["Type"]
                                .. 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