League of Legends Wiki

Want to contribute to this wiki?
Sign up for an account, and get started!
You can even turn off ads in your preferences.

Come join the LoL Wiki community Discord server!

READ MORE

League of Legends Wiki
No edit summary
No edit summary
(44 intermediate revisions by 3 users not shown)
Line 1: Line 1:
 
-- <pre>
 
-- <pre>
 
local p = {}
 
local p = {}
local lib = require('Module:Feature')
+
local lib = require('Module:Feature')
local col = require('Module:color')
+
local col = require('Module:Color')
local userError = require('Dev:User error')
+
local userError = require('Dev:User error')
  +
local fd_get = require('Module:fd').get
  +
local fd_getmulti = require('Module:fd').getmulti
   
 
function p.test(frame)
 
function p.test(frame)
 
local args; if frame.args[1] then args = frame.args else args = frame:getParent().args end
 
local args; if frame.args[1] then args = frame.args else args = frame:getParent().args end
local doubleto="yes"
+
local doubleto = "yes"
return string.gsub(doubleto,"true","")
+
return string.gsub(doubleto, "true", "")
 
end
 
end
   
Line 15: Line 17:
 
 
 
local start2, end2
 
local start2, end2
local values, values2 = "", ""
+
local values, values2 = "", ""
local count, countstatic = 30, 30
+
local count, countstatic = 30, 30
local fill, fill1 = 18, 18
+
local fill, fill1 = 18, 18
local to, to1 = 0, 0
+
local to, to1 = 0, 0
 
 
local displayformula = args["formula"]
+
local displayformula = args["formula"]
local round = args["round"] or 2
+
local round = args["round"] or 2
  +
if round == "false" then
local round1 = args["round1"]
 
  +
round = nil
local key = args["key"] or ""
 
  +
end
local key1 = args["key1"]
 
local label = args["label"]
+
local round1 = args["round1"]
local label1 = args["label1"] or args["type"]
+
local key = args["key"] or ""
local orig = mw.text.split(args[1] or "", "%;")
+
local key1 = args["key1"]
local orig1 = mw.text.split(args[2] or "", "%;")
+
local label = args["label"]
local _, bot_to_hits = string.gsub(args[1] or "", "to", "")
+
local label1 = args["label1"] or args["type"]
local _, top_to_hits = string.gsub(args[2] or "", "to", "")
+
local orig = lib.split(args[1] or "", "%;")
local _, bot_x_hits = string.gsub(args[1] or "", "x", "")
+
local orig1 = lib.split(args[2] or "", "%;")
local _, top_x_hits = string.gsub(args[2] or "", "x", "")
+
local _, bot_to_hits = string.gsub(args[1] or "", "to", "")
  +
local _, top_to_hits = string.gsub(args[2] or "", "to", "")
  +
local _, bot_x_hits = string.gsub(args[1] or "", "x", "")
  +
local _, top_x_hits = string.gsub(args[2] or "", "x", "")
 
local i = 1
 
local i = 1
 
 
 
if bot_to_hits + bot_x_hits ~= 0 or top_to_hits + top_x_hits ~= 0 then
 
if bot_to_hits + bot_x_hits ~= 0 or top_to_hits + top_x_hits ~= 0 then
local lastvalue=""
+
local lastvalue = ""
 
while orig[i] ~= nil and orig[i] ~= "" do
 
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], "to") ~= nil or string.find(orig[i], "x") ~= nil) and string.find(orig[i], "%<") == nil then
 
local start
 
local start
if string.find(orig[i],"to") ~= nil then
+
if string.find(orig[i], "to") ~= nil then
start=string.sub(orig[i],1,string.find(orig[i],"to")-1)
+
start = string.sub(orig[i], 1, string.find(orig[i], "to") - 1)
 
end
 
end
if string.find(orig[i],"x") == nil and pcall(expr,start.."*2")~=false then
+
if string.find(orig[i], "x") == nil and pcall(expr, start .. "*2") ~= false then
local finish,times
+
local finish, times
 
if string.find(orig[i], "by") ~= nil then
 
if string.find(orig[i], "by") ~= nil then
 
finish, times = orig[i]:match".* *to *([^ ]*) *by *([^ ]*)"
 
finish, times = orig[i]:match".* *to *([^ ]*) *by *([^ ]*)"
Line 60: Line 65:
 
times = tonumber(expr(times))
 
times = tonumber(expr(times))
 
if string.find(orig[i], "by") ~= nil then
 
if string.find(orig[i], "by") ~= nil then
times = rounding((finish-start)/times+1,0)
+
times = rounding(math.abs(finish - start) / times + 1, 0)
 
end
 
end
 
fill = fill - times
 
fill = fill - times
Line 74: Line 79:
 
end
 
end
 
else
 
else
local times,doubleto
+
local times, doubleto
if string.find(orig[i],"for") then
+
if string.find(orig[i], "for") then
doubleto,times = orig[i]:match"(.*) *for *([^ ]*)"
+
doubleto, times = orig[i]:match"(.*) *for *([^ ]*)"
 
else
 
else
 
doubleto = orig[i]
 
doubleto = orig[i]
 
end
 
end
local _,occurences = string.gsub(orig[i],"to","")
+
if occurences >0 and ((times ~= "" and times ~= nil and pcall(expr, times .. "*2") ~= false) or times == "" or times == nil) then
+
local _, occurences = string.gsub(orig[i], "to", "")
  +
if occurences > 0 and ((times ~= "" and times ~= nil and pcall(expr, times .. "*2") ~= false) or times == "" or times == nil) then
local times2=2
 
doubleto = string_to_formula(doubleto,times2)
+
local times2 = 2
  +
doubleto = string_to_formula(doubleto, times2)
 
end
 
end
local useformula = string.gsub(doubleto,"then","1")
+
  +
local useformula = string.gsub(doubleto, "then", "1")
 
if useformula ~= nil and pcall(expr, string.gsub(useformula, "x", "1") .. "*2") ~= false and ((times ~= "" and times ~= nil and pcall(expr, times .. "*2") ~= false) or times == "" or times == nil) then
 
if useformula ~= nil and pcall(expr, string.gsub(useformula, "x", "1") .. "*2") ~= false and ((times ~= "" and times ~= nil and pcall(expr, times .. "*2") ~= false) or times == "" or times == nil) then
 
if times ~= "" and times ~= nil then
 
if times ~= "" and times ~= nil then
Line 99: Line 106:
 
else
 
else
 
fill = fill - 1
 
fill = fill - 1
if pcall(expr, string.gsub(orig[i],"then",lastvalue) .. "*2") ~= false then
+
if pcall(expr, string.gsub(orig[i], "then", lastvalue) .. "*2") ~= false then
lastvalue=expr(string.gsub(orig[i],"then",lastvalue))
+
lastvalue = expr(string.gsub(orig[i], "then", lastvalue))
 
end
 
end
 
end
 
end
Line 114: Line 121:
 
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], "to") ~= nil or string.find(orig1[i], "x") ~= nil) and string.find(orig1[i], "%<") == nil then
 
local start1
 
local start1
if string.find(orig1[i],"to") ~= nil then
+
if string.find(orig1[i], "to") ~= nil then
start1=string.sub(orig1[i],1,string.find(orig1[i],"to")-1)
+
start1 = string.sub(orig1[i], 1, string.find(orig1[i], "to") - 1)
 
end
 
end
if string.find(orig1[i],"x") == nil and pcall(expr,start1.."*2")~=false then
+
if string.find(orig1[i], "x") == nil and pcall(expr, start1 .. "*2") ~= false then
local finish1,times1
+
local finish1, times1
 
if string.find(orig1[i], "by") ~= nil then
 
if string.find(orig1[i], "by") ~= nil then
 
finish1, times1 = orig1[i]:match".* *to *([^ ]*) *by *([^ ]*)"
 
finish1, times1 = orig1[i]:match".* *to *([^ ]*) *by *([^ ]*)"
Line 134: Line 141:
 
times1 = tonumber(expr(times1))
 
times1 = tonumber(expr(times1))
 
if string.find(orig1[i], "by") ~= nil then
 
if string.find(orig1[i], "by") ~= nil then
times1 = rounding((finish1-start1)/times1+1,0)
+
times1 = rounding(math.abs(finish1 - start1) / times1 + 1, 0)
 
end
 
end
 
fill1 = fill1 - times1
 
fill1 = fill1 - times1
Line 148: Line 155:
 
end
 
end
 
else
 
else
local times1,doubleto1
+
local times1, doubleto1
if string.find(orig1[i],"for") then
+
if string.find(orig1[i], "for") then
doubleto1,times1 = orig1[i]:match"(.*) *for *([^ ]*)"
+
doubleto1, times1 = orig1[i]:match"(.*) *for *([^ ]*)"
 
else
 
else
 
doubleto1 = orig1[i]
 
doubleto1 = orig1[i]
 
end
 
end
local _,occurences1 = string.gsub(orig1[i],"to","")
+
if occurences1 >0 and ((times1 ~= "" and times1 ~= nil and pcall(expr, times1 .. "*2") ~= false) or times1 == "" or times1 == nil) then
+
local _, occurences1 = string.gsub(orig1[i], "to", "")
  +
if occurences1 > 0 and ((times1 ~= "" and times1 ~= nil and pcall(expr, times1 .. "*2") ~= false) or times1 == "" or times1 == nil) then
local times2=2
 
doubleto1 = string_to_formula(doubleto1,times2)
+
local times2 = 2
  +
doubleto1 = string_to_formula(doubleto1, times2)
 
end
 
end
local useformula1 = string.gsub(doubleto1,"then","1")
+
  +
local useformula1 = string.gsub(doubleto1, "then", "1")
 
if useformula1 ~= nil and pcall(expr, string.gsub(useformula1, "x", "1") .. "*2") ~= false and ((times1 ~= "" and times1 ~= nil and pcall(expr, times1 .. "*2") ~= false) or times1 == "" or times1 == nil) then
 
if useformula1 ~= nil and pcall(expr, string.gsub(useformula1, "x", "1") .. "*2") ~= false and ((times1 ~= "" and times1 ~= nil and pcall(expr, times1 .. "*2") ~= false) or times1 == "" or times1 == nil) then
 
if times1 ~= "" and times1 ~= nil then
 
if times1 ~= "" and times1 ~= nil then
Line 173: Line 182:
 
else
 
else
 
fill1 = fill1 - 1
 
fill1 = fill1 - 1
if pcall(expr, string.gsub(orig1[i],"then",lastvalue1) .. "*2") ~= false then
+
if pcall(expr, string.gsub(orig1[i], "then", lastvalue1) .. "*2") ~= false then
lastvalue1=expr(string.gsub(orig1[i],"then",lastvalue1))
+
lastvalue1 = expr(string.gsub(orig1[i], "then", lastvalue1))
 
end
 
end
 
end
 
end
Line 206: Line 215:
 
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], "to") ~= nil or string.find(orig[i], "x") ~= nil) and string.find(orig[i], "%<") == nil then
 
local start
 
local start
if string.find(orig[i],"to") ~= nil then
+
if string.find(orig[i], "to") ~= nil then
start=string.sub(orig[i],1,string.find(orig[i],"to")-1)
+
start = string.sub(orig[i], 1, string.find(orig[i], "to") - 1)
 
end
 
end
if string.find(orig[i],"x") == nil and pcall(expr,start.."*2")~=false then
+
if string.find(orig[i], "x") == nil and pcall(expr, start .. "*2") ~= false then
local finish,times
+
local finish, times
 
if string.find(orig[i], "by") ~= nil then
 
if string.find(orig[i], "by") ~= nil then
 
finish, times = orig[i]:match".* *to *([^ ]*) *by *([^ ]*)"
 
finish, times = orig[i]:match".* *to *([^ ]*) *by *([^ ]*)"
Line 233: Line 242:
 
times = tonumber(expr(times))
 
times = tonumber(expr(times))
 
if string.find(orig[i], "by") ~= nil then
 
if string.find(orig[i], "by") ~= nil then
times = tonumber(rounding((finish-start)/times+1,0))
+
times = tonumber(rounding(math.abs(finish - start) / times + 1, 0))
 
end
 
end
 
end
 
end
Line 284: Line 293:
 
end
 
end
 
else
 
else
local times,doubleto
+
local times, doubleto
if string.find(orig[i],"for") then
+
if string.find(orig[i], "for") then
doubleto,times = orig[i]:match"(.*) *for *([^ ]*)"
+
doubleto, times = orig[i]:match"(.*) *for *([^ ]*)"
 
else
 
else
 
doubleto = orig[i]
 
doubleto = orig[i]
 
end
 
end
local _,occurences = string.gsub(orig[i],"to","")
+
local _, occurences = string.gsub(orig[i], "to", "")
if occurences >0 and ((times ~= "" and times ~= nil and pcall(expr, times .. "*2") ~= false) or times == "" or times == nil) then
+
if occurences > 0 and ((times ~= "" and times ~= nil and pcall(expr, times .. "*2") ~= false) or times == "" or times == nil) then
 
local times2
 
local times2
if times == "" or times==nil then
+
if times == "" or times == nil then
times2=fill
+
times2 = fill
 
else
 
else
times2=tonumber(expr(times))
+
times2 = tonumber(expr(times))
 
end
 
end
doubleto = string_to_formula(doubleto,times2)
+
doubleto = string_to_formula(doubleto, times2)
 
end
 
end
local useformula = string.gsub(doubleto,"then",lastvalue)
+
local useformula = string.gsub(doubleto, "then", lastvalue)
 
if useformula ~= nil and pcall(expr, string.gsub(useformula, "x", "1") .. "*2") ~= false and ((times ~= "" and times ~= nil and pcall(expr, times .. "*2") ~= false) or times == "" or times == nil) then
 
if useformula ~= nil and pcall(expr, string.gsub(useformula, "x", "1") .. "*2") ~= false and ((times ~= "" and times ~= nil and pcall(expr, times .. "*2") ~= false) or times == "" or times == nil) then
 
if displayformula == nil and orig[2] == nil then
 
if displayformula == nil and orig[2] == nil then
 
useformula2 = useformula
 
useformula2 = useformula
 
end
 
end
if times == "" or times==nil then
+
if times == "" or times == nil then
times=fill
+
times = fill
fill=0
+
fill = 0
 
else
 
else
times=tonumber(expr(times))
+
times = tonumber(expr(times))
 
end
 
end
 
local x = 1
 
local x = 1
Line 320: Line 329:
 
local values3 = expr(formula)
 
local values3 = expr(formula)
 
lastvalue = values3
 
lastvalue = values3
values3 = rounding(values3,round)
+
values3 = rounding(values3, round)
 
if values == "" then
 
if values == "" then
 
values = fd(values3)
 
values = fd(values3)
Line 351: Line 360:
 
end
 
end
 
local values3
 
local values3
if pcall(expr, string.gsub(orig[i],"then",lastvalue) .. "*2") ~= false then
+
if pcall(expr, string.gsub(orig[i], "then", lastvalue) .. "*2") ~= false then
values3 = expr(string.gsub(orig[i],"then",lastvalue))
+
values3 = expr(string.gsub(orig[i], "then", lastvalue))
 
lastvalue = values3
 
lastvalue = values3
values3 = rounding(values3,round)
+
values3 = rounding(values3, round)
 
else
 
else
 
values3 = orig[i]
 
values3 = orig[i]
Line 373: Line 382:
 
 
 
if args["color"] ~= nil then
 
if args["color"] ~= nil then
s = s .. " color:" ..col.keyword{args["color"]} ..";"
+
s = s .. " color:" .. col.keyword{args["color"]} .. ";"
 
end
 
end
 
s = s .. '"'
 
s = s .. '"'
Line 401: Line 410:
 
end
 
end
 
 
if round ~= 2 then
+
if round ~= 2 and round ~= nil then
 
s = s .. ' data-bot_round="' .. round .. '"'
 
s = s .. ' data-bot_round="' .. round .. '"'
 
end
 
end
Line 429: Line 438:
 
 
 
if (countstatic - count > 5 and args["changedisplay"] ~= "true") or (countstatic - count <= 5 and args["changedisplay"] == "true") then
 
if (countstatic - count > 5 and args["changedisplay"] ~= "true") or (countstatic - count <= 5 and args["changedisplay"] == "true") then
s = s .. fd(string.sub(values2, 1, (string.find(values2, "%/") or 1) - 2)) .. key .. " &minus; " .. fd(last(values2, "%/")) .. key
+
s = s .. fd(string.sub(values2, 1, (string.find(values2, "%/") or 1) - 2)) .. key .. " &minus; " .. fd(last(values2, "/")) .. key
 
else
 
else
 
s = s .. values .. key
 
s = s .. values .. key
Line 435: Line 444:
 
 
 
if args["showtype"] ~= "false" then
 
if args["showtype"] ~= "false" then
s = s .. " (based on " .. (args["type"] or args["label1"] or "level") ..")"
+
s = s .. " (based on " .. (args["type"] or args["label1"] or "level") .. ")"
 
end
 
end
 
 
Line 446: Line 455:
 
local args; if frame.args[1] then args = frame.args else args = frame:getParent().args end
 
local args; if frame.args[1] then args = frame.args else args = frame:getParent().args end
   
local label = args["bot_label"]
+
local label = args["bot_label"]
local label1 = string.gsub(args["top_label"],"[%[%]]","")
+
local label1 = args["top_label"]
local round = args["bot_round"]
+
local round = args["bot_round"]
local round1 = args["top_round"]
+
local round1 = args["top_round"]
local key = args["bot_key"]
+
if round1 == "false" then
local key1 = args["top_key"]
+
round1 = nil
  +
end
  +
local key = args["bot_key"]
  +
local key1 = args["top_key"]
 
local displayformula = args["displayformula"]
 
local displayformula = args["displayformula"]
local useformula = args["useformula"]
+
local useformula = args["useformula"]
local fill1 = tonumber(args["top_fill"])
+
local fill1 = tonumber(args["top_fill"])
local count1 = 30
+
local count1 = 30
local start = tonumber(args["start"])
+
local start = tonumber(args["start"])
local finish = tonumber(args["finish"])
+
local finish = tonumber(args["finish"])
 
 
 
if label1 == "" then
 
if label1 == "" then
 
label1 = "level"
 
label1 = "level"
 
end
 
end
  +
  +
local formulalabel1 = string.gsub(label1, "[%[%]]", "")
 
 
 
if label == "" then
 
if label == "" then
Line 475: Line 489:
 
end
 
end
 
 
local orig = mw.text.split(args["bot_values"], " %/")
+
local orig = lib.split(args["bot_values"], " %/")
local orig1 = mw.text.split(args["top_values"], "%;")
+
local orig1 = lib.split(args["top_values"], "%;")
 
 
 
local s = ""
 
local s = ""
Line 484: Line 498:
 
 
 
local lastvalue1 = ""
 
local lastvalue1 = ""
while (orig1[i]~=nil and orig1[i]~="") or (orig[j]~=nil and orig[j]~="") do
+
while (orig1[i] ~= nil and orig1[i] ~= "") or (orig[j] ~= nil and orig[j] ~= "") do
s= s .. '</th><th style="text-align: center;">'
+
s = s .. '</th><th style="text-align: center;">'
if orig1[1]~="" then
+
if orig1[1] ~= "" then
if orig1[i]~=nil and orig1[i]~="" 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], "to") ~= nil or string.find(orig1[i], "x") ~= nil) and string.find(orig1[i], "%<") == nil then
 
local start1
 
local start1
if string.find(orig1[i],"to") ~= nil then
+
if string.find(orig1[i], "to") ~= nil then
start1=string.sub(orig1[i],1,string.find(orig1[i],"to")-1)
+
start1 = string.sub(orig1[i], 1, string.find(orig1[i], "to") - 1)
 
end
 
end
if string.find(orig1[i],"x")==nil and pcall(expr,start1.."*2")~=false then
+
if string.find(orig1[i], "x") == nil and pcall(expr, start1 .. "*2") ~= false then
local finish1,times1
+
local finish1, times1
 
if string.find(orig1[i], "by") ~= nil then
 
if string.find(orig1[i], "by") ~= nil then
 
finish1, times1 = orig1[i]:match".* *to *([^ ]*) *by *([^ ]*)"
 
finish1, times1 = orig1[i]:match".* *to *([^ ]*) *by *([^ ]*)"
 
else
 
else
 
if string.find(orig1[i], "for") ~= nil then
 
if string.find(orig1[i], "for") ~= nil then
finish1,times1 = orig1[i]:match".* *to *([^ ]*) *for *([^ ]*)"
+
finish1, times1 = orig1[i]:match".* *to *([^ ]*) *for *([^ ]*)"
 
else
 
else
 
finish1 = orig1[i]:match".* *to *([^ ]*)"
 
finish1 = orig1[i]:match".* *to *([^ ]*)"
 
end
 
end
 
end
 
end
if finish1~=nil and pcall(expr,finish1.."*2")~=false and ((times1 ~= "" and times1 ~= nil and pcall(expr, times1 .. "*2") ~= false) or times1 == "" or times1 == nil) then
+
if finish1 ~= nil and pcall(expr, finish1 .. "*2") ~= false and ((times1 ~= "" and times1 ~= nil and pcall(expr, times1 .. "*2") ~= false) or times1 == "" or times1 == nil) then
start1=tonumber(expr(start1))
+
start1 = tonumber(expr(start1))
finish1=tonumber(expr(finish1))
+
finish1 = tonumber(expr(finish1))
if times1 == "" or times1==nil then
+
if times1 == "" or times1 == nil then
times1=fill1
+
times1 = fill1
fill1=0
+
fill1 = 0
 
else
 
else
times1=tonumber(expr(times1))
+
times1 = tonumber(expr(times1))
 
if string.find(orig1[i], "by") ~= nil then
 
if string.find(orig1[i], "by") ~= nil then
times1 = tonumber(rounding((finish1-start1)/times1+1,0))
+
times1 = tonumber(rounding(math.abs(finish1 - start1) / times1 + 1, 0))
 
end
 
end
 
end
 
end
if displayformula=="" and orig1[2]==nil then
+
if displayformula == "" and orig1[2] == nil then
start3=start1
+
start3 = start1
finish3=finish1
+
finish3 = finish1
times3=times1
+
times3 = times1
 
end
 
end
local x1,formula1
+
local x1, formula1
 
if lastvalue1 == start1 then
 
if lastvalue1 == start1 then
 
x1 = 2
 
x1 = 2
Line 532: Line 546:
 
end
 
end
 
 
while x1<=times1 do
+
while x1 <= times1 do
count1=count1-1
+
count1 = count1 - 1
if count1<0 then
+
if count1 <0 then
 
return userError("Maximum size exceeded", "LuaError")
 
return userError("Maximum size exceeded", "LuaError")
 
end
 
end
if x1==1 then
+
if x1 == 1 then
formula1=start1
+
formula1 = start1
 
else
 
else
formula1=formula1+(finish1-start1)/(times1-1)
+
formula1 = formula1 + (finish1 - start1) / (times1 - 1)
 
if lastvalue1 == start1 and x1 == 2 then
 
if lastvalue1 == start1 and x1 == 2 then
 
else
 
else
 
s = s .. '</th><th style="text-align: center;">'
 
s = s .. '</th><th style="text-align: center;">'
j=j+1
+
j = j + 1
 
end
 
end
 
end
 
end
s = s .. fd(rounding(formula1,round1))..key1
+
s = s .. fd(rounding(formula1, round1)) .. key1
x1=x1+1
+
x1 = x1 + 1
 
end
 
end
 
 
 
lastvalue1 = finish1
 
lastvalue1 = finish1
 
else
 
else
count1=count1-1
+
count1 = count1 - 1
if count1<0 then
+
if count1 < 0 then
 
return userError("Maximum size exceeded", "LuaError")
 
return userError("Maximum size exceeded", "LuaError")
 
end
 
end
Line 561: Line 575:
 
end
 
end
 
else
 
else
local times1,doubleto1
+
local times1, doubleto1
if string.find(orig1[i],"for") then
+
if string.find(orig1[i], "for") then
doubleto1,times1 = orig1[i]:match"(.*) *for *([^ ]*)"
+
doubleto1, times1 = orig1[i]:match"(.*) *for *([^ ]*)"
 
else
 
else
 
doubleto1 = orig1[i]
 
doubleto1 = orig1[i]
 
end
 
end
local _,occurences1 = string.gsub(orig1[i],"to","")
+
local _, occurences1 = string.gsub(orig1[i], "to", "")
if occurences1 >0 and ((times1 ~= "" and times1 ~= nil and pcall(expr, times1 .. "*2") ~= false) or times1 == "" or times1 == nil) then
+
if occurences1 > 0 and ((times1 ~= "" and times1 ~= nil and pcall(expr, times1 .. "*2") ~= false) or times1 == "" or times1 == nil) then
 
local times2
 
local times2
if times1 == "" or times1==nil then
+
if times1 == "" or times1 == nil then
times2=fill1
+
times2 = fill1
 
else
 
else
times2=tonumber(expr(times1))
+
times2 = tonumber(expr(times1))
 
end
 
end
doubleto1 = string_to_formula(doubleto1,times2)
+
doubleto1 = string_to_formula(doubleto1, times2)
 
end
 
end
local useformula1 = string.gsub(doubleto1,"then",lastvalue1)
+
local useformula1 = string.gsub(doubleto1, "then", lastvalue1)
if useformula1~=nil and pcall(expr,string.gsub(useformula1,"x","1").."*2")~=false and ((times1 ~= "" and times1 ~= nil and pcall(expr, times1 .. "*2") ~= false) or times1 == "" or times1 == nil) then
+
if useformula1 ~= nil and pcall(expr, string.gsub(useformula1, "x", "1") .. "*2") ~= false and ((times1 ~= "" and times1 ~= nil and pcall(expr, times1 .. "*2") ~= false) or times1 == "" or times1 == nil) then
if times1 == "" or times1==nil then
+
if times1 == "" or times1 == nil then
times1=fill1
+
times1 = fill1
fill1=0
+
fill1 = 0
 
else
 
else
times1=tonumber(expr(times1))
+
times1 = tonumber(expr(times1))
 
end
 
end
local x1=1
+
local x1 = 1
while x1<=times1 do
+
while x1 <= times1 do
count1=count1-1
+
count1 = count1 - 1
if count1<0 then
+
if count1 < 0 then
 
return userError("Maximum size exceeded", "LuaError")
 
return userError("Maximum size exceeded", "LuaError")
 
end
 
end
local formula1=string.gsub(useformula1,"x",x1)
+
local formula1 = string.gsub(useformula1, "x", x1)
 
if x1 ~= 1 then
 
if x1 ~= 1 then
 
s = s .. '</th><th style="text-align: center;">'
 
s = s .. '</th><th style="text-align: center;">'
j=j+1
+
j = j + 1
 
end
 
end
 
local values3 = expr(formula1)
 
local values3 = expr(formula1)
 
lastvalue1 = values3
 
lastvalue1 = values3
s = s .. fd(rounding(values3,round1))..key1
+
s = s .. fd(rounding(values3, round1)) .. key1
x1=x1+1
+
x1 = x1 + 1
 
end
 
end
 
else
 
else
count1=count1-1
+
count1 = count1 - 1
if count1<0 then
+
if count1 < 0 then
 
return userError("Maximum size exceeded", "LuaError")
 
return userError("Maximum size exceeded", "LuaError")
 
end
 
end
Line 610: Line 624:
 
end
 
end
 
else
 
else
count1=count1-1
+
count1 = count1 - 1
if count1<0 then
+
if count1 < 0 then
 
return userError("Maximum size exceeded", "LuaError")
 
return userError("Maximum size exceeded", "LuaError")
 
end
 
end
if pcall(expr, string.gsub(orig1[i],"then",lastvalue1) .. "*2") ~= false then
+
if pcall(expr, string.gsub(orig1[i], "then", lastvalue1) .. "*2") ~= false then
local values3 = expr(string.gsub(orig1[i],"then",lastvalue1))
+
local values3 = expr(string.gsub(orig1[i], "then", lastvalue1))
 
lastvalue1 = values3
 
lastvalue1 = values3
s = s .. fd(rounding(values3,round1))..key1
+
s = s .. fd(rounding(values3, round1)) .. key1
 
else
 
else
 
s = s .. fd(orig1[i])
 
s = s .. fd(orig1[i])
Line 626: Line 640:
 
s = s .. j
 
s = s .. j
 
end
 
end
i=i+1
+
i = i + 1
j=j+1
+
j = j + 1
 
end
 
end
 
s = s .. '</th></tr>'
 
s = s .. '</th></tr>'
Line 652: Line 666:
 
if orig1[1] ~= "" then
 
if orig1[1] ~= "" then
 
if start ~= nil and start3 ~= nil then
 
if start ~= nil and start3 ~= nil then
local scale = (finish-start) / (times3 - 1)
+
local scale = (finish - start) / (times3 - 1)
local scale1 = (finish3-start3) / (times3 - 1)
+
local scale1 = (finish3 - start3) / (times3 - 1)
 
formula = formula .. "'''Formula:''' "
 
formula = formula .. "'''Formula:''' "
 
if start ~= 0 then
 
if start ~= 0 then
formula = formula .. rounding(start , round + 1) .. key
+
formula = formula .. start .. key
 
if scale >= 0 then
 
if scale >= 0 then
 
formula = formula .. "+"
 
formula = formula .. "+"
Line 662: Line 676:
 
end
 
end
 
if label1 == "level" then
 
if label1 == "level" then
formula = formula .. rounding(scale, round + 1) .. key .. " for every "
+
formula = formula .. scale .. key .. " for every "
 
if math.abs(scale1) ~= 1 then
 
if math.abs(scale1) ~= 1 then
formula = formula .. rounding(scale1, round1 + 1)
+
formula = formula .. scale1
 
end
 
end
formula = formula .. key1 .. " "..label1
+
formula = formula .. key1 .. " " .. label1
 
if scale1 > 1 then
 
if scale1 > 1 then
 
formula = formula .. "s"
 
formula = formula .. "s"
 
end
 
end
 
if start3 ~= 0 and start3 ~= 1 then
 
if start3 ~= 0 and start3 ~= 1 then
formula = formula .. " starting from " .. label1 .. " " .. rounding(start3 , round1 + 1) .. key1 .. " and"
+
formula = formula .. " starting from " .. label1 .. " " .. start3 .. key1 .. " and"
 
else
 
else
 
formula = formula .. ","
 
formula = formula .. ","
 
end
 
end
formula = formula .. " capped at " .. label1 .. " " .. rounding(finish3 , round1 + 1) .. key1
+
formula = formula .. " capped at " .. label1 .. " " .. finish3 .. key1
 
else
 
else
formula = formula .. rounding(scale, round + 1) .. key .. " for every "
+
formula = formula .. scale .. key .. " for every "
 
if math.abs(scale1) ~= 1 then
 
if math.abs(scale1) ~= 1 then
formula = formula .. rounding(scale1, round1 + 1)
+
formula = formula .. scale1
 
end
 
end
 
formula = formula .. key1 .. " "
 
formula = formula .. key1 .. " "
 
if scale1 ~= 1 then
 
if scale1 ~= 1 then
 
formula = formula .. label1
 
formula = formula .. label1
if string.sub(label1,-1) ~= "s" then
+
if string.sub(formulalabel1, -1) ~= "s" then
 
formula = formula .. "s"
 
formula = formula .. "s"
 
end
 
end
 
else
 
else
if string.sub(label1,-1) == "s" then
+
if string.sub(formulalabel1, -1) == "s" then
formula = formula .. string.sub(label1,1,#label1-1)
+
if string.sub(label1, -1) == "s" then
  +
formula = formula .. string.sub(label1, 1, #label1 - 1)
  +
else
  +
formula = formula .. string.sub(label1, 1, #label1 - 3)
  +
end
 
else
 
else
 
formula = formula .. label1
 
formula = formula .. label1
Line 695: Line 713:
 
end
 
end
 
if start3 ~= 0 and start3 ~= 1 then
 
if start3 ~= 0 and start3 ~= 1 then
formula = formula .. " starting from " .. rounding(start3 , round1 + 1) .. key1 .. " "
+
formula = formula .. " starting from " .. start3 .. key1 .. " "
 
if start3 ~= 1 then
 
if start3 ~= 1 then
 
formula = formula .. label1
 
formula = formula .. label1
if string.sub(label1,-1) ~= "s" then
+
if string.sub(formulalabel1, -1) ~= "s" then
 
formula = formula .. "s"
 
formula = formula .. "s"
 
end
 
end
 
else
 
else
if string.sub(label1,-1) == "s" then
+
if string.sub(formulalabel1, -1) == "s" then
formula = formula .. string.sub(label1,1,#label1-1)
+
if string.sub(label1, -1) == "s" then
  +
formula = formula .. string.sub(label1, 1, #label1 - 1)
  +
else
  +
formula = formula .. string.sub(label1, 1, #label1 - 3)
  +
end
 
else
 
else
 
formula = formula .. label1
 
formula = formula .. label1
Line 712: Line 734:
 
formula = formula .. ","
 
formula = formula .. ","
 
end
 
end
formula = formula .. " capped at " .. rounding(finish3 , round1 + 1) .. key1 .. " "
+
formula = formula .. " capped at " .. finish3 .. key1 .. " "
 
if finish3 ~= 1 then
 
if finish3 ~= 1 then
 
formula = formula .. label1
 
formula = formula .. label1
if string.sub(label1,-1) ~= "s" then
+
if string.sub(formulalabel1, -1) ~= "s" then
 
formula = formula .. "s"
 
formula = formula .. "s"
 
end
 
end
 
else
 
else
if string.sub(label1,-1) == "s" then
+
if string.sub(formulalabel1, -1) == "s" then
formula = formula .. string.sub(label1,1,#label1-1)
+
if string.sub(label1, -1) == "s" then
  +
formula = formula .. string.sub(label1, 1, #label1 - 1)
  +
else
  +
formula = formula .. string.sub(label1, 1, #label1 - 3)
  +
end
 
else
 
else
 
formula = formula .. label1
 
formula = formula .. label1
Line 729: Line 755:
 
else
 
else
 
if start ~= nil then
 
if start ~= nil then
local scale = (finish-start) / (fill1 - 1)
+
local scale = (finish - start) / (fill1 - 1)
 
formula = formula .. "'''Formula:''' "
 
formula = formula .. "'''Formula:''' "
 
if tonumber(tostring(start)) == tonumber(tostring(scale)) then
 
if tonumber(tostring(start)) == tonumber(tostring(scale)) then
formula = formula .. rounding(start , round + 1) .. key .. "&#42;" .. label1
+
formula = formula .. start .. key .. "&#42;" .. label1
 
else
 
else
formula = formula .. rounding(start-scale , round + 1) .. key
+
formula = formula .. (start - scale) .. key
if scale >=0 then
+
if scale >= 0 then
 
formula = formula .. "+"
 
formula = formula .. "+"
 
if scale == 1 then
 
if scale == 1 then
 
formula = formula .. label1
 
formula = formula .. label1
 
else
 
else
formula = formula .. rounding(scale , round + 1) .. key .. "&#42;" .. label1
+
formula = formula .. scale .. key .. "&#42;" .. label1
 
end
 
end
 
else
 
else
Line 746: Line 772:
 
formula = formula .. "-" .. label1
 
formula = formula .. "-" .. label1
 
else
 
else
formula = formula .. rounding(scale , round + 1) .. key .. "&#42;" .. label1
+
formula = formula .. scale .. key .. "&#42;" .. label1
 
end
 
end
 
end
 
end
Line 758: Line 784:
 
 
 
if displayformula == "" then
 
if displayformula == "" then
formula = string.gsub(string.gsub(string.gsub(string.gsub(string.gsub(formula,"%/"," &divide; "),"%*","&#42;"),"&#42;"," &times; "),"%+"," + "),"%-"," &minus; ")
+
formula = string.gsub(string.gsub(string.gsub(string.gsub(string.gsub(formula, "%/", " &divide; "), "%*", "&#42;"), "&#42;", " &times; "), "%+", " + "), "%-", " &minus; ")
 
if useformula ~= "" then
 
if useformula ~= "" then
formula = string.gsub(formula,"x",label1)
+
formula = string.gsub(formula, "x", label1)
 
end
 
end
 
else
 
else
formula = string.gsub(string.gsub(string.gsub(string.gsub(string.gsub(formula,"%/","&divide;"),"%*","&#42;"),"&#42;","&times;"),"%+","+"),"%-","&minus;")
+
formula = string.gsub(string.gsub(string.gsub(string.gsub(string.gsub(formula, "%/", "&divide;"), "%*", "&#42;"), "&#42;", "&times;"), "%+", "+"), "%-", "&minus;")
 
end
 
end
 
 
Line 776: Line 802:
 
function p.ap(frame)
 
function p.ap(frame)
 
local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end
 
local args; if frame.args == nil then args = lib.arguments(frame) else args = lib.arguments(frame.args) end
local values=""
+
local values = ""
local orig=args
+
local orig = args
local count=6
+
local count = 6
 
local fill
 
local fill
local formula
+
local round = args["round"] or nil
if args["skill"]=="R" then
+
if args["skill"] == "R" then
fill=3
+
fill = 3
 
else
 
else
fill=5
+
fill = 5
 
end
 
end
i=1
+
local formula
local temp,a,b,c
+
local temp, a, b, c
  +
local round=args["round"] or nil
 
while orig[i]~=nil and orig[i]~="" do
+
local i = 1
if (string.find(orig[i],"to")~=nil or string.find(orig[i],"x")~=nil) and string.find(orig[i],"%<")==nil then
+
while orig[i] ~= nil and orig[i] ~= "" do
if string.find(orig[i],"to") ~= nil then
+
if (string.find(orig[i], "to") ~= nil or string.find(orig[i], "x") ~= nil) and string.find(orig[i], "%<") == nil then
start=string.sub(orig[i],1,string.find(orig[i],"to")-1)
+
if string.find(orig[i], "to") ~= nil then
  +
start = string.sub(orig[i], 1, string.find(orig[i], "to") - 1)
 
end
 
end
if string.find(orig[i],"x")==nil and pcall(expr,start.."*2")~=false then
+
if string.find(orig[i], "x") == nil and pcall(expr, start .. "*2") ~= false then
finish,times=orig[i]:match".* *to *([^ ]*) *([^ ]*)"
+
finish, times = orig[i]:match".* *to *([^ ]*) *([^ ]*)"
if finish~=nil and pcall(expr,finish.."*2")~=false and ((times ~= "" and times ~= nil and pcall(expr, times .. "*2") ~= false) or times == "" or times == nil) then
+
if finish ~= nil and pcall(expr, finish .. "*2") ~= false and ((times ~= "" and times ~= nil and pcall(expr, times .. "*2") ~= false) or times == "" or times == nil) then
start=tonumber(expr(start))
+
start = tonumber(expr(start))
finish=tonumber(expr(finish))
+
finish = tonumber(expr(finish))
if times == "" or times==nil then
+
if times == "" or times == nil then
times=fill
+
times = fill
fill=0
+
fill = 0
 
else
 
else
times=tonumber(expr(times))
+
times = tonumber(expr(times))
 
end
 
end
count=count-times
+
count = count - times
if count<0 then
+
if count < 0 then
 
return userError("Maximum size exceeded", "LuaError")
 
return userError("Maximum size exceeded", "LuaError")
 
end
 
end
x=1
+
x = 1
while x<=times do
+
while x <= times do
if x==1 then
+
if x == 1 then
 
formula = start
 
formula = start
 
scale = (finish - start) / (times - 1)
 
scale = (finish - start) / (times - 1)
Line 817: Line 844:
 
formula = formula + scale
 
formula = formula + scale
 
end
 
end
if values=="" then
+
if values == "" then
values=fd(rounding(formula,round))
+
values = fd(rounding(formula, round))
 
else
 
else
values=values.." / "..fd(rounding(formula,round))
+
values = values .. " / " .. fd(rounding(formula, round))
 
end
 
end
x=x+1
+
x = x + 1
 
end
 
end
 
else
 
else
count=count-1
+
count = count - 1
if count<0 then
+
if count < 0 then
 
return userError("Maximum size exceeded", "LuaError")
 
return userError("Maximum size exceeded", "LuaError")
 
end
 
end
if values=="" then
+
if values == "" then
values=fd(rounding(orig[i],round))
+
values = fd(rounding(orig[i], round))
 
else
 
else
values=values.." / "..fd(rounding(orig[i],round))
+
values = values .. " / " .. fd(rounding(orig[i], round))
 
end
 
end
 
end
 
end
Line 838: Line 865:
 
local times
 
local times
 
local doubleto = orig[i]
 
local doubleto = orig[i]
if last(orig[i]," ") ~= last(orig[i],"to ") then
+
if last(orig[i], " ") ~= last(orig[i], "to ") then
times = last(orig[i]," ")
+
times = last(orig[i], " ")
 
if pcall(expr, times .. "*2") ~= false then
 
if pcall(expr, times .. "*2") ~= false then
doubleto = string.sub(doubleto,1,#doubleto-#times)
+
doubleto = string.sub(doubleto, 1, #doubleto - #times)
 
else
 
else
 
times = nil
 
times = nil
Line 847: Line 874:
 
end
 
end
 
local _, occurences = string.gsub(orig[i], "to", "")
 
local _, occurences = string.gsub(orig[i], "to", "")
if occurences >0 and ((times ~= "" and times ~= nil and pcall(expr, times .. "*2") ~= false) or times == "" or times == nil) then
+
if occurences > 0 and ((times ~= "" and times ~= nil and pcall(expr, times .. "*2") ~= false) or times == "" or times == nil) then
 
local times2
 
local times2
if times == "" or times==nil then
+
if times == "" or times == nil then
times2=fill
+
times2 = fill
 
else
 
else
times2=tonumber(expr(times))
+
times2 = tonumber(expr(times))
 
end
 
end
doubleto = string_to_formula(doubleto,times2)
+
doubleto = string_to_formula(doubleto, times2)
 
end
 
end
 
useformula = doubleto
 
useformula = doubleto
if useformula~=nil and pcall(expr,string.gsub(useformula,"x","1").."*2")~=false and ((times ~= "" and times ~= nil and pcall(expr, times .. "*2") ~= false) or times == "" or times == nil) then
+
if useformula ~= nil and pcall(expr, string.gsub(useformula, "x", "1") .. "*2") ~= false and ((times ~= "" and times ~= nil and pcall(expr, times .. "*2") ~= false) or times == "" or times == nil) then
if times == "" or times==nil then
+
if times == "" or times == nil then
times=fill
+
times = fill
fill=0
+
fill = 0
 
else
 
else
times=tonumber(expr(times))
+
times = tonumber(expr(times))
 
end
 
end
x=1
+
x = 1
while x<=times do
+
while x <= times do
count=count-1
+
count = count - 1
if count<0 then
+
if count < 0 then
 
return userError("Maximum size exceeded", "LuaError")
 
return userError("Maximum size exceeded", "LuaError")
 
end
 
end
formula=string.gsub(useformula,"x",x)
+
formula = string.gsub(useformula, "x", x)
if values=="" then
+
if values =="" then
values=fd(rounding(expr(formula),round))
+
values = fd(rounding(expr(formula), round))
 
else
 
else
values=values.." / "..fd(rounding(expr(formula),round))
+
values = values .. " / " .. fd(rounding(expr(formula), round))
 
end
 
end
x=x+1
+
x = x + 1
 
end
 
end
 
else
 
else
count=count-1
+
count = count - 1
if count<0 then
+
if count < 0 then
 
return userError("Maximum size exceeded", "LuaError")
 
return userError("Maximum size exceeded", "LuaError")
 
end
 
end
if values=="" then
+
if values == "" then
values=fd(rounding(orig[i],round))
+
values = fd(rounding(orig[i], round))
 
else
 
else
values=values.." / "..fd(rounding(orig[i],round))
+
values = values .. " / " .. fd(rounding(orig[i], round))
 
end
 
end
 
end
 
end
 
end
 
end
 
else
 
else
count=count-1
+
count = count - 1
if count<0 then
+
if count < 0 then
 
return userError("Maximum size exceeded", "LuaError")
 
return userError("Maximum size exceeded", "LuaError")
 
end
 
end
if values=="" then
+
if values == "" then
values=fd(rounding(orig[i],round))
+
values = fd(rounding(orig[i], round))
 
else
 
else
values=values.." / "..fd(rounding(orig[i],round))
+
values = values .. " / " .. fd(rounding(orig[i], round))
 
end
 
end
 
end
 
end
i=i+1
+
i = i + 1
 
end
 
end
 
return values
 
return values
 
end
 
end
   
function string_to_formula(args,times)
+
function string_to_formula(args, times)
 
local val = args
 
local val = args
 
while string.find(val, "to") ~= nil do
 
while string.find(val, "to") ~= nil do
local to = mw.text.split(val, "to")
+
local to1 = string.sub(val, 1, string.find(val, "to") - 1)
local _, occurences1 = string.gsub(to[1], "%(", "")
+
local to2 = string.sub(val, string.find(val, "to") + 2)
local _, occurences2 = string.gsub(to[2], "%)", "")
+
local _, occurences1 = string.gsub(to1, "%(", "")
local para1 = mw.text.split(to[1], "%(")
+
local _, occurences2 = string.gsub(to2, "%)", "")
local para2 = mw.text.split(to[2], "%)")
+
local para1 = lib.split(to1, "%(")
local start,finish="",""
+
local para2 = lib.split(to2, "%)")
  +
local start, finish = "", ""
 
local times2
 
local times2
local occurences3=0
+
local occurences3 = 0
local j = occurences1 + 1
+
local j
  +
  +
j = occurences1 + 1
 
while j >= 2 do
 
while j >= 2 do
if j == occurences1+1 then
+
if j == occurences1 + 1 then
start=para1[j]
+
start = para1[j]
 
else
 
else
 
start = "(" .. para1[j] .. start
 
start = "(" .. para1[j] .. start
Line 931: Line 961:
 
j = j - 1
 
j = j - 1
 
end
 
end
  +
 
if pcall(expr, start .. "*2") == false then
 
if pcall(expr, start .. "*2") == false then
 
return args
 
return args
 
end
 
end
occurences3=0
+
  +
occurences3 = 0
 
j = 1
 
j = 1
 
while j <= occurences2 do
 
while j <= occurences2 do
Line 952: Line 984:
 
return args
 
return args
 
end
 
end
start = string.gsub(start,"([%-%+%*%/%^%(%)])","%%%1")
+
start = string.gsub(start, "([%-%+%*%/%^%(%)])", "%%%1")
finish = string.gsub(finish,"([%-%+%*%/%^%(%)])","%%%1")
+
finish = string.gsub(finish, "([%-%+%*%/%^%(%)])", "%%%1")
val = string.gsub(val, start .. "to" .. finish, "(" .. start .. ")" .. "+(" .. "(" .. finish .. ")" .. "-" .. "(" .. start .. ")" .. ")/(" .. times .. "-1)*(x-1)")
+
val = string.gsub(val, start .. "to" .. finish, "(" .. start .. ")" .. "+(" .. "(" .. finish .. ")" .. "-" .. "(" .. start .. ")" .. ")/(" .. times .. "-1)*(x-1)")
 
end
 
end
 
return val
 
return val
Line 960: Line 992:
 
 
 
function expr(val)
 
function expr(val)
if string.find(val,"[0-9]")==nil then
+
if string.find(val, "[0-9]") == nil then
 
return val
 
return val
 
end
 
end
  +
val = string.gsub(val," ","")
local val=string.gsub(string.gsub(string.gsub(string.gsub(val," ",""),"([%/%*%+%-%^])"," %1 "),"([^%d%(%)]) %- ","%1-"),"([^%d%(%)]) %+ ","%1+")
 
local i=1
+
local j=1
+
local symbol={
  +
["^"]=1,
local a,b,switcher,switcher2,switcher3,temp
 
while i>0 do
+
["/"]=2,
  +
["*"]=3,
while j>0 do
 
temp=val
+
["+"]=4,
  +
["-"]=5,
if string.find(val,"%)")~=nil then
 
  +
[")"]=6,
switchertemp=mw.text.split( val, "%)")
 
  +
["("]=7
temp=last(switchertemp[1],"%(")
 
end
+
}
  +
if string.find(temp," %^ ")~=nil then
 
  +
local getmath = {
a=mw.text.split(temp," %^ ")
 
  +
["^"] = function (a,b) return a^b end,
b=mw.text.split(a[2]," ")
 
  +
["/"] = function (a,b) return a/b end,
switcher=last( a[1]," ")
 
  +
["*"] = function (a,b) return a*b end,
switcher2=b[1]
 
  +
["+"] = function (a,b) return a+b end,
switcher3=switcher^switcher2
 
  +
["-"] = function (a,b) return a-b end
if string.find(switcher2,"%-")~=nil then
 
  +
}
switcher2="%-"..switcher2*(-1)
 
end
+
  +
local symbolstack = {}
val=string.gsub(val,switcher.." %^ "..switcher2,switcher3)
 
  +
local numberstack = {}
break
 
end
+
  +
local term=""
if string.find(temp," %/ ")~=nil then
 
  +
for i=1,#val,1 do
a=mw.text.split(temp," %/ ")
 
b=mw.text.split(a[2]," ")
+
term = term .. string.sub(val,i,i)
  +
if symbol[term] == nil or ((term == "-" or term == "+") and (symbol[string.sub(val,i-1,i-1)] ~= nil or i-1 == 0) and string.sub(val,i-1,i-1) ~= ")") then
switcher=last( a[1]," ")
 
  +
if symbol[string.sub(val,i+1,i+1)] ~= nil or i == #val then
switcher2=b[1]
 
  +
table.insert(numberstack,term)
switcher3=switcher/switcher2
 
  +
term=""
if string.find(switcher2,"%-")~=nil then
 
  +
end
switcher2="%-"..switcher2*(-1)
 
end
+
else
  +
if symbolstack[#symbolstack] ~= nil and symbol[symbolstack[#symbolstack]] < symbol[term] and term ~= "(" and term ~= ")" then
val=string.gsub(val,switcher.." %/ "..switcher2,switcher3)
 
  +
table.insert(numberstack,symbolstack[#symbolstack])
break
 
  +
symbolstack[#symbolstack] = term
end
 
  +
else
if string.find(temp," %* ")~=nil then
 
  +
table.insert(symbolstack,term)
a=mw.text.split( temp," %* ")
 
  +
end
b=mw.text.split(a[2]," ")
 
  +
if term == ")" then
switcher=last( a[1]," ")
 
  +
closed = true
switcher2=b[1]
 
  +
end
switcher3=switcher*switcher2
 
  +
term=""
if string.find(switcher2,"%-")~=nil then
 
  +
end
switcher2="%-"..switcher2*(-1)
 
end
+
if closed == true then
  +
table.remove(symbolstack,#symbolstack)
val=string.gsub(val,switcher.." %* "..switcher2,switcher3)
 
  +
while symbolstack[#symbolstack] ~= "(" do
break
 
  +
table.insert(numberstack,symbolstack[#symbolstack])
end
 
  +
table.remove(symbolstack,#symbolstack)
if string.find(temp," %- ")~=nil then
 
  +
end
a=mw.text.split( temp," %- ")
 
  +
closed = false
b=mw.text.split(a[2]," ")
 
  +
table.remove(symbolstack,#symbolstack)
switcher=last( a[1]," ")
 
  +
end
switcher2=b[1]
 
  +
end
if switcher=="" then
 
  +
if string.find(switcher2,"%-")~=nil then
 
  +
for i = #symbolstack, 1, -1 do
switcher2="%-"..switcher2*(-1)
 
  +
table.insert(numberstack,symbolstack[i])
end
 
  +
end
val=string.gsub(val," %- "..switcher2,"%-"..switcher2)
 
  +
break
 
  +
local tempstack = {}
else
 
  +
switcher3=switcher-switcher2
 
  +
while numberstack[#numberstack] ~= nil do
if string.find(switcher2,"%-")~=nil then
 
  +
if symbol[numberstack[1]] == nil then
switcher2="%-"..switcher2*(-1)
 
  +
table.insert(tempstack,numberstack[1])
end
 
  +
else
val=string.gsub(val,switcher.." %- "..switcher2,switcher3)
 
  +
table.insert(tempstack,getmath[numberstack[1]](tempstack[#tempstack-1], tempstack[#tempstack]))
break
 
  +
table.remove(tempstack,#tempstack-1)
end
 
  +
table.remove(tempstack,#tempstack-1)
end
 
  +
end
if string.find(temp," %+ ")~=nil then
 
  +
table.remove(numberstack,1)
a=mw.text.split( temp," %+ ")
 
  +
end
b=mw.text.split(a[2]," ")
 
  +
switcher=last( a[1]," ")
 
  +
if tempstack[1] * 2 ~= nil then
switcher2=b[1]
 
  +
return tempstack[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 and 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
 
end
return temp
 
 
end
 
end
   
function last(val,sign)
+
function last(val, sign)
  +
return string.sub(val, 1 - (string.find(string.reverse(val), string.reverse(sign), 1, true) or 0))
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
 
end
   
 
function fd(val)
 
function fd(val)
  +
return fd_get{args = {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"([^.]*).(.*)</span>(.*)"
 
if string.find(val,"span")<=string.find(val,"%.") then
 
return a .. ".<small>" .. b .. "</small></span>" .. c
 
else
 
return a .. ".<small>" .. b .. "</span></small>" .. c
 
end
 
else
 
a,b,c = val:match"([^.]*).([0-9]*)(.*)"
 
return a .. ".<small>" .. b .. "</small>" .. c
 
end
 
 
end
 
end
   
 
function fdmulti(val)
 
function fdmulti(val)
  +
return fd_getmulti{args = {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"(.*)</span>(.*)"
 
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 .. ".<small>" .. b .. "</small></span>" .. c
 
else
 
values = values .. ".<small>" .. b .. "</span></small>" .. 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 .. ".<small>" .. b .. "</small>" .. c
 
end
 
end
 
i = i + 1
 
end
 
 
return values
 
 
end
 
end
   
Line 1,135: Line 1,086:
 
local round
 
local round
 
local val = tostring(val)
 
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
+
if decimals == nil or string.find(val, "[0-9]") == nil or string.find(val, "<span") ~= nil or string.find(val, "%.") == nil then
 
return val
 
return val
 
end
 
end
local a,b,c,d = val:match"([^0-9]*)([0-9]*).([0-9]*)(.*)"
+
local a, b, c, d = val:match"([^0-9]*)([0-9]*).([0-9]*)(.*)"
val=tonumber(b.."."..c)
+
val = tonumber(b .. "." .. c)
 
if decimals == "abs" then
 
if decimals == "abs" then
 
round = math.abs(val)
 
round = math.abs(val)
Line 1,150: Line 1,101:
 
end
 
end
 
if decimals == "trunc" then
 
if decimals == "trunc" then
round = string.sub(val,1,(string.find(val,"%.") or 0) - 1)
+
round = string.sub(val, 1, (string.find(val, "%.") or 0) - 1)
 
end
 
end
 
if round == nil then
 
if round == nil then
local mult = 10^(decimals)
+
local mult = 10 ^ (decimals)
 
round = math.floor(val * mult + 0.5) / mult
 
round = math.floor(val * mult + 0.5) / mult
 
end
 
end
return a..round..d
+
return a .. round .. d
 
end
 
end
   

Revision as of 00:28, 17 September 2020

Documentation for this module may be created at Module:Ability progression/doc

-- <pre>
local p = {}
local lib         = require('Module:Feature')
local col         = require('Module:Color')
local userError   = require('Dev:User error')
local fd_get      = require('Module:fd').get
local fd_getmulti = require('Module:fd').getmulti

function p.test(frame)
    local args; if frame.args[1] then args = frame.args else args = frame:getParent().args end
    local doubleto = "yes"
    return string.gsub(doubleto, "true", "")
end

function p.pp(frame)
    local args; if frame.args[1] then args = frame.args else args = frame:getParent().args end
        
    local start2, end2
    local values, values2    = "", ""
    local count, countstatic = 30, 30
    local fill,  fill1       = 18, 18
    local to, to1            = 0, 0
    
    local displayformula     = args["formula"]
    local round              = args["round"] or 2
    if round == "false" then
        round = nil
    end
    local round1             = args["round1"]
    local key                = args["key"] or ""
    local key1               = args["key1"]
    local label              = args["label"]
    local label1             = args["label1"] or args["type"]
    local orig               = lib.split(args[1] or "", "%;")
    local orig1              = lib.split(args[2] or "", "%;")
    local _, bot_to_hits     = string.gsub(args[1] or "", "to", "")
    local _, top_to_hits     = string.gsub(args[2] or "", "to", "")
    local _, bot_x_hits      = string.gsub(args[1] or "", "x",  "")
    local _, top_x_hits      = string.gsub(args[2] or "", "x",  "")
	local i = 1
	
    if bot_to_hits + bot_x_hits ~= 0 or top_to_hits + top_x_hits ~= 0 then
        local lastvalue = ""
        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
                local start
                if string.find(orig[i], "to") ~= nil then
                    start = string.sub(orig[i], 1, string.find(orig[i], "to") - 1)
                end
                if string.find(orig[i], "x") == nil and pcall(expr, start .. "*2") ~= false then
                    local finish, times
                    if string.find(orig[i], "by") ~= nil then
                        finish, times = orig[i]:match".* *to *([^ ]*) *by *([^ ]*)"
                    else
                        if string.find(orig[i], "for") ~= nil then
                            finish, times = orig[i]:match".* *to *([^ ]*) *for *([^ ]*)"
                        else
                            finish = orig[i]:match".* *to *([^ ]*)"
                        end
                    end
                    if finish ~= nil and pcall(expr, finish .. "*2") ~= false and ((times ~= "" and times ~= nil and pcall(expr, times .. "*2") ~= false) or times == "" or times == nil) then
                        start = tonumber(expr(start))
                        finish = tonumber(expr(finish))
                        if times ~= "" and times ~= nil then
                            times = tonumber(expr(times))
                            if string.find(orig[i], "by") ~= nil then
                                times = rounding(math.abs(finish - start) / times + 1, 0)
                            end
                            fill = fill - times
                            if string.find(orig[i], "by") ~= nil and lastvalue == start then
                                fill = fill + 1
                            end
                        else
                            to = 1
                        end
                        lastvalue = finish
                    else
                        fill = fill - 1
                    end
                else
                    local times, doubleto
                    if string.find(orig[i], "for") then
                        doubleto, times = orig[i]:match"(.*) *for *([^ ]*)"
                    else
                        doubleto = orig[i]
                    end
                    
                    local _, occurences = string.gsub(orig[i], "to", "") 
                    if occurences > 0 and ((times ~= "" and times ~= nil and pcall(expr, times .. "*2") ~= false) or times == "" or times == nil) then
                        local times2 = 2
                        doubleto = string_to_formula(doubleto, times2)
                    end
                    
                    local useformula = string.gsub(doubleto, "then", "1")
                    if useformula ~= nil and pcall(expr, string.gsub(useformula, "x", "1") .. "*2") ~= false and ((times ~= "" and times ~= nil and pcall(expr, times .. "*2") ~= false) or times == "" or times == nil) 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
                if pcall(expr, string.gsub(orig[i], "then", lastvalue) .. "*2") ~= false then
                    lastvalue = expr(string.gsub(orig[i], "then", lastvalue))
                end
            end
            i = i + 1
        end
    end
    
    i = 1
    
    if bot_to_hits + bot_x_hits ~= 0 or top_to_hits + top_x_hits ~= 0 then
        local lastvalue1 = ""
        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
                local start1
                if string.find(orig1[i], "to") ~= nil then
                    start1 = string.sub(orig1[i], 1, string.find(orig1[i], "to") - 1)
                end
                if string.find(orig1[i], "x") == nil and pcall(expr, start1 .. "*2") ~= false then
                    local finish1, times1
                    if string.find(orig1[i], "by") ~= nil then
                        finish1, times1 = orig1[i]:match".* *to *([^ ]*) *by *([^ ]*)"
                    else
                        if string.find(orig1[i], "for") ~= nil then
                            finish1, times1 = orig1[i]:match".* *to *([^ ]*) *for *([^ ]*)"
                        else
                            finish1 = orig1[i]:match".* *to *([^ ]*)"
                        end
                    end
                    if finish1 ~= nil and pcall(expr, finish1 .. "*2") ~= false and ((times1 ~= "" and  times1 ~= nil and pcall(expr, times1 .. "*2") ~= false) or times1 == "" or times1 == nil) then
                        start1 = tonumber(expr(start1))
                        finish1 = tonumber(expr(finish1))
                        if times1 ~= "" and times1 ~= nil then
                            times1 = tonumber(expr(times1))
                            if string.find(orig1[i], "by") ~= nil then
                                times1 = rounding(math.abs(finish1 - start1) / times1 + 1, 0)
                            end
                            fill1 = fill1 - times1
                            if string.find(orig1[i], "by") ~= nil and lastvalue1 == start1 then
                                fill1 = fill1 + 1
                            end
                        else
                            to1 = 1
                        end
                        lastvalue1 = finish1
                    else
                        fill1 = fill1 - 1
                    end
                else
                    local times1, doubleto1
                    if string.find(orig1[i], "for") then
                        doubleto1, times1 = orig1[i]:match"(.*) *for *([^ ]*)"
                    else
                        doubleto1 = orig1[i]
                    end
                    
                    local _, occurences1 = string.gsub(orig1[i], "to", "") 
                    if occurences1 > 0 and ((times1 ~= "" and times1 ~= nil and pcall(expr, times1 .. "*2") ~= false) or times1 == "" or times1 == nil) then
                        local times2 = 2
                        doubleto1 = string_to_formula(doubleto1, times2)
                    end
                    
                    local useformula1 = string.gsub(doubleto1, "then", "1")
                    if useformula1 ~= nil and pcall(expr, string.gsub(useformula1, "x", "1") .. "*2") ~= false and ((times1 ~= "" and  times1 ~= nil and pcall(expr, times1 .. "*2") ~= false) or times1 == "" or times1 == nil) then
                        if times1 ~= "" and times1 ~= nil then
                            times1 = tonumber(expr(times1))  
                            fill1 = fill1 - times1
                        else
                            to1 = 1
                        end
                    else
                        fill1 = fill1 - 1
                    end
                end
            else
                fill1 = fill1 - 1
                if pcall(expr, string.gsub(orig1[i], "then", lastvalue1) .. "*2") ~= false then
                    lastvalue1 = expr(string.gsub(orig1[i], "then", lastvalue1))
                end
            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
    
    local lastvalue = ""
    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
            local start
            if string.find(orig[i], "to") ~= nil then
                start = string.sub(orig[i], 1, string.find(orig[i], "to") - 1)
            end
            if string.find(orig[i], "x") == nil and pcall(expr, start .. "*2") ~= false then
                local finish, times
                if string.find(orig[i], "by") ~= nil then
                    finish, times = orig[i]:match".* *to *([^ ]*) *by *([^ ]*)"
                else
                    if string.find(orig[i], "for") ~= nil then
                        finish, times = orig[i]:match".* *to *([^ ]*) *for *([^ ]*)"
                    else
                        finish = orig[i]:match".* *to *([^ ]*)"
                    end
                end
                if finish ~= nil and pcall(expr, finish .. "*2") ~= false and ((times ~= "" and times ~= nil and pcall(expr, times .. "*2") ~= false) or times == "" or times == nil) then
                    start = tonumber(expr(start))
                    finish = tonumber(expr(finish))
                    if displayformula == nil and orig[2] == nil then
                        start2 = start
                        finish2 = finish
                    end
                    if times == "" or  times == nil then
                        times = fill
                        fill = 0
                    else
                        times = tonumber(expr(times))
                        if string.find(orig[i], "by") ~= nil then
                            times = tonumber(rounding(math.abs(finish - start) / times + 1, 0))
                        end
                    end
                    local x
                    if lastvalue == start then
                        x = 2
                        if string.find(orig[i], "by") == nil then
                            times = times + 1
                        end
                    else
                        x = 1
                    end
                    lastvalue = finish
                    count = count - times
                    if count < 0 then
                        return userError("Maximum size exceeded", "LuaError")
                    end
					
					local formula = start
                    local scale = (finish - start) / (times - 1)
					
                    while x <= times do
                        if x ~= 1 then
                            formula = formula + scale
                        end
                        local values3 = rounding(formula, round)
                        if values == "" then
                            values = fd(values3)
                            values2 = values3
                        else
                            values = values .. " / " .. fd(values3)
                            values2 = values2 .. " / " .. values3
                        end
                        x = x + 1
                    end
                else
                    count = count - 1
                    if count < 0 then
                        return userError("Maximum size exceeded", "LuaError")
                    end
                    local values3 = orig[i]
                    lastvalue = orig[i]
                    if values == "" then
                        values = fd(values3)
                        values2 = values3
                    else
                        values = values .. " / " .. fd(values3)
                        values2 = values2 .. " / " .. values3
                    end
                end
            else
                local times, doubleto
                if string.find(orig[i], "for") then
                    doubleto, times = orig[i]:match"(.*) *for *([^ ]*)"
                else
                    doubleto = orig[i]
                end
                local _, occurences = string.gsub(orig[i], "to", "") 
                if occurences > 0 and ((times ~= "" and times ~= nil and pcall(expr, times .. "*2") ~= false) or times == "" or times == nil) then
                    local times2
                    if times == "" or times == nil then
                        times2 = fill
                    else
                        times2 = tonumber(expr(times))  
                    end
                    doubleto = string_to_formula(doubleto, times2)
                end
                local useformula = string.gsub(doubleto, "then", lastvalue)
                if useformula ~= nil and pcall(expr, string.gsub(useformula, "x", "1") .. "*2") ~= false and ((times ~= "" and times ~= nil and pcall(expr, times .. "*2") ~= false) or times == "" or times == nil) 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
                    local x = 1
                    while x <= times do
                        count = count - 1
                        if count < 0 then
                            return userError("Maximum size exceeded", "LuaError")
                        end
                        local formula = string.gsub(useformula, "x", x)
                        local values3 = expr(formula)
                        lastvalue = values3
                        values3 = rounding(values3, round)
                        if values == "" then
                            values = fd(values3)
                            values2 = values3
                        else
                            values = values .. " / " .. fd(values3)
                            values2 = values2 .. " / " .. values3
                        end
                        x = x + 1
                    end
                else
                    count = count - 1
                    if count < 0 then
                        return userError("Maximum size exceeded", "LuaError")
                    end
                    local values3 = orig[i]
                    if values == "" then
                        values = fd(values3)
                        values2 = values3
                    else
                        values = values .. " / " .. fd(values3)
                        values2 = values2 .. " / " .. values3
                    end
                end
            end
        else
            count = count - 1
            if count < 0 then
                return userError("Maximum size exceeded", "LuaError")
            end
            local values3
            if pcall(expr, string.gsub(orig[i], "then", lastvalue) .. "*2") ~= false then
                values3 = expr(string.gsub(orig[i], "then", lastvalue))
                lastvalue = values3
                values3 = rounding(values3, round)
            else
                values3 = orig[i]
            end
            if values == "" then
                values = fd(values3)
                values2 = values3
            else
                values = values .. " / " .. fd(values3)
                values2 = values2 .. " / " .. values3
            end
        end
        i = i + 1
    end
    
    local s = ""
    s = s .. '<span class="pp-tooltip2" style="position:relative; border-bottom:1px dotted; cursor:help;'
    
    if args["color"] ~= nil then
        s = s .. " color:" .. col.keyword{args["color"]} .. ";"
    end
    s = s .. '"'
    
    if label ~= nil then
        s = s .. ' data-bot_label="' .. label .. '"'
    end
    
    if label1 ~= nil then
        s = s .. ' data-top_label="' .. string.gsub(string.gsub(label1, "'''", ""), "''", "") .. '"'
    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-bot_values="' .. values2 .. '"'
    end
    
    if args[2] ~= nil then
        s = s .. ' data-top_values="' .. args[2] .. '"'
    end
    
    if round ~= 2 and round ~= nil then
        s = s .. ' data-bot_round="' .. round .. '"'
    end
    
    if round1 ~= nil then
        s = s .. ' data-top_round="' .. round1 .. '"'
    end
    
    if key ~= "" then
        s = s .. ' data-bot_key="' .. key .. '"'
    end
    
    if key1 ~= nil then
        s = s .. ' data-top_key="' .. key1 .. '"'
    end
    
    if start2 ~= nil then
        s = s .. ' data-start="' .. start2  .. '"'
        s = s .. ' data-finish="' .. finish2 .. '"'
    end
    
    if top_to_hits + top_x_hits ~= 0 or start2 ~= nil then
        s = s .. ' data-top_fill="' .. fill1 .. '"'
    end
    
    s = s .. ">"
    
    if (countstatic - count > 5 and args["changedisplay"] ~= "true") or (countstatic - count <= 5 and args["changedisplay"] == "true") then
        s = s .. fd(string.sub(values2, 1, (string.find(values2, "%/") or 1) - 2)) .. key .. " &minus; " .. fd(last(values2, "/")) .. key
    else
        s = s .. values .. key
    end
    
    if args["showtype"] ~= "false" then
        s = s .. " (based on " .. (args["type"] or args["label1"] or "level") .. ")" 
    end
    
    s = s .. "</span>"
     
    return s
end

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

    local label          = args["bot_label"]
    local label1         = args["top_label"]
    local round          = args["bot_round"]
    local round1         = args["top_round"]
    if round1 == "false" then
        round1 = nil
    end
    local key            = args["bot_key"]
    local key1           = args["top_key"]
    local displayformula = args["displayformula"]
    local useformula     = args["useformula"]
    local fill1          = tonumber(args["top_fill"])
    local count1         = 30
    local start          = tonumber(args["start"])
    local finish         = tonumber(args["finish"])
    
    if label1 == "" then
        label1 = "level"
    end
    
    local formulalabel1 = string.gsub(label1, "[%[%]]", "")
    
    if label == "" then
        label = "value"
    end
    
    if tonumber(round) == nil then
        round = 2
    end
    
    if round1 == "" then
        round1 = 2
    end
    
    local orig  = lib.split(args["bot_values"], " %/")
    local orig1 = lib.split(args["top_values"], "%;")
    
    local s = ""
    
    local i = 1
    local j = 1
    
    local lastvalue1 = ""
    while (orig1[i] ~= nil and orig1[i] ~= "") or (orig[j] ~= nil and orig[j] ~= "") do
        s = s .. '</th><th style="text-align: center;">'
        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
                    local start1
                    if string.find(orig1[i], "to") ~= nil then
                        start1 = string.sub(orig1[i], 1, string.find(orig1[i], "to") - 1)
                    end
                    if string.find(orig1[i], "x") == nil and pcall(expr, start1 .. "*2") ~= false then
                        local finish1, times1
                        if string.find(orig1[i], "by") ~= nil then
                            finish1, times1 = orig1[i]:match".* *to *([^ ]*) *by *([^ ]*)"
                        else
                            if string.find(orig1[i], "for") ~= nil then
                                finish1, times1 = orig1[i]:match".* *to *([^ ]*) *for *([^ ]*)"
                            else
                                finish1 = orig1[i]:match".* *to *([^ ]*)"
                            end
                        end
                        if finish1 ~= nil and pcall(expr, finish1 .. "*2") ~= false and ((times1 ~= "" and times1 ~= nil and pcall(expr, times1 .. "*2") ~= false) or times1 == "" or times1 == nil) then
                            start1  = tonumber(expr(start1))
                            finish1 = tonumber(expr(finish1))
                            if times1 == "" or times1 == nil then
                                times1 = fill1
                                fill1  = 0
                            else
                                times1 = tonumber(expr(times1))
                                if string.find(orig1[i], "by") ~= nil then
                                    times1 = tonumber(rounding(math.abs(finish1 - start1) / times1 + 1, 0))
                                end
                            end
                            if displayformula == "" and orig1[2] == nil then
                                start3  = start1
                                finish3 = finish1
                                times3  = times1
                            end
                            local x1, formula1
                            if lastvalue1 == start1 then
                                x1 = 2
                                formula1 = start1
                                if string.find(orig1[i], "by") == nil then
                                    times1 = times1 + 1
                                end
                            else
                                x1 = 1
                            end
                            
                            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)
                                    if lastvalue1 == start1 and x1 == 2 then
                                    else
                                        s = s .. '</th><th style="text-align: center;">'
                                        j = j + 1
                                    end
                                end
                                s = s .. fd(rounding(formula1, round1)) .. key1
                                x1 = x1 + 1
                            end
                            
                            lastvalue1 = finish1
                        else
                            count1 = count1 - 1
                            if count1 < 0 then
                                return userError("Maximum size exceeded", "LuaError")
                            end
                            s = s .. fd(orig1[i])
                            lastvalue1 = orig1[i]
                        end
                    else
                        local times1, doubleto1
                        if string.find(orig1[i], "for") then
                            doubleto1, times1 = orig1[i]:match"(.*) *for *([^ ]*)"
                        else
                            doubleto1 = orig1[i]
                        end
                        local _, occurences1 = string.gsub(orig1[i], "to", "")
                        if occurences1 > 0 and ((times1 ~= "" and times1 ~= nil and pcall(expr, times1 .. "*2") ~= false) or times1 == "" or times1 == nil) then
                            local times2
                            if times1 == "" or times1 == nil then
                                times2 = fill1
                            else
                                times2 = tonumber(expr(times1))  
                            end
                            doubleto1 = string_to_formula(doubleto1, times2)
                        end
                        local useformula1 = string.gsub(doubleto1, "then", lastvalue1)
                        if useformula1 ~= nil and pcall(expr, string.gsub(useformula1, "x", "1") .. "*2") ~= false and ((times1 ~= "" and times1 ~= nil and pcall(expr, times1 .. "*2") ~= false) or times1 == "" or times1 == nil) then
                            if times1 == "" or times1 == nil then
                                times1 = fill1
                                fill1  = 0
                            else
                                times1 = tonumber(expr(times1))  
                            end
                            local x1 = 1
                            while x1 <= times1 do
                                count1 = count1 - 1
                                if count1 < 0 then
                                    return userError("Maximum size exceeded", "LuaError")
                                end
                                local formula1 = string.gsub(useformula1, "x", x1)
                                if x1 ~= 1 then
                                    s = s .. '</th><th style="text-align: center;">'
                                    j = j + 1
                                end
                                local values3 = expr(formula1)
                                lastvalue1 = values3
                                s = s .. fd(rounding(values3, round1)) .. key1
                                x1 = x1 + 1
                            end
                        else
                            count1 = count1 - 1
                            if count1 < 0 then
                                return userError("Maximum size exceeded", "LuaError")
                            end
                            s = s .. fd(orig1[i])
                        end
                    end
                else
                    count1 = count1 - 1
                    if count1 < 0 then
                        return userError("Maximum size exceeded", "LuaError")
                    end
                    if pcall(expr, string.gsub(orig1[i], "then", lastvalue1) .. "*2") ~= false then
                        local values3 = expr(string.gsub(orig1[i], "then", lastvalue1))
                        lastvalue1 = values3
                        s = s .. fd(rounding(values3, round1)) .. key1
                    else
                        s = s .. fd(orig1[i])
                    end
                end
            end
        else
            s = s .. j
        end
        i = i + 1
        j = j + 1
    end
    s = s .. '</th></tr>'
    s = s .. '<tr><th style="text-align: center;">' .. mw.ustring.gsub(label, "^.", mw.ustring.upper) .. '</th>'
    
    i = 1
    while orig[i] ~= nil and orig[i] ~= "" do
        s = s .. '<td>'
        s = s .. fd(orig[i])
        if pcall(expr, orig[i] .. "*2") ~= false then
            s = s .. key
        end
        s = s .. '</td>'
        i = i + 1
    end
    
    s = s .. '</tr></table>'

    local formula = ""
    
    if displayformula ~= "" then
        formula = formula .. "'''Formula:''' " .. displayformula
    else
        if orig1[1] ~= "" then
            if start ~= nil and start3 ~= nil then
                local scale  = (finish - start) / (times3 - 1)
                local scale1 = (finish3 - start3) / (times3 - 1)
                formula = formula .. "'''Formula:''' "
                if start ~= 0 then
                    formula = formula .. start .. key
                    if scale >= 0 then
                        formula = formula .. "+"
                    end
                end
                if label1 == "level" then
                    formula = formula .. scale .. key .. " for every "
                    if math.abs(scale1) ~= 1 then
                        formula = formula .. scale1
                    end
                    formula = formula .. key1 .. " " .. label1
                    if scale1 > 1 then
                        formula = formula .. "s"
                    end
                    if start3 ~= 0 and start3 ~= 1 then
                        formula = formula .. " starting from " .. label1 .. " " .. start3 .. key1 .. " and"
                    else
                        formula = formula .. ","
                    end
                    formula = formula .. " capped at " .. label1 .. " " .. finish3 .. key1
                else
                    formula = formula .. scale .. key .. " for every "
                    if math.abs(scale1) ~= 1 then
                        formula = formula .. scale1
                    end
                    formula = formula .. key1 .. " "
                    if scale1 ~= 1 then
                        formula = formula .. label1
                        if string.sub(formulalabel1, -1) ~= "s" then
                            formula = formula .. "s"
                        end
                    else
                        if string.sub(formulalabel1, -1) == "s" then
                            if string.sub(label1, -1) == "s" then
                                formula = formula .. string.sub(label1, 1, #label1 - 1)
                            else
                                formula = formula .. string.sub(label1, 1, #label1 - 3)
                            end
                        else
                            formula = formula .. label1
                        end
                    end
                    if start3 ~= 0 and start3 ~= 1 then
                        formula = formula .. " starting from " .. start3 .. key1 .. " "
                        if start3 ~= 1 then
                            formula = formula .. label1
                            if string.sub(formulalabel1, -1) ~= "s" then
                                formula = formula .. "s"
                            end
                        else
                            if string.sub(formulalabel1, -1) == "s" then
                                if string.sub(label1, -1) == "s" then
                                    formula = formula .. string.sub(label1, 1, #label1 - 1)
                                else
                                    formula = formula .. string.sub(label1, 1, #label1 - 3)
                                end
                            else
                                formula = formula .. label1
                            end
                        end
                        formula = formula .. " and"
                    else
                        formula = formula .. ","
                    end
                    formula = formula .. " capped at " .. finish3 .. key1 .. " "
                    if finish3 ~= 1 then
                        formula = formula .. label1
                        if string.sub(formulalabel1, -1) ~= "s" then
                            formula = formula .. "s"
                        end
                    else
                        if string.sub(formulalabel1, -1) == "s" then
                            if string.sub(label1, -1) == "s" then
                                formula = formula .. string.sub(label1, 1, #label1 - 1)
                            else
                                formula = formula .. string.sub(label1, 1, #label1 - 3)
                            end
                        else
                            formula = formula .. label1
                        end
                    end
                end
            end
        else
            if start ~= nil then
                local scale = (finish - start) / (fill1 - 1)
                formula = formula .. "'''Formula:''' "
                if tonumber(tostring(start)) == tonumber(tostring(scale)) then
                    formula = formula .. start .. key .. "&#42;" .. label1
                else
                    formula = formula .. (start - scale) .. key
                    if scale >= 0 then
                        formula = formula .. "+"
                        if scale == 1 then
                            formula = formula .. label1
                        else
                            formula = formula .. scale .. key .. "&#42;" .. label1
                        end
                    else
                        if scale == -1 then
                            formula = formula .. "-" .. label1
                        else
                            formula = formula .. scale .. key .. "&#42;" .. label1
                        end
                    end
                end
            end
            if useformula ~= "" then
                formula = formula .. "'''Formula:''' " .. useformula
            end
        end
    end
    
    if displayformula == "" then
        formula = string.gsub(string.gsub(string.gsub(string.gsub(string.gsub(formula, "%/", " &divide; "), "%*", "&#42;"), "&#42;", " &times; "), "%+", " + "), "%-", " &minus; ")
        if useformula ~= "" then
            formula = string.gsub(formula, "x", label1)
        end
    else
        formula = string.gsub(string.gsub(string.gsub(string.gsub(string.gsub(formula, "%/", "&divide;"), "%*", "&#42;"), "&#42;", "&times;"), "%+", "+"), "%-", "&minus;")
    end
    
    formula = fdmulti(formula)
    local s2 = '<div class="blue-tooltip" style="padding: 10px;">' .. formula
    s2 = s2 .. '<table class="wikitable" style="text-align: center; table-layout: fixed; margin: 0;">'
    s2 = s2 .. '<tr><th style="text-align: center;">' .. mw.ustring.gsub(label1, "^.", mw.ustring.upper)
    
    return s2 .. s .. "</div>"
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 orig   = args
    local count  = 6
    local fill
    local round  = args["round"] or nil
    if args["skill"] == "R" then
        fill = 3
    else
        fill = 5
    end
    local formula
    local temp, a, b, c
    
    local 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], "to") ~= nil then
                start = string.sub(orig[i], 1, string.find(orig[i], "to") - 1)
            end
            if string.find(orig[i], "x") == nil and pcall(expr, start .. "*2") ~= false then
                finish, times = orig[i]:match".* *to *([^ ]*) *([^ ]*)"
                if finish ~= nil and pcall(expr, finish .. "*2") ~= false and ((times ~= "" and times ~= nil and pcall(expr, times .. "*2") ~= false) or times == "" or times == nil) 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
                    count = count - times
                    if count < 0 then
                        return userError("Maximum size exceeded", "LuaError")
                    end
                    x = 1
                    while x <= times do
                        if x == 1 then
                            formula = start
                            scale = (finish - start) / (times - 1)
                        else
                            formula = formula + scale
                        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(orig[i], round))
                    else
                        values = values .. " / " .. fd(rounding(orig[i], round))
                    end
                end
            else
                local times
                local doubleto = orig[i]
                if last(orig[i], " ") ~= last(orig[i], "to ") then
                    times = last(orig[i], " ")
                    if pcall(expr, times .. "*2") ~= false then
                        doubleto = string.sub(doubleto, 1, #doubleto - #times)
                    else
                        times = nil
                    end
                end
                local _, occurences = string.gsub(orig[i], "to", "")
                if occurences > 0 and ((times ~= "" and times ~= nil and pcall(expr, times .. "*2") ~= false) or times == "" or times == nil) then
                    local times2
                    if times == "" or times == nil then
                        times2 = fill
                    else
                        times2 = tonumber(expr(times))  
                    end
                    doubleto = string_to_formula(doubleto, times2)
                end
                useformula = doubleto
                if useformula ~= nil and pcall(expr, string.gsub(useformula, "x", "1") .. "*2") ~= false and ((times ~= "" and times ~= nil and pcall(expr, times .. "*2") ~= false) or times == "" or times == nil) then
                    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)
                        if values =="" then
                            values = fd(rounding(expr(formula), round))
                        else
                            values = values .. " / " .. fd(rounding(expr(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(orig[i], round))
                    else
                        values = values .. " / " .. fd(rounding(orig[i], round))
                    end
                end
            end
        else
            count = count - 1
            if count < 0 then
                return userError("Maximum size exceeded", "LuaError")
            end
            if values == "" then
                values = fd(rounding(orig[i], round))
            else
                values = values .. " / " .. fd(rounding(orig[i], round))
            end
        end
        i = i + 1
    end
    return values
end

function string_to_formula(args, times)
    local val = args
    while string.find(val, "to") ~= nil do
        local to1            = string.sub(val, 1, string.find(val, "to") - 1)
        local to2            = string.sub(val, string.find(val, "to") + 2)
        local _, occurences1 = string.gsub(to1, "%(", "")
        local _, occurences2 = string.gsub(to2, "%)", "")
        local para1          = lib.split(to1, "%(")
        local para2          = lib.split(to2, "%)")
        local start, finish  = "", ""
        local times2
        local occurences3    = 0
        local j
        
        j = occurences1 + 1
        while j >= 2 do
            if j == occurences1 + 1 then
                start = para1[j]
            else
                start = "(" .. para1[j] .. start
            end
            _, times2 = string.gsub(para1[j], "%)", "")
            occurences3 = occurences3 + times2
            if occurences1 + 2 - j > occurences3 then
                break
            end
            j = j - 1
        end
        
        if pcall(expr, start .. "*2") == false then
            return args
        end
        
        occurences3 = 0
        j = 1
        while j <= occurences2 do
            if j == 1 then
                finish = para2[j]
            else
                finish = finish .. para2[j] .. ")"
            end
            _, times2 = string.gsub(para2[j], "%(", "")
            occurences3 = occurences3 + times2
            if j > occurences3 then
                break
            end
            j = j + 1
        end
        if pcall(expr, finish .. "*2") == false then
            return args
        end
        start  = string.gsub(start, "([%-%+%*%/%^%(%)])", "%%%1")
        finish = string.gsub(finish, "([%-%+%*%/%^%(%)])", "%%%1")
        val    = string.gsub(val, start .. "to" .. finish, "(" .. start .. ")" .. "+(" .. "(" .. finish .. ")" .. "-" .. "(" .. start .. ")" .. ")/(" .. times .. "-1)*(x-1)")
    end
    return val
end    
    
function expr(val)
    if string.find(val, "[0-9]") == nil then
        return val
    end
    val = string.gsub(val," ","")
    
    local symbol={
    ["^"]=1,
    ["/"]=2,
    ["*"]=3,
    ["+"]=4,
    ["-"]=5,
    [")"]=6,
    ["("]=7
    }
    
    local getmath = {
    ["^"] = function (a,b) return a^b end,
    ["/"] = function (a,b) return a/b end,
    ["*"] = function (a,b) return a*b end,
    ["+"] = function (a,b) return a+b end,
    ["-"] = function (a,b) return a-b end
    }
    
    local symbolstack = {}
    local numberstack = {}
    
    local term=""
    for i=1,#val,1 do
    	term = term .. string.sub(val,i,i)
    	if symbol[term] == nil or ((term == "-" or term == "+") and (symbol[string.sub(val,i-1,i-1)] ~= nil or i-1 == 0) and string.sub(val,i-1,i-1) ~= ")")  then
    		if symbol[string.sub(val,i+1,i+1)] ~= nil or i == #val then
    			table.insert(numberstack,term)
    			term=""
    		end
    	else
    		if symbolstack[#symbolstack] ~= nil and symbol[symbolstack[#symbolstack]] < symbol[term] and term ~= "(" and term ~= ")" then
    			table.insert(numberstack,symbolstack[#symbolstack])
    			symbolstack[#symbolstack] = term
    		else
    			table.insert(symbolstack,term)
    		end
    		if term == ")" then
    			closed = true
    		end
    		term=""
    	end
    	if closed == true then
    		table.remove(symbolstack,#symbolstack)
    		while symbolstack[#symbolstack] ~= "(" do
    			table.insert(numberstack,symbolstack[#symbolstack])
    			table.remove(symbolstack,#symbolstack)
    		end
    		closed = false
    		table.remove(symbolstack,#symbolstack)
    	end
    end
    
    for i = #symbolstack, 1, -1 do
    	table.insert(numberstack,symbolstack[i])
    end
    
    local tempstack = {}
    
    while numberstack[#numberstack] ~= nil do
    	if symbol[numberstack[1]] == nil then
    		table.insert(tempstack,numberstack[1])
    	else
    		table.insert(tempstack,getmath[numberstack[1]](tempstack[#tempstack-1], tempstack[#tempstack]))
    		table.remove(tempstack,#tempstack-1)
    		table.remove(tempstack,#tempstack-1)
    	end
    	table.remove(numberstack,1)
    end
    
    if tempstack[1] * 2 ~= nil then
        return tempstack[1] 
    end
end

function last(val, sign)
    return string.sub(val, 1 - (string.find(string.reverse(val), string.reverse(sign), 1, true) or 0))
end

function fd(val)
    return fd_get{args = {val}}
end

function fdmulti(val)
    return fd_getmulti{args = {val}}
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 = 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 decimals == "trunc" then
        round = string.sub(val, 1, (string.find(val, "%.") or 0) - 1)
    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

-- </pre>
--[[Category:Lua]]