Module:AbilityTable: Difference between revisions

Jump to navigation Jump to search
Vergir (talk | contribs)
mNo edit summary
Vergir (talk | contribs)
healreduce: remove Duration column; iterate stat_to_props for amount; drop find_base_duration (with help from vergir-bot LLM)
Line 52: Line 52:
     },
     },
     ["moveslow"] = {
     ["moveslow"] = {
         ["Grapple Arm"] = "Applies a short strong slow when the victim reaches Bebop.",
         ["Grapple Arm"]   = "Applies a short strong slow when the victim reaches Bebop.",
         ["Heavy Barrage"] = "Slows McGinnis by unknown amount."
         ["Heavy Barrage"] = "Slows McGinnis by unknown amount.",
     },
     },
}
}
Line 77: Line 77:
local column_suffix = {
local column_suffix = {
     ["Time Between Charges"] = "s",
     ["Time Between Charges"] = "s",
    ["Duration"]            = "s",
}
}


Line 238: Line 237:
     if #upgrade_notes > 0 then cells["Notes"] = table.concat(upgrade_notes, " ") end
     if #upgrade_notes > 0 then cells["Notes"] = table.concat(upgrade_notes, " ") end
     return cells
     return cells
end
local function find_base_duration(ability)
    for _, field in ipairs({ "VenomDuration", "DebuffDuration", "AbilityDuration", "BurnDuration" }) do
        local v = num_val(ability[field])
        if v and v > 0 then return v, field end
    end
    return nil, nil
end
end


Line 251: Line 242:
     local cells = {}
     local cells = {}
     local notes = {}
     local notes = {}
     local base_dur, dur_field = find_base_duration(ability)
     local props = stat_to_props["healreduce"]


    -- Find the first heal reduction value, at base or in upgrades.
    -- DisableHealing is a flag (value=100%); all other props are negative percentages.
     local first_pct, first_tier, first_is_disable = nil, nil, false
     local first_pct, first_tier, first_is_disable = nil, nil, false
     local base_receive = num_val(ability["HealAmpReceivePenaltyPercent"])
 
    local base_regen  = num_val(ability["HealAmpRegenPenaltyPercent"])
     for _, prop in ipairs(props) do
    local base_pct_raw = base_receive or base_regen
        local v = num_val(ability[prop])
    if base_pct_raw and base_pct_raw ~= 0 then
        if v and v ~= 0 then
        first_pct = math.abs(base_pct_raw)
            if prop == "DisableHealing" then
    elseif ability["DisableHealing"] and ability["DisableHealing"] ~= 0 then
                first_is_disable = true
         first_is_disable = true
            else
     else
                first_pct = math.abs(v)
            end
            break
         end
    end
     if not first_pct and not first_is_disable then
         local upgrades = ability["Upgrades"]
         local upgrades = ability["Upgrades"]
         if type(upgrades) == "table" then
         if type(upgrades) == "table" then
             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 up_raw = num_val(tier["HealAmpReceivePenaltyPercent"])
                     for _, prop in ipairs(props) do
                                or num_val(tier["HealAmpRegenPenaltyPercent"])
                        local v = num_val(tier[prop])
                    if up_raw and up_raw ~= 0 then
                        if v and v ~= 0 then
                        first_pct, first_tier = math.abs(up_raw), i
                            if prop == "DisableHealing" then
                        break
                                first_is_disable, first_tier = true, i
                    elseif tier["DisableHealing"] and tier["DisableHealing"] ~= 0 then
                            else
                        first_is_disable, first_tier = true, i
                                first_pct, first_tier = math.abs(v), i
                         break
                            end
                            break
                         end
                     end
                     end
                 end
                 end
                if first_pct or first_is_disable then break end
             end
             end
         end
         end
Line 285: Line 286:
         cells["Heal Reduction"] = tostring(first_pct) .. "%" .. (first_tier and " (T" .. first_tier .. ")" or "")
         cells["Heal Reduction"] = tostring(first_pct) .. "%" .. (first_tier and " (T" .. first_tier .. ")" or "")
     end
     end
    if base_dur then cells["Duration"] = tostring(base_dur) end


    -- Upgrade notes: percent changes after the first value.
     local upgrades = ability["Upgrades"]
     local upgrades = ability["Upgrades"]
     if type(upgrades) == "table" then
     if type(upgrades) == "table" then
         local running_pct, running_dur = first_pct, base_dur
         local running        = first_pct
         local first_pct_seen = (first_tier == nil)
         local first_pct_seen = (first_tier == nil)
         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 tier_notes = {}
                local pct_delta = num_val(tier["HealAmpReceivePenaltyPercent"])
                              or num_val(tier["HealAmpRegenPenaltyPercent"])
                 if first_tier == i then
                 if first_tier == i then
                     first_pct_seen = true
                     first_pct_seen = true
                     if first_pct then running_pct = first_pct end
                     if first_pct then running = first_pct end
                 elseif first_pct_seen and pct_delta and pct_delta ~= 0 then
                 elseif first_pct_seen then
                     local delta_abs = math.abs(pct_delta)
                     local delta = nil
                     local total = (running_pct or 0) + delta_abs
                     for _, prop in ipairs(props) do
                    table.insert(tier_notes, "T" .. i .. " upgrade increases heal reduction by "
                         if prop ~= "DisableHealing" then
                         .. delta_abs .. "% (total " .. total .. "%).")
                            local v = num_val(tier[prop])
                    running_pct = total
                            if v and v ~= 0 then delta = math.abs(v); break end
                end
                        end
                if dur_field then
                    end
                    local dur_delta = num_val(tier[dur_field])
                    if delta then
                    if dur_delta and dur_delta ~= 0 and running_dur then
                         local total = (running or 0) + delta
                         local total_dur = running_dur + dur_delta
                         table.insert(notes, "T" .. i .. " upgrade increases heal reduction by "
                         table.insert(tier_notes, "T" .. i .. " upgrade "
                             .. delta .. "% (total " .. total .. "%).")
                            .. (dur_delta > 0 and "increases" or "decreases")
                         running = total
                             .. " duration by " .. math.abs(dur_delta)
                            .. "s (total " .. total_dur .. "s).")
                         running_dur = total_dur
                     end
                     end
                 end
                 end
                for _, n in ipairs(tier_notes) do table.insert(notes, n) end
             end
             end
         end
         end
Line 449: Line 444:
     },
     },
     ["healreduce"] = {
     ["healreduce"] = {
         headers  = { "Heal Reduction", "Duration", "Notes" },
         headers  = { "Heal Reduction", "Notes" },
         get_cells = healreduce_cells,
         get_cells = healreduce_cells,
     },
     },