Module:Infobox Monster

-- local p = {}

-- "imports" local onmain = require('Module:Mainonly').on_main local paramtest = require('Module:Paramtest') local yesno = require('Module:Yesno') local commas = require('Module:Addcommas')._add local infobox = require('Module:Infobox')

-- -- Mapping -- local attack_styles = { melee = { image = 'Attack-icon', link = 'Melee' }, ranged = { image = 'Ranged-icon', link = 'Ranged' }, magic = { image = 'Magic-icon', link = 'Magic' }, dragonfire = { image = 'Dragonfire icon', link = 'Dragonfire' }, }

local styles_map = { melee = 'melee', magic = 'magic', mage = 'magic', range = 'ranged', ranged = 'ranged', ranging = 'ranged', dragonfire = 'dragonfire', ['dragon fire'] = 'dragonfire', dragonbreath = 'dragonfire', ['dragon breath'] = 'dragonfire' }

local slay_masters = { turael = { text = 'Turael or Spria', chathead = 'turael chathead', category = 'Monsters assigned by Turael or Spria' }, mazchna = { text = 'Mazchna or Achtryn', chathead = 'mazchna chathead', category = 'Monsters assigned by Mazchna or Achtryn' }, chaeldar = { text = 'Chaeldar', chathead = 'chaeldar chathead', category = 'Monsters assigned by Chaeldar' }, sumona = { text = 'Sumona', chathead = 'sumona chathead', category = 'Monsters assigned by Sumona' }, vannaka = { text = 'Vannaka', chathead = 'vannaka chathead', category = 'Monsters assigned by Vannaka' }, duradel = { text = 'Duradel or Lapalok', chathead = 'duradel chathead', category = 'Monsters assigned by Duradel or Lapalok' }, kuradal = { text = 'Kuradal', chathead = 'kuradal chathead', category = 'Monsters assigned by Kuradal' }, morvran = { text = 'Morvran', chathead = 'morvran chathead', category = 'Monsters assigned by Morvran' }, }

local slay_masters_map = { turael = 'turael', spria = 'turael', mazchna = 'mazchna', achtryn = 'mazchna', chaeldar = 'chaeldar', sumona = 'sumona', vannaka = 'vannaka', duradel = 'duradel', lapalok = 'duradel', kuradal = 'kuradal', morvran = 'morvran', no = 'none', none = 'none', ['n/a'] = 'none', ['not assigned'] = 'none' }

local speeds = { [0] = 'N/A', [1] = '1 tick (0.6s)', [2] = '2 ticks (1.2s)', [3] = '3 ticks (1.8s)', [4] = '4 ticks (2.4s)', [5] = '5 ticks (3.0s)', [6] = '6 ticks (3.6s)', [7] = '7 ticks (4.2s)', [8] = '8 ticks (4.8s)', [9] = '9 ticks (5.4s)' }

local speed_map = { ['1'] = 1,	instant = 1, ['2'] = 2,	['3'] = 3,	['4'] = 4,	fastest = 4, ['5'] = 5,	fast = 5, ['6'] = 6,	average = 6, ['7'] = 7,	slow = 7, ['8'] = 8,	slowest = 8, ['9'] = 9,	abysmal = 9, ['n/a'] = 0, ['0'] = 0 }

-- load weaknesses instead of remapping local weaknesses = mw.loadData('Module:Weakness clickpic/data')

-- Main function called with invokes function p.main(frame) local args = frame:getParent.args local ret = infobox:new(args) local yn_args = { 'aggressive', 'immune_to_poison', 'immune_to_deflect', 'immune_to_stun', 'immune_to_drain' }	local num_args = { 'level', 'slaylvl', 'slayxp', 'max_melee', 'max_ranged', 'max_magic', 'max_spec', 'acc_melee', 'acc_ranged', 'acc_magic', 'armour', 'aff_weakness', 'aff_melee', 'aff_ranged', 'aff_magic' } for _, v in ipairs(yn_args) do		ret:define_params{ { name = v, func = boolargs } } end for _, v in ipairs(num_args) do		ret:define_params{ { name = v, func = { name = numberargs, params = { v, v }, flag = { 'p', 'r' } } }} end ret:define_params{ { name = 'poisonous', func = poisonarg }, { name = 'style', func = stylearg }, { name = 'lifepoints', func = numargcommas }, { name = 'experience', func = numargcommas }, { name = 'hpxp', func = { name = hpxparg, params = { 'experience' } } }, { name = 'weakness', func = weaknessarg }, { name = 'explicit_weakness', func = { name = explicitwkarg, params = { 'weakness' }, flag = 'p' } }, { name = 'abilities', func = abilarg }, { name = 'assigned_by', func = slayerarg }, { name = 'not_assigned', func = { name = notassarg, params = { 'assigned_by' }, flag = 'p' } }, { name = 'release', func = 'release' }, { name = 'removal', func = 'removal' }, { name = 'speed', func = speedarg } }	ret:define_params { { name = 'name', func = function(arg) return paramtest.has_content(arg) and arg or mw.title.getCurrentTitle.fullText end }, { name = 'aka', func = function(arg) return paramtest.has_content(arg) and arg or false end }, { name = 'members', func = function(arg) return paramtest.has_content(arg) and arg or nil end }, { name = 'image', func = function(arg) return paramtest.has_content(arg) and arg or No image end }, { name = 'examine', func = function(arg) return paramtest.has_content(arg) and arg or nil end }, { name = 'slayercat', func = function(arg) return paramtest.has_content(arg) and arg or 'N/A' end } }	ret:create ret:clean_params ret:caption ret:addClass('infobox-monster') ret:defineName('Infobox Monster') -- PARAMETER: image ret:addrow{ { tag = 'argd', content = 'image', css = { ['text-align'] = 'center' }, colspan = '4' } }

-- PARAMETER: release -- (update included automatically by infobox) :addrow{ { tag = 'th', content = 'Release' }, { tag = 'argd', content = 'release', css = { ['text-align'] = 'left' }, colspan = '3' } }

-- PARAMETER: removal if ret:paramdefined('removal') then ret:addrow{ { tag = 'th', content = 'Removal' }, { tag = 'argd', content = 'removal', css = { ['text-align'] = 'left' }, colspan = '3' } } end

-- PARAMETER: aka -- add only if it exists if ret:paramdefined('aka') then ret:addrow{ { tag = 'th', content = 'AKA' }, { tag = 'argd', content = 'aka', css = { ['text-align'] = 'left' }, colspan = '3' } } end -- PARAMETER: members ret:addrow{ { tag = 'th', content = 'Members' }, { tag = 'argd', content = 'members', css = { ['text-align'] = 'left' }, colspan = '3' } } :addrow{ { tag = 'th', content = 'Examine', colspan = '4' } } -- PARAMETER: examine :addrow{ { tag = 'argd', content = 'examine', css = { ['text-align'] = 'left', ['max-width'] = '250px' }, colspan = '4' } }

-- COMBAT INFO :addrow{ { tag = 'th', content = 'Combat info', css = { ['font-variant'] = 'small-caps' }, colspan = '4' } } -- PARAMETER: level | lifepoints | experience | hpxp :addrow{ { tag = 'th', content = 'Level', css = { width = '25%' } }, { tag = 'th', content = 'LP', css = { width = '25%' } }, { tag = 'th', content = ' XP', css = { width = '25%' }, title = 'Combat style experience' }, { tag = 'th', content = ' XP', css = { width = '25%' }, title = 'Constitution experience' } }

{ tag = 'argd', content = 'lifepoints' }, { tag = 'argd', content = 'experience' }, { tag = 'argd', content = 'hpxp' } } -- PARAMETER: aggressive | poisonous :addrow{ { tag = 'th', content = 'Aggressive', colspan = '2' }, { tag = 'th', content = 'Poisonous', colspan = '2' } } :addrow{ { tag = 'argd', content = 'aggressive', colspan = '2' }, { tag = 'argd', content = 'poisonous', colspan = '2' } } -- Slayer information -- dynamic size, dependent on whether or not the monster is assigned local slayer_level = ret:paramdefined('slaylvl','all') local not_assigned = ret:param('not_assigned','f') local _not_assigned = true if not_assigned.d == false then _not_assigned = false elseif not_assigned.switches then for _, v in ipairs(not_assigned.switches) do			if v == false then _not_assigned = false break end end end -- do slayer row if a monster is assigned, or has a required level if _not_assigned == false or slayer_level == true then -- PARAMETER: slaylvl | slayxp | slayercat ret:addrow{ { tag = 'th', content = 'Slayer', class = 'slayer-header', colspan = '4' } } :addrow{ { tag = 'th', content = 'Level' }, { tag = 'th', content = 'XP' }, { tag = 'th', content = 'Category', colspan = '2' } } :addrow{ { tag = 'argd', content = 'slaylvl' }, { tag = 'argd', content = 'slayxp' }, { tag = 'argd', content = 'slayercat', colspan = '2' } } :addrow{ { tag = 'th', content = 'Assigned by', colspan = '4' } } :addrow{ { tag = 'argd', content = 'assigned_by',colspan = '4' } } end -- OFFENSIVE STATS ret:addrow{ { tag = 'th', content = 'Offensive', class = 'offensive-header', colspan = '4' } } :addrow{ { tag = 'th', content = 'Max hit', class = 'offensive-subheader', colspan = '4' } } -- PARAMETER: max_melee | max_ranged | max_magic | max_spec :addrow{ { tag = 'th', content = '', title = 'Maximum melee hit' }, { tag = 'th', content = '', title = 'Maximum ranged hit' }, { tag = 'th', content = '', title = 'Maximum magic hit' }, { tag = 'th', content = '', title = 'Maximum typeless/special hit' } }

{ tag = 'argd', content = 'max_ranged' }, { tag = 'argd', content = 'max_magic' }, { tag = 'argd', content = 'max_spec' } } -- PARAMETER: style | speed :addrow{ { tag = 'th', content = 'Style', class = 'offensive-subheader', colspan = '2' }, { tag = 'th', content = 'Speed', class = 'offensive-subheader', colspan = '2' } }

{ tag = 'argd', content = 'speed', colspan = '2' } }

-- PARAMETER: acc_melee | acc_ranged | acc_magic :addrow{ { tag = 'th', content = 'Accuracy', class = 'offensive-subheader', colspan = '4' } }

--		Accuracy parameters		It's a big job because we need to have a nested table, so it's very hacky	-- local acc_melee, acc_ranged, acc_magic = ret:param('acc_melee','r') , ret:param('acc_ranged','r'), ret:param('acc_magic','r') ret:tag('tr') :addClass('nestedinfo') :tag('td') :attr('colspan','4') :tag('table') :addClass('wikitable') :tag('tr') :tag('th') :attr('title','Melee accuracy as a function of 2.5 * f(x)') :css('width','33%') :wikitext('') :done :tag('th') :attr('title','Ranged accuracy as a function of 2.5 * f(x)') :css('width','33%') :wikitext('') :done :tag('th') :attr('title','Magic accuracy as a function of 2.5 * f(x)') :css('width','33%') :wikitext('') :done :done :tag('tr') -- PARAMETER: melee accuracy :tag('td') :css('width','33%') :wikitext(acc_melee) :attr('data-attr-param','acc_melee') :done -- PARAMETER: ranged accuracy :tag('td') :css('width','33%') :wikitext(acc_ranged) :attr('data-attr-param','acc_ranged') :done -- PARAMETER: magic accuracy :tag('td') :css('width','33%') :wikitext(acc_magic) :attr('data-attr-param','acc_magic') :done :done :done :done :done -- ACCURACY DONE (thank god!) -- PARAMETER: abilities -- only add if they exist local abilities = ret:param('abilities','f') local _abilities = false if abilities.d and abilities.d ~= 'None' then _abilities = true end if abilities.switches then for _, v in ipairs(abilities.switches) do			if v ~= _nil then _abilities = true break end end end if _abilities then ret:addrow{ { tag = 'th', content = 'Abilities used', class = 'offensive-subheader', colspan = '4' } } :addrow{ { tag = 'argd', content = 'abilities', colspan = '4' } }

end -- DEFENSIVE STATS ret:addrow{ { tag = 'th', content = 'Defensive', class = 'defensive-header', colspan = '4' } } -- PARAMETER: armour | weakness :addrow{ { tag = 'th', content = 'Armour', class = 'defensive-subheader', colspan = '2' }, { tag = 'th', content = 'Weakness', class = 'defensive-subheader', colspan = '2' } } :addrow{ { tag = 'argd', content = 'armour', colspan = '2' }, { tag = 'argd', content = 'weakness', colspan = '2' } }

-- PARAMETER: explicit_weakness -- PARAMETER: aff_weakness | aff_melee | aff_ranged | aff_magic :addrow{ { tag = 'th', content = 'Affinities', class = 'defensive-subheader', colspan = '4' } } :addrow{ { tag = 'argh', content = 'explicit_weakness', title = 'Affinity value of the monster\'s explicit weakness' }, { tag = 'th', content = '', title = 'Affinity value of the monster against melee attacks' }, { tag = 'th', content = '', title = 'Affinity value of the monster against ranged attacks' }, { tag = 'th', content = '', title = 'Affinity value of the monster against magic attacks' } } :addrow{ { tag = 'argd', content = 'aff_weakness' }, { tag = 'argd', content = 'aff_melee' }, { tag = 'argd', content = 'aff_ranged' }, { tag = 'argd', content = 'aff_magic' } }

-- PARAMETER: immune_to_poison | immune_to_deflect | immune_to_stun | immune_to_drain :addrow{ { tag = 'th', content = 'Immunities', class = 'defensive-subheader', colspan = '4' } } :addrow{ { tag = 'th', content = '', title = 'Immune to poison' }, { tag = 'th', content = '', title = 'Immune to deflect' }, { tag = 'th', content = '', title = 'Immune to stun' }, { tag = 'th', content = '', title = 'Immune to stat drain' } } :addrow{ { tag = 'argd', content = 'immune_to_poison' }, { tag = 'argd', content = 'immune_to_deflect' }, { tag = 'argd', content = 'immune_to_stun' }, { tag = 'argd', content = 'immune_to_drain' } } ret:finish if onmain then local a1 = ret:param('all') local a2 = ret:categorydata ret:wikitext(addcategories(a1,a2)) end return ret:tostring end

-- For numerical args function numberargs(arg,v) local arg_v = (arg or ):find('%S') and string.gsub(arg,',',) or -1 local arg_i if arg_v == -1 then arg_i = nil elseif string.lower(arg_v) == 'n/a' then arg_i = 'N/A' else arg_i = tonumber(arg_v:gsub(',',''),10) if not arg_i then arg_i = badarg(v,'should be a single numerical value.') end end return arg_i end

-- For numbers (adds commas) function numargcommas(arg) local ret = numberargs(arg) return ret and commas(numberargs(arg)) end

-- For hp xp function hpxparg(arg) local xp = string.gsub(arg or ,',',) if string.lower(xp) == 'n/a' then return 'N/A' else xp = tonumber(xp) end if type(xp) == 'number' then return commas(math.floor(xp*3.3)/10) else return nil end end

-- For true/false function boolargs(arg) local arg_v = (arg or ''):find('%S') and arg or -1 local arg_i if arg_v == -1 then arg_i = nil else arg_v = yesno(arg_v) if arg_v then arg_i = '' else arg_i = '' end end return arg_i end

-- Poison function poisonarg(arg) return tonumber(arg,10) or '' end

-- style function stylearg(arg) -- split by commas local atts = mw.text.split(string.lower(arg or ''),'%s*,%s*') local _atts = {} -- remake the list as a table, remove anything that's blank/doesn't exist for _, v in ipairs(atts) do		local att_x = styles_map[v] if att_x then table.insert(_atts,attack_styles[att_x]) end end local p_att if #_atts == 0 then p_att = nil else p_att = {} for _, v in ipairs(_atts) do			table.insert(p_att,string.format('',v.image,v.link)) end p_att = table.concat(p_att,' ') end return p_att end

-- weakness function weaknessarg(arg) -- split by commas local wk = mw.text.split(string.lower(arg or ''),'%s*,%s*') local _wk = {}

-- remake the list as a table, remove anything that's blank/doesn't exist for _, v in ipairs(wk) do		local wk_x = weaknesses[v] if wk_x then table.insert(_wk,wk_x) end end local p_wk if #_wk == 0 then p_wk = nil else p_wk = {} for _, v in ipairs(_wk) do			table.insert(p_wk,string.format('',v.image,v.link)) end p_wk = table.concat(p_wk,' ') end return p_wk end

-- Explicit weakness -- weakness / explicit weakness function explicitwkarg(arg) -- split by commas local wk = mw.text.split(string.lower(arg or ''),'%s*,%s*') local _wk = weaknesses[wk[1]] if _wk then return string.format('',_wk.image) else return nil end end

function wkcats(arg,tbl) for _, v in pairs(weaknesses) do		if arg:find(v.image) then if v.category then table.insert(tbl,v.category) end end end end

function slaycats(arg,tbl) for _, v in pairs(slay_masters) do		if arg:find(v.chathead) then if v.category then table.insert(tbl,v.category) end end end end

-- Slayer assigners function slayerarg(_arg) local arg = _arg if arg then arg = mw.text.split(string.lower(arg),'%s*,%s*') local slayer_master_list = { turael = false, spria = false, mazchna = false, achtryn = false, vannaka = false, chaeldar = false, sumona = false, duradel = false, lapalok = false, kuradal = false, morvran = false, none = false }		for _, v in ipairs(arg) do			if slay_masters_map[v] then slayer_master_list[slay_masters_map[v]] = true end end if slayer_master_list.none then arg = 'Not assigned' else arg = {} for n, v in pairs(slayer_master_list) do				if v then --table.insert(params.assigned_by, slay_masters[n].text) table.insert(arg, 1, string.format('',slay_masters[n].chathead,n)) end end arg = table.concat(arg,' ') end else arg = nil end return arg end

-- Not assigned function notassarg(arg) if arg then if arg:find('%?action=edit') or not arg:find('%S') then return true end arg = mw.text.split(string.lower(arg),'%s*,%s*') for _, v in ipairs(arg) do			if slay_masters_map[v] == 'none' then return true end end end return false end

-- Abilities used function abilarg(arg) arg = paramtest.default_to(arg,false) if not arg then arg = 'None' elseif arg:find('clickpic') then arg = mw.getCurrentFrame:preprocess(arg) else arg = 'None' end return arg end

-- Attacks speed function speedarg(arg) if paramtest.is_empty(arg) then return nil end _,_,arg = string.find(arg:lower..' ','^(.-)%s') arg = speeds[speed_map[arg]] or badarg('speed',' is not a valid attack speed') return arg end

-- red ERR span with title hover for explanation function badarg(argname, argmessage) return ''.. 'ERR ' end

function addcategories(args,catargs) local ret = {} local cat_map = { -- Added if the parameter has content defined = { aka = 'Pages with AKA' },		-- Added if the parameter has no content notdefined = { image = 'Needs image', members = 'Needs members status', release = 'Needs release date', examine = 'Needs examine added', level = 'Needs combat level', immune_to_stun = 'Missing immunity information', immune_to_poison = 'Missing immunity information', immune_to_deflect = 'Missing immunity information', immune_to_drain = 'Missing immunity information' },		-- Parameters that are either true or false -- map a category to a boolean value yesno = { members = { [true] = '', [false] = 'F2P bestiary' }, abilities = { [true] = 'Monsters that use abilities', [false] = '' }, immune_to_stun = { [true] = 'Stun-immune', [false] = '' }, }	}	-- Run and add mapped categories for n, v in pairs(cat_map.defined) do		if catargs[n] and catargs[n].one_defined then table.insert(ret,v) end end for n, v in pairs(cat_map.notdefined) do		if catargs[n].all_defined == false then table.insert(ret,v) end end if args.members.d:find('[Nn]o') then table.insert(ret,'F2P bestiary') elseif args.members.switches then for _, v in ipairs(args.members.switches) do			if v:find('[Nn]o') then table.insert(ret,'F2P bestiary') break end end end if args.abilities.d:find('clickpic') then table.insert(ret,'Monsters that use abilities') elseif args.abilities.switches then for _, v in ipairs(args.abilities.switches) do			if v:find('clickpic') then table.insert(ret,'Monsters that use abilities') break end end end if args.weakness.d then wkcats(args.weakness.d,ret) end if args.weakness.switches then for _, v in ipairs(args.weakness.switches) do			if v ~= _nil then wkcats(v,ret) end end end

if args.assigned_by.d then slaycats(args.assigned_by.d,ret) end if args.assigned_by.switches then for _, v in ipairs(args.assigned_by.switches) do			if v ~= _nil then slaycats(v,ret) end end end -- combine table and format category wikicode for i, v in ipairs(ret) do		ret[i] = string.format('',v) end

return table.concat(ret,'') end

return p