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', locationSprite='_locationSprite' }},	{ '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.mobSpawnsTableLocation(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._mobSpawnsTableLocation(list) end

function p._mobSpawnsTableLocation(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.mobSpawnsTableMob(frame) local args = getArgs(frame) local list = { {   		location = args[1] or args.location or args.loc, isSprite = yesno(args.is_sprite, true), 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] = { location = args['location'..i] or args['loc'..i], isSprite = yesno(args['is_sprite'..i], true), spots = args['spots'..i], time = args['time'..i], max = args['max'..i], }   	i = i + 1 end return p._mobSpawnsTableMob(list) end

function p._mobSpawnsTableMob(list) local wikitable = mw.html.create('table') :addClass('wikitable') :tag('tr') :tag('th'):wikitext('Location'):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, location in ipairs(list) do		wikitable:tag('tr') :tag('td'):wikitext(location.isSprite and locationSprite(location.location, nil, true) or location.location):done :tag('td'):wikitext(location.spots):done :tag('td'):wikitext(location.time):done :tag('td'):wikitext(location.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 or '', 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] or '', 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		if drop.drop:lower == 'none' then wikitable:tag('tr') :tag('td'):wikitext(itemDisplay(drop.drop, true)):attr{ colspan=4 }:done :done break else 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 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