Module:Ability progression

-- local p = {} local lib      = require('Module:Feature')

function p.get(frame) local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end values="" count=7 fill=5 i=1 local temp,a,b,c local round=args["round"] or 2 while args[i]~=nil do       if string.find(args[i],"%:")~=nil and string.find(args[i],"%<")==nil then times=args[i]:match"[^:]*: *[^ ]* *(.*)" if times~="" and times~=nil then times=tonumber(expr(times)) fill=fill-times end else fill=fill-1 end if fill<=0 then fill=0 break end i=i+1 end i=1 while args[i]~=nil do       if string.find(args[i],"%:")~=nil and string.find(args[i],"%<")==nil then start,finish,times=args[i]:match"([^:]*): *([^ ]*) *(.*)" 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 i=-1 break 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 break 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 p.get2(frame) local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end values="" count=7 fill=5 i=1 local temp,a,b,c local round=args["round"] or 2 while args[i]~=nil do       if string.find(args[i],"to")~=nil and string.find(args[i],"%<")==nil then times=args[i]:match"[^to]*to *[^ ]* *(.*)" if times~="" and times~=nil then times=tonumber(expr(times)) fill=fill-times end else fill=fill-1 end if fill<=0 then fill=0 break end i=i+1 end i=1 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]*)to *([^ ]*) *(.*)" 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 i=-1 break 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 break 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) val=string.gsub(string.gsub(string.gsub(string.gsub(string.gsub(string.gsub(string.gsub(string.gsub(val," ",""),"%/"," / "),"%*"," * "),"%+"," + "),"%-"," - "),"%^ %- ","^-"),"%( %- ","(-"),"%^"," %^ ") local i=1 local j=1 local a,b,switcher,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] 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(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) and ((a[j]~="") or (sign=="%(")) then j=j+1 else break end end return a[j-1] end function fd(val) if string.find(val,"[0-9]")==nil then return val end local a,b,c local val=tostring(val) if string.find(val,"%.")==nil then return val else if string.find(val,"span")~=nil then a,b = val:match"([^.]*).(.*)" b = '. ' .. b.. ' '       c="" else a,b,c = val:match"([^.]*).([0-9]*)(.*)" b = '. ' .. b.. ' '       end end return a..b..c end function rounding(num, numDecimalPlaces) if string.find(num,"[0-9]")==nil or string.find(num,"<span")~=nil or string.find(num,"%.")==nil then return num end local a,b,c local val=tostring(num) a,b,c = val:match"([^.]*).([0-9]*)(.*)" b = "."..b   val=tonumber(a..b)    local mult = 10^(numDecimalPlaces) local round=math.floor(val * mult + 0.5) / mult return round..c end return p

-- --