Module:Ability progression

-- local p = {} local lib      = require('Module:Feature') local userError = require('Dev:User error') local col      = require('Module:color')

function p.pp(frame) local args; if frame.args[1] then args = frame.args else args = frame:getParent.args end local values, values2, values3 = "", "", "" local count                    = 30 local fill                     = 18 local fill1                    = 18 local temp, a, b, c,start2,end2 local displayformula           = args["formula"] local round                    = args["round"]   or 2 local round1                   = args["round1"] local key                      = args["key"]     or "" local key1                     = args["key1"] local labelbot                 = args["labelbot"] local labeltop                 = args["labeltop"]  or args["type"] local orig                     = mw.text.split(args[1] or "", "%;") local orig1                    = mw.text.split(args[2] or "", "%;") local i                        = 1 local _, occurences            = string.gsub(args[1] or "", "to", "") local _, occurences1           = string.gsub(args[1] or "", "x",  "") local _, occurences2           = string.gsub(args[2] or "", "to", "") local _, occurences3           = string.gsub(args[2] or "", "x",  "") local to, to1                  = 0, 0 if occurences+occurences1~=0 or occurences2+occurences3~=0 then while orig[i]~=nil and orig[i]~="" do           if (string.find(orig[i],"to")~=nil or string.find(orig[i],"x")~=nil) and string.find(orig[i],"%<")==nil then if string.find(orig[i],"x")==nil then start,finish,times=orig[i]:match"(.*) *to *([^ ]*) *([^ ]*)" if start~=nil and finish~=nil and pcall(expr,start.."*2")~=false and pcall(expr,finish.."*2")~=false then if times~="" and times~=nil then times=tonumber(expr(times)) fill=fill-times else to=1 end else fill=fill-1 end else useformula,times=orig[i]:match"([^ ]*) *([^ ]*)" if useformula~=nil and pcall(expr,string.gsub(useformula,"x","1").."*2")~=false then if times~="" and times~=nil then times=tonumber(expr(times)) fill=fill-times else to=1 end else fill=fill-1 end end else fill=fill-1 end i=i+1 end end i=1 if occurences+occurences1~=0 or occurences2+occurences3~=0 then while orig1[i]~=nil and orig1[i]~="" do           if (string.find(orig1[i],"to")~=nil or string.find(orig1[i],"x")~=nil) and string.find(orig1[i],"%<")==nil then if string.find(orig1[i],"x")==nil then start,finish,times=orig1[i]:match"(.*) *to *([^ ]*) *([^ ]*)" if start~=nil and finish~=nil and pcall(expr,start.."*2")~=false and pcall(expr,finish.."*2")~=false then if times~="" and times~=nil then times=tonumber(expr(times)) fill1=fill1-times else to1=1 end else fill1=fill1-1 end else useformula,times=orig1[i]:match"([^ ]*) *([^ ]*)" if useformula~=nil and pcall(expr,string.gsub(useformula,"x","1").."*2")~=false then if times~="" and times~=nil then times=tonumber(expr(times)) fill1=fill1-times else to1=1 end else fill1=fill1-1 end end else fill1=fill1-1 end i=i+1 end end if 18-fill>=18-fill1 then if to==0 then fill1=fill1-fill end else if to1==0 then fill=fill-fill1 end end if fill<0 then fill=0 end if fill1<0 then fill1=0 end i=1 while orig[i]~=nil and orig[i]~="" do       if (string.find(orig[i],"to")~=nil or string.find(orig[i],"x")~=nil) and string.find(orig[i],"%<")==nil then if string.find(orig[i],"x")==nil then start,finish,times=orig[i]:match"(.*) *to *([^ ]*) *([^ ]*)" if start~=nil and finish~=nil and pcall(expr,start.."*2")~=false and pcall(expr,finish.."*2")~=false then start=tonumber(expr(start)) finish=tonumber(expr(finish)) if displayformula==nil and orig[2]==nil then start2=start finish2=finish fill2=fill end if times=="" or times==nil then times=fill fill=0 else times=tonumber(expr(times)) end x=1 while x<=times do                       count=count-1 if count<0 then return userError("Maximum size exceeded", "LuaError") end if x==1 then formula=start else formula=formula+(finish-start)/(times-1) end values3=rounding(formula,round) if values=="" then values=fd(values3)..key values2=values3..key else values=values.." / "..fd(values3)..key values2=values2.." / "..values3..key end x=x+1 end else count=count-1 if count<0 then return userError("Maximum size exceeded", "LuaError") end values3=rounding(expr(orig[i]),round) if values=="" then values=fd(values3)..key values2=values3..key else values=values.." / "..fd(values3)..key values2=values2.." / "..values3..key end end else useformula,times=orig[i]:match"([^ ]*) *([^ ]*)" if useformula~=nil and pcall(expr,string.gsub(useformula,"x","1").."*2")~=false then if displayformula==nil and orig[2]==nil then useformula2=useformula end if times=="" or times==nil then times=fill fill=0 else times=tonumber(expr(times)) end x=1 while x<=times do                       count=count-1 if count<0 then return userError("Maximum size exceeded", "LuaError") end formula=string.gsub(useformula,"x",x) values3=rounding(expr(formula),round) if values=="" then values=fd(values3)..key values2=values3..key else values=values.." / "..fd(values3)..key values2=values2.." / "..values3..key end x=x+1 end else count=count-1 if count<0 then return userError("Maximum size exceeded", "LuaError") end values3=rounding(expr(orig[i]),round) if values=="" then values=fd(values3)..key values2=values3..key else values=values.." / "..fd(values3)..key values2=values2.." / "..values3..key end end end else count=count-1 if count<0 then return userError("Maximum size exceeded", "LuaError") end values3=rounding(expr(orig[i]),round) if values=="" then values=fd(values3)..key values2=values3..key else values=values.." / "..fd(values3)..key values2=values2.." / "..values3..key end end i=i+1 end local s = "" if args["notooltip"] ~= "true" then s = s .. '<span class="pp-tooltip2" style="position:relative; border-bottom:1px dotted; cursor:help; color: '       if args["color"] ~= nil then            s = s .. col.keyword{args["color"]}        else            s = s.."inherit"        end        s = s .. ';"' if labelbot ~= nil then s = s .. ' data-labelbot="' .. mw.ustring.gsub(labelbot, "^.", mw.ustring.upper) .. '"' end if labeltop ~= nil then s = s .. ' data-labeltop="' .. mw.ustring.gsub(string.gsub(string.gsub(labeltop, "'", ""), "", ""), "^.", mw.ustring.upper) .. '"' end if displayformula ~= nil then s = s .. ' data-displayformula="' .. displayformula .. '"' end if useformula2 ~= nil then s = s .. ' data-useformula="' .. useformula2 .. '"' end if values2 ~= nil then s = s .. ' data-values="' .. values2 .. '"' end if args[2] ~= nil then s = s .. ' data-values1="' .. args[2] .. '"' end if args["round"] ~= nil then s = s .. ' data-round="' .. round .. '"' end if round1 ~= nil then s = s .. ' data-round1="' .. round1 .. '"' end if args["key"] ~= nil then s = s .. ' data-key="' .. key .. '"' end if key1 ~= nil then s = s .. ' data-key1="' .. key1 .. '"' end if start2 ~= nil then s = s .. ' data-start="' .. start2 .. '"' s = s .. ' data-finish="' .. finish2 .. '"' end if occurences2+occurences3 ~= 0 or start2~=nil then s = s .. ' data-fill1="' .. fill1 .. '"' end s = s .. ">"   end s = s .. values if args["notooltip"] ~= "true" then s = s .. " "   end return s end

-- https://leagueoflegends.fandom.com/wiki/MediaWiki:Common.js classname: 'pp-tooltip' parse: '

function p.pptooltip(frame) local args; if frame.args[1] then args = frame.args else args = frame:getParent.args end

local labelbot = args["labelbot"] local labeltop = args["labeltop"] local round  = args["round"] local round1  = args["round1"] local key    = args["key"] local key1    = args["key1"] local displayformula = fdmulti(args["displayformula"]) local useformula = args["useformula"] local fill1   = tonumber(args["fill1"]) local count1   = 30 local start   = args["start"] local finish   = args["finish"] local scale if labeltop == "" then labeltop = "Level" end if labelbot == "" then labelbot = "Value" end if round == "" then round = 2 end if round1 == "" then round1 = 2 end local orig = mw.text.split(args["values"], "%/") local orig1 = mw.text.split(args["values1"], "%;") local s = "" local i = 1 local j = 1 while (orig1[i]~=nil and orig1[i]~="") or (orig[j]~=nil and orig[j]~="") do       s= s .. ' ' if orig1[1]~="" then if orig1[i]~=nil and orig1[i]~="" then if (string.find(orig1[i],"to")~=nil or string.find(orig1[i],"x")~=nil) and string.find(orig1[i],"%<")==nil then if string.find(orig1[i],"x")==nil then start1,finish1,times1=orig1[i]:match"(.*) *to *([^ ]*) *([^ ]*)" if start1~=nil and finish1~=nil and pcall(expr,start1.."*2")~=false and pcall(expr,finish1.."*2")~=false then start1=tonumber(expr(start1)) finish1=tonumber(expr(finish1)) if displayformula==nil and orig1[2]==nil then start3=start1 finish3=finish1 end if times1=="" or times1==nil then times1=fill1 fill1=0 else times1=tonumber(expr(times1)) end x1=1 while x1<=times1 do                               count1=count1-1 if count1<0 then return userError("Maximum size exceeded", "LuaError") end if x1==1 then formula1=start1 else formula1=formula1+(finish1-start1)/(times1-1) s = s .. ' ' j=j+1 end s = s .. fd(rounding(formula1,round1))..key1 x=x+1 end else count1=count1-1 if count1<0 then return userError("Maximum size exceeded", "LuaError") end s = s .. fd(rounding(expr(orig1[i]),round1))..key1 end else useformula1,times1=orig1[i]:match"([^ ]*) *([^ ]*)" if useformula1~=nil and pcall(expr,string.gsub(useformula1,"x","1").."*2")~=false then if times1=="" or times1==nil then times1=fill1 fill1=0 else times1=tonumber(expr(times1)) end x1=1 while x1<=times1 do                               count1=count1-1 if count1<0 then return userError("Maximum size exceeded", "LuaError") end formula1=string.gsub(useformula1,"x",x1) if x1 ~= 1 then s = s .. ' ' j=j+1 end s = s .. fd(rounding(expr(formula1),round1))..key1 x1=x1+1 end else count1=count1-1 if count1<0 then return userError("Maximum size exceeded", "LuaError") end s = s .. fd(rounding(expr(orig1[i]),round1))..key1 end end else count1=count1-1 if count1<0 then return userError("Maximum size exceeded", "LuaError") end s = s .. fd(rounding(expr(orig1[i]),round1))..key1 end end else s = s .. j       end i=i+1 j=j+1 end s = s .. ' '    s = s .. ' ' .. labelbot .. ' '   i = 1 while orig[i] ~= nil and orig[i] ~= "" do       s = s .. ' '       s = s .. fd(orig[i]) .. ' '       i = i + 1 end s = s .. ' '    local s2 = ' ' if displayformula ~= "" then s2 = s2 .. "Formula: " .. fdmulti(displayformula) else if orig1[1] ~= "" then if start ~= "" and start3 ~= nil then s2 = s2 .. "Formula: " .. fdmulti(displayformula) end else if start ~= "" then s2 = s2 .. "Formula: " scale = (finish-start) / (fill1 - 1) if start == scale then s2 = s2 .. fd(rounding(start, round + 1)) .. key .. "&#42;x" else s2 = s2 .. fd(rounding(start-scale, round + 1)) .. key if scale >=0 then s2 = s2 .. "+"                       if scale == 1 then s2 = s2 .. "x" else s2 = s2 .. fd(rounding(scale, round + 1)) .. key .. "&#42;x" end else if scale == -1 then s2 = s2 .. "x" else s2 = s2 .. scale .. key .. "&#42;x" end end end end if useformula ~= "" then s2 = s2 .. "Formula: " .. fdmulti(useformula) end end end s2 = s2 .. ' '   s2 = s2 .. ' ' .. labeltop return s2 .. s .. " " end

function p.ap(frame) local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end local values="" local count=6 local fill local formula if args["skill"]=="R" then fill=3 else fill=5 end i=1 local temp,a,b,c local round=args["round"] or nil while args[i]~=nil do       if string.find(args[i],"to")~=nil and string.find(args[i],"%<")==nil then start,finish,times=args[i]:match"(.*) *to *([^ ]*) *([^ ]*)" if start~=nil and finish~=nil and pcall(expr,start.."*2")~=false and pcall(expr,finish.."*2")~=false then start=tonumber(expr(start)) finish=tonumber(expr(finish)) if times=="" or times==nil then times=fill fill=0 else times=tonumber(expr(times)) end x=1 while x<=times do                   count=count-1 if count<0 then return userError("Maximum size exceeded", "LuaError") end if x==1 then formula=start else formula=formula+(finish-start)/(times-1) end if values=="" then values=fd(rounding(formula,round)) else values=values.." / "..fd(rounding(formula,round)) end x=x+1 end else count=count-1 if count<0 then return userError("Maximum size exceeded", "LuaError") end if values=="" then values=fd(rounding(args[i],round)) else values=values.." / "..fd(rounding(args[i],round)) end end else count=count-1 if count<0 then return userError("Maximum size exceeded", "LuaError") end if values=="" then values=fd(rounding(args[i],round)) else values=values.." / "..fd(rounding(args[i],round)) end end i=i+1 end return values end

function expr(val) if string.find(val,"[0-9]")==nil then return val end local val=string.gsub(string.gsub(string.gsub(string.gsub(string.gsub(string.gsub(string.gsub(string.gsub(val," ",""),"%/"," / "),"%*"," * "),"%+"," + "),"%-"," - "),"%^"," %^ "),"([^%d%(%)]) %- ","%1-"),"([^%d%(%)]) %+ ","%1+") local i=1 local j=1 local a,b,switcher,switcher2,switcher3,temp while i>0 do       while j>0 do            temp=val if string.find(val,"%)")~=nil then               switchertemp=mw.text.split( val, "%)") temp=last(switchertemp[1],"%(")           end            if string.find(temp," %^ ")~=nil then                a=mw.text.split(temp," %^ ")                b=mw.text.split(a[2]," ")                switcher=last( a[1]," ")                switcher2=b[1]                switcher3=switcher^switcher2                if string.find(switcher2,"%-")~=nil then                     switcher2="%-"..switcher2*(-1)                end                val=string.gsub(val,switcher.." %^ "..switcher2,switcher3)                break            end            if string.find(temp," %/ ")~=nil then                a=mw.text.split(temp," %/ ")                b=mw.text.split(a[2]," ")                switcher=last( a[1]," ")                switcher2=b[1]                switcher3=switcher/switcher2                if string.find(switcher2,"%-")~=nil then                     switcher2="%-"..switcher2*(-1) end val=string.gsub(val,switcher.." %/ "..switcher2,switcher3) break end if string.find(temp," %* ")~=nil then a=mw.text.split( temp," %* ") b=mw.text.split(a[2]," ") switcher=last( a[1]," ") switcher2=b[1] switcher3=switcher*switcher2 if string.find(switcher2,"%-")~=nil then switcher2="%-"..switcher2*(-1) end val=string.gsub(val,switcher.." %* "..switcher2,switcher3) break end if string.find(temp," %- ")~=nil then a=mw.text.split( temp," %- ") b=mw.text.split(a[2]," ") switcher=last( a[1]," ") switcher2=b[1] if switcher=="" then if string.find(switcher2,"%-")~=nil then switcher2="%-"..switcher2*(-1) end val=string.gsub(val," %- "..switcher2,"%-"..switcher2) break else switcher3=switcher-switcher2 if string.find(switcher2,"%-")~=nil then switcher2="%-"..switcher2*(-1) end val=string.gsub(val,switcher.." %- "..switcher2,switcher3) break end end if string.find(temp," %+ ")~=nil then a=mw.text.split( temp," %+ ") b=mw.text.split(a[2]," ") switcher=last( a[1]," ") switcher2=b[1] if switcher=="" then if string.find(switcher2,"%-")~=nil then switcher2="%-"..switcher2*(-1) end val=string.gsub(val," %+ "..switcher2,switcher2) break else switcher3=switcher+switcher2 if string.find(switcher2,"%-")~=nil then switcher2="%-"..switcher2*(-1) end val=string.gsub(val,switcher.." %+ "..switcher2,switcher3) break end end if string.find(val,"%)")~=nil then               if string.find(temp,"%-")~=nil then                     temp="%-"..temp*(-1)                end                val=string.gsub(val,"%("..temp.."%)",temp)                break            else                i=0            end            break        end    end    return temp end

function last(val,sign) local a=mw.text.split(val,sign) local j=1 while j>0 do       if a[j] ~=nil then j=j+1 else break end end return a[j-1] end

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

function fdmulti(val) if string.find(val,"[0-9]") == nil or string.find(val,"%.") == nil then return val end local val   = mw.text.split(val,"%.") local values = val[1] local i     = 2 local b,c while val[i] ~= nil do       if string.find(val[i],"span") ~= nil then b,c   = val[i]:match"(.*) (.*)" if string.find(tostring(b),"[0-9]")==nil then values=values.."."..val[i] else if string.find(val[i],"span")<=string.find(val[i],"%.") then values = values .. ". " .. b .. " " .. c               else values = values .. ". " .. b .. " " .. c               end end else b,c   = val[i]:match"([0-9]*)(.*)" if string.find(tostring(b),"[0-9]")==nil then values=values.."."..val[i] else values = values .. ". " .. b .. " " .. c           end end i = i + 1 end return values end

function rounding(val, decimals) local round local val=tostring(val) if decimals==nil or string.find(val,"[0-9]")==nil or string.find(val,"<span")~=nil or string.find(val,"%.")==nil then return val end local a,b,c,d a,b,c,d = val:match"([^0-9]*)([0-9]*).([0-9]*)(.*)" val=tonumber(b.."."..c)   if decimals=="abs" then round=math.abs(val) end if decimals=="floor" then round=math.floor(val) end if decimals=="ceil" then round=math.ceil(val) end if round==nil then local mult = 10^(decimals) round=math.floor(val * mult + 0.5) / mult end return a..round..d end

return p

-- --