Module:Heart of the Mountain

-- local p = {}

local getArgs = require('Module:Arguments').getArgs require('Module:LibraryUtil') local string = require('Module:String')

local title = mw.title.getCurrentTitle.fullText local lang = mw.language.getContentLanguage

local ts = '-4 hours' -- This timestamp value is required to have result shown based on hypixel date reset instead of UTC

-- Invoked directly by Template:Calculator/HotM_perk_powder function p.calcPowderCostForLevel(frame) local args = getArgs(frame) local perk = args[1] or args['perk'] local target = args[2] or args['target'] or args['to'] assertTrue(perk, 'perk must be specified', 0) assertTrue(target, 'Must specify a target level', 0) return p._calcPowderCostForLevel(perk, target) end

function p._calcPowderCostForLevel(perk, target) checkType(1, perk, 'string') checkType(2, target, 'number', true) perk = perk:lower local functionData = { ['crystallized'] =			function(n) return math.floor(math.pow(n+1, 3.4)) end, ['daily powder'] =			function(n) return 182 + 18 * n end, ['efficient miner'] =       function(n) return math.floor(math.pow(n+1, 2.6)) end, ['luck of the cave'] =		function(n) return math.floor(math.pow(n+1, 3.07)) end, ['mining fortune'] =		function(n) return math.floor(math.pow(n+1, 3.05)) end, ['mining speed'] =			function(n) return math.floor(math.pow(n+1, 3)) end, ['orbiter']	=				function(n) return 70 * n end, ['peak of the mountain'] =	function(n) return 25000 * n end, ['quick forge']	=			function(n) return math.floor(math.pow(n+1, 4)) end, ['seasoned mineman'] =		function(n) return math.floor(math.pow(n+1, 2.3)) end, ['titanium insanium'] = 	function(n) return math.floor(math.pow(n+1, 3.1)) end, }	local calc = functionData[perk] assertTrue(calc, 'Invalid perk name specified %q', 0, perk) local powder = 0 for i = 2,target,1 do 		powder = powder + calc(i) end return powder end

-- Invoked directly by Fetchur -- Not really HotM related, but semi related and didn't feel like making a new module function p.currentFetchurFetchQuest(frame) local args = getArgs(frame) -- Fetch Quest is based on current date local date = args[1] or args.date or lang:formatDate('Y-m-d',ts) return p._questItem(date) end

function p._questItem(date) local items = { { 'Yellow Stained Glass', 20, name='Yellow Stained Glass' }, { 'Compass', 1, name='Compass' }, { 'Mithril', 20, name='Mithril' }, { 'Firework Rocket', 1, name='Firework Rocket' }, { 'Cheap Coffee', 1, name='Cheap Coffee or Decent Coffee' }, { 'Oak Door', 1, name='Any Wooden Door or Iron Door' }, { 'Rabbit\'s Foot', 3, name='Rabbit\'s Foot' }, { 'Superboom TNT', 1, name='Superboom TNT' }, { 'Pumpkin', 1, name='Pumpkin' }, { 'Flint and Steel', 1, name='Flint and Steel' }, { 'Nether Quartz Ore', 50, name='Nether Quartz Ore' }, { 'Red Wool', 50, name='Red Wool' }, }	local day = tonumber(lang:formatDate('j',date)) local i = day%(#items) if i == 0 then i = #items end local item = items[i] return mw.html.create('div') :addClass('article-fetchur-request') :tag('span'):addClass('custom-widgetbox-gold') :tag('span') :addClass('plainlinks') :wikitext(lang:formatDate('l',ts), '\'s Request',						' (', string.fullUrl(title, { action='purge' }, 'refresh'), ')'					) :done :tag('hr'):done :wikitext(item[2], 'x', ' ', string.makeImage(item[1], { ext='png', size='x24px', link=item[1] }), ' ', item.name or item[1]) :done :done :done end

function p.fetchurCalendar(frame) local args = getArgs(frame) -- Fetch Quest is based on current date local date = args[1] or args.date or lang:formatDate('Y-m-d',ts) return p._fetchurCalendar(date) end

function p._fetchurCalendar(date) local function lookup(m, y)		local t = { 31, 28 + (((y % 4 == 0 and y % 100 ~= 0) or y % 400 == 0) and 1 or 0), 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 } return t[m] end local function firstDayOfWeek(m, y)		return lang:formatDate('w', ('%s-%s-%s'):format(y, m, 1)) end local function lastDayOfWeek(m, y)		return lang:formatDate('w', ('%s-%s-%s'):format(y, m, lookup(m, y))) end local curr, next, today = {}, {}, {} curr.month = tonumber(lang:formatDate('m',date)) curr.year = tonumber(lang:formatDate('Y',date)) curr.daysInMonth = lookup(curr.month, curr.year) next.month = (curr.month + 1 == 13) and 1 or curr.month + 1 next.year = curr.month == 1 and curr.year + 1 or curr.year next.daysInMonth = lookup(next.month, next.year) today.date = tonumber(lang:formatDate('j',ts)) today.month = tonumber(lang:formatDate('m',ts)) today.year = tonumber(lang:formatDate('Y',ts)) local calendar = mw.html.create('div') :addClass('article-calendar article-fetchur-calendar') :tag('div') :addClass('article-calendar-title') :wikitext('Server Date: ' .. lang:formatDate('F Y',date)) :done local daysOfWeek = {'Sun', 'Mon', 'Tue', 'Wed', 'Thur', 'Fri', 'Sat'} for i = 1, 7 do		calendar:tag('div'):addClass('article-calendar-header'):wikitext(daysOfWeek[i]) end for i = 1, (firstDayOfWeek(curr.month, curr.year) + 1) - 1 do		calendar:tag('div'):addClass('article-calendar-date article-calendar-empty') end for i = 1, curr.daysInMonth do		local isToday = (i == today.date) and (curr.month == today.month) and (curr.year == today.year) calendar:tag('div'):addClass('article-calendar-date' .. (isToday and ' article-calendar-today' or '')):wikitext(i) end for i = 1, 7 - (lastDayOfWeek(curr.month, curr.year) + 1) do		calendar:tag('div'):addClass('article-calendar-date article-calendar-empty') end return string.wrapHtml(tostring(calendar), 'div', { class = 'article-calendar-wrapper' }) end

return p