Module:HeroDataArrays: Difference between revisions

Jump to navigation Jump to search
No edit summary
crit bonus scale
Line 510: Line 510:
             }
             }
         },
         },
    }
    local output = ""
    for _, tableDef in ipairs(tableDefs) do
        local filteredRows = {}
        for _, r in ipairs(rows) do
            local hasValue = false
            for _, col in ipairs(tableDef.columns) do
                if r[col.field] ~= 0 then
                    hasValue = true
                    break
                end
            end
            if hasValue then
                table.insert(filteredRows, r)
            end
        end
        if #filteredRows > 0 then
            local header = ""
            for _, col in ipairs(tableDef.columns) do
                header = header.." !! "..col.label
            end
            local t = "{| class=\"wikitable sortable mw-collapsible\" style=\"text-align:center\" \n"..
                "|+ "..tableDef.title.." \n"..
                "! Hero"..header.." \n"
            for _, r in ipairs(filteredRows) do
                local cells = ""
                for _, col in ipairs(tableDef.columns) do
                    cells = cells.." || "..r[col.field]
                end
                t = t..
                    "|- \n"..
                    "| style=\"text-align:left;\" | "..
                        frame:expandTemplate{title="PageRef", args={r.name}}..
                        cells.." \n"
            end
            t = t.."|}"
            if output ~= "" then
                output = output.."\n\n"
            end
            output = output..t
        end
    end
    return output
end
p.heroCritTable = function(frame)
    local heroCritData = heroDataArray({"Name", "CritDamageBonusPercent"})
    local rows = {}
    for name, data in pairs(heroDamageResistData) do
        table.insert(rows, {
            name = name,
            critBonusScale  = data["CritDamageBonusPercent"] or 0
        })
    end
    table.sort(rows, function(a, b) return a.name:lower() < b.name:lower() end)
    local tableDefs = {
            title  = "Hero Base Crit Bonus Scale Stats",
            columns = {
                { label = "Crit Bonus Scale (%)", field = "critBonusScale"  }
            }
     }
     }