Module:Base stats

-- 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.test(frame) local a,b,c= cmd.main{"PatchId"}:match"([^%.]*).([^%.]*).([^%.]*)" return loadData(a..".6."..c) end

function p.get(frame) local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end local stat3      = string.lower(args[1] or "as") local rangetype  = args["rangetype"] or nil local sortby    = args["sortby"] or nil if rangetype~=nil then rangetype=string.lower(rangetype) end if sortby~=nil then sortby=string.lower(sortby) end local size       = tonumber(args["size"] or 5) local stat,stat2="","" if stat3=="ad" or stat3=="dam" or stat3=="attack damage" then stat="dam" stat2="AD" else if stat3=="attack speed" or stat3=="as" then stat="as" stat2="AS" else if stat3=="health" or stat3=="hp" then stat="hp" stat2="health" else if stat3=="health regeneration" or stat3=="hp5" then stat="hp5" stat2="hp5" else if stat3=="mana" or stat3=="mp" then stat="mp" stat2="mana" else if stat3=="mana regeneration" or stat3=="mp5" then stat="mp5" stat2="mp5" else if stat3=="armor" or stat3=="armor" then stat="arm" stat2="armor" else if stat3=="magic resistance" or stat3=="mr" then stat="mr" stat2="MR" else stat=stat3 stat2=stat3 end end end end end end end end local s          = '{| class="wikitable"\n|+' if rangetype~=nil then s=s..mw.ustring.gsub(rangetype, "^.", mw.ustring.upper).." c"   else s=s.."C" end s=s..'hampions with the ' if sortby~=nil then if sortby=="top" then s=s.."highest " else if sortby=="bot" then s=s.."lowest " else end end else s=s.."lowest or highest " end s=s..stat3..' before items, runes, or abilities\n! width="100pt" | Champion Level' if sortby~=nil then if sortby=="top" then s=s..'\n! colspan="2" width="200pt" | Top '..size..' champions' else if sortby=="bot" then s=s..'\n! colspan="2" width="200pt" | Bottom '..size..' champions' else end end else s=s..'\n! colspan="2" width="200pt" | Top '..size..' champions\n! colspan="2" width="200pt" | Bottom '..size..' champions' end s=s..'\n|-\n! rowspan="'..size..'" | Level 1' s=s..getstats(1,stat,stat2,frame,rangetype,sortby,size) s=s..'\n|-\n! colspan="5" height="5pt" |\n|-\n! rowspan="'..size..'" | Level 18' s=s..getstats(18,stat,stat2,frame,rangetype,sortby,size) return s.."\n|}" end

function getstats(lvl,stat,stat2,frame,rangetype,sortby,size) local a,b,c= cmd.main{"PatchId"}:match"([^%.]*).([^%.]*).([^%.]*)" a=tonumber(a) b=tonumber(b) c=tonumber(c) local stop=false while a>=0 do       if b==0 then b=24 end while b>=1 do           if b==24 and c==0 then c=2 else c=1 end while c>=1 do               local luadata     = loadData(a.."."..b.."."..c)                if luadata~=nil then stop=true break end c=c-1 end if stop==true then break end b=b-1 end if stop==true then break end a=a-1 end local stats={} local s="" for champname in pairs(luadata) do       if (stat=="mp" or stat=="mp5") and pst2(champname,"resource",frame)~="" and pst2(champname,"resource",frame)~="" and string.lower(pst2(champname,"resource",frame))~="mana" then else if rangetype==nil or string.lower(pst2(champname,"rangetype",frame))==rangetype then base=tonumber(pst2(champname,stat.."_base",frame)) or tonumber(pst2(champname,stat,frame)) xlvl=tonumber(pst2(champname,stat.."_lvl",frame)) or 0 if stat=="as" then as_lvl1=tonumber(pst2(champname,"as_lvl1",frame)) or tonumber(pst2(champname,"as_base",frame)) table.insert(stats,{champname, as_lvl1+base*xlvl/100*(lvl-1)*(0.7025+0.0175*(lvl-1))}) else table.insert(stats,{champname, base+xlvl*(lvl-1)*(0.7025+0.0175*(lvl-1))}) end end end end table.sort(stats, function(a, b) return a[2]=1 and sortby~="bot" do       if j==#stats then top[k]="\n| "..k..". "..ci(stats[j][1],frame) else if stats[j][2]==stats[j+1][2] then top[k]=top[k].." "..k..". "..ci(stats[j][1],frame) else top[k]=top[k].."\n| "..fd(round(stats[j+1][2])).." "..stat2 k=k+1 if k>size then break end top[k]="\n| "..k..". "..ci(stats[j][1],frame) if j==1 then top[k]=top[k].."\n| "..fd(round(stats[j][2])).." "..stat2 end end end j=j-1 end j=1 k=1 while j<=#stats and sortby~="top" do       if j==1 then bot[k]="\n| "..k..". "..ci(stats[j][1],frame) else if stats[j][2]==stats[j-1][2] then bot[k]=bot[k].." "..k..". "..ci(stats[j][1],frame) else bot[k]=bot[k].."\n| "..fd(round(stats[j-1][2])).." "..stat2 k=k+1 if k>size then break end bot[k]="\n| "..k..". "..ci(stats[j][1],frame) if j==#stats then bot[k]=bot[k].."\n| "..fd(round(stats[j][2])).." "..stat2 end end end j=j+1 end k=1 while k<=size do       if sortby~=nil then if sortby=="top" then if top[k]~=nil then s=s..top[k] else s=s.."\n|\n|" end else if sortby=="bot" then if bot[k]~=nil then s=s..bot[k] else s=s.."\n|\n|" end end end else if top[k]~=nil then s=s..top[k] else s=s.."\n|\n|" end if bot[k]~=nil then s=s..bot[k] else s=s.."\n|\n|" end end s=s.."\n|-" k=k+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

function ci(champion, frame) return frame:expandTemplate{ title = "ci", args = {champion} } end

function fd(val) val=tostring(val) if string.find(val,"[0-9]") == nil or string.find(val,"%.") == nil then return val end local a,b = val:match"([0-9]*).([0-9]*)" return a .. ". " .. b .. " " end

function round(val) local mult = 10^3 local rounding=math.floor(val * mult + 0.5) / mult return rounding end return p --