Module:ChampionData

-- local p   = {} local lib      = require('Module:Feature') local userError = require('Dev:User error') local cmd      = require('Module:Maintenance data') local FN       = require('Module:Filename')

function p.get(frame) local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end local get      = require ('Module:ChampionData/getter') local champname = args['champname'] or args[1] local datatype = args['datatype']  or args[2] local output   = args['output']    or args[3] or nil local result   = get[datatype](champname) or nil if output ~= nil and type(result) == "table" then if output == "csv" then return table.concat(result, ",") elseif output == "tip" then table.sort(result) return frame:preprocess(" ") end elseif result == nil then return "" else return result end end

function p.getRoster local lolData = mw.loadData('Module:ChampionData/data') local tftData = require('Module:TFTUnitData') local lolTable = {} local s       = "" for x in pairs(lolData) do       table.insert(lolTable, x)    end table.sort(lolTable) for _, champion in pairs(lolTable) do       --custom searches local search = champion if lolData[champion]["title"]   then search = search .. "," .. lolData[champion]["title"]   end if lolData[champion]["fullname"] then search = search .. "," .. lolData[champion]["fullname"] end if lolData[champion]["nickname"] then search = search .. "," .. lolData[champion]["nickname"] end --game titles local games = "LOL" if tftData.checkRoster{champion} then games = games .. ",TFT," .. tftData.getTooltipSets{champion} end --champion roles local role = p.mainrole{champion} .. "," .. p.get{champion, "role", "csv"} local rangetype = lolData[champion]["rangetype"] s = s .. ' ' end return s end

function p.main(frame) local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end local patchid     = args[1] or args['patchid'] or cmd.main{"PatchId"} local luadata     = loadData(patchid) local o           = mw.loadData('Module:StatTable/data/' .. patchid) local s           = "" local championdata = {} for championname in pairs(o) do       table.insert(championdata, championname) end table.sort(championdata) -- ============================   -- = Generate lua data output = -- ============================   s = s .. '-- \n' s = s .. '-- Champion data for patch version: ' .. patchid .. '\n' s = s .. '\n' s = s .. 'return {\n'

for i, champname in pairs(championdata) do       local t = o[champname] -- StatTable data s = s .. ' ["' .. champname .. '"] = {\n' s = s .. '   ["id"]         = '  .. t['id']                           .. ',\n' s = s .. '   ["apiname"]    = "' .. t['apiname']                       .. '",\n' s = s .. '   ["title"]      = "' .. t['title']                         .. '",\n' s = s .. '   ["attack"]     = '  .. t['attack']                       .. ',\n' s = s .. '   ["defense"]    = '  .. t['defense']                      .. ',\n' s = s .. '   ["magic"]      = '  .. t['magic']                        .. ',\n' s = s .. '   ["difficulty"] = '  .. t['difficulty']                   .. ',\n' s = s .. '   ["herotype"]   = "'  .. t['herotype']                     .. '",\n' if t['alttype'] ~= nil then s = s .. '   ["alttype"]    = "'  .. t['alttype']                  .. '",\n' end s = s .. '   ["resource"]   = "'  .. t['resource']                     .. '",\n' s = s .. '   ["stats"] = {\n' s = s .. '     ["hp_base"]  = '  .. pst2(champname, "hp_base")        .. ',\n' s = s .. '     ["hp_lvl"]   = '  .. pst2(champname, "hp_lvl")        .. ',\n' s = s .. '     ["mp_base"]  = '  .. pst2(champname, "mp_base")        .. ',\n' s = s .. '     ["mp_lvl"]   = '  .. pst2(champname, "mp_lvl")        .. ',\n' s = s .. '     ["arm_base"] = '  .. pst2(champname, "arm_base")        .. ',\n' s = s .. '     ["arm_lvl"]  = '  .. pst2(champname, "arm_lvl")        .. ',\n' s = s .. '     ["mr_base"]  = '  .. pst2(champname, "mr_base")        .. ',\n' s = s .. '     ["mr_lvl"]   = '  .. pst2(champname, "mr_lvl")        .. ',\n' s = s .. '     ["hp5_base"] = '  .. pst2(champname, "hp5_base")        .. ',\n' s = s .. '     ["hp5_lvl"]  = '  .. pst2(champname, "hp5_lvl")        .. ',\n' s = s .. '     ["mp5_base"] = '  .. pst2(champname, "mp5_base")        .. ',\n' s = s .. '     ["mp5_lvl"]  = '  .. pst2(champname, "mp5_lvl")        .. ',\n' s = s .. '     ["dam_base"] = '  .. pst2(champname, "dam_base")        .. ',\n' s = s .. '     ["dam_lvl"]  = '  .. pst2(champname, "dam_lvl")        .. ',\n' s = s .. '     ["as_base"]  = '  .. pst2(champname, "as_base")        .. ',\n' as_lvl1 = pst2(champname, "as_lvl1") if as_lvl1 ~= "" then s = s .. '     ["as_lvl1"]  = '  .. pst2(champname, "as_lvl1")        .. ',\n' end as_lvl1 = pst2(champname, "as_lvl1_bonus") if as_lvl1 ~= "" then s = s .. '     ["as_lvl1_bonus"]  = '  .. pst2(champname, "as_lvl1_bonus")        .. ',\n' end s = s .. '     ["as_lvl"]   = '  .. t['stats']['as_lvl']              .. ',\n' s = s .. '     ["range"]    = '  .. t['stats']['range']               .. ',\n' s = s .. '     ["ms"]       = '  .. t['stats']['ms']                  .. '\n' s = s .. '   },\n' -- Additional data from champion data templates fullname = pst2(champname, "fullname") if fullname ~= "" then s = s .. '   ["fullname"]   = "' .. fullname                       .. '",\n' end nickname = pst2(champname, "nickname") if nickname ~= "" then s = s .. '   ["nickname"]   = "' .. nickname                       .. '",\n' end s = s .. '   ["rangetype"]   = "' .. pst2(champname, "rangetype")           .. '",\n' s = s .. '   ["date"]        = "' .. pst2(champname, "date")                .. '",\n' s = s .. '   ["patch"]       = "' .. pst2(champname, "patch")               .. '",\n' s = s .. '   ["changes"]     = "' .. pst2(champname, "changes")             .. '",\n' s = s .. '   ["role"]        = {' .. strtoluadata(pst2(champname, "role"), ",") .. '},\n' s = s .. '   ["damage"]      = '  .. pst2(champname, "damage")             .. ',\n' s = s .. '   ["toughness"]   = '  .. pst2(champname, "toughness")          .. ',\n' s = s .. '   ["control"]     = '  .. pst2(champname, "control")            .. ',\n' s = s .. '   ["mobility"]    = '  .. pst2(champname, "mobility")           .. ',\n' s = s .. '   ["utility"]     = '  .. pst2(champname, "utility")            .. ',\n' s = s .. '   ["style"]       = '  .. pst2(champname, "style")              .. ',\n' s = s .. '   ["adaptivetype"]= "' .. pst2(champname, "adaptivetype")        .. '",\n' s = s .. '   ["be"]          = '  .. pst2(champname, "be")                 .. ',\n' s = s .. '   ["rp"]          = '  .. pst2(champname, "rp")                 .. ',\n' s = s .. '   ["skill_i"]     = {' .. strtoluadatai(pst2(champname, "skill_i"), ";") .. '},\n' s = s .. '   ["skill_q"]     = {' .. strtoluadatai(pst2(champname, "skill_q"), ";") .. '},\n' s = s .. '   ["skill_w"]     = {' .. strtoluadatai(pst2(champname, "skill_w"), ";") .. '},\n' s = s .. '   ["skill_e"]     = {' .. strtoluadatai(pst2(champname, "skill_e"), ";") .. '},\n' s = s .. '   ["skill_r"]     = {' .. strtoluadatai(pst2(champname, "skill_r"), ";") .. '}\n' s = s .. ' }' .. lib.ternary(i ~= #championdata, ',\n','\n') end s = s .. '}\n' s = s .. '-- \n' -- pre needs to be splitted with, because of Lua weirdness s = s .. '-- '   return ' ' .. mw.text.nowiki(s) .. ' ' end

function p.main2(frame) local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end local patchid     = args[1] or args['patchid'] or cmd.main{"PatchId"} local luadata     = loadData(patchid) local o           = mw.loadData('Module:StatTable/data/' .. patchid) local s           = "" local championdata = {} if type(luadata)    == nil then return userError("No data available for patch " .. patchid, "LuaError") end for championname in pairs(o) do       table.insert(championdata, championname) end table.sort(championdata) -- ============================   -- = Generate lua data output = -- ============================   s = s .. '-- \n' s = s .. '-- Champion data for patch version: ' .. patchid .. '\n' s = s .. '\n' s = s .. 'return {\n'

for i, champname in pairs(championdata) do       local t = o[champname] -- StatTable data s = s .. ' ["' .. champname .. '"] = {\n' s = s .. '   ["id"]         = '  .. t['id']                           .. ',\n' s = s .. '   ["apiname"]    = "' .. t['apiname']                       .. '",\n' s = s .. '   ["title"]      = "' .. t['title']                         .. '",\n' s = s .. '   ["attack"]     = '  .. t['attack']                       .. ',\n' s = s .. '   ["defense"]    = '  .. t['defense']                      .. ',\n' s = s .. '   ["magic"]      = '  .. t['magic']                        .. ',\n' s = s .. '   ["difficulty"] = '  .. t['difficulty']                   .. ',\n' s = s .. '   ["herotype"]   = "'  .. t['herotype']                     .. '",\n' if t['alttype'] ~= nil then s = s .. '   ["alttype"]    = "'  .. t['alttype']                  .. '",\n' end s = s .. '   ["resource"]   = "'  .. t['resource']                     .. '",\n' s = s .. '   ["stats"] = {\n' s = s .. '     ["hp_base"]  = '  .. t['stats']['hp_base']             .. ',\n' s = s .. '     ["hp_lvl"]   = '  .. t['stats']['hp_lvl']              .. ',\n' s = s .. '     ["mp_base"]  = '  .. t['stats']['mp_base']             .. ',\n' s = s .. '     ["mp_lvl"]   = '  .. t['stats']['mp_lvl']              .. ',\n' s = s .. '     ["arm_base"] = '  .. t['stats']['arm_base']            .. ',\n' s = s .. '     ["arm_lvl"]  = '  .. t['stats']['arm_lvl']             .. ',\n' s = s .. '     ["mr_base"]  = '  .. t['stats']['mr_base']             .. ',\n' s = s .. '     ["mr_lvl"]   = '  .. t['stats']['mr_lvl']              .. ',\n' s = s .. '     ["hp5_base"] = '  .. t['stats']['hp5_base']            .. ',\n' s = s .. '     ["hp5_lvl"]  = '  .. t['stats']['hp5_lvl']             .. ',\n' s = s .. '     ["mp5_base"] = '  .. t['stats']['mp5_base']            .. ',\n' s = s .. '     ["mp5_lvl"]  = '  .. t['stats']['mp5_lvl']             .. ',\n' s = s .. '     ["dam_base"] = '  .. t['stats']['dam_base']            .. ',\n' s = s .. '     ["dam_lvl"]  = '  .. t['stats']['dam_lvl']             .. ',\n' s = s .. '     ["as_base"]  = '  .. pst2(champname, "as_base")        .. ',\n' if t['stats']['as_lvl1'] ~= nil and t['stats']['as_lvl1'] ~= tonumber(pst2(champname, "as_base")) then s = s .. '     ["as_lvl1"]  = '     .. t['stats']['as_lvl1']      .. ',\n' end if t['stats']['attack_delay'] ~= nil then s = s .. '     ["attack_delay"] = ' .. t['stats']['attack_delay'] .. ',\n' end as_lvl1 = pst2(champname, "as_lvl1_bonus") if as_lvl1 ~= "" then s = s .. '     ["as_lvl1_bonus"]  = '  .. pst2(champname, "as_lvl1_bonus")        .. ',\n' end s = s .. '     ["as_lvl"]   = '  .. t['stats']['as_lvl']              .. ',\n' s = s .. '     ["range"]    = '  .. pst2(champname, "range")          .. ',\n' s = s .. '     ["ms"]       = '  .. pst2(champname, "ms")             .. '\n' s = s .. '   },\n' -- Additional data from champion data templates fullname = pst2(champname, "fullname") if fullname ~= "" then s = s .. '   ["fullname"]   = "' .. fullname                       .. '",\n' end nickname = pst2(champname, "nickname") if nickname ~= "" then s = s .. '   ["nickname"]   = "' .. nickname                       .. '",\n' end s = s .. '   ["rangetype"]   = "' .. pst2(champname, "rangetype")           .. '",\n' s = s .. '   ["date"]        = "' .. pst2(champname, "date")                .. '",\n' s = s .. '   ["patch"]       = "' .. pst2(champname, "patch")               .. '",\n' s = s .. '   ["changes"]     = "' .. pst2(champname, "changes")             .. '",\n' s = s .. '   ["role"]        = {' .. strtoluadata(pst2(champname, "role"), ",") .. '},\n' s = s .. '   ["damage"]      = '  .. pst2(champname, "damage")             .. ',\n' s = s .. '   ["toughness"]   = '  .. pst2(champname, "toughness")          .. ',\n' s = s .. '   ["control"]     = '  .. pst2(champname, "control")            .. ',\n' s = s .. '   ["mobility"]    = '  .. pst2(champname, "mobility")           .. ',\n' s = s .. '   ["utility"]     = '  .. pst2(champname, "utility")            .. ',\n' s = s .. '   ["style"]       = '  .. pst2(champname, "style")              .. ',\n' s = s .. '   ["adaptivetype"]= "' .. pst2(champname, "adaptivetype")        .. '",\n' s = s .. '   ["be"]          = '  .. pst2(champname, "be")                 .. ',\n' s = s .. '   ["rp"]          = '  .. pst2(champname, "rp")                 .. ',\n' s = s .. '   ["skill_i"]     = {' .. strtoluadatai(pst2(champname, "skill_i"), ";") .. '},\n' s = s .. '   ["skill_q"]     = {' .. strtoluadatai(pst2(champname, "skill_q"), ";") .. '},\n' s = s .. '   ["skill_w"]     = {' .. strtoluadatai(pst2(champname, "skill_w"), ";") .. '},\n' s = s .. '   ["skill_e"]     = {' .. strtoluadatai(pst2(champname, "skill_e"), ";") .. '},\n' s = s .. '   ["skill_r"]     = {' .. strtoluadatai(pst2(champname, "skill_r"), ";") .. '}\n' s = s .. ' }' .. lib.ternary(i ~= #championdata, ',\n','\n') end s = s .. '}\n' s = s .. '-- \n' -- pre needs to be splitted with, because of Lua weirdness s = s .. '-- '   return ' ' .. mw.text.nowiki(s) .. ' ' end

function p.mainrole(frame) local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end local parentroletable = { ["Catcher"]   = "Controller", ["Enchanter"] = "Controller", ["Diver"]     = "Fighter", ["Juggernaut"] = "Fighter", ["Battlemage"] = "Mage", ["Burst"]     = "Mage", ["Artillery"] = "Mage", ["Assassin"]  = "Slayer", ["Skirmisher"] = "Slayer", ["Vanguard"]  = "Tank", ["Warden"]    = "Tank", ["Marksman"]  = "", ["Specialist"] = "", }   local champname = args[1] or args['champname'] local get      = require ('Module:ChampionData/getter') local item     = get.role(champname) local s        = "" for i, subrole in pairs(item) do       if i ~= 1 then s = s .. ","       end s = s .. parentroletable[subrole] end return s end

function p.minmaxstattable local o           = mw.loadData('Module:ChampionData/data') local stat        = 'hp5_lvl' local stattable   = {} for champion in pairs(o) do       -- mw.log(champion, o[champion].stats.hp5_base) table.insert(stattable, {champion, o[champion].stats.hp5_base, o[champion].stats.hp5_lvl, o[champion].stats.hp5_base + o[champion].stats.hp5_lvl * (18-1) * (0.7025 + 0.0175 * (18 - 1))}) end table.sort(stattable, function(a, b) return a[2] > b[2] end) -- mw.log(lib.tbl(stattable)) result ={} size = 0 for i, t in ipairs(stattable) do       if i == 1 then table.insert(result, t)           size = size + 1 elseif result[i-1][2] ~= t[2] then table.insert(result, t)           size = size + 1 elseif size <= 5 then table.insert(result, t)       else break end end -- if i == 1 then --    table.insert(result, t)        --     size = size + 1 -- elseif size < 5 then --    if result[i-1][2] ~= t[2] then --        table.insert(result, t)        --         size = size + 1 --    end -- else --    break -- end table.sort(result, function(a, b) return a[2] < b[2] end) mw.log(lib.tbl(result)) end

-- -- local funtions --

function strtoluadata(str, sep) x = mw.text.split(str, sep) i = 1 s = '"' .. mw.text.trim(x[i]) .. '"' i = i + 1 while i <= #x do       s = s .. ', "' .. mw.text.trim(x[i]) .. '"' i = i + 1 end return s end

function strtoluadatai(str, sep) x = mw.text.split(str, sep) i = 1 s = '[' .. i .. '] = "' .. mw.text.trim(x[i]) .. '"' i = i + 1 while i <= #x do       s = s .. ', [' .. i .. '] = "' .. mw.text.trim(x[i]) .. '"' i = i + 1 end return s end

function pst2(champion, stat) local frame = mw.getCurrentFrame return frame:expandTemplate{ title = 'Data ' .. champion, args = {'pst2', stat} } end

function loadData(patchid) if exists('Module:StatTable/data/' .. patchid) then return mw.loadData('Module:StatTable/data/' .. patchid) end return nil end function exists(page) local sPage = page if sPage then local _, val = pcall(package.loaders[2], sPage) if type(val) == "function" or type(val) == "string" then return true end end return false end

return p -- --