英雄联盟维基
(update from 英文版本)
(update from English version)
 
第1行: 第1行:
 
-- <pre>
 
-- <pre>
 
local p = {}
 
local p = {}
local lib = require('Module:Feature')
+
local lib = require('Module:Feature')
local col = require('Module:Color')
+
local fd_get = require('Module:fd').get
local userError = require('Dev:User error')
+
local fd_getmulti = require('Module:fd').getmulti
  +
local gsub,find,sub,len = string.gsub,string.find,string.sub,string.len
local fd_get = require('Module:fd').get
 
  +
local abs,floor,ceil = math.abs,math.floor,math.ceil
local fd_getmulti = require('Module:fd').getmulti
 
local gsub = string.gsub
+
local concat = table.concat
  +
local tostring,tonumber,match,pcall = tostring,tonumber,match,pcall
local find = string.find
 
  +
local sub = string.sub
 
local abs = math.abs
+
local getmath = {
  +
["^"] = function (a,b) return a^b end,
local floor = math.floor
 
  +
["/"] = function (a,b) return a/b end,
local ceil = math.ceil
 
  +
["*"] = function (a,b) return a*b end,
local insert = table.insert
 
  +
["%"] = function (a,b) return a%b end,
local remove = table.remove
 
  +
["+"] = function (a,b) return a+b end,
local reverse = string.reverse
 
  +
["-"] = function (a,b) return a-b end
 
  +
}
  +
  +
local symbol={
  +
["^"]=1,
  +
["/"]=2,
  +
["*"]=2,
  +
["%"]=2,
  +
["+"]=3,
  +
["-"]=3,
  +
[")"]=4,
  +
["("]=4
  +
}
  +
 
local function expr(val)
 
local function expr(val)
 
if find(val, "[0-9]") == nil then
 
if find(val, "[0-9]") == nil then
 
return val
 
return val
 
end
 
end
  +
 
val = gsub(val," ","")
 
val = gsub(val," ","")
  +
 
  +
local symbolstack = {}
local symbol={
 
  +
local numberstack = {}
["^"]=1,
 
  +
local term=""
["/"]=2,
 
  +
local closed
["*"]=3,
 
  +
local len_number, len_symbol = 0,0
["+"]=4,
 
  +
local len_val = #val
["-"]=5,
 
  +
[")"]=6,
 
  +
for i=1,len_val do
["("]=7
 
  +
local temp_term = sub(val,i,i)
}
 
  +
 
  +
if symbol[temp_term] == nil or ((temp_term == "-" or temp_term == "+") and (symbol[sub(val,i-1,i-1)] or i-1 == 0) and sub(val,i-1,i-1) ~= ")") then
local getmath = {
 
  +
if symbol[sub(val,i+1,i+1)] or i == len_val then
["^"] = function (a,b) return a^b end,
 
  +
len_number = len_number + 1
["/"] = function (a,b) return a/b end,
 
  +
numberstack[len_number] = term .. temp_term
["*"] = function (a,b) return a*b end,
 
  +
term = ""
["+"] = function (a,b) return a+b end,
 
  +
else
["-"] = function (a,b) return a-b end
 
  +
term = term .. temp_term
}
 
  +
end
 
local symbolstack = {}
+
else
  +
if symbolstack[len_symbol] and symbol[symbolstack[len_symbol]] <= symbol[temp_term] and temp_term ~= "(" and temp_term ~= ")" then
local numberstack = {}
 
  +
len_number = len_number + 1
local tempstack
 
  +
numberstack[len_number] = symbolstack[len_symbol]
local closed
 
  +
symbolstack[len_symbol] = temp_term
local term=""
 
  +
else
 
  +
len_symbol = len_symbol + 1
for i=1,#val,1 do
 
  +
symbolstack[len_symbol] = temp_term
term = term .. sub(val,i,i)
 
  +
end
if symbol[term] == nil or ((term == "-" or term == "+") and (symbol[sub(val,i-1,i-1)] ~= nil or i-1 == 0) and sub(val,i-1,i-1) ~= ")") then
 
  +
if symbol[sub(val,i+1,i+1)] ~= nil or i == #val then
 
  +
if temp_term == ")" then
insert(numberstack,term)
 
  +
closed = true
term=""
 
end
+
end
  +
end
else
 
  +
if symbolstack[#symbolstack] ~= nil and symbol[symbolstack[#symbolstack]] < symbol[term] and term ~= "(" and term ~= ")" then
 
  +
if closed then
insert(numberstack,symbolstack[#symbolstack])
 
  +
len_symbol = len_symbol - 1
symbolstack[#symbolstack] = term
 
  +
else
 
insert(symbolstack,term)
+
while symbolstack[len_symbol] ~= "(" and len_symbol > 0 do
  +
len_number = len_number + 1
end
 
  +
numberstack[len_number] = symbolstack[len_symbol]
if term == ")" then
 
  +
len_symbol = len_symbol - 1
closed = true
 
end
+
end
  +
term=""
 
  +
if len_symbol == 0 then
end
 
  +
error("Brackets are unlinked.")
if closed == true then
 
  +
end
remove(symbolstack,#symbolstack)
 
  +
while symbolstack[#symbolstack] ~= "(" do
 
  +
closed = false
insert(numberstack,symbolstack[#symbolstack])
 
  +
len_symbol = len_symbol - 1
remove(symbolstack,#symbolstack)
 
end
+
end
  +
end
closed = false
 
  +
remove(symbolstack,#symbolstack)
 
  +
for i = len_symbol, 1, -1 do
end
 
  +
len_number = len_number + 1
end
 
  +
numberstack[len_number] = symbolstack[i]
 
  +
end
for i = #symbolstack, 1, -1 do
 
  +
insert(numberstack,symbolstack[i])
 
  +
local tempstack = {}
end
 
  +
local len_temp = 0
 
  +
tempstack = {}
 
  +
for i = 1, len_number do
 
while numberstack[#numberstack] ~= nil do
+
if symbol[numberstack[i]] then
if symbol[numberstack[1]] == nil then
+
tempstack[len_temp - 1] = getmath[numberstack[i]](tempstack[len_temp - 1], tempstack[len_temp])
  +
len_temp = len_temp - 1
insert(tempstack,numberstack[1])
 
else
+
else
  +
len_temp = len_temp + 1
insert(tempstack,getmath[numberstack[1]](tempstack[#tempstack-1], tempstack[#tempstack]))
 
remove(tempstack,#tempstack-1)
+
tempstack[len_temp] = numberstack[i]
  +
end
remove(tempstack,#tempstack-1)
 
end
+
end
  +
remove(numberstack,1)
 
  +
if tempstack[1] * 2 then
  +
return tonumber(tempstack[1])
 
end
 
end
 
if tempstack[1] * 2 ~= nil then
 
return tempstack[1]
 
end
 
end
 
 
local function last(val, sign)
 
return sub(val, 1 - (find(reverse(val), reverse(sign), 1, true) or 0))
 
 
end
 
end
   
第111行: 第119行:
   
 
local function rounding(val, decimals)
 
local function rounding(val, decimals)
  +
if decimals == nil or find(val, "[0-9]") == nil or find(val, "<span", 1, true) or find(val, ".", 1, true) == nil then
local round
 
local val = tostring(val)
 
if decimals == nil or find(val, "[0-9]") == nil or find(val, "<span") ~= nil or 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 = tostring(val):match"([^0-9]*)([0-9]*).([0-9]*)(.*)"
 
val = tonumber(b .. "." .. c)
 
val = tonumber(b .. "." .. c)
  +
if decimals == "abs" then
 
round = abs(val)
+
local round = (
  +
decimals == "abs" and abs(val)
  +
or decimals == "floor" and floor(val)
  +
or decimals == "ceil" and ceil(val)
  +
or decimals == "trunc" and sub(val, 1, (find(val, ".", 1, true) or 0) - 1)
  +
or floor(val * 10 ^ (decimals) + 0.5) / (10 ^ (decimals))
  +
)
  +
  +
val = a .. round .. d
  +
  +
if tonumber(val) then
  +
return tonumber(val)
 
end
 
end
  +
if decimals == "floor" then
 
round = floor(val)
+
return val
end
 
if decimals == "ceil" then
 
round = ceil(val)
 
end
 
if decimals == "trunc" then
 
round = sub(val, 1, (find(val, "%.") or 0) - 1)
 
end
 
if round == nil then
 
local mult = 10 ^ (decimals)
 
round = floor(val * mult + 0.5) / mult
 
end
 
return a .. round .. d
 
 
end
 
end
   
local function string_to_formula(args, times)
+
local function string_to_formula(args)
local val = args
+
local val = gsub(args," ","")
  +
while find(val, "to") ~= nil do
 
local to1 = sub(val, 1, find(val, "to") - 1)
+
while find(val, "to", 1, true) do
local to2 = sub(val, find(val, "to") + 2)
+
local to = sub(val, 1, find(val, "to", 1, true) - 1)
local _, occurences1 = gsub(to1, "%(", "")
+
local para = lib.split(to, "(",true)
  +
local para_len = #para
local _, occurences2 = gsub(to2, "%)", "")
 
local para1 = lib.split(to1, "%(")
+
local j = para_len
local para2 = lib.split(to2, "%)")
+
local total_times = 0
  +
local start, finish = "", ""
 
local times2
 
local occurences3 = 0
 
local j
 
 
j = occurences1 + 1
 
 
while j >= 2 do
 
while j >= 2 do
if j == occurences1 + 1 then
+
local _, times = gsub(para[j], "%)", "")
start = para1[j]
+
total_times = total_times + times
  +
else
 
start = "(" .. para1[j] .. start
+
if para_len - j >= total_times then
end
 
_, times2 = gsub(para1[j], "%)", "")
 
occurences3 = occurences3 + times2
 
if occurences1 + 2 - j > occurences3 then
 
 
break
 
break
 
end
 
end
  +
 
j = j - 1
 
j = j - 1
 
end
 
end
  +
 
  +
local start = concat(para,"(",j)
  +
 
if pcall(expr, start .. "*2") == false then
 
if pcall(expr, start .. "*2") == false then
 
return args
 
return args
 
end
 
end
  +
 
  +
to = sub(val, find(val, "to", 1, true) + 2)
occurences3 = 0
 
j = 1
+
para = lib.split(to, ")", true)
  +
para_len = #para
while j <= occurences2 do
 
  +
j = 1
if j == 1 then
 
  +
total_times = 0
finish = para2[j]
 
  +
else
 
  +
while j < para_len do
finish = finish .. para2[j] .. ")"
 
end
+
local _, times = gsub(para[j], "%(", "")
_, times2 = gsub(para2[j], "%(", "")
+
total_times = total_times + times
  +
occurences3 = occurences3 + times2
 
if j > occurences3 then
+
if j > total_times then
 
break
 
break
 
end
 
end
  +
 
j = j + 1
 
j = j + 1
 
end
 
end
  +
if pcall(expr, finish .. "*2") == false then
 
return args
+
local finish = concat(para,")",1,j)
  +
local post_finish
end
 
  +
  +
if find(finish,"to",1,true) then
  +
post_finish = string_to_formula(finish)
  +
  +
if post_finish == finish then
  +
return args
  +
end
  +
elseif pcall(expr, finish .. "*2") == false then
  +
return args
  +
end
  +
 
start = gsub(start, "([%-%+%*%/%^%(%)])", "%%%1")
 
start = gsub(start, "([%-%+%*%/%^%(%)])", "%%%1")
 
finish = gsub(finish, "([%-%+%*%/%^%(%)])", "%%%1")
 
finish = gsub(finish, "([%-%+%*%/%^%(%)])", "%%%1")
val = gsub(val, start .. "to" .. finish, "(" .. start .. ")" .. "+(" .. "(" .. finish .. ")" .. "-" .. "(" .. start .. ")" .. ")/(" .. times .. "-1)*(x-1)")
+
val = gsub(val, start .. "to" .. finish, "(" .. start .. ")" .. "+(" .. "(" .. (post_finish or finish) .. ")" .. "-" .. "(" .. start .. ")" .. ")/(times-1)*(x-1)")
 
end
 
end
  +
 
return val
 
return val
end
+
end
   
function p.test(frame)
+
local function gsub_x(val1,val2)
  +
if val1 == "" and val2 == "" then
local args; if frame.args[1] then args = frame.args else args = frame:getParent().args end
 
  +
return 1
local doubleto = "yes"
 
  +
end
return gsub(doubleto, "true", "")
 
 
end
 
end
   
 
function p.pp(frame)
 
function p.pp(frame)
local args; if frame.args[1] then args = frame.args else args = frame:getParent().args end
+
local args = (frame.args[1] and frame.args) or frame:getParent().args
  +
 
  +
local userError = require('Dev:User error')
local start2, end2
 
  +
local values, values2 = "", ""
 
  +
do
local count, countstatic = 30, 30
 
  +
local accepted_args = mw.loadData("Module:Ability_progression/parameters")
local fill, fill1 = 18, 18
 
  +
local to, to1 = 0, 0
 
  +
for i in pairs(args) do
  +
if accepted_args[i] == nil then
  +
return userError("Parameter '" .. i .. "' is not accepted", "LuaError")
  +
end
  +
end
  +
end
  +
  +
local nowiki = mw.text.nowiki
 
 
  +
local function gsub_nowiki(val1,val2,val3) --Currently used for "<" and ">" when necessary to not break the tooltip
local displayformula = args["formula"]
 
  +
if val1 == "" and val3 == "" then
local round = args["round"] or 2
 
  +
return nowiki(val2)
if round == "false" then
 
  +
end
round = nil
 
end
+
end
  +
local round1 = args["round1"]
 
local key = args["key"] or ""
+
local count, countstatic = {30,30}, 30
local key1 = args["key1"]
+
local default_fill = 18
  +
local label = args["label"]
 
local label1 = args["label1"] or args["type"]
+
local displayformula = args["formula"]
  +
local special_displayformula_values = {{},{}}
local orig = lib.split(args[1] or "", "%;")
 
  +
local useformula2
local orig1 = lib.split(args[2] or "", "%;")
 
  +
local _, bot_to_hits = gsub(args[1] or "", "to", "")
 
local _, top_to_hits = gsub(args[2] or "", "to", "")
+
local key = args["key"] or ""
local _, bot_x_hits = gsub(args[1] or "", "x", "")
+
local key1 = args["key1"]
local _, top_x_hits = gsub(args[2] or "", "x", "")
+
local round = {
  +
(args["round"] ~= "false" and (args["round"] or 2)) or nil,
local i = 1
 
  +
(args["round1"] ~= "false" and (args["round1"] or 2)) or nil
  +
}
  +
  +
local label = args["label"]
  +
local label1 = args["label1"] or args["type"]
  +
  +
local orig = lib.split(args[1] or "", ";", true)
  +
local orig1 = lib.split(args[2] or "", ";", true)
  +
  +
local origtable = {orig,orig1}
  +
local save_to = {{},{}}
  +
local save_to_index = {}
  +
local resulttable = {{},{}}
  +
  +
for orig_index = 1, 2 do
  +
local orig = origtable[orig_index]
  +
local lastvalue = ""
  +
local i = 1
  +
local len_resulttable = 0
  +
  +
while orig[i] and orig[i] ~= "" do
  +
orig[i] = gsub(orig[i],"([^%d ]?)([<>])([^%d ]?)",gsub_nowiki)
  +
local temp_find_to = find(orig[i], "to", 1, true)
  +
local temp_find_x = find(orig[i], "x", 1, true)
  +
  +
if (temp_find_to or temp_find_x) and find(orig[i], "<", 1, true) == nil then
  +
local start, finish, times
  +
  +
if temp_find_to then
  +
start = sub(orig[i], 1, temp_find_to - 1)
 
 
  +
if find(orig[i], "by", 1, true) then
if bot_to_hits + bot_x_hits ~= 0 or top_to_hits + top_x_hits ~= 0 then
 
  +
finish, times = orig[i]:match".* *to *([^ ]*) *by *([^ ]*)$"
local lastvalue = ""
 
while orig[i] ~= nil and orig[i] ~= "" do
+
elseif find(orig[i], "for", 1, true) then
if (find(orig[i], "to") ~= nil or find(orig[i], "x") ~= nil) and find(orig[i], "%<") == nil then
+
finish, times = orig[i]:match".* *to *([^ ]*) *for *([^ ]*)$"
local start
+
else
if find(orig[i], "to") ~= nil then
+
finish = orig[i]:match".* *to *([^ ]*)"
start = sub(orig[i], 1, find(orig[i], "to") - 1)
+
end
end
+
end
  +
if find(orig[i], "x") == nil and pcall(expr, start .. "*2") ~= false then
 
local finish, times
+
start, finish, times = start or "", finish or "", times or ""
if find(orig[i], "by") ~= nil then
+
local check_for_times = false
  +
finish, times = orig[i]:match".* *to *([^ ]*) *by *([^ ]*)"
 
  +
if temp_find_x == nil and pcall(expr, start .. "*2") and pcall(expr, finish .. "*2") and
else
 
if find(orig[i], "for") ~= nil then
+
(pcall(expr, times .. "*2") or times == "") then
finish, times = orig[i]:match".* *to *([^ ]*) *for *([^ ]*)"
+
check_for_times = true
  +
start = expr(start)
  +
finish = expr(finish)
  +
  +
if displayformula == nil and orig[2] == nil then
  +
special_displayformula_values[orig_index][1] = start
  +
special_displayformula_values[orig_index][2] = finish
  +
end
  +
  +
if times == "" then
  +
if save_to_index[orig_index] then
  +
check_for_times = false
 
else
 
else
finish = orig[i]:match".* *to *([^ ]*)"
+
save_to[orig_index] = {start,finish, lastvalue}
  +
save_to_index[orig_index] = len_resulttable + 1
  +
lastvalue = finish
 
end
 
end
end
+
else
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
+
times = expr(times)
start = tonumber(expr(start))
+
local scale
finish = tonumber(expr(finish))
+
local formula = start
  +
if times ~= "" and times ~= nil then
 
times = tonumber(expr(times))
+
if find(orig[i], "by", 1, true) then
if find(orig[i], "by") ~= nil then
+
times = rounding(abs(finish - start) / times + 1, 0)
times = rounding(abs(finish - start) / times + 1, 0)
+
scale = (finish - start) / (times - 1)
  +
end
 
fill = fill - times
+
if lastvalue == start then
if find(orig[i], "by") ~= nil and lastvalue == start then
+
times = times - 1
fill = fill + 1
+
else
  +
formula = formula - scale
 
end
 
end
  +
elseif lastvalue == start then
  +
scale = (finish - start) / times
 
else
 
else
to = 1
+
scale = (finish - start) / (times - 1)
  +
formula = formula - scale
  +
end
  +
  +
count[orig_index] = count[orig_index] - times
  +
  +
if count[orig_index] < 0 then
  +
return userError("Maximum size exceeded", "LuaError")
  +
end
  +
  +
for x = 1, times do
  +
formula = formula + scale
  +
len_resulttable = len_resulttable + 1
  +
resulttable[orig_index][len_resulttable] = rounding(formula, round[orig_index])
 
end
 
end
  +
 
lastvalue = finish
 
lastvalue = finish
else
 
fill = fill - 1
 
 
end
 
end
 
else
 
else
local times, doubleto
+
start, finish, times = nil, nil, nil
if find(orig[i], "for") then
+
local useformula, doubleto
  +
doubleto, times = orig[i]:match"(.*) *for *([^ ]*)"
 
else
+
if find(orig[i], "for", 1, true) then
doubleto = orig[i]
+
useformula, times = orig[i]:match"(.*) *for *([^ ]*)$"
 
end
 
end
 
 
local _, occurences = gsub(orig[i], "to", "")
+
useformula, times = useformula or orig[i], times or ""
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 = gsub(doubleto, "then", "1")
+
if lastvalue ~= "" then
if useformula ~= nil and pcall(expr, gsub(useformula, "x", "1") .. "*2") ~= false and ((times ~= "" and times ~= nil and pcall(expr, times .. "*2") ~= false) or times == "" or times == nil) then
+
useformula = gsub(useformula, "then", lastvalue,1)
if times ~= "" and times ~= nil then
 
times = tonumber(expr(times))
 
fill = fill - times
 
else
 
to = 1
 
end
 
else
 
fill = fill - 1
 
 
end
 
end
  +
end
 
else
+
if pcall(expr, times .. "*2") then
fill = fill - 1
+
check_for_times = true
if pcall(expr, gsub(orig[i], "then", lastvalue) .. "*2") ~= false then
+
times = expr(times)
lastvalue = expr(gsub(orig[i], "then", lastvalue))
+
elseif times == "" then
end
+
check_for_times = true
end
+
times = nil
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 (find(orig1[i], "to") ~= nil or find(orig1[i], "x") ~= nil) and find(orig1[i], "%<") == nil then
 
local start1
 
if find(orig1[i], "to") ~= nil then
 
start1 = sub(orig1[i], 1, find(orig1[i], "to") - 1)
 
end
 
if find(orig1[i], "x") == nil and pcall(expr, start1 .. "*2") ~= false then
 
local finish1, times1
 
if find(orig1[i], "by") ~= nil then
 
finish1, times1 = orig1[i]:match".* *to *([^ ]*) *by *([^ ]*)"
 
else
 
if find(orig1[i], "for") ~= nil then
 
finish1, times1 = orig1[i]:match".* *to *([^ ]*) *for *([^ ]*)"
 
else
 
finish1 = orig1[i]:match".* *to *([^ ]*)"
 
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
 
start1 = tonumber(expr(start1))
+
local _,occurences = gsub(orig[i],"to","")
  +
finish1 = tonumber(expr(finish1))
 
if times1 ~= "" and times1 ~= nil then
+
if check_for_times and occurences > 0 then
times1 = tonumber(expr(times1))
+
doubleto = string_to_formula(useformula)
if find(orig1[i], "by") ~= nil then
+
useformula = gsub(doubleto,"times",tostring(times or "2"))
times1 = rounding(abs(finish1 - start1) / times1 + 1, 0)
+
-- The '2' is a temporary value, until it will later on be switched with the fill one
  +
end
  +
  +
times = times or ""
  +
  +
if check_for_times and pcall(expr, gsub(useformula, "([%.%d]?)x([%.%d]?)", gsub_x) .. "*2") then
  +
if times == "" then
  +
if orig_index == 1 and displayformula == nil and orig[2] == nil and useformula2 == nil then
  +
if doubleto then
  +
useformula2 = gsub(doubleto,"times", default_fill)
  +
else
  +
useformula2 = useformula
  +
end
 
end
 
end
  +
fill1 = fill1 - times1
 
if find(orig1[i], "by") ~= nil and lastvalue1 == start1 then
+
if save_to_index[orig_index] then
fill1 = fill1 + 1
+
check_for_times = false
  +
else
  +
save_to[orig_index] = {doubleto or useformula}
  +
save_to_index[orig_index] = len_resulttable + 1
  +
lastvalue = ""
 
end
 
end
 
else
 
else
to1 = 1
+
if orig_index == 1 and displayformula == nil and orig[2] == nil and useformula2 == nil then
  +
useformula2 = useformula
  +
end
  +
  +
count[orig_index] = count[orig_index] - times
  +
  +
if count[orig_index] < 0 then
  +
return userError("Maximum size exceeded", "LuaError")
  +
end
  +
  +
for x = 1, times do
  +
lastvalue = expr(gsub(useformula, "x", x))
  +
len_resulttable = len_resulttable + 1
  +
resulttable[orig_index][len_resulttable] = rounding(lastvalue, round[orig_index])
  +
end
 
end
 
end
lastvalue1 = finish1
 
 
else
 
else
fill1 = fill1 - 1
+
check_for_times = false
 
end
 
end
else
+
end
  +
local times1, doubleto1
 
if find(orig1[i], "for") then
+
if check_for_times == false then
doubleto1, times1 = orig1[i]:match"(.*) *for *([^ ]*)"
+
lastvalue = ""
else
+
count[orig_index] = count[orig_index] - 1
  +
doubleto1 = orig1[i]
 
  +
if count[orig_index] < 0 then
  +
return userError("Maximum size exceeded", "LuaError")
 
end
 
end
  +
 
  +
len_resulttable = len_resulttable + 1
local _, occurences1 = gsub(orig1[i], "to", "")
 
  +
resulttable[orig_index][len_resulttable] = orig[i]
if occurences1 > 0 and ((times1 ~= "" and times1 ~= nil and pcall(expr, times1 .. "*2") ~= false) or times1 == "" or times1 == nil) then
 
local times2 = 2
+
end
  +
else
doubleto1 = string_to_formula(doubleto1, times2)
 
end
+
count[orig_index] = count[orig_index] - 1
  +
 
local useformula1 = gsub(doubleto1, "then", "1")
+
if count[orig_index] < 0 then
  +
return userError("Maximum size exceeded", "LuaError")
if useformula1 ~= nil and pcall(expr, 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
+
end
  +
times1 = tonumber(expr(times1))
 
fill1 = fill1 - times1
+
local value = (lastvalue == "" and orig[i]) or gsub(orig[i], "then", lastvalue,1)
  +
else
 
to1 = 1
+
if pcall(expr, value .. "*2") then
end
+
value = expr(value)
  +
  +
if find(orig[i+1] or "", "to",1,true) then
  +
lastvalue = ""
 
else
 
else
fill1 = fill1 - 1
+
lastvalue = value
 
end
 
end
  +
  +
value = rounding(value, round[orig_index])
  +
elseif lastvalue ~= "" then
  +
lastvalue = ""
  +
value = orig[i]
 
end
 
end
  +
else
 
  +
len_resulttable = len_resulttable + 1
fill1 = fill1 - 1
 
  +
resulttable[orig_index][len_resulttable] = value
if pcall(expr, gsub(orig1[i], "then", lastvalue1) .. "*2") ~= false then
 
lastvalue1 = expr(gsub(orig1[i], "then", lastvalue1))
 
end
 
 
end
 
end
  +
 
i = i + 1
 
i = i + 1
 
end
 
end
 
end
 
end
  +
 
  +
local fill = {default_fill - #resulttable[1], default_fill - #resulttable[2]}
 
  +
if 18 - fill >= 18 - fill1 then
 
if to == 0 then
+
if default_fill - fill[1] >= default_fill - fill[2] then
fill1 = fill1 - fill
+
if save_to_index[1] == nil then
end
+
fill[2] = fill[2] - fill[1]
else
 
if to1 == 0 then
 
fill = fill - fill1
 
 
end
 
end
  +
elseif save_to_index[2] == nil then
  +
fill[1] = fill[1] - fill[2]
 
end
 
end
 
 
 
 
if fill < 0 then
+
if fill[1] < 0 then
fill = 0
+
fill[1] = 0
 
end
 
end
 
 
if fill1 < 0 then
+
if fill[2] < 0 then
fill1 = 0
+
fill[2] = 0
 
end
 
end
 
 
local lastvalue = ""
+
local insert = table.insert
  +
i = 1
 
while orig[i] ~= nil and orig[i] ~= "" do
+
for orig_index = 1, #save_to do
  +
local to = save_to[orig_index]
if (find(orig[i], "to") ~= nil or find(orig[i], "x") ~= nil) and find(orig[i], "%<") == nil then
 
  +
local start
 
if find(orig[i], "to") ~= nil then
+
if to[1] then
start = sub(orig[i], 1, find(orig[i], "to") - 1)
+
if to[2] then
end
+
local lastvalue = to[3]
if find(orig[i], "x") == nil and pcall(expr, start .. "*2") ~= false then
+
local start, finish = to[1], to[2]
local finish, times
+
local times = fill[orig_index]
if find(orig[i], "by") ~= nil then
+
local scale
finish, times = orig[i]:match".* *to *([^ ]*) *by *([^ ]*)"
+
local formula = start
  +
  +
if lastvalue == start then
  +
scale = (finish - start) / times
 
else
 
else
if find(orig[i], "for") ~= nil then
+
scale = (finish - start) / (times - 1)
finish, times = orig[i]:match".* *to *([^ ]*) *for *([^ ]*)"
+
formula = formula - scale
else
 
finish = orig[i]:match".* *to *([^ ]*)"
 
end
 
 
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))
+
count[orig_index] = count[orig_index] - times
  +
finish = tonumber(expr(finish))
 
if displayformula == nil and orig[2] == nil then
+
if count[orig_index] < 0 then
start2 = start
+
return userError("Maximum size exceeded", "LuaError")
finish2 = finish
+
end
  +
end
 
if times == "" or times == nil then
+
for x = 1, times do
times = fill
+
formula = formula + scale
fill = 0
+
insert(resulttable[orig_index], save_to_index[orig_index] + x - 1, rounding(formula, round[orig_index]))
else
 
times = tonumber(expr(times))
 
if find(orig[i], "by") ~= nil then
 
times = tonumber(rounding(abs(finish - start) / times + 1, 0))
 
end
 
end
 
local x
 
if lastvalue == start then
 
x = 2
 
if 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
 
end
 
else
 
else
local times, doubleto
+
local useformula = gsub(to[1],"times",fill[orig_index])
if find(orig[i], "for") then
+
local times = fill[orig_index]
doubleto, times = orig[i]:match"(.*) *for *([^ ]*)"
+
count[orig_index] = count[orig_index] - times
  +
else
 
doubleto = orig[i]
+
if count[orig_index] < 0 then
  +
return userError("Maximum size exceeded", "LuaError")
 
end
 
end
  +
local _, occurences = gsub(orig[i], "to", "")
 
  +
for x = 1, times do
if occurences > 0 and ((times ~= "" and times ~= nil and pcall(expr, times .. "*2") ~= false) or times == "" or times == nil) then
 
  +
insert(resulttable[orig_index], save_to_index[orig_index] + x - 1, rounding(expr(gsub(useformula, "x", x)), round[orig_index]))
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 = gsub(doubleto, "then", lastvalue)
 
if useformula ~= nil and pcall(expr, 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 = 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
end
 
else
 
count = count - 1
 
if count < 0 then
 
return userError("Maximum size exceeded", "LuaError")
 
end
 
local values3
 
if pcall(expr, gsub(orig[i], "then", lastvalue) .. "*2") ~= false then
 
values3 = expr(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
 
end
 
end
i = i + 1
 
 
end
 
end
 
 
  +
if #resulttable[2] ~= 0 and #resulttable[1] ~= #resulttable[2] then
local s = ""
 
  +
return userError("Variables are unmatched", "LuaError")
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
 
end
  +
s = s .. '"'
 
  +
local s = {}
  +
local s_len = 1
  +
s[s_len] = '<span class="pp-tooltip" style="position:relative; border-bottom:1px dotted; cursor:help;'
 
 
if label ~= nil then
+
if args["color"] then
s = s .. ' data-bot_label="' .. label .. '"'
+
s_len = s_len + 1
  +
s[s_len] = " color:" .. require('Module:Color').keyword{args["color"]} .. ";"
 
end
 
end
 
 
if label1 ~= nil then
+
s_len = s_len + 1
  +
s[s_len] = '"'
s = s .. ' data-top_label="' .. gsub(gsub(label1, "'''", ""), "''", "") .. '"'
 
end
 
 
 
if displayformula ~= nil then
+
if label then
  +
s_len = s_len + 1
s = s .. ' data-displayformula="' .. displayformula .. '"'
 
  +
s[s_len] = ' data-bot_label="' .. label .. '"'
 
end
 
end
 
 
if useformula2 ~= nil then
+
if label1 then
  +
s_len = s_len + 1
s = s .. ' data-useformula="' .. useformula2 .. '"'
 
  +
s[s_len] = ' data-top_label="' .. gsub(gsub(label1, "'''", ""), "''", "") .. '"'
 
end
 
end
 
 
if values2 ~= nil then
+
if displayformula then
s = s .. ' data-bot_values="' .. values2 .. '"'
+
s_len = s_len + 1
  +
s[s_len] = ' data-displayformula="' .. displayformula .. '"'
 
end
 
end
 
 
if args[2] ~= nil then
+
if useformula2 then
s = s .. ' data-top_values="' .. args[2] .. '"'
+
s_len = s_len + 1
  +
s[s_len] = ' data-useformula="' .. useformula2 .. '"'
 
end
 
end
 
 
if round ~= 2 and round ~= nil then
+
if resulttable[1] then
s = s .. ' data-bot_round="' .. round .. '"'
+
s_len = s_len + 1
  +
s[s_len] = ' data-bot_values="' .. concat(resulttable[1],";") .. '"'
 
end
 
end
 
 
if round1 ~= nil then
+
if resulttable[2] then
s = s .. ' data-top_round="' .. round1 .. '"'
+
s_len = s_len + 1
  +
s[s_len] = ' data-top_values="' .. concat(resulttable[2],";") .. '"'
 
end
 
end
 
 
 
if key ~= "" then
 
if key ~= "" then
s = s .. ' data-bot_key="' .. key .. '"'
+
s_len = s_len + 1
  +
s[s_len] = ' data-bot_key="' .. key .. '"'
 
end
 
end
 
 
if key1 ~= nil then
+
if key1 then
s = s .. ' data-top_key="' .. key1 .. '"'
+
s_len = s_len + 1
  +
s[s_len] = ' data-top_key="' .. key1 .. '"'
 
end
 
end
 
 
  +
if special_displayformula_values[1][1] or special_displayformula_values[2][1] then
if start2 ~= nil then
 
s = s .. ' data-start="' .. start2 .. '"'
+
s_len = s_len + 1
s = s .. ' data-finish="' .. finish2 .. '"'
+
s[s_len] = (
  +
' data-start="' .. (special_displayformula_values[1][1] or "") .. ";" .. (special_displayformula_values[2][1] or "") .. '"' ..
  +
' data-finish="' .. (special_displayformula_values[1][2] or "") .. ";" .. (special_displayformula_values[2][2] or "") .. '"')
 
end
 
end
 
 
  +
s_len = s_len + 1
if top_to_hits + top_x_hits ~= 0 or start2 ~= nil then
 
  +
s[s_len] = ">"
s = s .. ' data-top_fill="' .. fill1 .. '"'
 
  +
end
 
  +
if (countstatic - count[1] > 5 and args["changedisplay"] ~= "true") or (countstatic - count[1] <= 5 and args["changedisplay"] == "true") then
 
s = s .. ">"
+
s_len = s_len + 1
  +
s[s_len] = fd(resulttable[1][1] or "NULL") .. key .. " &minus; " .. fd(resulttable[1][#resulttable[1]] or "NULL") .. key
 
if (countstatic - count > 5 and args["changedisplay"] ~= "true") or (countstatic - count <= 5 and args["changedisplay"] == "true") then
 
s = s .. fd(sub(values2, 1, (find(values2, "%/") or 1) - 2)) .. key .. " &minus; " .. fd(last(values2, "/")) .. key
 
 
else
 
else
s = s .. values .. key
+
s_len = s_len + 1
  +
s[s_len] = fdmulti(concat(resulttable[1]," / ")) .. key
 
end
 
end
 
 
 
if args["showtype"] ~= "false" then
 
if args["showtype"] ~= "false" then
  +
s_len = s_len + 1
s = s .. " (based on " .. (args["type"] or args["label1"] or "level") .. ")"
 
  +
s[s_len] = " (based on " .. (args["type"] or args["label1"] or "level") .. ")"
 
end
 
end
 
 
s = s .. "</span>"
+
s_len = s_len + 1
  +
s[s_len] = "</span>"
 
 
return s
+
return concat(s)
 
end
 
end
   
 
function p.pptooltip(frame)
 
function p.pptooltip(frame)
local args; if frame.args[1] then args = frame.args else args = frame:getParent().args end
+
local args = frame.args[1] and frame.args or frame:getParent().args
   
local label = args["bot_label"]
+
local label = (args["bot_label"] == "" and "value") or args["bot_label"]
local label1 = args["top_label"]
+
local label1 = (args["top_label"] == "" and "level") or args["top_label"]
local round = args["bot_round"]
+
local key = args["bot_key"]
local round1 = args["top_round"]
+
local key1 = args["top_key"]
  +
local displayformula = args["displayformula"]
if round1 == "false" then
 
round1 = nil
+
local useformula = args["useformula"]
  +
local start = lib.split(args["start"], ";", true)
end
 
local key = args["bot_key"]
+
local start2,start3 = (tonumber(start[1]) or ""), (tonumber(start[2]) or "")
local key1 = args["top_key"]
+
local finish = lib.split(args["finish"], ";", true)
  +
local finish2,finish3 = (tonumber(finish[1]) or ""), (tonumber(finish[2]) or "")
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 = 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 formulalabel1 = gsub(label1, "[%[%]]", "")
local orig1 = lib.split(args["top_values"], "%;")
 
 
 
local s = ""
+
local orig = lib.split(args["bot_values"], ";", true)
  +
local orig1 = lib.split(args["top_values"], ";", true)
 
 
  +
local s = {}
  +
local s_len = 0
 
local i = 1
 
local i = 1
  +
local j = 1
 
  +
while (orig1[i] and orig1[i] ~= "") or (orig[i] and orig[i] ~= "") do
 
local lastvalue1 = ""
+
s_len = s_len + 1
  +
s[s_len] = '</th><th style="text-align: center;">'
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[1] == "" then
if orig1[i] ~= nil and orig1[i] ~= "" then
+
s_len = s_len + 1
  +
s[s_len] = i
if (find(orig1[i], "to") ~= nil or find(orig1[i], "x") ~= nil) and find(orig1[i], "%<") == nil then
 
local start1
+
else
if find(orig1[i], "to") ~= nil then
+
s_len = s_len + 1
start1 = sub(orig1[i], 1, find(orig1[i], "to") - 1)
+
s[s_len] = fd(orig1[i] or "")
end
+
if find(orig1[i], "x") == nil and pcall(expr, start1 .. "*2") ~= false then
+
if pcall(expr, (orig1[i] or "") .. "*2") then
local finish1, times1
+
s_len = s_len + 1
if find(orig1[i], "by") ~= nil then
+
s[s_len] = key1
finish1, times1 = orig1[i]:match".* *to *([^ ]*) *by *([^ ]*)"
 
else
 
if 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 find(orig1[i], "by") ~= nil then
 
times1 = tonumber(rounding(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 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 find(orig1[i], "for") then
 
doubleto1, times1 = orig1[i]:match"(.*) *for *([^ ]*)"
 
else
 
doubleto1 = orig1[i]
 
end
 
local _, occurences1 = 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 = gsub(doubleto1, "then", lastvalue1)
 
if useformula1 ~= nil and pcall(expr, 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 = 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, gsub(orig1[i], "then", lastvalue1) .. "*2") ~= false then
 
local values3 = expr(gsub(orig1[i], "then", lastvalue1))
 
lastvalue1 = values3
 
s = s .. fd(rounding(values3, round1)) .. key1
 
else
 
s = s .. fd(orig1[i])
 
end
 
end
 
 
end
 
end
else
 
s = s .. j
 
 
end
 
end
  +
 
i = i + 1
 
i = i + 1
j = j + 1
 
 
end
 
end
  +
s = s .. '</th></tr>'
 
  +
s_len = s_len + 1
s = s .. '<tr><th style="text-align: center;">' .. mw.ustring.gsub(label, "^.", mw.ustring.upper) .. '</th>'
 
  +
s[s_len] = '</th></tr><tr><th style="text-align: center;">' .. mw.ustring.gsub(label, "^.", mw.ustring.upper) .. '</th>'
 
 
 
i = 1
 
i = 1
  +
while orig[i] ~= nil and orig[i] ~= "" do
 
s = s .. '<td>'
+
while orig[i] and orig[i] ~= "" do
s = s .. fd(orig[i])
+
s_len = s_len + 1
if pcall(expr, orig[i] .. "*2") ~= false then
+
s[s_len] = '<td>' .. fd(orig[i])
  +
s = s .. key
 
  +
if pcall(expr, orig[i] .. "*2") then
  +
s_len = s_len + 1
  +
s[s_len] = key
 
end
 
end
  +
s = s .. '</td>'
 
  +
s_len = s_len + 1
  +
s[s_len] = '</td>'
 
i = i + 1
 
i = i + 1
 
end
 
end
 
 
s = s .. '</tr></table>'
+
s_len = s_len + 1
  +
s[s_len] = '</tr></table>'
  +
  +
s = concat(s)
   
local formula = ""
+
local formula = {}
  +
local len_formula = 0
 
 
 
if displayformula ~= "" then
 
if displayformula ~= "" then
  +
len_formula = len_formula + 1
formula = formula .. "'''Formula:''' " .. displayformula
 
  +
formula[len_formula] = "'''Formula:''' " .. displayformula
else
 
if orig1[1] ~= "" then
+
elseif orig1[1] ~= "" then
if start ~= nil and start3 ~= nil then
+
if start2 ~= "" and start3 ~= "" then
local scale = (finish - start) / (times3 - 1)
+
local orig1_len = #orig1
local scale1 = (finish3 - start3) / (times3 - 1)
+
local scale = (finish2 - start2) / (orig1_len - 1)
formula = formula .. "'''Formula:''' "
+
local scale1 = (finish3 - start3) / (orig1_len - 1)
  +
if start ~= 0 then
 
formula = formula .. start .. key
+
len_formula = len_formula + 1
if scale >= 0 then
+
formula[len_formula] = "'''Formula:''' "
  +
formula = formula .. "+"
 
end
+
if start2 ~= 0 then
  +
len_formula = len_formula + 1
  +
formula[len_formula] = start2 .. key
  +
  +
if scale >= 0 then
  +
len_formula = len_formula + 1
  +
formula[len_formula] = "+"
 
end
 
end
if label1 == "level" then
+
end
  +
formula = formula .. scale .. key .. " for every "
 
if abs(scale1) ~= 1 then
+
if label1 == "level" then
formula = formula .. scale1
+
len_formula = len_formula + 1
end
+
formula[len_formula] = scale .. key .. " for every "
  +
formula = formula .. key1 .. " " .. label1
 
if scale1 > 1 then
+
if abs(scale1) ~= 1 then
formula = formula .. "s"
+
len_formula = len_formula + 1
  +
formula[len_formula] = scale1
  +
end
  +
  +
len_formula = len_formula + 1
  +
formula[len_formula] = key1 .. " " .. label1
  +
  +
if scale1 > 1 then
  +
len_formula = len_formula + 1
  +
formula[len_formula] = "s"
  +
end
  +
  +
if start3 ~= 0 and start3 ~= 1 then
  +
len_formula = len_formula + 1
  +
formula[len_formula] = " starting from " .. label1 .. " " .. start3 .. key1 .. " and"
  +
else
  +
len_formula = len_formula + 1
  +
formula[len_formula] = ","
  +
end
  +
  +
len_formula = len_formula + 1
  +
formula[len_formula] = " capped at " .. label1 .. " " .. finish3 .. key1
  +
else
  +
local label1_len = #label1
  +
  +
len_formula = len_formula + 1
  +
formula[len_formula] = scale .. key .. " for every "
  +
  +
if abs(scale1) ~= 1 then
  +
len_formula = len_formula + 1
  +
formula[len_formula] = scale1
  +
end
  +
  +
len_formula = len_formula + 1
  +
formula[len_formula] = key1 .. " "
  +
  +
if scale1 ~= 1 then
  +
len_formula = len_formula + 1
  +
formula[len_formula] = label1
  +
  +
if sub(formulalabel1, -1) ~= "s" then
  +
len_formula = len_formula + 1
  +
formula[len_formula] = "s"
 
end
 
end
if start3 ~= 0 and start3 ~= 1 then
+
elseif sub(formulalabel1, -1) == "s" then
formula = formula .. " starting from " .. label1 .. " " .. start3 .. key1 .. " and"
+
if sub(label1, -1) == "s" then
  +
len_formula = len_formula + 1
  +
formula[len_formula] = sub(label1, 1, label1_len - 1)
 
else
 
else
formula = formula .. ","
+
len_formula = len_formula + 1
  +
formula[len_formula] = sub(label1, 1, label1_len - 3)
 
end
 
end
formula = formula .. " capped at " .. label1 .. " " .. finish3 .. key1
 
 
else
 
else
formula = formula .. scale .. key .. " for every "
+
len_formula = len_formula + 1
if abs(scale1) ~= 1 then
+
formula[len_formula] = label1
formula = formula .. scale1
+
end
  +
end
 
formula = formula .. key1 .. " "
+
if start3 ~= 0 and start3 ~= 1 then
if scale1 ~= 1 then
+
len_formula = len_formula + 1
formula = formula .. label1
+
formula[len_formula] = " starting from " .. start3 .. key1 .. " "
  +
  +
if start3 ~= 1 then
  +
len_formula = len_formula + 1
  +
formula[len_formula] = label1
  +
 
if sub(formulalabel1, -1) ~= "s" then
 
if sub(formulalabel1, -1) ~= "s" then
formula = formula .. "s"
+
len_formula = len_formula + 1
  +
formula[len_formula] = "s"
 
end
 
end
else
+
elseif sub(formulalabel1, -1) == "s" then
if sub(formulalabel1, -1) == "s" then
+
if sub(label1, -1) == "s" then
if sub(label1, -1) == "s" then
+
len_formula = len_formula + 1
formula = formula .. sub(label1, 1, #label1 - 1)
+
formula[len_formula] = sub(label1, 1, label1_len - 1)
else
 
formula = formula .. sub(label1, 1, #label1 - 3)
 
end
 
 
else
 
else
formula = formula .. label1
+
len_formula = len_formula + 1
  +
formula[len_formula] = sub(label1, 1, label1_len - 3)
 
end
 
end
end
 
if start3 ~= 0 and start3 ~= 1 then
 
formula = formula .. " starting from " .. start3 .. key1 .. " "
 
if start3 ~= 1 then
 
formula = formula .. label1
 
if sub(formulalabel1, -1) ~= "s" then
 
formula = formula .. "s"
 
end
 
else
 
if sub(formulalabel1, -1) == "s" then
 
if sub(label1, -1) == "s" then
 
formula = formula .. sub(label1, 1, #label1 - 1)
 
else
 
formula = formula .. sub(label1, 1, #label1 - 3)
 
end
 
else
 
formula = formula .. label1
 
end
 
end
 
formula = formula .. " and"
 
 
else
 
else
formula = formula .. ","
+
len_formula = len_formula + 1
  +
formula[len_formula] = label1
 
end
 
end
  +
formula = formula .. " capped at " .. finish3 .. key1 .. " "
 
if finish3 ~= 1 then
+
len_formula = len_formula + 1
formula = formula .. label1
+
formula[len_formula] = " and"
if sub(formulalabel1, -1) ~= "s" then
+
else
formula = formula .. "s"
+
len_formula = len_formula + 1
end
+
formula[len_formula] = ","
  +
end
  +
  +
len_formula = len_formula + 1
  +
formula[len_formula] = " capped at " .. finish3 .. key1 .. " "
  +
  +
if finish3 ~= 1 then
  +
len_formula = len_formula + 1
  +
formula[len_formula] = label1
  +
  +
if sub(formulalabel1, -1) ~= "s" then
  +
len_formula = len_formula + 1
  +
formula[len_formula] = "s"
  +
end
  +
elseif sub(formulalabel1, -1) == "s" then
  +
if sub(label1, -1) == "s" then
  +
len_formula = len_formula + 1
  +
formula[len_formula] = sub(label1, 1, label1_len - 1)
 
else
 
else
if sub(formulalabel1, -1) == "s" then
+
len_formula = len_formula + 1
if sub(label1, -1) == "s" then
+
formula[len_formula] = sub(label1, 1, label1_len - 3)
formula = formula .. sub(label1, 1, #label1 - 1)
 
else
 
formula = formula .. sub(label1, 1, #label1 - 3)
 
end
 
else
 
formula = formula .. label1
 
end
 
 
end
 
end
  +
else
  +
len_formula = len_formula + 1
  +
formula[len_formula] = label1
 
end
 
end
 
end
 
end
else
+
end
  +
else
if start ~= nil then
 
  +
if start2 ~= "" then
local scale = (finish - start) / (fill1 - 1)
 
formula = formula .. "'''Formula:''' "
+
local scale = (finish2 - start2) / (#orig - 1)
  +
len_formula = len_formula + 1
if tonumber(tostring(start)) == tonumber(tostring(scale)) then
 
formula = formula .. start .. key .. "&#42;" .. label1
+
formula[len_formula] = "'''Formula:''' "
  +
else
 
formula = formula .. (start - scale) .. key
+
if tonumber(tostring(start2)) == tonumber(tostring(scale)) then
if scale >= 0 then
+
len_formula = len_formula + 1
formula = formula .. "+"
+
formula[len_formula] = start2 .. key .. "&#42;" .. label1
if scale == 1 then
+
elseif len(sub(scale,find(scale,".",1,true) or 1)) <= 4 then
formula = formula .. label1
+
len_formula = len_formula + 1
else
+
formula[len_formula] = (start2 - scale) .. key
  +
formula = formula .. scale .. key .. "&#42;" .. label1
 
end
+
if scale >= 0 then
  +
len_formula = len_formula + 1
  +
formula[len_formula] = "+"
  +
  +
if scale == 1 then
  +
len_formula = len_formula + 1
  +
formula[len_formula] = label1
 
else
 
else
if scale == -1 then
+
len_formula = len_formula + 1
formula = formula .. "-" .. label1
+
formula[len_formula] = scale .. key .. "&#42;" .. label1
else
 
formula = formula .. scale .. key .. "&#42;" .. label1
 
end
 
 
end
 
end
  +
elseif scale == -1 then
  +
len_formula = len_formula + 1
  +
formula[len_formula] = "-" .. label1
  +
else
  +
len_formula = len_formula + 1
  +
formula[len_formula] = scale .. key .. "&#42;" .. label1
 
end
 
end
  +
else
  +
len_formula = len_formula + 1
  +
formula[len_formula] = start2 .. key
  +
  +
if finish2 - start2 >= 0 then
  +
len_formula = len_formula + 1
  +
formula[len_formula] = "+"
  +
end
  +
  +
len_formula = len_formula + 1
  +
formula[len_formula] = (finish2 - start2) .. key .. "/" .. (#orig - 1) .. "&#42;(" .. label1 .. "-1)"
 
end
 
end
if useformula ~= "" then
+
elseif useformula ~= "" then
formula = formula .. "'''Formula:''' " .. useformula
+
len_formula = len_formula + 1
  +
formula[len_formula] = "'''Formula:''' " .. useformula
end
 
 
end
 
end
 
end
 
end
  +
  +
formula = concat(formula)
 
 
 
if displayformula == "" then
 
if displayformula == "" then
 
formula = gsub(gsub(gsub(gsub(gsub(formula, "%/", " &divide; "), "%*", "&#42;"), "&#42;", " &times; "), "%+", " + "), "%-", " &minus; ")
 
formula = gsub(gsub(gsub(gsub(gsub(formula, "%/", " &divide; "), "%*", "&#42;"), "&#42;", " &times; "), "%+", " + "), "%-", " &minus; ")
  +
 
if useformula ~= "" then
 
if useformula ~= "" then
 
formula = gsub(formula, "x", label1)
 
formula = gsub(formula, "x", label1)
第981行: 第882行:
 
 
 
formula = fdmulti(formula)
 
formula = fdmulti(formula)
  +
local s2 = '<div class="blue-tooltip" style="padding: 10px;">' .. formula
 
  +
return (
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)
+
'<div ' .. (formula == "" and "" or 'class="blue-tooltip" ') .. 'style="padding: 10px;">' .. formula ..
  +
'<table class="wikitable" style="text-align: center; table-layout: fixed; margin: 0;">' ..
 
  +
'<tr><th style="text-align: center;">' .. mw.ustring.gsub(label1, "^.", mw.ustring.upper) ..
return s2 .. s .. "</div>"
 
  +
s .. "</div>"
  +
)
 
end
 
end
   
 
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 = (frame.args and lib.arguments(frame.args)) or lib.arguments(frame)
  +
local values = ""
 
  +
local userError = require('Dev:User error')
local orig = args
 
local count = 6
+
local orig = args
local fill
+
local count = 6
local round = args["round"] or nil
+
local round = args["round"] or nil
if args["skill"] == "R" then
+
local fill = (args["skill"] ~= "R" and 5) or 3
  +
fill = 3
 
  +
local resulttable = {}
else
 
fill = 5
+
local len_resulttable = 0
  +
local i = 1
end
 
  +
local formula
 
local temp, a, b, c
+
while orig[i] and orig[i] ~= "" do
  +
local temp_find_to = find(orig[i], "to", 1, true)
 
  +
local temp_find_x = find(orig[i], "x", 1, true)
local i = 1
 
  +
while orig[i] ~= nil and orig[i] ~= "" do
 
if (find(orig[i], "to") ~= nil or find(orig[i], "x") ~= nil) and find(orig[i], "%<") == nil then
+
if (temp_find_to or temp_find_x) and find(orig[i], "<", 1, true) == nil then
if find(orig[i], "to") ~= nil then
+
local start, finish, times
  +
start = sub(orig[i], 1, find(orig[i], "to") - 1)
 
end
+
if temp_find_to then
if find(orig[i], "x") == nil and pcall(expr, start .. "*2") ~= false then
+
start = sub(orig[i], 1, temp_find_to - 1)
finish, times = orig[i]:match".* *to *([^ ]*) *([^ ]*)"
+
finish, times = orig[i]:match".* *to *([^ ]*) *([^ ]*)$"
  +
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))
+
start, finish, times = start or "", finish or "", times or ""
if times == "" or times == nil then
+
local check_for_times = false
  +
  +
if temp_find_x == nil and pcall(expr, start .. "*2") and pcall(expr, finish .. "*2") and
  +
(pcall(expr, times .. "*2") or times == "") then
  +
check_for_times = true
  +
start = expr(start)
  +
finish = expr(finish)
  +
  +
if times == "" then
  +
if fill ~= 0 then
 
times = fill
 
times = fill
fill = 0
+
fill = 0
 
else
 
else
times = tonumber(expr(times))
+
check_for_times = false
 
end
 
end
  +
else
  +
times = expr(times)
  +
end
  +
  +
if check_for_times then
 
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
 
while x <= times do
+
local scale = (finish - start) / (times - 1)
if x == 1 then
+
local formula = start - scale
  +
formula = start
 
scale = (finish - start) / (times - 1)
+
for x = 1, times do
else
+
formula = formula + scale
formula = formula + scale
+
len_resulttable = len_resulttable + 1
end
+
resulttable[len_resulttable] = rounding(formula, round)
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
 
end
 
end
 
else
 
else
local times
+
local useformula,times = orig[i]:match"(.*[0-9x%)]) +([^ ]*)$"
  +
useformula, times = useformula or orig[i], times or ""
local doubleto = orig[i]
 
  +
if last(orig[i], " ") ~= last(orig[i], "to ") then
 
times = last(orig[i], " ")
+
if pcall(expr, times .. "*2") then
  +
check_for_times = true
if pcall(expr, times .. "*2") ~= false then
 
  +
times = expr(times)
doubleto = sub(doubleto, 1, #doubleto - #times)
 
  +
elseif times == "" and fill ~= 0 then
else
 
  +
check_for_times = true
times = nil
 
end
+
times = fill
  +
fill = 0
  +
end
  +
  +
local _,occurences = gsub(orig[i],"to","")
  +
  +
if check_for_times and occurences > 0 then
  +
useformula = gsub(string_to_formula(useformula),"times",tostring(times))
 
end
 
end
  +
local _, occurences = 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 check_for_times and pcall(expr, gsub(useformula, "([%.%d]?)x([%.%d]?)", gsub_x) .. "*2") then
local times2
+
count = count - times
  +
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, 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 = 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
 
if count < 0 then
 
return userError("Maximum size exceeded", "LuaError")
 
return userError("Maximum size exceeded", "LuaError")
 
end
 
end
  +
if values == "" then
 
values = fd(rounding(orig[i], round))
+
for x = 1, times do
else
+
len_resulttable = len_resulttable + 1
values = values .. " / " .. fd(rounding(orig[i], round))
+
resulttable[len_resulttable] = rounding(expr(gsub(useformula, "x", x)), round)
 
end
 
end
  +
else
  +
check_for_times = false
 
end
 
end
  +
end
  +
  +
if check_for_times == false then
  +
count = count - 1
  +
  +
if count < 0 then
  +
return userError("Maximum size exceeded", "LuaError")
  +
end
  +
  +
len_resulttable = len_resulttable + 1
  +
resulttable[len_resulttable] = orig[i]
 
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
 
values = fd(rounding(orig[i], round))
+
local value = (pcall(expr, orig[i] .. "*2") and rounding(orig[i], round)) or orig[i]
  +
else
 
  +
len_resulttable = len_resulttable + 1
values = values .. " / " .. fd(rounding(orig[i], round))
 
end
+
resulttable[len_resulttable] = value
 
end
 
end
  +
 
i = i + 1
 
i = i + 1
 
end
 
end
  +
return values
 
  +
return fdmulti(concat(resulttable," / "))
 
end
 
end
   

2021年3月4日 (四) 07:30的最新版本

此模块的文档可以在Module:Ability progression/doc创建

-- <pre>
local p = {}
local lib       	= require('Module:Feature')
local fd_get    	= require('Module:fd').get
local fd_getmulti	= require('Module:fd').getmulti
local gsub,find,sub,len = string.gsub,string.find,string.sub,string.len
local abs,floor,ceil = math.abs,math.floor,math.ceil
local concat = table.concat
local tostring,tonumber,match,pcall = tostring,tonumber,match,pcall

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,
["-"] = function (a,b) return a-b end
}

local symbol={
["^"]=1,
["/"]=2,
["*"]=2,
["%"]=2,
["+"]=3,
["-"]=3,
[")"]=4,
["("]=4
}

local function expr(val)
    if find(val, "[0-9]") == nil then
        return val
    end

    val = gsub(val," ","")

	local symbolstack = {}
	local numberstack = {}
	local term=""
	local closed
	local len_number, len_symbol = 0,0
	local len_val = #val

	for i=1,len_val do
		local temp_term = sub(val,i,i)

		if symbol[temp_term] == nil or ((temp_term == "-" or temp_term == "+") and (symbol[sub(val,i-1,i-1)] or i-1 == 0) and sub(val,i-1,i-1) ~= ")")  then
			if symbol[sub(val,i+1,i+1)] or i == len_val then
				len_number = len_number + 1
				numberstack[len_number] = term .. temp_term
				term = ""
			else
				term = term .. temp_term
			end
        else
			if symbolstack[len_symbol] and symbol[symbolstack[len_symbol]] <= symbol[temp_term] and temp_term ~= "(" and temp_term ~= ")" then
				len_number = len_number + 1
				numberstack[len_number] = symbolstack[len_symbol]
				symbolstack[len_symbol] = temp_term
			else
				len_symbol = len_symbol + 1
				symbolstack[len_symbol] = temp_term
			end

			if temp_term == ")" then
				closed = true
			end
		end

		if closed then
			len_symbol = len_symbol - 1

			while symbolstack[len_symbol] ~= "(" and len_symbol > 0 do
				len_number = len_number + 1
				numberstack[len_number] = symbolstack[len_symbol]
				len_symbol = len_symbol - 1
			end
			
			if len_symbol == 0 then
				error("Brackets are unlinked.")
			end

			closed = false
			len_symbol = len_symbol - 1
		end
	end

	for i = len_symbol, 1, -1 do
		len_number = len_number + 1
		numberstack[len_number] = symbolstack[i]
	end

	local tempstack = {}
	local len_temp = 0

	for i = 1, len_number do
		if symbol[numberstack[i]] then
			tempstack[len_temp - 1] = getmath[numberstack[i]](tempstack[len_temp - 1], tempstack[len_temp])
			len_temp = len_temp - 1
		else
			len_temp = len_temp + 1
			tempstack[len_temp] = numberstack[i]
		end
	end

    if tempstack[1] * 2 then
        return tonumber(tempstack[1])
    end
end

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

local function fdmulti(val)
    return fd_getmulti{args = {val}}
end

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

    return val
end

local function string_to_formula(args)
    local val = gsub(args," ","")

    while find(val, "to", 1, true) do
        local to       		= sub(val, 1, find(val, "to", 1, true) - 1)
        local para         	= lib.split(to, "(",true)
		local para_len 		= #para
        local j             = para_len
		local total_times   = 0

        while j >= 2 do
            local _, times = gsub(para[j], "%)", "")
            total_times = total_times + times

            if para_len - j >= total_times then
                break
            end

            j = j - 1
        end

        local start = concat(para,"(",j)

        if pcall(expr, start .. "*2") == false then
            return args
        end

        to	       		= sub(val, find(val, "to", 1, true) + 2)
        para			= lib.split(to, ")", true)
		para_len		= #para
		j 				= 1
		total_times		= 0

        while j < para_len do
            local _, times = gsub(para[j], "%(", "")
            total_times = total_times + times

            if j > total_times then
                break
            end

            j = j + 1
        end

        local finish = concat(para,")",1,j)
		local post_finish

		if find(finish,"to",1,true) then
			post_finish = string_to_formula(finish)

			if post_finish == finish then
				return args
			end
		elseif pcall(expr, finish .. "*2") == false then
			return args
		end

        start  = gsub(start, "([%-%+%*%/%^%(%)])", "%%%1")
        finish = gsub(finish, "([%-%+%*%/%^%(%)])", "%%%1")
        val    = gsub(val, start .. "to" .. finish, "(" .. start .. ")" .. "+(" .. "(" .. (post_finish or finish) .. ")" .. "-" .. "(" .. start .. ")" .. ")/(times-1)*(x-1)")
    end

    return val
end

local function gsub_x(val1,val2)
	if val1 == "" and val2 == "" then
		return 1
	end
end

function p.pp(frame)
    local args = (frame.args[1] and frame.args) or frame:getParent().args
	
	local userError 	= require('Dev:User error')

	do
		local accepted_args = mw.loadData("Module:Ability_progression/parameters")
	
	    for i in pairs(args) do
	    	if accepted_args[i] == nil then
	    		return userError("Parameter '" .. i .. "' is not accepted", "LuaError")
	    	end
	    end
	end

	local nowiki		= mw.text.nowiki
    
    local function gsub_nowiki(val1,val2,val3) --Currently used for "<" and ">" when necessary to not break the tooltip
		if val1 == "" and val3 == "" then
			return nowiki(val2)
		end
	end

    local count, countstatic            = {30,30}, 30
    local default_fill                  = 18

    local displayformula                = args["formula"]
    local special_displayformula_values = {{},{}}
    local useformula2

    local key                           = args["key"] or ""
    local key1                          = args["key1"]
    local round                         = {
    	(args["round"] ~= "false" and (args["round"] or 2)) or nil, 
    	(args["round1"] ~= "false" and (args["round1"] or 2)) or nil
    }

    local label                         = args["label"]
    local label1                        = args["label1"] or args["type"]

    local orig                          = lib.split(args[1] or "", ";", true)
    local orig1                         = lib.split(args[2] or "", ";", true)

	local origtable                     = {orig,orig1}
    local save_to                       = {{},{}}
    local save_to_index                 = {}
    local resulttable                   = {{},{}}

	for orig_index = 1, 2 do
		local orig = origtable[orig_index]
	    local lastvalue = ""
        local i = 1
        local len_resulttable = 0

        while orig[i] and orig[i] ~= "" do
        	orig[i] = gsub(orig[i],"([^%d ]?)([<>])([^%d ]?)",gsub_nowiki)
        	local temp_find_to = find(orig[i], "to", 1, true)
        	local temp_find_x = find(orig[i], "x", 1, true)

            if (temp_find_to or temp_find_x) and find(orig[i], "<", 1, true) == nil then
            	local start, finish, times

            	if temp_find_to then
	            	start = sub(orig[i], 1, temp_find_to - 1)
	
	                if find(orig[i], "by", 1, true) then
	                    finish, times = orig[i]:match".* *to *([^ ]*) *by *([^ ]*)$"
	                elseif find(orig[i], "for", 1, true) then
	                    finish, times = orig[i]:match".* *to *([^ ]*) *for *([^ ]*)$"
	                else
	                    finish = orig[i]:match".* *to *([^ ]*)"
	                end
	            end
	            
	            start, finish, times = start or "", finish or "", times or ""
                local check_for_times = false
                
                if temp_find_x == nil and pcall(expr, start .. "*2") and pcall(expr, finish .. "*2") and 
                (pcall(expr, times .. "*2") or times == "") then
                    check_for_times = true
                    start = expr(start)
                    finish = expr(finish)

                    if displayformula == nil and orig[2] == nil then
                        special_displayformula_values[orig_index][1] = start
                        special_displayformula_values[orig_index][2] = finish
                    end

                    if times == "" then
                        if save_to_index[orig_index] then
                        	check_for_times = false
                        else
                            save_to[orig_index] = {start,finish, lastvalue}
                            save_to_index[orig_index] = len_resulttable + 1
                            lastvalue = finish
                        end
                    else
                        times = expr(times)
                        local scale
                        local formula = start

                        if find(orig[i], "by", 1, true) then
                            times = rounding(abs(finish - start) / times + 1, 0)
                            scale = (finish - start) / (times - 1)

                            if lastvalue == start then
                                times = times - 1
                            else
                                formula = formula - scale
                            end
                        elseif lastvalue == start then
                            scale = (finish - start) / times
                        else
                            scale = (finish - start) / (times - 1)
                            formula = formula - scale
                        end

                        count[orig_index] = count[orig_index] - times

                        if count[orig_index] < 0 then
                            return userError("Maximum size exceeded", "LuaError")
                        end

                        for x = 1, times do
                            formula = formula + scale
                            len_resulttable = len_resulttable + 1
                            resulttable[orig_index][len_resulttable] = rounding(formula, round[orig_index])
                        end
                        
                        lastvalue = finish
                    end
                else
                	start, finish, times = nil, nil, nil
                    local useformula, doubleto

                    if find(orig[i], "for", 1, true) then
                        useformula, times = orig[i]:match"(.*) *for *([^ ]*)$"
                    end
                    
                    useformula, times = useformula or orig[i], times or ""
                    
                    if lastvalue ~= "" then
                        useformula = gsub(useformula, "then", lastvalue,1)
                    end

                    if pcall(expr, times .. "*2") then
                    	check_for_times = true
                    	times = expr(times)
                	elseif times == "" then
                		check_for_times = true
                        times = nil
                    end
                    
                    local _,occurences = gsub(orig[i],"to","")

                    if check_for_times and occurences > 0 then
                        doubleto = string_to_formula(useformula)
                        useformula = gsub(doubleto,"times",tostring(times or "2"))
                        -- The '2' is a temporary value, until it will later on be switched with the fill one			
                    end
                    
                    times = times or ""

                    if check_for_times and pcall(expr, gsub(useformula, "([%.%d]?)x([%.%d]?)", gsub_x) .. "*2") then
    					if times == "" then
    					    if orig_index == 1 and displayformula == nil and orig[2] == nil and useformula2 == nil then
    					    	if doubleto then
    					    		useformula2 = gsub(doubleto,"times", default_fill)
    					    	else
    					    		useformula2 = useformula
    					    	end
                            end

                            if save_to_index[orig_index] then
                            	check_for_times = false
                            else
                                save_to[orig_index] = {doubleto or useformula}
                                save_to_index[orig_index] = len_resulttable + 1
                                lastvalue = ""
                            end
                        else
                            if orig_index == 1 and displayformula == nil and orig[2] == nil and useformula2 == nil then
                                useformula2 = useformula
                            end
                            
                            count[orig_index] = count[orig_index] - times

                            if count[orig_index] < 0 then
                                return userError("Maximum size exceeded", "LuaError")
                            end

                            for x = 1, times do
                                lastvalue = expr(gsub(useformula, "x", x))
                                len_resulttable = len_resulttable + 1
                                resulttable[orig_index][len_resulttable] = rounding(lastvalue, round[orig_index])
                            end
                        end
                    else
                        check_for_times = false
                    end
                end

                if check_for_times == false then
                    lastvalue = ""
                    count[orig_index] = count[orig_index] - 1

                    if count[orig_index] < 0 then
                        return userError("Maximum size exceeded", "LuaError")
                    end
					
					len_resulttable = len_resulttable + 1
                    resulttable[orig_index][len_resulttable] =  orig[i]
                end
            else
                count[orig_index] = count[orig_index] - 1

                if count[orig_index] < 0 then
                    return userError("Maximum size exceeded", "LuaError")
                end

                local value = (lastvalue == "" and orig[i]) or gsub(orig[i], "then", lastvalue,1)

                if pcall(expr, value .. "*2") then
                    value = expr(value)

                    if find(orig[i+1] or "", "to",1,true) then
                    	lastvalue = ""
                    else
                    	lastvalue = value
                    end

                    value = rounding(value, round[orig_index])
                elseif lastvalue ~= "" then
                    lastvalue = ""
                    value = orig[i]
                end
				
				len_resulttable = len_resulttable + 1
                resulttable[orig_index][len_resulttable] = value
            end

            i = i + 1
        end
    end

    local fill = {default_fill - #resulttable[1], default_fill - #resulttable[2]}

    if default_fill - fill[1] >= default_fill - fill[2] then
        if save_to_index[1] == nil then
            fill[2] = fill[2] - fill[1]
        end
    elseif save_to_index[2] == nil then
        fill[1] = fill[1] - fill[2]
    end
	
	
    if fill[1] < 0 then
        fill[1] = 0
    end
	
    if fill[2] < 0 then
        fill[2] = 0
    end
    
    local insert = table.insert

    for orig_index = 1, #save_to do
    	local to = save_to[orig_index]

        if to[1] then
            if to[2] then
                local lastvalue = to[3]
                local start, finish = to[1], to[2]
                local times = fill[orig_index]
                local scale
                local formula = start

                if lastvalue == start then
                    scale = (finish - start) / times
                else
                    scale = (finish - start) / (times - 1)
                    formula = formula - scale
                end

                count[orig_index] = count[orig_index] - times

                if count[orig_index] < 0 then
                    return userError("Maximum size exceeded", "LuaError")
                end

                for x = 1, times do
                    formula = formula + scale
                    insert(resulttable[orig_index], save_to_index[orig_index] + x - 1, rounding(formula, round[orig_index]))
                end
            else
                local useformula = gsub(to[1],"times",fill[orig_index])
                local times = fill[orig_index]
                count[orig_index] = count[orig_index] - times

                if count[orig_index] < 0 then
                    return userError("Maximum size exceeded", "LuaError")
                end

                for x = 1, times do
                    insert(resulttable[orig_index], save_to_index[orig_index] + x - 1, rounding(expr(gsub(useformula, "x", x)), round[orig_index]))
                end
            end
        end
    end
    
    if #resulttable[2] ~= 0 and #resulttable[1] ~= #resulttable[2] then
    	return userError("Variables are unmatched", "LuaError")
    end

    local s = {}
    local s_len = 1
    s[s_len] = '<span class="pp-tooltip" style="position:relative; border-bottom:1px dotted; cursor:help;'
    
    if args["color"] then
        s_len = s_len + 1
        s[s_len] = " color:" .. require('Module:Color').keyword{args["color"]} .. ";"
    end
    
    s_len = s_len + 1
    s[s_len] = '"'
    
    if label then
        s_len = s_len + 1
        s[s_len] = ' data-bot_label="' .. label .. '"'
    end
    
    if label1 then
        s_len = s_len + 1
        s[s_len] = ' data-top_label="' .. gsub(gsub(label1, "'''", ""), "''", "") .. '"'
    end
    
    if displayformula then
        s_len = s_len + 1
        s[s_len] = ' data-displayformula="' .. displayformula .. '"'
    end
    
    if useformula2 then
        s_len = s_len + 1
        s[s_len] = ' data-useformula="' .. useformula2 .. '"'
    end
    
    if resulttable[1] then
        s_len = s_len + 1
        s[s_len] = ' data-bot_values="' .. concat(resulttable[1],";") .. '"'
    end
    
    if resulttable[2] then
        s_len = s_len + 1
        s[s_len] = ' data-top_values="' .. concat(resulttable[2],";") .. '"'
    end
    
    if key ~= "" then
        s_len = s_len + 1
        s[s_len] = ' data-bot_key="' .. key .. '"'
    end
    
    if key1 then
        s_len = s_len + 1
        s[s_len] = ' data-top_key="' .. key1 .. '"'
    end
    
    if special_displayformula_values[1][1] or special_displayformula_values[2][1] then
        s_len = s_len + 1
        s[s_len] = (
            ' data-start="' .. (special_displayformula_values[1][1] or "") .. ";" .. (special_displayformula_values[2][1] or "") .. '"' .. 
            ' data-finish="' .. (special_displayformula_values[1][2] or "") .. ";" .. (special_displayformula_values[2][2] or "") .. '"')
    end
    
    s_len = s_len + 1
    s[s_len] = ">"

    if (countstatic - count[1] > 5 and args["changedisplay"] ~= "true") or (countstatic - count[1] <= 5 and args["changedisplay"] == "true") then
        s_len = s_len + 1
        s[s_len] = fd(resulttable[1][1] or "NULL") .. key .. " &minus; " .. fd(resulttable[1][#resulttable[1]] or "NULL")  .. key
    else
        s_len = s_len + 1
        s[s_len] = fdmulti(concat(resulttable[1]," / ")) .. key
    end
    
    if args["showtype"] ~= "false" then
        s_len = s_len + 1
        s[s_len] = " (based on " .. (args["type"] or args["label1"] or "level") .. ")" 
    end
    
    s_len = s_len + 1
    s[s_len] = "</span>"
     
    return concat(s)
end

function p.pptooltip(frame)
    local args = frame.args[1] and frame.args or frame:getParent().args

    local label             = (args["bot_label"] == "" and "value") or args["bot_label"]
    local label1            = (args["top_label"] == "" and "level") or args["top_label"]
    local key               = args["bot_key"]
    local key1              = args["top_key"]
    local displayformula    = args["displayformula"]
    local useformula        = args["useformula"]
    local start             = lib.split(args["start"], ";", true)
    local start2,start3     = (tonumber(start[1]) or ""), (tonumber(start[2]) or "")
    local finish            = lib.split(args["finish"], ";", true)
    local finish2,finish3   = (tonumber(finish[1]) or ""), (tonumber(finish[2]) or "")
    
    local formulalabel1 	= gsub(label1, "[%[%]]", "")
    
    local orig  			= lib.split(args["bot_values"], ";", true)
    local orig1 			= lib.split(args["top_values"], ";", true)
    
    local s = {}
    local s_len = 0
    local i = 1

    while (orig1[i] and orig1[i] ~= "") or (orig[i] and orig[i] ~= "") do
        s_len = s_len + 1
        s[s_len] = '</th><th style="text-align: center;">'
        
        if orig1[1] == "" then
            s_len = s_len + 1
            s[s_len] = i
        else
            s_len = s_len + 1
            s[s_len] = fd(orig1[i] or "")
            
            if pcall(expr, (orig1[i] or "") .. "*2") then
                s_len = s_len + 1
                s[s_len] = key1
            end
        end

        i = i + 1
    end

    s_len = s_len + 1
    s[s_len] = '</th></tr><tr><th style="text-align: center;">' .. mw.ustring.gsub(label, "^.", mw.ustring.upper) .. '</th>'
    
    i = 1

    while orig[i] and orig[i] ~= "" do
        s_len = s_len + 1
        s[s_len] = '<td>' .. fd(orig[i])

        if pcall(expr, orig[i] .. "*2") then
            s_len = s_len + 1
            s[s_len] = key
        end

        s_len = s_len + 1
        s[s_len] = '</td>'
        i = i + 1
    end
    
    s_len = s_len + 1
    s[s_len] = '</tr></table>'
    
    s = concat(s)

    local formula = {}
    local len_formula = 0
    
    if displayformula ~= "" then
        len_formula = len_formula + 1
        formula[len_formula] = "'''Formula:''' " .. displayformula
    elseif orig1[1] ~= "" then
        if start2 ~= "" and start3 ~= "" then
        	local orig1_len = #orig1
            local scale  = (finish2 - start2) / (orig1_len - 1)
            local scale1 = (finish3 - start3) / (orig1_len - 1)

            len_formula = len_formula + 1
            formula[len_formula] = "'''Formula:''' "

            if start2 ~= 0 then
                len_formula = len_formula + 1
                formula[len_formula] = start2 .. key

                if scale >= 0 then
                    len_formula = len_formula + 1
                    formula[len_formula] = "+"
                end
            end

            if label1 == "level" then
                len_formula = len_formula + 1
                formula[len_formula] = scale .. key .. " for every "

                if abs(scale1) ~= 1 then
                    len_formula = len_formula + 1
                    formula[len_formula] = scale1
                end

                len_formula = len_formula + 1
                formula[len_formula] = key1 .. " " .. label1

                if scale1 > 1 then
                    len_formula = len_formula + 1
                    formula[len_formula] = "s"
                end

                if start3 ~= 0 and start3 ~= 1 then
                	len_formula = len_formula + 1
                    formula[len_formula] = " starting from " .. label1 .. " " .. start3 .. key1 .. " and"
                else
                	len_formula = len_formula + 1
                    formula[len_formula] = ","
                end

                len_formula = len_formula + 1
                formula[len_formula] = " capped at " .. label1 .. " " .. finish3 .. key1
            else
            	local label1_len = #label1

                len_formula = len_formula + 1
                formula[len_formula] = scale .. key .. " for every "

                if abs(scale1) ~= 1 then
                    len_formula = len_formula + 1
                    formula[len_formula] = scale1
                end

                len_formula = len_formula + 1
                formula[len_formula] = key1 .. " "

                if scale1 ~= 1 then
                	len_formula = len_formula + 1
                    formula[len_formula] = label1

                    if sub(formulalabel1, -1) ~= "s" then
                        len_formula = len_formula + 1
                        formula[len_formula] = "s"
                    end
                elseif sub(formulalabel1, -1) == "s" then
                    if sub(label1, -1) == "s" then
                    	len_formula = len_formula + 1
                        formula[len_formula] = sub(label1, 1, label1_len - 1)
                    else
                    	len_formula = len_formula + 1
                        formula[len_formula] = sub(label1, 1, label1_len - 3)
                    end
                else
                	len_formula = len_formula + 1
                    formula[len_formula] = label1
                end

                if start3 ~= 0 and start3 ~= 1 then
                	len_formula = len_formula + 1
                    formula[len_formula] = " starting from " .. start3 .. key1 .. " "

                    if start3 ~= 1 then
                    	len_formula = len_formula + 1
                        formula[len_formula] = label1

                        if sub(formulalabel1, -1) ~= "s" then
                            len_formula = len_formula + 1
                            formula[len_formula] = "s"
                        end
                    elseif sub(formulalabel1, -1) == "s" then
                        if sub(label1, -1) == "s" then
                        	len_formula = len_formula + 1
                            formula[len_formula] = sub(label1, 1, label1_len - 1)
                        else
                        	len_formula = len_formula + 1
                            formula[len_formula] = sub(label1, 1, label1_len - 3)
                        end
                    else
                    	len_formula = len_formula + 1
                        formula[len_formula] = label1
                    end

                    len_formula = len_formula + 1
                    formula[len_formula] = " and"
                else
                	len_formula = len_formula + 1
                    formula[len_formula] = ","
                end

                len_formula = len_formula + 1
                formula[len_formula] = " capped at " .. finish3 .. key1 .. " "

                if finish3 ~= 1 then
                	len_formula = len_formula + 1
                    formula[len_formula] = label1

                    if sub(formulalabel1, -1) ~= "s" then
                        len_formula = len_formula + 1
                        formula[len_formula] = "s"
                    end
                elseif sub(formulalabel1, -1) == "s" then
                    if sub(label1, -1) == "s" then
                    	len_formula = len_formula + 1
                        formula[len_formula] = sub(label1, 1, label1_len - 1)
                    else
                    	len_formula = len_formula + 1
                        formula[len_formula] = sub(label1, 1, label1_len - 3)
                    end
                else
                	len_formula = len_formula + 1
                    formula[len_formula] = label1
                end
            end
        end
    else
        if start2 ~= "" then
            local scale = (finish2 - start2) / (#orig - 1)
            len_formula = len_formula + 1
            formula[len_formula] = "'''Formula:''' "

            if tonumber(tostring(start2)) == tonumber(tostring(scale)) then
            	len_formula = len_formula + 1
                formula[len_formula] = start2 .. key .. "&#42;" .. label1
            elseif len(sub(scale,find(scale,".",1,true) or 1)) <= 4 then
            	len_formula = len_formula + 1
                formula[len_formula] = (start2 - scale) .. key

	            if scale >= 0 then
                	len_formula = len_formula + 1
                    formula[len_formula]  = "+"

                    if scale == 1 then
                    	len_formula = len_formula + 1
                        formula[len_formula] = label1
                    else
                    	len_formula = len_formula + 1
                        formula[len_formula] = scale .. key .. "&#42;" .. label1
                    end
                elseif scale == -1 then
                	len_formula = len_formula + 1
                    formula[len_formula] = "-" .. label1
                else
                	len_formula = len_formula + 1
                    formula[len_formula] = scale .. key .. "&#42;" .. label1
                end
	        else
	        	len_formula = len_formula + 1
	        	formula[len_formula] = start2 .. key
	        	
	        	if finish2 - start2 >= 0 then
	    			len_formula = len_formula + 1
	        		formula[len_formula] = "+"
	        	end

	        	len_formula = len_formula + 1
	        	formula[len_formula] = (finish2 - start2) .. key .. "/" .. (#orig - 1) .. "&#42;(" .. label1 .. "-1)"
            end
        elseif useformula ~= "" then
            len_formula = len_formula + 1
            formula[len_formula] = "'''Formula:''' " .. useformula
        end
    end
    
    formula = concat(formula)
    
    if displayformula == "" then
        formula = gsub(gsub(gsub(gsub(gsub(formula, "%/", " &divide; "), "%*", "&#42;"), "&#42;", " &times; "), "%+", " + "), "%-", " &minus; ")

        if useformula ~= "" then
            formula = gsub(formula, "x", label1)
        end
    else
        formula = gsub(gsub(gsub(gsub(gsub(formula, "%/", "&divide;"), "%*", "&#42;"), "&#42;", "&times;"), "%+", "+"), "%-", "&minus;")
    end
    
    formula = fdmulti(formula)

	return (
		'<div ' .. (formula == "" and "" or 'class="blue-tooltip" ') .. 'style="padding: 10px;">' .. formula .. 
        '<table class="wikitable" style="text-align: center; table-layout: fixed; margin: 0;">' .. 
        '<tr><th style="text-align: center;">' .. mw.ustring.gsub(label1, "^.", mw.ustring.upper) ..
        s .. "</div>"
    )
end

function p.ap(frame)
    local args = (frame.args and lib.arguments(frame.args)) or lib.arguments(frame)

	local userError = require('Dev:User error')
    local orig  	= args
    local count 	= 6
    local round 	= args["round"] or nil
	local fill		= (args["skill"] ~= "R" and 5) or 3

    local resulttable = {}
    local len_resulttable = 0
	local i = 1

    while orig[i] and orig[i] ~= "" do
    	local temp_find_to = find(orig[i], "to", 1, true)
		local temp_find_x = find(orig[i], "x", 1, true)

        if (temp_find_to or temp_find_x) and find(orig[i], "<", 1, true) == nil then
        	local start, finish, times
        	
        	if temp_find_to then
	        	start = sub(orig[i], 1, temp_find_to - 1)
	            finish, times = orig[i]:match".* *to *([^ ]*) *([^ ]*)$"
	        end

            start, finish, times = start or "", finish or "", times or ""
            local check_for_times = false
            
            if temp_find_x == nil and pcall(expr, start .. "*2") and pcall(expr, finish .. "*2") and 
            (pcall(expr, times .. "*2") or times == "") then
            	check_for_times = true
                start = expr(start)
                finish = expr(finish)

                if times == "" then
                    if fill ~= 0 then
                        times = fill
                        fill = 0
                    else
                        check_for_times = false
                    end
                else
                    times = expr(times)
                end
                
                if check_for_times then
                    count = count - times

                    if count < 0 then
                        return userError("Maximum size exceeded", "LuaError")
                    end
					
                    local scale = (finish - start) / (times - 1)
                    local formula = start - scale

                    for x = 1, times do
                        formula = formula + scale
                        len_resulttable = len_resulttable + 1
                        resulttable[len_resulttable] = rounding(formula, round)
                    end
                end
            else
                local useformula,times = orig[i]:match"(.*[0-9x%)]) +([^ ]*)$"
				useformula, times = useformula or orig[i], times or ""
				
				if pcall(expr, times .. "*2") then
					check_for_times = true
					times = expr(times)
				elseif times == "" and fill ~= 0 then
					check_for_times = true
                    times = fill
                    fill = 0
	            end

                local _,occurences = gsub(orig[i],"to","")

                if check_for_times and occurences > 0 then
                    useformula = gsub(string_to_formula(useformula),"times",tostring(times))
                end

                if check_for_times and pcall(expr, gsub(useformula, "([%.%d]?)x([%.%d]?)", gsub_x) .. "*2") then
                    count = count - times

                    if count < 0 then
                        return userError("Maximum size exceeded", "LuaError")
                    end

                    for x = 1, times do
                    	len_resulttable = len_resulttable + 1
                        resulttable[len_resulttable] =  rounding(expr(gsub(useformula, "x", x)), round)
                    end
                else
                    check_for_times = false
                end
            end

            if check_for_times == false then
                count = count - 1

                if count < 0 then
                    return userError("Maximum size exceeded", "LuaError")
                end
				
				len_resulttable = len_resulttable + 1
                resulttable[len_resulttable] = orig[i]
            end
        else
            count = count - 1

            if count < 0 then
                return userError("Maximum size exceeded", "LuaError")
            end

            local value = (pcall(expr, orig[i] .. "*2") and rounding(orig[i], round)) or orig[i]

			len_resulttable = len_resulttable + 1
            resulttable[len_resulttable] = value
        end

        i = i + 1
    end

    return fdmulti(concat(resulttable," / "))
end

return p

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