Module:Sandbox/AnataBakka2

-- local p   = {} local lib      = require('Module:Feature') local json     = require('Module:JSON') local cmd      = require('Module:Maintenance data') local userError = require('Dev:User error') local IL       = require('Module:ImageLink')

function p.get(frame) local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end local patchid    = args[3] or cmd.main{"PatchId"} local luadata    = loadData(patchid) local stat       = args[1] local lvl        = args[2] local s          = "" local champions  = {} local stats  = {} i=0 for champname, champdata in pairs(luadata) do           base=champdata.stats[stat.."_base"] or champdata.stats[stat] xlvl=champdata.stats[stat.."_lvl"] or 0 i=i+1 table.insert(champions, champname) if stat=="as" then as_lvl1=tonumber(pst2(champname,"as_base",frame)) table.insert(stats, as_lvl1+base*xlvl/100*(lvl-1)*(0.7025+0.0175*(lvl-1))) else table.insert(stats, base+xlvl*(lvl-1)*(0.7025+0.0175*(lvl-1))) end end j=1 while j<=i do           k=j+1 while k<=i do               if stats[j]>stats[k] then temp=stats[k] temp2=champions[k] stats[k]=stats[j] champions[k]=champions[j] stats[j]=temp champions[j]=temp2 end k=k+1 end j=j+1 end j=1 k=1 while j<=i do           if j==1 then s="1. "..champions[1] else if stats[j]==stats[j-1] then s=s..", "..champions[j] else k=k+1 if k==6 then break else s=s.." "..k..". "..champions[j] end end end j=j+1 end j=i k=6 while j>=1 do           if j==i then s=s.." 6. "..champions[i] else if stats[j]==stats[j+1] then s=s..", "..champions[j] else k=k+1 if k==11 then break end s=s.." "..k..". "..champions[j] end end j=j-1 end return s 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

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