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, fishing_xp = args.fishing_xp, exp = args.exp, mithril_powder = args.mithril_powder, 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 if list[1].drop then wikitable: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('Drop 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', makeOdds(drop.chance, nil, nil, true)))):done :done end 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 if list.fishing_xp and list.combat_xp or not list.fishing_xp then wikitable:tag('tr') :tag('td'):attr{ ['colspan']=1 }:wikitext(''):done :tag('td'):attr{ ['colspan']=3 }:wikitext(isInfoNeeded(list.combat_xp) and infoNeeded or string.wrapTag(makeColor('blue', list.combat_xp), 'b')):done :done end if list.fishing_xp then wikitable:tag('tr') :tag('td'):attr{ ['colspan']=1 }:wikitext(''):done :tag('td'):attr{ ['colspan']=3 }:wikitext(isInfoNeeded(list.fishing_xp) and infoNeeded or string.wrapTag(makeColor('blue', list.fishing_xp), 'b')):done :done end 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 if list.mithril_powder then wikitable:tag('tr') :tag('td'):attr{ ['colspan']=1 }:wikitext(makeColor('green', itemDisplay('Mithril Powder', true))):done :tag('td'):attr{ ['colspan']=3 }:wikitext(isInfoNeeded(list.mithril_powder) and infoNeeded or string.wrapTag(makeColor('green', list.mithril_powder), 'b')):done :done end return tostring(wikitable) end

function p.mobInfo(frame) local statdata = mw.loadData('Module:Statname/Data') local args = getArgs(frame) local data = { mob = args.mob or args.name or args[1] or mw.title.getCurrentTitle.namespace == 0 and mw.title.getCurrentTitle.prefixedText, image = args.image, caption = args.caption, levels = {args.level}, spawn_locations = {args.spawn_location}, stats = {}, drops = { combat_xp = {args.combat_xp or args.cxp}, experience = {args.experience or args.exp}, coins = {args.coins or args.c}, },	}	for k, v in pairs(statdata) do		if args[v.name:lower:gsub(' ', '_')] or args[v.nameShort:lower:gsub(' ', '_')] or args[v.nameSuperShort:lower:gsub(' ', '_')] or args[v.shortcode] then data.stats[v.shortcode] = {color = v.color, aliases = {v.name:lower:gsub(' ', '_'), v.nameShort:lower:gsub(' ', '_'), v.nameSuperShort:lower:gsub(' ', '_'), v.shortcode}} data.stats[v.shortcode][1] = args[v.shortcode] end end for i = 2, table.length(args), 1 do       data.levels[i] = args['level'..i]        data.spawn_locations[i] = args['spawn_location'..i]

for k, v in pairs(data.stats) do       	for _, alias in ipairs(v.aliases) do        		if not data.stats[k][i] then data.stats[k][i] = args[alias..i]		       end end end

data.drops.combat_xp[i] = args['combat_xp'..i] or args['cxp'..i]       data.drops.experience[i] = args['experience'..i] or args['exp'..i]		data.drops.coins[i] = args['coins'..i] or args['c'..i]	end -- mw.logObject(data) return mw.getCurrentFrame:preprocess(p._mobInfo(data)) end

function p._mobInfo(data) local ROWS = math.max(#data.levels, #data.spawn_locations, #data.drops.combat_xp, #data.drops.experience, #data.drops.coins)

local wikitable = mw.html.create('table'):addClass('wikitable centertext') wikitable:tag('caption'):wikitext(data.caption):done :tag('tr') :tag('th'):attr('rowspan', '2'):wikitext('Mob'):done :tag('th'):attr('rowspan', '2'):wikitext('Level'):done :tag('th'):attr('rowspan', '2'):wikitext('Spawn Location'):done :tag('th'):attr('colspan', table.length(data.stats)):wikitext('Stats'):done :tag('th'):attr('colspan', '3'):wikitext('Drops'):done :done

local row = wikitable:tag('tr') for k, v in pairs(data.stats) do	           row:tag('th'):wikitext(''):done end row:tag('th'):wikitext(''):done :tag('th'):wikitext('Experience'):done :tag('th'):wikitext(''):done row:done

local row = wikitable:tag('tr') :tag('td'):attr('rowspan', ROWS):wikitext(' \'\'\ .. data.mob .. '\'\'\):done :tag('td'):wikitext(''):done :tag('td'):wikitext(data.spawn_locations[1]):done for k, v in pairs(data.stats) do           row:tag('td'):wikitext(makeColor(v.color, string._formatNum(v[1] or '0'))):done end row:tag('td'):wikitext(makeColor('green', data.drops.combat_xp[1] or '0')):done :tag('td'):wikitext(makeColor('blue', data.drops.experience[1] or '0')):done :tag('td'):wikitext(makeColor('gold', data.drops.coins[1] or '0')):done row:done

for i = 2, ROWS, 1 do       local row = wikitable:tag('tr') :tag('td'):wikitext(''):done :tag('td'):wikitext(data.spawn_locations[i]):done for k, v in pairs(data.stats) do	           row:tag('td'):wikitext(makeColor(v.color, string._formatNum(v[i] or '0'))):done end row:tag('td'):wikitext(makeColor('green', data.drops.combat_xp[i] or '0')):done :tag('td'):wikitext(makeColor('blue', data.drops.experience[i] or '0')):done :tag('td'):wikitext(makeColor('gold', data.drops.coins[i] or '0')):done row:done end

return tostring(wikitable) end

return p