FANDOM


-- <nowiki>
local p = {}
 
-- pretty map display
function p.main(frame)
	local wave = tonumber(frame.args[1])
	return make_map(wave)
end
 
-- main map is 36x36 
-- shrinks 4 squares each time, each wall moves in 2 squares
local map_data = {
	-- wall locations
	walls = {
			{2,25},{3,25},{4,25},{5,25},{6,25},{7,25},
			{11,2},{11,3},{11,4},{11,5},{12,5},{10,5},{9,5},
			{18,19},{18,20},
			{22,30},{22,31},{22,32},{22,33},
			{37,13},{36,13},{35,13},{34,13},{33,13},{32,13},
			{37,26},{36,26},{35,26},{34,26},{33,26},{33,25}
	},
	-- shrinkage
	-- waves 1–10
	map_a = 1,
	-- waves 11–20
	map_b = 3,
	-- waves 21–30
	map_c = 5,
	-- waves 31–33
	map_d = 7,
	-- waves 34–36 & aken
	map_e = 9
}
 
-- spawn locations
local loc_data = {
	['ne1'] = { 3, -3 },
	['ne2'] = { 2, -2 },
	['ne3'] = { 1, -1 },
	['nw1'] = { 3, 3 },
	['nw2'] = { 2, 2 },
	['nw3'] = { 1, 1 },
	['se1'] = { -3, -3 },
	['se2'] = { -2, -2 },
	['se3'] = { -1, -1 },
	['sw1'] = { -3, 3 },
	['sw2'] = { -2, 2 },
	['sw3'] = { -1, 1 },
	-- har aken
	['ha'] = { -23, -12 }
}
 
-- monster/tile shorthand names
local td = {
	-- Ranged monsters
	['r1'] = { name = 'TokHaar-Xil', style = { background = '#00FF00' } },
	['r2'] = { name = 'TokHaar-Tok-Xil', style = { background = '#008800' } },
	-- Melee monsters
	['m1'] = { name = 'TokHaar-Hur', style = { background = '#FF8800' } },
	['m2'] = { name = 'TokHaar-Ket', style = { background = '#AA6600' } },
	['m3'] = { name = 'TokHaar-Yt-MejKot', style = { background = '#CC0000' } },
	-- Magic monsters
	['x1'] = { name = 'TokHaar-Mej', style = { background = '#0000FF' } },
	['x2'] = { name = 'TokHaar-Ket-Zek', style = { background = '#000077' } },
	-- Misc
	['d'] = { name = 'TokHaar-Ket-Dill', style = { background = '#FFFF44' } },
	['j'] = { name = 'TokHaar-Jad', style = { background = '#CC00CC' } },
	['ha'] = { name = 'Har-Aken', style = { background = '#880088' } },
	-- Crystals
	['ci'] = { name = 'Crystal (invulnerability)', style = { background = '#4DFDE8' } },
	['cc'] = { name = 'Crystal (constitution)', style = { background = '#8D48ED' } },
	['cm'] = { name = 'Crystal (magic)', style = { background = '#474BEA' } },
	['cr'] = { name = 'Crystal (ranged)', style = { background = '#4CFA50' } },
	['cs'] = { name = 'Crystal (strength)', style = { background = '#F5F0F0' } },
	['ch'] = { name = 'Crystal (restoration)', style = { background = '#FA574C' } },
	-- Other
	-- lava
	['l'] = { name = nil, style = { background = '#FFE417' } },
	-- wall
	['w'] = { name = nil, style = { background = '#C0C1C1' } },
	-- blank tile (floor)
	['x'] = { name = nil, style = { background = '#2D2929' } }
}
 
-- monsters and their locations, crystal too
local wave_data = {
	-- 1-10
	[1] = {
			crystal = nil,
			map = 'map_a',
			monsters = {
				{ n = 'r1', loc = 'ne1' },
				{ n = 'r1', loc = 'nw1' },
				{ n = 'r2', loc = 'se2' },
				{ n = 'm1', loc = 'sw1' },
				{ n = 'm1', loc = 'se1' }
			}
	},
	[2] = {
			crystal = 'ci',
			map = 'map_a',
			monsters = {
				{ n = 'r1', loc = 'nw1' },
				{ n = 'r1', loc = 'nw2' },
				{ n = 'r2', loc = 'ne1' },
				{ n = 'r2', loc = 'se2' },
				{ n = 'm1', loc = 'se1' }
			}
	},
	[3] = {
			crystal = nil,
			map = 'map_a',
			monsters = {
				{ n = 'r1', loc = 'sw1' },
				{ n = 'r2', loc = 'ne1' },
				{ n = 'r2', loc = 'nw1' },
				{ n = 'r2', loc = 'se2' },
				{ n = 'm1', loc = 'se1' }
			}
	},
	[4] = {
			crystal = 'ch',
			map = 'map_a',
			monsters = {
				{ n = 'r2', loc = 'nw1' },
				{ n = 'r2', loc = 'sw2' },
				{ n = 'r2', loc = 'se1' },
				{ n = 'x1', loc = 'ne1' },
				{ n = 'x1', loc = 'se2' }
			}
	},
	[5] = {
			crystal = nil,
			map = 'map_a',
			monsters = {
				{ n = 'r1', loc = 'se1' },
				{ n = 'r2', loc = 'nw1' },
				{ n = 'r2', loc = 'sw1' },
				{ n = 'r2', loc = 'se2' },
				{ n = 'd', loc = 'ne1' }
			}
	},
	[6] = {
			crystal = 'cm',
			map = 'map_a',
			monsters = {
				{ n = 'r1', loc = 'se1' },
				{ n = 'r2', loc = 'nw1' },
				{ n = 'r2', loc = 'sw1' },
				{ n = 'r2', loc = 'sw2' },
				{ n = 'x1', loc = 'ne1' },
				{ n = 'x1', loc = 'se2' }
			}
	},
	[7] = {
			crystal = nil,
			map = 'map_a',
			monsters = {
				{ n = 'r1', loc = 'se2' },
				{ n = 'r2', loc = 'ne1' },
				{ n = 'r2', loc = 'nw1' },
				{ n = 'r2', loc = 'sw1' },
				{ n = 'r2', loc = 'sw2' },
				{ n = 'x1', loc = 'se1' }
			}
	},
	[8] = {
			crystal = 'cr',
			map = 'map_a',
			monsters = {
				{ n = 'r2', loc = 'nw1' },
				{ n = 'r2', loc = 'sw1' },
				{ n = 'x2', loc = 'se1' },
			}
	},
	[9] = {
			crystal = nil,
			map = 'map_a',
			monsters = {
				{ n = 'r2', loc = 'ne1' },
				{ n = 'r2', loc = 'nw1' },
				{ n = 'r2', loc = 'sw1' },
				{ n = 'r2', loc = 'sw2' },
				{ n = 'r2', loc = 'se1' },
				{ n = 'r2', loc = 'se2' }
			}
	},
	[10] = {
			crystal = 'cs',
			map = 'map_a',
			monsters = {
				{ n = 'j', loc = 'sw1' },
				{ n = 'r2', loc = 'se1' }
			}
	},
	-- 11-20
	[11] = {
			crystal = nil,
			map = 'map_b',
			monsters = {
				{ n = 'x1', loc = 'ne1' },
				{ n = 'x1', loc = 'nw1' },
				{ n = 'x1', loc = 'sw1' },
				{ n = 'x1', loc = 'se1' }
			}
	},
	[12] = {
			crystal = 'cc',
			map = 'map_b',
			monsters = {
				{ n = 'x1', loc = 'ne1' },
				{ n = 'x1', loc = 'se1' },
				{ n = 'r2', loc = 'nw1' },
				{ n = 'r2', loc = 'sw1' }
			}
	},
	[13] = {
			crystal = nil,
			map = 'map_b',
			monsters = {
				{ n = 'x1', loc = 'nw1' },
				{ n = 'x1', loc = 'sw1' },
				{ n = 'x2', loc = 'se1' }
			}
	},
	[14] = {
			crystal = 'ci',
			map = 'map_b',
			monsters = {
				{ n = 'x1', loc = 'ne1' },
				{ n = 'x1', loc = 'nw1' },
				{ n = 'x2', loc = 'sw1' },
				{ n = 'x2', loc = 'se1' }
			}
	},
	[15] = {
			crystal = nil,
			map = 'map_b',
			monsters = {
				{ n = 'x2', loc = 'sw1' },
				{ n = 'x2', loc = 'se1' },
				{ n = 'r2', loc = 'nw1' }
			}
	},
	[16] = {
			crystal = 'ch',
			map = 'map_b',
			monsters = {
				{ n = 'x1', loc = 'ne1' },
				{ n = 'x1', loc = 'se2' },
				{ n = 'x2', loc = 'sw1' },
				{ n = 'x2', loc = 'se1' },
				{ n = 'r2', loc = 'nw1' }
			}
	},
	[17] = {
			crystal = nil,
			map = 'map_b',
			monsters = {
				{ n = 'x1', loc = 'se2' },
				{ n = 'x2', loc = 'sw1' },
				{ n = 'x2', loc = 'se1' },
				{ n = 'r2', loc = 'nw1' },
				{ n = 'm3', loc = 'ne1' }
			}
	},
	[18] = {
			crystal = 'cm',
			map = 'map_b',
			monsters = {
				{ n = 'x1', loc = 'sw2' },
				{ n = 'x2', loc = 'sw1' },
				{ n = 'x2', loc = 'se1' },
				{ n = 'r2', loc = 'nw1' },
				{ n = 'r2', loc = 'se2' },
				{ n = 'm3', loc = 'ne1' }
			}
	},
	[19] = {
			crystal = nil,
			map = 'map_b',
			monsters = {
				{ n = 'x1', loc = 'ne1' },
				{ n = 'x1', loc = 'nw1' },
				{ n = 'x1', loc = 'nw2' },
				{ n = 'x1', loc = 'sw1' },
				{ n = 'x1', loc = 'sw2' },
				{ n = 'x1', loc = 'se1' },
				{ n = 'x1', loc = 'se2' },
				{ n = 'x1', loc = 'se3' },
				{ n = 'd', loc = 'ne2' }
			}
	},
	[20] = {
			crystal = 'cr',
			map = 'map_b',
			monsters = {
				{ n = 'j', loc = 'sw1' },
				{ n = 'x2', loc = 'se1' }
			}
	},
	-- 21-30
	[21] = {
			crystal = nil,
			map = 'map_c',
			monsters = {
				{ n = 'm1', loc = 'ne1' },
				{ n = 'm1', loc = 'ne2' },
				{ n = 'm1', loc = 'ne3' },
				{ n = 'm1', loc = 'nw1' },
				{ n = 'm1', loc = 'nw2' },
				{ n = 'm1', loc = 'nw3' },
				{ n = 'm1', loc = 'sw1' },
				{ n = 'm1', loc = 'sw2' },
				{ n = 'm1', loc = 'sw3' },
				{ n = 'm1', loc = 'se1' },
				{ n = 'm1', loc = 'se2' },
				{ n = 'm1', loc = 'se3' }
			}
	},
	[22] = {
			crystal = 'cs',
			map = 'map_c',
			monsters = {
				{ n = 'm1', loc = 'sw1' },
				{ n = 'm1', loc = 'se1' },
				{ n = 'm2', loc = 'ne1' },
				{ n = 'm2', loc = 'nw1' },
				{ n = 'm3', loc = 'se2' }
			}
	},
	[23] = {
			crystal = nil,
			map = 'map_c',
			monsters = {
				{ n = 'm1', loc = 'sw1' },
				{ n = 'm1', loc = 'se1' },
				{ n = 'm2', loc = 'nw1' },
				{ n = 'm3', loc = 'ne1' },
				{ n = 'm3', loc = 'se2' }
			}
	},
	[24] = {
			crystal = 'cc',
			map = 'map_c',
			monsters = {
				{ n = 'm3', loc = 'ne1' },
				{ n = 'm3', loc = 'sw1' },
				{ n = 'm3', loc = 'se1' },
				{ n = 'm3', loc = 'se2' },
				{ n = 'r2', loc = 'nw1' }
			}
	},
	[25] = {
			crystal = nil,
			map = 'map_c',
			monsters = {
				{ n = 'm3', loc = 'sw1' },
				{ n = 'm3', loc = 'se1' },
				{ n = 'r2', loc = 'ne1' },
				{ n = 'r2', loc = 'nw1' },
				{ n = 'x2', loc = 'se2' }
			}
	},
	[26] = {
			crystal = 'ci',
			map = 'map_c',
			monsters = {
				{ n = 'm3', loc = 'sw1' },
				{ n = 'm3', loc = 'se1' },
				{ n = 'r2', loc = 'nw1' },
				{ n = 'x2', loc = 'ne1' },
				{ n = 'x2', loc = 'se2' }
			}
	},
	[27] = {
			crystal = nil,
			map = 'map_c',
			monsters = {
				{ n = 'm2', loc = 'sw1' },
				{ n = 'm2', loc = 'se1' },
				{ n = 'm3', loc = 'sw2' },
				{ n = 'm3', loc = 'se2' },
				{ n = 'r2', loc = 'nw1' },
				{ n = 'x2', loc = 'ne1' }
			}
	},
	[28] = {
			crystal = 'ch',
			map = 'map_c',
			monsters = {
				{ n = 'd', loc = 'ne1' },
				{ n = 'd', loc = 'nw1' },
				{ n = 'd', loc = 'sw1' },
				{ n = 'd', loc = 'sw2' },
				{ n = 'd', loc = 'se1' },
				{ n = 'd', loc = 'se2' },
				{ n = 'x2', loc = 'nw2' }
			}
	},
	[29] = {
			crystal = nil,
			map = 'map_c',
			monsters = {
				{ n = 'm3', loc = 'ne1' },
				{ n = 'm3', loc = 'nw1' },
				{ n = 'm3', loc = 'sw1' },
				{ n = 'm3', loc = 'sw2' },
				{ n = 'm3', loc = 'se1' },
				{ n = 'm3', loc = 'se2' }
			}
	},
	[30] = {
			crystal = 'cm',
			map = 'map_c',
			monsters = {
				{ n = 'm3', loc = 'ne1' },
				{ n = 'm3', loc = 'nw1' },
				{ n = 'm3', loc = 'se1' },
				{ n = 'j', loc = 'sw1' }
			}
	},
	-- 31-33
	[31] = {
			crystal = nil,
			map = 'map_d',
			monsters = {
				{ n = 'r2', loc = 'ne1' },
				{ n = 'r2', loc = 'nw1' },
				{ n = 'r2', loc = 'sw1' },
				{ n = 'r2', loc = 'se1' }
			}
	},
	[32] = {
			crystal = 'cr',
			map = 'map_d',
			monsters = {
				{ n = 'm3', loc = 'ne1' },
				{ n = 'm3', loc = 'nw1' },
				{ n = 'm3', loc = 'sw1' },
				{ n = 'm3', loc = 'se1' }
			}
	},
	[33] = {
			crystal = nil,
			map = 'map_d',
			monsters = {
				{ n = 'x2', loc = 'ne1' },
				{ n = 'x2', loc = 'nw1' },
				{ n = 'x2', loc = 'sw1' },
				{ n = 'x2', loc = 'se1' }
			}
	},
	-- 34 - 36 + Aken
	[34] = {
			crystal = 'cs',
			map = 'map_e',
			monsters = {
				{ n = 'j', loc = 'se1' },
				{ n = 'm3', loc = 'nw1' },
				{ n = 'r2', loc = 'sw1' }
			}
	},
	[35] = {
			crystal = nil,
			map = 'map_e',
			monsters = {
				{ n = 'j', loc = 'ne1' },
				{ n = 'm3', loc = 'nw1' },
				{ n = 'r2', loc = 'sw1' },
				{ n = 'x2', loc = 'se1' }
			}
	},
	[36] = {
			crystal = 'cc',
			map = 'map_e',
			monsters = {
				{ n = 'j', loc = 'sw1' },
				{ n = 'j', loc = 'se1' }
			}
	},
	[37] = {
			crystal = nil,
			map = 'map_e',
			monsters = {
				{ n = 'ha', loc = 'ha' }
			}
	}
}
 
-- pretty map display
function make_map(wave)
	-- fetch data
	local _data = wave_data[wave]
	local s = map_data[_data.map]
 
	-- create base outline
	local builder = {}
	local ret = mw.html.create('table')
					:css({ ['border-collapse'] = 'collapse' })
					:tag('caption')
						:tag('b')
							:wikitext('Wave '..wave)
						:done()
					:done()
 
	-- build base map
	for i=1,38 do
		local row = {}
		for j=1,38 do
			-- blank floor
			-- check if in bounds
			if i > s and i < 39 - s and
				j > s and j < 39 - s then
					table.insert(row,td.x)
			else -- Lava
					table.insert(row,td.l)
			end
		end
		table.insert(builder,row)
	end
 
	-- add walls
	for _, v in ipairs(map_data.walls) do
		local i,j = v[1],v[2]
		if i > s and i < 39 - s and
			j > s and j < 39 - s then
				builder[i][j] = td.w
		end
	end
 
	-- Monster counts
	local m_counts = {
		['r1'] = 0,
		['r2'] = 0,
	-- Melee monsters
		['m1'] = 0,
		['m2'] = 0,
		['m3'] = 0,
	-- Magic monsters
		['x1'] = 0,
		['x2'] = 0,
	-- Misc
		['d'] = 0,
		['j'] = 0,
		['ha'] = 0
	}
 
	-- count monsters
	for _, v in ipairs(_data.monsters) do
		m_counts[v.n] = m_counts[v.n] + 1
		local r,c = unpack(loc_data[v.loc])
 
		-- calculate spawn location
		if r < 0 then
			r = 39 - s + r
		else
			r = s + r
		end
		if c < 0 then
			c = 39 - s + c
		else
			c = s + c
		end
 
		-- add into builder map
		builder[r][c] = td[v.n]
	end
 
	-- helper function to create monster names
	local function msquare(n,c)
		local _ret = {
			'<span style="padding-left:3px; border-left: 14px solid ',
			n.style.background,
			';">',
			c or '',
			' [[',
			n.name,
			']]',
			'</span>'
		}
		return table.concat(_ret,'')
	end
 
	local m_ret = {}
 
	-- add crystal if there (always the same spawn location)
	if _data.crystal then
		builder[19][20] = td[_data.crystal]
		-- add to monster list
		table.insert(m_ret,msquare(td[_data.crystal]))
	end
 
	-- monster list
	for n, v in pairs(m_counts) do
		-- Adding monsters
		if v > 0 then
			table.insert(m_ret,msquare(td[n],v))
		end
	end
 
	-- create map
	for i, v in ipairs(builder) do
		local row = ret:tag('tr')
		for j, w in ipairs(v) do
			local css = w.style
			css.width = '7px'
			css.height = '7px'
			row:tag('td')
				:attr({ title = w.name })
				:css(css)
		end
	end
 
	-- Add monsters
	ret:tag('tr')
			:tag('td')
				:attr('colspan','38')
				:wikitext(table.concat(m_ret,'<br>'))
			:done()
	return tostring(ret)
end
 
-- table display
function p.make_table()
	local ret = mw.html.create('table')
					:addClass('wikitable')
					:tag('tr')
						:tag('th')
							:wikitext('Wave')
						:done()
						:tag('th')
							:wikitext('Monsters')
						:done()
						:tag('th')
							:wikitext('Crystal')
						:done()
					:done()
	for i=1,37 do
		local _data = wave_data[i]
		-- Monster counts
		local m_counts = {
			['r1'] = 0,
			['r2'] = 0,
		-- Melee monsters
			['m1'] = 0,
			['m2'] = 0,
			['m3'] = 0,
		-- Magic monsters
			['x1'] = 0,
			['x2'] = 0,
		-- Misc
			['d'] = 0,
			['j'] = 0,
			['ha'] = 0
		}
		for _, v in ipairs(_data.monsters) do
			m_counts[v.n] = m_counts[v.n] + 1
		end
		local m_ret = {}
		-- monster names cell
		for n, v in pairs(m_counts) do
			if v > 0 then
				table.insert(m_ret,string.format('%s [[%s]]',v,td[n].name))
			end
		end
 
		ret:tag('tr')
				:tag('th')
					:wikitext(i)
				:done()
				:tag('td')
					:wikitext(table.concat(m_ret,', '))
				:done()
				:tag('td')
					:wikitext(_data.crystal and (
								string.format('[[File:%s.png|link=%s',
									td[_data.crystal].name,td[_data.crystal].name..']]'))
									or 'None')
			:done()
		end
	return ret
end
 
return p

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.