Module:HeroDataArrays: Difference between revisions

No edit summary
finished refactoring, added spirit scaling table
Line 124: Line 124:
             name = name,
             name = name,
             maxHealth = tonumber(data["MaxHealth"]) or 0,
             maxHealth = tonumber(data["MaxHealth"]) or 0,
             scalingHealth = tonumber(data["LevelScaling>MaxHealth"]) or 0
             scalingHealth = "+" .. tonumber(data["LevelScaling>MaxHealth"]) or 0,
            maxScalingHealth = tonumber(roundValue(data["MaxHealth"] + data["LevelScaling>MaxHealth"] * soul_unlock.get_max("PowerIncrease"))) or 0
         })
         })
     end
     end
     table.sort(rows, function(a, b) return a.name:lower() < b.name:lower() end)
     table.sort(rows, function(a, b) return a.name:lower() < b.name:lower() end)


    -- Input table will be called a, output wikitable will be called z
     local tableDefs = {
     local z = "{| class=\"wikitable sortable mw-collapsible\" style=\"text-align:center\" \n"..
         {
         "|+ Hero Base Health Stats \n"..
            title = "Hero Base Health Stats",
        "! Hero !! Starting !! Added per Boon !! At Max Boon \n"
            columns = {
                { label = "Starting", field = "maxHealth" },
                { label = "Added per Boon", field = "scalingHealth" },
                { label = "At Max Boon", field = "maxScalingHealth" },
            }
        }
    }
   
local output = {}
    for _, def in ipairs(tableDefs) do
        local t = buildTable(frame, rows, def, def.options)
        if t ~= "" then
            table.insert(output, t)
        end
    end


     -- Iterate over heroes adding a new row to the wikitable for each
     return table.concat(output, "\n\n")
    for _, r in ipairs(rows) do
        z = z..
            "|- \n"..
            "| style=\"text-align:left;\" | "..
                frame:expandTemplate{title="PageRef", args={r.name}}..
                " || "..r.maxHealth.." || +"..r.scalingHealth.." || "..
                tostring(roundValue(r.maxHealth + r.scalingHealth * soul_unlock.get_max('PowerIncrease'))).." \n"
    end
   
    z = z.."|}"
    return z
end
end


Line 298: Line 302:
         })
         })
     end
     end
    table.sort(rows, function(a, b) return a.name:lower() < b.name:lower() end)
 
    local z = "{| class=\"wikitable sortable mw-collapsible\" style=\"text-align:center\" \n"..
        "|+ Base Ammo Count \n"..
        "! Hero !! Ammo \n"
 
    for _, r in ipairs(rows) do
        z = z..
            "|- \n"..
            "| style=\"text-align:left;\" | "..
                frame:expandTemplate{title="PageRef", args={r.name}}..
                " || "..r.clipSize.." \n"
    end
    z = z.."|}"
   
     table.sort(rows, function(a, b) return a.name:lower() < b.name:lower() end)
     table.sort(rows, function(a, b) return a.name:lower() < b.name:lower() end)


     local tableDefs = {
     local tableDefs = {
    {
            title  = "Base Ammo Count",
            columns = {
                { label = "Ammo", field = "clipSize"  },
            }
        },
     {
     {
             title  = "Alt-Fire Ammo Cost",
             title  = "Alt-Fire Ammo Cost",
Line 324: Line 320:
     }
     }


     local output = ""
     local output = {}
 
     for _, def in ipairs(tableDefs) do
     for _, tableDef in ipairs(tableDefs) do
         local t = buildTable(frame, rows, def, def.options)
         local filteredRows = {}
        if t ~= "" then
        for _, r in ipairs(rows) do
             table.insert(output, t)
            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
     end
     end


     return z .. "\n\n" .. output
     return table.concat(output, "\n\n")
end
end


Line 385: Line 342:
         })
         })
     end
     end
    table.sort(rows, function(a, b) return a.name:lower() < b.name:lower() end)
    local z = "{| class=\"wikitable sortable mw-collapsible\" style=\"text-align:center\" \n"..
        "|+ Base Fire Rate \n"..
        "! Hero !! Rounds/s \n"
    for _, r in ipairs(rows) do
        z = z..
            "|- \n"..
            "| style=\"text-align:left;\" | "..
                frame:expandTemplate{title="PageRef", args={r.name}}..
                " || "..r.roundsPerSecond.." \n"
    end
    z = z.."|}"
   
     table.sort(rows, function(a, b) return a.name:lower() < b.name:lower() end)
     table.sort(rows, function(a, b) return a.name:lower() < b.name:lower() end)


     local tableDefs = {
     local tableDefs = {
    {
            title  = "Base Fire Rate",
            columns = {
                { label = "Rounds/s", field = "roundsPerSecond"  },
            }
        },
     {
     {
             title  = "Base Alt-Fire Fire Rate",
             title  = "Base Alt-Fire Fire Rate",
Line 411: Line 359:
     }
     }


     local output = ""
     local output = {}
 
     for _, def in ipairs(tableDefs) do
     for _, tableDef in ipairs(tableDefs) do
         local t = buildTable(frame, rows, def, def.options)
         local filteredRows = {}
        if t ~= "" then
        for _, r in ipairs(rows) do
             table.insert(output, t)
            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
     end
     end


     return z .. "\n\n" .. output
     return table.concat(output, "\n\n")
end
end


Line 476: Line 385:
         })
         })
     end
     end
    table.sort(rows, function(a, b) return a.name:lower() < b.name:lower() end)
    local z = "{| class=\"wikitable sortable mw-collapsible\" style=\"text-align:center\" \n"..
        "|+ Base Falloff Range \n"..
        "! Hero !! Minimum Range (m) !! Maximum Range (m)  \n"
    for _, r in ipairs(rows) do
        z = z..
            "|- \n"..
            "| style=\"text-align:left;\" | "..
                frame:expandTemplate{title="PageRef", args={r.name}}..
                " || "..r.falloffStartRange.." || "..r.falloffEndRange.." \n"
    end
    z = z.."|}"
     table.sort(rows, function(a, b) return a.name:lower() < b.name:lower() end)
     table.sort(rows, function(a, b) return a.name:lower() < b.name:lower() end)


     local tableDefs = {
     local tableDefs = {
    {
            title  = "Base Falloff Range",
            columns = {
                { label = "Minimum Range (m)", field = "falloffStartRange"  },
                { label = "Maximum Range (m)", field = "falloffEndRange"  },
            }
        } ,
     {
     {
             title  = "Base Alt-Fire Falloff Range",
             title  = "Base Alt-Fire Falloff Range",
Line 503: Line 405:
     }
     }


     local output = ""
     local output = {}
 
     for _, def in ipairs(tableDefs) do
     for _, tableDef in ipairs(tableDefs) do
         local t = buildTable(frame, rows, def, def.options)
         local filteredRows = {}
        if t ~= "" then
        for _, r in ipairs(rows) do
             table.insert(output, t)
            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
     end
     end


     return z .. "\n\n" .. output
     return table.concat(output, "\n\n")
end
end


Line 562: Line 425:
             name = name,
             name = name,
             bulletDamage = tonumber(data["Weapon>BulletDamage"]) or 0,
             bulletDamage = tonumber(data["Weapon>BulletDamage"]) or 0,
             scalingDamage = tonumber(data["LevelScaling>BulletDamage"]) or 0,
             scalingDamage = "+" .. tonumber(data["LevelScaling>BulletDamage"]) or 0,
            maxScalingDamage =  tonumber(roundValue(data["Weapon>BulletDamage"] + data["LevelScaling>BulletDamage"] * soul_unlock.get_max("PowerIncrease"))) or 0,
             altBulletDamage = tonumber(data["Weapon>AltFire>BulletDamage"]) or 0,
             altBulletDamage = tonumber(data["Weapon>AltFire>BulletDamage"]) or 0,
             altScalingDamage = tonumber(data["LevelScaling>BulletDamageAltFire"]) or 0
             spiritScalingDamage = "+" .. (tonumber(data["SpiritScaling>BulletDamage"]) or 0),
         })
         })
     end
     end
     table.sort(rows, function(a, b) return a.name:lower() < b.name:lower() end)
     table.sort(rows, function(a, b) return a.name:lower() < b.name:lower() end)


     local z = "{| class=\"wikitable sortable mw-collapsible\" style=\"text-align:center\" \n"..
     local tableDefs = {
        "|+ Hero Base Bullet Damage Stats \n"..
    {
        "! Hero !! Starting !! Added per Boon !! At Max Boon \n"
            title  = "Hero Base Bullet Damage Stats",
            columns = {
                { label = "Starting", field = "bulletDamage"  },
                { label = "Added per Boon", field = "scalingDamage"  },
                { label = "At Max Boon", field = "maxScalingDamage"  },
            }
        },
    }


     -- Iterate over heroes adding a new row to the wikitable for each
     local output = {}
     for _, r in ipairs(rows) do
     for _, def in ipairs(tableDefs) do
         z = z..
         local t = buildTable(frame, rows, def, def.options)
            "|- \n"..
        if t ~= "" then
            "| style=\"text-align:left;\" | "..
            table.insert(output, t)
                frame:expandTemplate{title="PageRef", args={r.name}}..
        end
                " || "..r.bulletDamage.." || +"..r.scalingDamage.." || "..
                tostring(roundValue(r.bulletDamage + r.scalingDamage * soul_unlock.get_max('PowerIncrease'))).." \n"
     end
     end
   
 
     z = z.."|}"
     return table.concat(output, "\n\n")
    return z
end
end


Line 596: Line 464:
             name = name,
             name = name,
             lightMeleeDamage = tonumber(data["LightMeleeDamage"]) or 0,
             lightMeleeDamage = tonumber(data["LightMeleeDamage"]) or 0,
             scalingDamage = tonumber(data["LevelScaling>LightMeleeDamage"]) or 0
             scalingDamage = "+" .. tonumber(data["LevelScaling>LightMeleeDamage"]) or 0,
            maxScalingDamage =  tonumber(roundValue(data["LightMeleeDamage"] + data["LevelScaling>LightMeleeDamage"] * soul_unlock.get_max("PowerIncrease"))) or 0,
         })
         })
     end
     end
     table.sort(rows, function(a, b) return a.name:lower() < b.name:lower() end)
     table.sort(rows, function(a, b) return a.name:lower() < b.name:lower() end)


     local z = "{| class=\"wikitable sortable mw-collapsible\" style=\"text-align:center\" \n"..
     local tableDefs = {
        "|+ Hero Base Light Melee Stats \n"..
    {
        "! Hero !! Starting !! Added per Boon !! At Max Boon \n"
            title  = "Hero Base Light Melee Stats",
            columns = {
                { label = "Starting", field = "lightMeleeDamage"  },
                { label = "Added per Boon", field = "scalingDamage"  },
                { label = "At Max Boon", field = "maxScalingDamage"  },
            }
        }
    }
   
    local output = {}
    for _, def in ipairs(tableDefs) do
        local t = buildTable(frame, rows, def, def.options)
        if t ~= "" then
            table.insert(output, t)
        end
    end


     -- Iterate over heroes adding a new row to the wikitable for each
     return table.concat(output, "\n\n")
    for _, r in ipairs(rows) do
        z = z..
            "|- \n"..
            "| style=\"text-align:left;\" | "..
                frame:expandTemplate{title="PageRef", args={r.name}}..
                " || "..r.lightMeleeDamage.." || +"..r.scalingDamage.." || "..
                tostring(roundValue(r.lightMeleeDamage + r.scalingDamage * soul_unlock.get_max('PowerIncrease'))).." \n"
    end
   
    z = z.."|}"
    return z
end
end


Line 628: Line 501:
             name = name,
             name = name,
             heavyMeleeDamage = tonumber(data["HeavyMeleeDamage"]) or 0,
             heavyMeleeDamage = tonumber(data["HeavyMeleeDamage"]) or 0,
             scalingDamage = tonumber(data["LevelScaling>HeavyMeleeDamage"]) or 0
             scalingDamage = "+" .. tonumber(data["LevelScaling>HeavyMeleeDamage"]) or 0,
            maxScalingDamage =  tonumber(roundValue(data["HeavyMeleeDamage"] + data["LevelScaling>HeavyMeleeDamage"] * soul_unlock.get_max("PowerIncrease"))) or 0,
            spiritScalingDamage = "+" .. (tonumber(data["SpiritScaling>HeavyMeleeDamage"]) or 0),
         })
         })
     end
     end
     table.sort(rows, function(a, b) return a.name:lower() < b.name:lower() end)
     table.sort(rows, function(a, b) return a.name:lower() < b.name:lower() end)


     local z = "{| class=\"wikitable sortable mw-collapsible\" style=\"text-align:center\" \n"..
     local tableDefs = {
        "|+ Hero Base Heavy Melee Stats \n"..
    {
        "! Hero !! Starting !! Added per Boon !! At Max Boon \n"
            title  = "Hero Base Heavy Melee Stats",
            columns = {
                { label = "Starting", field = "heavyMeleeDamage"  },
                { label = "Added per Boon", field = "scalingDamage"  },
                { label = "At Max Boon", field = "maxScalingDamage"  },
            }
        }
    }
   
    local output = {}
    for _, def in ipairs(tableDefs) do
        local t = buildTable(frame, rows, def, def.options)
        if t ~= "" then
            table.insert(output, t)
        end
    end


     -- Iterate over heroes adding a new row to the wikitable for each
     return table.concat(output, "\n\n")
    for _, r in ipairs(rows) do
        z = z..
            "|- \n"..
            "| style=\"text-align:left;\" | "..
                frame:expandTemplate{title="PageRef", args={r.name}}..
                " || "..r.heavyMeleeDamage.." || +"..r.scalingDamage.." || "..
                tostring(roundValue(r.heavyMeleeDamage + r.scalingDamage * soul_unlock.get_max('PowerIncrease'))).." \n"
    end
   
    z = z.."|}"
    return z
end
end


Line 664: Line 543:
     table.sort(rows, function(a, b) return a.name:lower() < b.name:lower() end)
     table.sort(rows, function(a, b) return a.name:lower() < b.name:lower() end)


     local z = "{| class=\"wikitable sortable mw-collapsible\" style=\"text-align:center\" \n"..
     local tableDefs = {
         "|+ Hero Base Stamina Stats \n"..
    {
         "! Hero !! Stamina Bars !! Cooldown (s) \n"
            title  = "Hero Base Stamina Stats",
            columns = {
                { label = "Stamina Bars", field = "stamina" },
                { label = "Cooldown (s)", field = "staminaCooldown" },
            }
        }
    }
   
    local output = {}
    for _, def in ipairs(tableDefs) do
        local t = buildTable(frame, rows, def, def.options)
         if t ~= "" then
            table.insert(output, t)
         end
    end


     for _, r in ipairs(rows) do
     return table.concat(output, "\n\n")
        z = z..
            "|- \n"..
            "| style=\"text-align:left;\" | "..
                frame:expandTemplate{title="PageRef", args={r.name}}..
                " || "..r.stamina.." || "..r.staminaCooldown.." \n"
    end
    z = z.."|}"
    return z
end
end


Line 686: Line 571:
         table.insert(rows, {
         table.insert(rows, {
             name    = name,
             name    = name,
             duration = tonumber(data.GroundDashSpeed) or 0
             dashSpeed = data["GroundDashSpeed"] or 0
         })
         })
     end
     end
     table.sort(rows, function(a, b) return a.name:lower() < b.name:lower() end)
     table.sort(rows, function(a, b) return a.name:lower() < b.name:lower() end)
   
    local tableDefs = {
    {
            title  = "Hero Base Dash Speed Stats",
            columns = {
                { label = "Dash Speed (m/s)", field = "dashSpeed"  },
            }
        }
    }
   
    local output = {}
    for _, def in ipairs(tableDefs) do
        local t = buildTable(frame, rows, def, def.options)
        if t ~= "" then
            table.insert(output, t)
        end
    end


     local z = '{| class="wikitable sortable mw-collapsible" style="text-align:center"\n' ..
     return table.concat(output, "\n\n")
              '|+ Hero Base Dash Speed Stats\n' ..
              '! Hero !! Dash Speed (m/s)\n'
    for _, r in ipairs(rows) do
        z = z .. '|-\n| style="text-align:left;" | ' ..
              frame:expandTemplate{title = 'PageRef', args = {r.name}} ..
              ' || ' .. r.duration .. '\n'
    end
    return z .. '|}'
end
end


Line 705: Line 599:
     local heroReloadData = heroDataArray({"Name", "Weapon>ReloadTime"})
     local heroReloadData = heroDataArray({"Name", "Weapon>ReloadTime"})


    -- 1. collect rows
     local rows = {}
     local rows = {}
     for name, data in pairs(heroReloadData) do
     for name, data in pairs(heroReloadData) do
Line 714: Line 607:
     end
     end


    -- 2. alphabetical by hero name
     table.sort(rows, function(a, b) return a.name:lower() < b.name:lower() end)
     table.sort(rows, function(a, b) return a.name:lower() < b.name:lower() end)


    -- 3. build table
     local tableDefs = {
     local z = '{| class="wikitable sortable mw-collapsible" style="text-align:center"\n' ..
    {
              '|+ Hero Base Reload Time Stats\n' ..
            title  = "Hero Base Reload Time Stats",
              '! Hero !! Reload Time (s) \n'
            columns = {
                { label = "Reload Time (s)", field = "reloadTime"  },
            }
        }
    }
   
    local output = {}
    for _, def in ipairs(tableDefs) do
        local t = buildTable(frame, rows, def, def.options)
        if t ~= "" then
            table.insert(output, t)
        end
    end


     for _, r in ipairs(rows) do
     return table.concat(output, "\n\n")
        z = z ..
            '|-\n' ..
            '| style="text-align:left;" | ' ..
            frame:expandTemplate{title = 'PageRef', args = {r.name}} ..
            ' || '.. r.reloadTime ..' \n'
    end
    return z .. '|}'
end
end


Line 772: Line 669:
             name = name,
             name = name,
             moveSpeed = tonumber(data["MaxMoveSpeed"]) or 0,
             moveSpeed = tonumber(data["MaxMoveSpeed"]) or 0,
             sprintSpeed = tonumber(data["SprintSpeed"]) or 0
             sprintSpeed = tonumber(data["SprintSpeed"]) or 0,
            totalSpeed = tonumber(data["MaxMoveSpeed"] + data["SprintSpeed"]) or 0,
         })
         })
     end
     end
     table.sort(rows, function(a, b) return a.name:lower() < b.name:lower() end)
     table.sort(rows, function(a, b) return a.name:lower() < b.name:lower() end)


     local z = "{| class=\"wikitable sortable mw-collapsible\" style=\"text-align:center\" \n"..
     local tableDefs = {
        "|+ Hero Base Move Speed Stats \n"..
    {
        "! Hero !! Move Speed (m/s) !! Sprint Speed (m/s) !! Total Speed (m/s) \n"
            title  = "Hero Base Move Speed Stats",
            columns = {
                { label = "Move Speed (m/s)", field = "moveSpeed"  },
                { label = "Sprint Speed (m/s)", field = "sprintSpeed"  },
                { label = "Total Speed (m/s)", field = "totalSpeed"  },
            }
        }   
    }


     for _, r in ipairs(rows) do
    local output = {}
         z = z..
     for _, def in ipairs(tableDefs) do
            "|- \n"..
         local t = buildTable(frame, rows, def, def.options)
             "| style=\"text-align:left;\" | "..
        if t ~= "" then
                frame:expandTemplate{title="PageRef", args={r.name}}..
             table.insert(output, t)
                " || "..r.moveSpeed.." || "..r.sprintSpeed.." || "..r.moveSpeed + r.sprintSpeed .." \n"
        end
     end
     end
     z = z.."|}"
 
    return z
     return table.concat(output, "\n\n")
end
end


Line 866: Line 771:
             columns = {
             columns = {
                 { label = "Crit Bonus Scale (%)", field = "critBonusScale"  }
                 { label = "Crit Bonus Scale (%)", field = "critBonusScale"  }
            }
        }   
    }
    local output = {}
    for _, def in ipairs(tableDefs) do
        local t = buildTable(frame, rows, def, def.options)
        if t ~= "" then
            table.insert(output, t)
        end
    end
    return table.concat(output, "\n\n")
end
p.heroSpiritTable = function(frame)
    local heroSpiritData = heroDataArray({"Name", "TechPower"})
    local rows = {}
    for name, data in pairs(heroCritData) do
        table.insert(rows, {
            name = name,
            spiritScaling  = "+".. data["TechPower"] or 0,
            maxSpiritScaling = tonumber(data["TechPower"] * soul_unlock.get_max("PowerIncrease")) or 0,
        })
    end
    table.sort(rows, function(a, b) return a.name:lower() < b.name:lower() end)
    local tableDefs = {
    {
            title  = "Hero Spirit Scaling Stats",
            columns = {
                { label = "Spirit Per Boon", field = "spiritScaling"  },
                { label = "At Max Boon", field = "maxSpiritScaling"  },
             }
             }
         }     
         }