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.compare2(frame) local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end local wikidata = mw.loadData('Module:ChampionData/data') local wikistatdata local a,b,c= cmd.main{"PatchId"}:match"([^%.]*).([^%.]*).([^%.]*)" s="" a=tonumber(a) b=tonumber(b) c=tonumber(c) local stop=false local luadata 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 if c==0 then c=1 end end while c>=1 do               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 championtable={} local stattable={} local resulttable={} for championname,championdata in pairs(luadata) do       for stat,statdata in pairs(championdata.stats) do            if stat == "as_lvl1" then stat = "as_ratio" end wikistatdata = wikidata[championname]["stats"][stat] if tonumber(statdata)~=tonumber(wikistatdata) then if resulttable[championname]==nil then resulttable[championname]={} stattable[championname]={} table.insert(championtable,championname) end table.insert(stattable[championname],stat) resulttable[championname][stat]=statdata end end end table.sort(championtable) for _,championname in pairs(championtable) do       table.sort(stattable[championname]) s=s..ci(championname,true).."\n" for _,stat in pairs(stattable[championname]) do           s=s.."*"..stat.."= "..resulttable[championname][stat].."\n" end end return "Patch Data: "..a.."."..b.."."..c.." "..s end

function p.compare(frame) local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end local a,b,c= cmd.main{"PatchId"}:match"([^%.]*).([^%.]*).([^%.]*)" s="" a=tonumber(a) b=tonumber(b) c=tonumber(c) local stop=false local luadata 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 if c==0 then c=1 end end while c>=1 do               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 championtable={} local stattable={} local resulttable={} for championname,championdata in pairs(luadata) do       for stat,statdata in pairs(championdata.stats) do            wikistatdata=pst2(championname,stat,frame) if wikistatdata=="" then wikistatdata=pst2(championname,"as_base",frame) end if tonumber(statdata)~=tonumber(wikistatdata) then if resulttable[championname]==nil then resulttable[championname]={} stattable[championname]={} table.insert(championtable,championname) end table.insert(stattable[championname],stat) resulttable[championname][stat]=statdata end end end table.sort(championtable) for _,championname in pairs(championtable) do       table.sort(stattable[championname]) s=s..ci(championname,true).."\n" for _,stat in pairs(stattable[championname]) do           s=s.."*"..stat.."= "..resulttable[championname][stat].."\n" end end return "Patch Data: "..a.."."..b.."."..c.." "..s 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"] local sortby     = args["sortby"] local lvl        = args["lvl"] local show       = tonumber(args["show"] or 1) local get = args["get"] 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 if lvl~=nil and size==1 and sortby~=nil then return getstats(lvl,stat,stat2,frame,rangetype,sortby,size,show,get) else 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' s=s..'\n! colspan="2" width="200pt" | ' if sortby~=nil then if sortby=="top" then s=s..'Top' end if sortby=="bot" then s=s..'Bottom' end else s=s..'Top' if size~=1 then s=s.." "..size..' champions' else s=s..' champion' end s=s..'\n! colspan="2" width="200pt" | Bottom' end if size~=1 then s=s.." "..size..' champions' else s=s..' champion' end s=s..'\n|-\n! rowspan="'..size..'" | Level ' if lvl~=nil then s=s..lvl s=s..getstats(lvl,stat,stat2,frame,rangetype,sortby,size) else s=s.."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) end return s.."\n|}" end end

-- HELPER FUNCTIONS --

function getstats(lvl,stat,stat2,frame,rangetype,sortby,size,show,get) local a,b,c= cmd.main{"PatchId"}:match"([^%.]*).([^%.]*).([^%.]*)" a=tonumber(a) b=tonumber(b) c=tonumber(c) local stop=false local luadata 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 if c==0 then c=1 end end while c>=1 do               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]<b[2] end) if lvl~=nil and size==1 and sortby~=nil then if get~="champ" then if sortby=="top" then s = s .. fd(round(stats[#stats-show+1][2])) else s = s .. fd(round(stats[show][2])) end end if get == nil then s = s .. " ("       end        if get ~= "stat" then            if sortby=="top" then                s = s .. ci(stats[#stats-show+1][1],frame)            else                s = s .. ci(stats[show][1],frame)            end        end        if get == nil then            s = s .. ")" end return s   else local bot={} local top={} j=#stats k=1 while j>=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 end

function loadData(patchid) if exists('Module:StatTable/data/' .. patchid) and pcall(mw.loadData,'Module:StatTable/data/' .. patchid) ~= false 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,edit) return tostring(IL.champion{           ["champion"] = champion,            ["edit"] = edit or ""        }) 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 --