Module:Decoration

local p = {} local deco =mw.loadData('Module:Decoration/data')

function range(a, b, step) if not b then b = a   a = 1 end step = step or 1 local f = step > 0 and function(_, lastvalue) local nextvalue = lastvalue + step if nextvalue <= b then return nextvalue end end or   step < 0 and function(_, lastvalue) local nextvalue = lastvalue + step if nextvalue >= b then return nextvalue end end or     function(_, lastvalue) return lastvalue end return f, nil, a - step end

function bonus(data,step) local bonus = data.bonus local op = data.operation local bonusi = 0 local c = 0 if (type(data.bonusi) == "string" and string.match(data.bonusi, "every")~="every") then return data.bonusi elseif string.match(data.bonusi, "every") then bonusi= data.bonusi:gsub("every","") bonusi = tonumber(bonusi) if step%bonusi==0 then for i in range(0,step+1) do               if i%bonusi==0 then c=c+1 end end return c..op        else return "/" end elseif (type(data.bonusi) ~= "number" and type(data.bonusi) ~= "boolean" and type(data.bonusi) ~= "nil")then for i, j in pairs(data.bonusi) do           if  (type(j) == "string" and step == 0) then return j end if j==step then return (bonus+(j*step))..op       end end return "/" else bonusi=data.bonusi return (bonus+(bonusi*step))..op   end end

function check(num) if num == nil then return "Please insert data to Module:Decoration/data" end return num end

function p.infobox(frame) local name = mw.title.getCurrentTitle.text local char_data=deco[name] if char_data == nil then return " Please insert data to Module:Decoration/data." end local data = {} local infobox = { image = frame:expandTemplate {title = 'Decoration images'}, benefit = char_data.benefit, max_level = char_data.maxlvl }   table.insert(data, frame:expandTemplate { title = 'Decoration info', args = infobox }) table.insert(data, frame:expandTemplate { title = 'Clear'}) return table.concat(data, '\n') end

function p.stats(frame) local name =mw.title.getCurrentTitle.text local deco_data = deco[name] if deco_data == nil then return "Please insert data to Module:Decoration/data" end local data = { '{| class="wikitable" style="float: left; text-align: center; width:100%;"', '|-',       '! LvL', '! Bonus', '! Prestige', '! Cost', '|-'   }    for i in range(0,deco_data.maxlvl-1) do        if (i+1)==deco_data.maxlvl then num = (i+1).." MAX LVL" else num = i+1 end table.insert(data, '| '..num) table.insert(data, '| '..bonus(deco_data,i)) table.insert(data, '| '..deco_data.prestige+(deco_data.prestigei*i)) table.insert(data, '| '..check(deco_data.cost[i+1])) table.insert(data, '|-') end table.insert(data, '|}') for i, j in pairs(data) do mw.log(j) end return table.concat(data, '\n') end

function p.list(frame) return "" end

return p