Module:Mob

-- local p = {}

require('Module:LoadLib')(_G, {	{ 'Odds', values={ makeOdds='_odds' }},	{ 'Arguments', values={ 'getArgs' }},	{ 'Item', values={ itemDisplay='_itemDisplay' }},	{ 'RarityTier', values={ makeRarity='_link' }},	{ "Sprite", values={ mobSprite='_mobSprite' }},	{ 'Notice', values={ infoNeeded='_info_needed' }},	{ 'Currency', values={ makeCoins='_coins' }},	{ "Color", values={ 'makeColor' }},	string='String',	table='Table',	yesno='Yesno',	format='Format', }, { doAutoLoads=false })

local function isInfoNeeded(str) str = str:lower local keys = table.Set{ 'infoneeded', 'in', 'moreinfoneeded', 'min', 'moreinfo', }

return keys[str] end function rarityOrOdds(str) str = str:lower local keys = table.Set{ 'rngesus', 'rng', }	return keys[str] end

function p.mobSpawnsTable(frame) local args = getArgs(frame) local list = { {   		mob = args[1] or args.mob, spots = args[2] or args.spots, time = args[3] or args.time, max = args[4] or args.max, },   }    local i = 2 while args['mob'..i] do   	list[i] = { mob = args['mob'..i], spots = args['spots'..i], time = args['time'..i], max = args['max'..i], }   	i = i + 1 end return p._mobSpawnsTable(list) end

function p._mobSpawnsTable(list) local wikitable = mw.html.create('table') :addClass('wikitable') :tag('tr') :tag('th'):wikitext('Mob'):done :tag('th'):wikitext(format._makeAbbr('The number of spots in the location where this mob can spawn in.' ,'Spawn Spots')):done :tag('th'):wikitext(format._makeAbbr('The time, after which a new mob spawns in every spot.', 'Spawn Delay')):done :tag('th'):wikitext(format._makeAbbr('The maximum number of mobs that can exist in each spot at a time.', 'Max per spot')):done :done --if true then return tostring(wikitable) end for i, mob in ipairs( list ) do		wikitable:tag('tr') :tag('td'):wikitext(mobSprite(mob.mob, nil, true)):done :tag('td'):wikitext(mob.spots):done :tag('td'):wikitext(mob.time):done :tag('td'):wikitext(mob.max):done :done end return tostring(wikitable) end

function p.mobDropsTable(frame) local args = getArgs(frame) local list = { coins = args.coins or args.c,		combat_xp = args.combat_xp or args.cxp, exp = args.exp, caption = args.caption, {   		drop = args[1] or args.drop or args.d,			rarity = args[2] or args.rarity or args.r,    		chance = args[3] or args.chance or args.ch, count = args[4] or args.count or args.co, odds = yesno(args.odds, false), },   }    local i = 2 while args['drop'..i] do   	list[i] = { drop = args['drop'..i] or args['d'..i], rarity = args['rarity'..i] or args['r'..i], chance = args['chance'..i] or args['ch'..i], count = args['count'..i] or args['co'..i], odds = yesno(args['odds'..i], false), }   	i = i + 1 end return frame:preprocess(p._mobDropsTable(list)) end

function p._mobDropsTable(list) local wikitable = mw.html.create('table'):addClass('wikitable') :tag('caption'):wikitext(list.caption):done :tag('tr') :tag('th'):attr{ ['colspan']=4 }:wikitext('Item drops'):done :done :tag('tr') :tag('th'):wikitext('Drop'):done :tag('th'):wikitext('Count'):done :tag('th'):wikitext('Rarity'):done :tag('th'):wikitext('Chance'):done :done --if true then return tostring(wikitable) end for i, drop in ipairs( list ) do		wikitable:tag('tr') :tag('td'):wikitext(isInfoNeeded(drop.drop) and infoNeeded or itemDisplay(drop.drop, true)):done :tag('td'):wikitext(isInfoNeeded(drop.count) and infoNeeded or drop.count):done :tag('td'):wikitext(isInfoNeeded(drop.rarity) and infoNeeded or (rarityOrOdds(drop.rarity) and makeOdds(drop.rarity, true) or makeRarity(drop.rarity))):done :tag('td'):wikitext(isInfoNeeded(drop.chance) and infoNeeded or (drop.odds and makeOdds(drop.chance, false, false, true) or makeColor('green', drop.chance))):done :done end wikitable:tag('tr') :tag('th'):attr{ ['colspan']=4 }:wikitext('Non-item drops'):done :done wikitable:tag('tr') :tag('th'):attr{ ['colspan']=1 }:wikitext('Drop'):done :tag('th'):attr{ ['colspan']=3 }:wikitext('Count'):done :done wikitable:tag('tr') :tag('td'):attr{ ['colspan']=1 }:wikitext(makeColor('gold', itemDisplay('Coins', true))):done :tag('td'):attr{ ['colspan']=3 }:wikitext(isInfoNeeded(list.coins) and infoNeeded or string.wrapTag(makeColor('gold', list.coins), 'b')):done :done wikitable:tag('tr') :tag('td'):attr{ ['colspan']=1 }:wikitext('Combat XP'):done :tag('td'):attr{ ['colspan']=3 }:wikitext(isInfoNeeded(list.combat_xp) and infoNeeded or string.wrapTag(makeColor('blue', list.combat_xp), 'b')):done :done wikitable:tag('tr') :tag('td'):attr{ ['colspan']=1 }:wikitext(itemDisplay('Experience Orbs', true)):done :tag('td'):attr{ ['colspan']=3 }:wikitext(isInfoNeeded(list.exp) and infoNeeded or string.wrapTag(makeColor('blue', list.exp), 'b')):done :done return tostring(wikitable) end

return p