Module:Mob

-- local p = {}

local getArgs = require('Module:Arguments').getArgs local string = require(Module:String) local _error = string._error local yesno = require('Module:Yesno') local mobSprite = require(Module:Sprite)._mobSprite local format = require(Module:Format) local itemDisplay = require(Module:Item)._itemDisplay local makeRarity = require('Module:RarityTier')._link local makeOdds = require(Module:Odds)._odds local makeCoins = require(Module:Currency)._coins local color = require(Module:Color)._colorTemplates local infoNeeded = require(Module:Notice)._info_needed

function isInfoNeeded(str) str = str:lower if str == 'infoneeded' or str == 'in' or str == 'moreinfoneeded' or str == 'min' or str == 'moreinfo' then return true else return false end end function rarityOrOdds(str) str = str:lower if str == 'rngesus' or str == 'rng' then return true else return false end 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 color('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(color('gold', itemDisplay('Coins', true))):done :tag('td'):attr{ ['colspan']=3 }:wikitext(isInfoNeeded(list.coins) and infoNeeded or table.concat{, color('gold', list.coins), }):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 table.concat{, color('blue', list.combat_xp), }):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 table.concat{, color('blue', list.exp), }):done :done return tostring(wikitable) end

return p