FANDOM


-- <pre>
-- Split master list alphabetically?
local p = {}
 
local data = mw.loadData('Module:Bestiary/Data')
 
local weaknesses = {
 	ML = 'Melee',
	SL = 'Slash', ST = 'Stab', CR = 'Crush',
	RN = 'Ranged',
	BT = 'Bolts', AW = 'Arrows', TW = 'Thrown',
	MG = 'Magic',
	AR = 'Air', WT = 'Water', ER = 'Earth', FR = 'Fire',
	NA = 'None'
}
function p.main()
	local _d = p.filter_list{ level_filter = level_range(110,200) }
	return wikitable(_d)
end
 
--[=[
-- Filter through a list (specified or master) with
-- user defined functions based on:
-- name, level, weakness, members
-- An example would be:
	p.filter_list{ list = monsters,
			filter_n = function(nm) return nm:find('a') end
	}
-- Which will only add monsters to a new list if it finds a lowercase "a" in the name
--]=]
function p.filter_list(...)
	local args = ...
	local _data = args.list or data
	local filter_n = type(args.name_filter) == 'function' and args.name_filter or nil
	local filter_l =  type(args.level_filter) == 'function' and args.level_filter or nil
	local filter_w =  type(args.weakness_filter) == 'function' and args.weakness_filter or nil
	local filter_m =  type(args.mems_filter) == 'function' and args.mems_filter or nil
 
	local ret = {}
	for _, v in ipairs(_data) do
		local addx = true
		if filter_n then
			if not filter_n(v.name) then
				addx = false
			end
		end
		if filter_l and addx then
			if not filter_l(v.level) then
				addx = false
			end
		end
		if filter_w and addx then
			if not filter_w(v.weakness) then
				addx = false
			end
		end
		if filter_m and addx then
			if not filter_m(v.members) then
				addx = false
			end
		end
		if addx then
			table.insert(ret,v)
		end
	end
	return ret
end
 
function wikitable(_data)
	local ret = mw.html.create('table')
			:addClass('wikitable')
			:tag('tr')
				:tag('th'):wikitext('Monster'):done()
				:tag('th'):wikitext('Level'):done()
				:tag('th'):wikitext('Life points'):done()
				:tag('th'):wikitext('Weakness'):done()
				:tag('th'):wikitext('Members?'):done()
			:done()
	for _, v in ipairs(_data) do
		ret:tag('tr')
			:tag('td'):wikitext('[['..v.name..']]'):done()
			:tag('td'):wikitext(v.level):done()
			:tag('td'):wikitext(v.lifepoints):done()
			:tag('td'):wikitext(weaknesses[v.weakness] or '---'):done()
			:tag('td'):wikitext(v.members and 'Yes' or 'No'):done()
		:done()
	end
	return ret
end
 
--[====[
-- Some basic filters
-- All simple
-- But cleaner to do this if they get used a lot
--]====]
-- level greater than or equal to
function level_gt(x)
	return function(y) return y >= x end
end
 
-- level less than or equal to
function level_lt(x)
	return function(y) return y <= x end
end
 
-- level in range [x,y]
function level_range(x,y)
	return function(z) return z>=x and z<=y end
end
 
-- members only
function mems_only()
	return function(m) return m and m==true end
end
 
-- f2p only
function f2p_only()
	return function(m) return not (m and m==true) end
end
 
function p.cook()
    return data[2000].name
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.