Module:HeroDataArrays

From The Deadlock Wiki
Revision as of 16:16, 23 August 2025 by Gammaton32 (talk | contribs) (stamina and dash speed)
Jump to navigation Jump to search

Overview

This module consists of one generic function, heroDataArray, and a series of functions that create specific wikitables using the output from heroDataArray.


local p = {};
local util_module = require('Module:Utilities')
local allHeroData = mw.loadJsonData("Data:HeroData.json")
local soul_unlock = require('Module:SoulUnlock')
local inGameHeroData = {}

-- Just get heroes that are playable
for i, heroData in pairs(allHeroData) do
    if heroData["IsDisabled"] == false then
        table.insert(inGameHeroData, heroData)
    end
end

-- Helper function to round numeric values
local function roundValue(value)
    if type(value) == "number" then
        return util_module.round_to_sig_fig(value, 3)
    end
    return value
end

-- heroDataArray takes as argument a table of any length containing keys or 
-- paths of keys in the HeroData JSON, e.g. {Name, MaxHealth, LevelScaling>Health}.
-- A path of keys should be specified as such, with the ">" character separating
-- subsequent keys.
local heroDataArray = function(args)
    local outData = {}
    
    for i, heroData in ipairs(inGameHeroData) do            -- Iterate over each hero
        local out = {}                                      -- First creating a table to hold data
        for j, key in pairs(args) do                        -- Iterate over each key:
            if string.find(key, ">") ~= nil then            -- If the key is actually a path of keys,
                local node = heroData                       -- start with the biggest node heroData, and
                for k in string.gmatch(key, "([^>]+)") do   -- iterate over each key, splitting on ">",
                    if node[k] ~= nil then                  -- trying the key as a string e.g. "1",
                        node = node[k]                      
                    else                                    -- else using the key as numeric,
                        node = node[tonumber(k)]
                    end                                     -- drilling down the JSON node after node
                end
                out[key] = roundValue(node)                 -- until outputting the final node (rounded)
            else
                out[key] = roundValue(heroData[key])        -- or just grab the data if not a path (rounded)
            end
        end
        outData[heroData["Name"]] = out                     -- Save data in the big table of heroes
    end
    return(outData)
end

p.heroHealthTable = function(frame)
    -- Pull data
    heroHealthData = heroDataArray({"Name", "MaxHealth", "LevelScaling>MaxHealth"})

    -- Input table will be called a, output wikitable will be called z
    -- From a to z, haha get it
    z = "{| class=\"wikitable sortable mw-collapsible\" style=\"text-align:center\" \n"..
        "|+ Hero Base Health Stats \n"..
        "! Hero !! Starting !! Added per Boon !! At Max Boon \n"

    -- Iterate over heroes adding a new row to the wikitable for each
    for i,a in pairs(heroHealthData) do
        z = z..
            "|- \n"..
            "| style=\"text-align:left;\" | "..
                frame:expandTemplate{title="PageRef", args={a["Name"]}}..
                " || "..a["MaxHealth"].." || +"..a["LevelScaling>MaxHealth"].." || "..
                tostring(roundValue(tonumber(a["MaxHealth"])+tonumber(a["LevelScaling>MaxHealth"])*soul_unlock.get_max('PowerIncrease'))).." \n"
    end
    
    -- Cap it off
    z = z.."|}"
    
    return z
end

p.heroRegenTable = function(frame)
    heroRegenData = heroDataArray({"Name", "BaseHealthRegen"})
    
    z = "{| class=\"wikitable sortable mw-collapsible\" style=\"text-align:center\" \n"..
        "|+ Hero Base Health Regen \n"..
        "! Hero !! HP/s \n"

    for i,a in pairs(heroRegenData) do
        z = z..
            "|- \n"..
            "| style=\"text-align:left;\" | "..
                frame:expandTemplate{title="PageRef", args={a["Name"]}}..
                " || "..a["BaseHealthRegen"].." \n"
    end
    z = z.."|}"
    return z
end

p.heroDpsTable = function(frame)
    heroDpsData = heroDataArray({"Name","ReloadSingle","ReloadDelay","ReloadTime",
        "ClipSize","RoundsPerSecond","BulletDamage","BulletsPerShot"})
   
    z = "{| class=\"wikitable sortable mw-collapsible\" style=\"text-align:center\" \n"..
        "|+ Hero Base Damage \n"..
        "! Hero !! Reload Delay (s) !! Reload Time (s) !! Ammo !! Bullets per sec !! Bullet Damage !! Bullets Per Shot \n"
        
    for i,a in pairs(heroDpsData) do
        z = z..
            "|- \n"..
            "| style=\"text-align:left;\" | "..
                frame:expandTemplate{title="PageRef", args={a["Name"]}}..
                " || "..a["ReloadDelay"].." || "..a["ReloadTime"].."  || "..a["ClipSize"]..
                " || "..a["RoundsPerSecond"].." || "..a["BulletDamage"].." || "..a["BulletsPerShot"].." \n"
    end
    z = z.."|}"
    return z
end

p.heroBulletSpeedTable = function(frame)
    heroBulletSpeedData = heroDataArray({"Name", "BulletSpeed"})
    
    z = "{| class=\"wikitable sortable mw-collapsible\" style=\"text-align:center\" \n"..
        "|+ Base Bullet Velocity \n"..
        "! Hero !! m/s \n"

    for i,a in pairs(heroBulletSpeedData) do
        z = z..
            "|- \n"..
            "| style=\"text-align:left;\" | "..
                frame:expandTemplate{title="PageRef", args={a["Name"]}}..
                " || "..a["BulletSpeed"].." \n"
    end
    z = z.."|}"
    return z
end

p.heroClipSizeTable = function(frame)
    heroClipSizeData = heroDataArray({"Name", "ClipSize"})
    
    z = "{| class=\"wikitable sortable mw-collapsible\" style=\"text-align:center\" \n"..
        "|+ Base Ammo Count \n"..
        "! Hero !! Ammo \n"

    for i,a in pairs(heroClipSizeData) do
        z = z..
            "|- \n"..
            "| style=\"text-align:left;\" | "..
                frame:expandTemplate{title="PageRef", args={a["Name"]}}..
                " || "..a["ClipSize"].." \n"
    end
    z = z.."|}"
    return z
end

p.heroMoveSpeedTable = function(frame)
    heroMoveSpeedData = heroDataArray({"Name", "MoveSpeed"})
    
    z = "{| class=\"wikitable sortable mw-collapsible\" style=\"text-align:center\" \n"..
        "|+ Base Movement Speed \n"..
        "! Hero !! m/s \n"

    for i,a in pairs(heroMoveSpeedData) do
        z = z..
            "|- \n"..
            "| style=\"text-align:left;\" | "..
                frame:expandTemplate{title="PageRef", args={a["Name"]}}..
                " || "..a["MoveSpeed"].." \n"
    end
    z = z.."|}"
    return z
end

p.heroRoundsPerSecondTable = function(frame)
    heroRoundsPerSecondData = heroDataArray({"Name", "RoundsPerSecond"})
    
    z = "{| class=\"wikitable sortable mw-collapsible\" style=\"text-align:center\" \n"..
        "|+ Base Fire Rate \n"..
        "! Hero !! Rounds/s \n"

    for i,a in pairs(heroRoundsPerSecondData) do
        z = z..
            "|- \n"..
            "| style=\"text-align:left;\" | "..
                frame:expandTemplate{title="PageRef", args={a["Name"]}}..
                " || "..a["RoundsPerSecond"].." \n"
    end
    z = z.."|}"
    return z
end

p.heroFalloffRangeTable = function(frame)
    heroFalloffRangeData = heroDataArray({"Name", "FalloffStartRange", "FalloffEndRange"})
    
    z = "{| class=\"wikitable sortable mw-collapsible\" style=\"text-align:center\" \n"..
        "|+ Base Falloff Range \n"..
        "! Hero !! Minimum Range (m) !! Maximum Range (m)  \n"

    for i,a in pairs(heroFalloffRangeData) do
        z = z..
            "|- \n"..
            "| style=\"text-align:left;\" | "..
                frame:expandTemplate{title="PageRef", args={a["Name"]}}..
                " || "..a["FalloffStartRange"].." || "..a["FalloffEndRange"].." \n"
    end
    z = z.."|}"
    return z
end

p.heroBulletDamageTable = function(frame)
    -- Pull data
    heroBulletDamageData = heroDataArray({"Name", "BulletDamage", "LevelScaling>BulletDamage"})

    -- Input table will be called a, output wikitable will be called z
    -- From a to z, haha get it
    z = "{| class=\"wikitable sortable mw-collapsible\" style=\"text-align:center\" \n"..
        "|+ Hero Base Bullet Damage Stats \n"..
        "! Hero !! Starting !! Added per Boon !! At Max Boon \n"

    -- Iterate over heroes adding a new row to the wikitable for each
    for i,a in pairs(heroBulletDamageData) do
        z = z..
            "|- \n"..
            "| style=\"text-align:left;\" | "..
                frame:expandTemplate{title="PageRef", args={a["Name"]}}..
                " || "..a["BulletDamage"].." || +"..a["LevelScaling>BulletDamage"].." || "..
                tostring(roundValue(tonumber(a["BulletDamage"])+tonumber(a["LevelScaling>BulletDamage"])*soul_unlock.get_max('PowerIncrease'))).." \n"
    end
    
    -- Cap it off
    z = z.."|}"
    
    return z
end

p.heroLightMeleeTable = function(frame)
    -- Pull data
    heroLightMeleeData = heroDataArray({"Name", "LightMeleeDamage", "LevelScaling>LightMeleeDamage"})

    -- Input table will be called a, output wikitable will be called z
    -- From a to z, haha get it
    z = "{| class=\"wikitable sortable mw-collapsible\" style=\"text-align:center\" \n"..
        "|+ Hero Base Light Melee Stats \n"..
        "! Hero !! Starting !! Added per Boon !! At Max Boon \n"

    -- Iterate over heroes adding a new row to the wikitable for each
    for i,a in pairs(heroLightMeleeData) do
        z = z..
            "|- \n"..
            "| style=\"text-align:left;\" | "..
                frame:expandTemplate{title="PageRef", args={a["Name"]}}..
                " || "..a["LightMeleeDamage"].." || +"..a["LevelScaling>LightMeleeDamage"].." || "..
                tostring(roundValue(tonumber(a["LightMeleeDamage"])+tonumber(a["LevelScaling>LightMeleeDamage"])*soul_unlock.get_max('PowerIncrease'))).." \n"
    end
    
    -- Cap it off
    z = z.."|}"
    
    return z
end

p.heroHeavyMeleeTable = function(frame)
    -- Pull data
    heroHeavyMeleeData = heroDataArray({"Name", "HeavyMeleeDamage", "LevelScaling>HeavyMeleeDamage"})

    -- Input table will be called a, output wikitable will be called z
    -- From a to z, haha get it
    z = "{| class=\"wikitable sortable mw-collapsible\" style=\"text-align:center\" \n"..
        "|+ Hero Base Heavy Melee Stats \n"..
        "! Hero !! Starting !! Added per Boon !! At Max Boon \n"

    -- Iterate over heroes adding a new row to the wikitable for each
    for i,a in pairs(heroHeavyMeleeData) do
        z = z..
            "|- \n"..
            "| style=\"text-align:left;\" | "..
                frame:expandTemplate{title="PageRef", args={a["Name"]}}..
                " || "..a["HeavyMeleeDamage"].." || +"..a["LevelScaling>HeavyMeleeDamage"].." || "..
                tostring(roundValue(tonumber(a["HeavyMeleeDamage"])+tonumber(a["LevelScaling>HeavyMeleeDamage"])*soul_unlock.get_max('PowerIncrease'))).." \n"
    end
    
    -- Cap it off
    z = z.."|}"
    
    return z
end

p.heroStaminaTable = function(frame)
    heroStaminaData = heroDataArray({"Name", "Stamina"})

    z = "{| class=\"wikitable sortable mw-collapsible\" style=\"text-align:center\" \n"..
        "|+ Hero Base Stamina Stats \n"..
        "! Hero !! Stamina Bars \n"

    for i,a in pairs(heroStaminaData) do
        z = z..
            "|- \n"..
            "| style=\"text-align:left;\" | "..
                frame:expandTemplate{title="PageRef", args={a["Name"]}}..
                " || "..a["Stamina"].." \n"
    end
    z = z.."|}"
    return z
end

p.heroDashTable = function(frame)
    heroDashData = heroDataArray({"Name", "GroundDashDuration"})

    z = "{| class=\"wikitable sortable mw-collapsible\" style=\"text-align:center\" \n"..
        "|+ Hero Base Dash Speed Stats \n"..
        "! Hero !! Dash Speed \n"

    for i,a in pairs(heroDashData) do
        z = z..
            "|- \n"..
            "| style=\"text-align:left;\" | "..
                frame:expandTemplate{title="PageRef", args={a["Name"]}}..
                " || "..a["GroundDashDuration"].." \n"
    end
    z = z.."|}"
    return z
end

return p