FANDOM


-- <pre>
local p = {}
local JSONS = require('Dev:Json')
 
function p.main(frame)
	-- This template is fairly expensive to use, so it should be limited
	mw.incrementExpensiveFunctionCount()
 
	local args = frame:getParent().args
 
	local monster = string.gsub(args['?monster'] or args.monster or '','[][]','')
	monster = mw.text.decode(monster)
 
	local drop = string.lower(args.userparam or args.drop or '')
	drop = mw.text.decode(drop)
 
	-- escape lua characters
	local _drop = drop:gsub('([%^%$%(%)%%%.%[%]%*%+%-%?])','%%%1')
 
	local smwdata = frame:preprocess('{{'..
					'{{{|safesubst:}}}#show:'..
					monster..
				[[
					|?Drop JSON
					|?All Combat level=&&SPLITPOINT&&Combat level:
					|headers=plain
					|format=list
					}}
				]])
 
	smwdata = mw.text.decode(tostring(smwdata))
	local _found = false
 
	local json, cmb = unpack( mw.text.split(smwdata,'%(&&SPLITPOINT&&') )
 
	local json_good
	json_good, json = pcall(JSONS.decode,string.format('[ %s ]',json))
 
	if not json_good then
		return ''
	end
 
	cmb = string.format( '(%s',cmb or '?' )
 
	local ret = {}
 
	for _, v in pairs(json) do
		if drop == string.lower(v.name) then
			table.insert(ret,v)
			_found = true
		end
	end
 
	if not _found then
		return ''
	end
 
	local combat = mw.ustring.match(cmb:lower(),'%(combat level: (.-)%)') or 'N/A'
	combat = mw.ustring.gsub(combat,'(%d),(%d%d%d)','%1%2')
	local retString = {}
 
	for _, v in pairs(ret) do
		local _min,_max = v.quantity[1],v.quantity[2]
		local quantity
 
		if tonumber(_min) == tonumber(_max) then
			quantity = _min
		else
			quantity = string.format('%s-%s',_min,_max)
		end
 
		table.insert(retString,
				string.format('{{ItemDropsLine|Monster=%s|Combat=%s|Quantity=%s|Rarity=%s}}',
				monster,
				combat,
				quantity,
				v.rarity)
			)
	end
 
	return frame:preprocess(table.concat(retString,'\n'))
end
 
return p

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.