Module:Events

local p = {} local event = mw.loadData('Module:Events/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 compareLess(x, y)   return x[1] < y[1] end function compareMore(x, y)   return x[1] > y[1] end function tableSort(table1,table2,more) for i,v in ipairs(table1) do       table1[i] = {table1[i], table2[i]} end if more == 'less' then table.sort(table1, compareLess) else table.sort(table1, compareMore) end for i, v in ipairs(table1) do       table1[i] = v[1] table2[i] = v[2] end return table2 end function eventSorted(datas, var) local key = {} local keydata = {} local more for name, data in pairs(datas) do       if var == nil then table.insert(key, eventDate(data)) else table.insert(key, data.lvl) more='less' end table.insert(keydata, name) end return tableSort(key,keydata,more) end function eventDate(data) if data.ends[1] ~= nil then return ((((data.ends[3]*100)+data.ends[2])*100)+data.ends[1]) else return 0 end end

function active local currentDate = ((((os.date('*t').year*100)+os.date('*t').month)*100)+os.date('*t').day) for name, data in pairs(event) do       if eventDate(data)-currentDate > 0 then return name end end return nil end

function missingImage(picture) local img = '' if picture == "" then img = 'Missing.jpg' else img = picture end return img end

function p.event(frame) local typ = frame.args[1] local data = {' '} local sorted = eventSorted(event) local active = active local c = 0 if active ~= nil then table.insert(data, '==Current Event==') table.insert(data, '') end for name, dat in pairs(sorted) do       event_data=event[dat] if dat ~= active then if c == 0 then table.insert(data, '==Past Event==') end c = c + 1 if c < 9 or typ~='mainPage' then table.insert(data, '') end end end table.insert(data,' ') for i, dat in pairs(data) do mw.log(dat) end return table.concat(data,"\n") end

function p.event_page(frame) local event_data = event[frame.args[1]] if event_data == nil then return "Please insert data to Module:Events/data" end local data = {} local c = 0 local ch = "" table.insert(data, '==Tasks==') table.insert(data, '{| class="wikitable mw-datatable" style="text-align: center;"') table.insert(data, '|-') table.insert(data, '! Task') table.insert(data, '! Requirement') table.insert(data, '! Skip') table.insert(data, '! Rewards') table.insert(data, '|-') for i, dat in pairs(event_data.tasks) do       if c== 0 then for j, a in pairs(dat.rewards) do c=c+1 end end table.insert(data, '| rowspan='..c..'|'..dat.task) table.insert(data, '| rowspan='..c..'|'..dat.requirements) table.insert(data, '| rowspan='..c..'|'..dat.skip) for j, a in pairs(dat.rewards) do           if a.quantity ~= nil then q=a.quantity..'x ' else q ='' end table.insert(data, '|'..q..a.reward) table.insert(data, '|-') end end table.insert(data, '|}') table.insert(data, '==Rewards==') table.insert(data, "When all tasks are completed you get rewards") table.insert(data, '{| class="wikitable mw-datatable" style="text-align: center;"') table.insert(data, '|-') table.insert(data, '!Rewards') table.insert(data, '|-') for i, dat in pairs(event_data.rewards) do       if dat.quantity ~= nil then q=dat.quantity..'x ' else q = '' end if string.match(dat.reward, "h-scene") then for a,b in pairs(dat.characters) do                if a ~= 1 then ch=ch.." x " end ch=ch..""..b.."" end ch=ch.." " else ch = "" end table.insert(data, '|'..q..""..ch..""..dat.reward) table.insert(data, '|-')

end table.insert(data, '|}') for i, dat in pairs(data) do mw.log(dat) end return table.concat(data,"\n") end return p