Module:Get drop info

From Minecraft Wiki
Jump to navigation Jump to search
Documentation[view] [edit] [history] [purge]Jump to code ↴
Image
This module is deprecated. It should not be used anywhere except sandboxes.
 
Please use {{DropTable}} instead.

Was called by {{Drop sources}}.

[view] [edit] [history] [purge]The above documentation is transcluded from Module:Get drop info/doc.
-- Portions sourced from https://oldschool.runescape.wiki/w/Module:Get_drop_info
local p = {}
local spriteFile = require("Module:SpriteFile")
local dropsline = require("Module:DropsLine")

function p.main(frame)
	return p._main(frame:getParent().args)
end

function p._main(args)
	local itemName = args.name or args[1]
	
	if not itemName then
		itemName = mw.title.getCurrentTitle().text
	end
	
	local query = bucket('droptable')
					.select('item', 'json')
					.where('item', itemName)
					.limit(500)
	
	local retTable = {}
	if query then
		for i, v in ipairs(query) do
			local dropJSON = mw.text.jsonDecode(v['json'] or '{}')
			table.insert(retTable, makeDropLine(itemName, dropJSON))
		end
	end
	
	-- Create the html table to display results
	local t = mw.html.create('table')
	t	:addClass('wikitable sortable')
		:css('text-align', 'center')
		:tag('tr')
		:tag('th'):attr('colspan', 1):attr('rowspan', 2):wikitext('Source'):done()
		:tag('th'):attr('rowspan', 2):wikitext('Roll Chance'):done()
		:tag('th'):attr('colspan', 4):wikitext('Quantity (Roll Chance)'):done()
		:done()
		:tag('tr')
		:tag('th'):wikitext('Default'):done()
		:tag('th'):wikitext('Looting I'):done()
		:tag('th'):wikitext('Looting II'):done()
		:tag('th'):wikitext('Looting III'):done()

	
	-- insert all the drop lines we made before
	mw.log('reTable pairs: ' .. #retTable)
	for i,v in ipairs(retTable) do
		mw.log('Entry: ' .. tostring(v))
		t:node(v)
	end

	local ret = mw.html.create():wikitext(tostring(t) .. mw.getCurrentFrame():extensionTag{name="references", args = {group='d'}})
		
	--TODO auto categories if on mainspace
	return ret
end

function makeDropLine(itemName, data)
	local dropSource = data['Dropped from']
	-- local droppedItemNote = data['Dropped item note']
	local quantityText = data['Quantity text']
	local rollChanceText = data['Roll chance text']
	local rollChanceNote = data['Roll chance note']
	local version = data['Version']
	local playerKillRequired = data['Player kill required']

	local ret = mw.html.create('tr')
	local nameTag = ret:css('text-align', 'center')
		:tag('td')
		:css('text-align', 'left')
			:wikitext(spriteFile.link({name = "EntitySprite", scale = 2, align = 'middle',  dropSource}))
	if version == 'je' then
		nameTag:wikitext(mw.getCurrentFrame():extensionTag{ name='sub', content='(JE)', args = {title="Only in Java Edition", style='cursor:help; margin-left:3px;'} })
	elseif version == 'be' then
		nameTag:wikitext(mw.getCurrentFrame():extensionTag{ name='sub', content='(BE)', args = {title="Only in Bedrock Edition", style='cursor:help; margin-left:3px;'} })
	end
	-- if droppedItemNote then -- Having to use this here indicates that it should really be split into just multiple items
		-- nameTag:wikitext(mw.getCurrentFrame():extensionTag{ name='ref', content=droppedItemNote, args = {group='d'}})
	-- end

	local rollChanceTag = ret:tag('td'):wikitext(rollChanceText)
	if playerKillRequired == "yes" then
		rollChanceTag:wikitext(mw.getCurrentFrame():extensionTag{ name='ref', content="Dropped only when kill credit is given to the player", args = {group='d', name='player-kill'}})
	end
	if rollChanceNote then
		rollChanceTag:wikitext(mw.getCurrentFrame():extensionTag{ name='ref', content=rollChanceNote, args = {group='d'}})
	end
	
	 ret:tag('td'):wikitext(quantityText[1]):done()
		:tag('td'):wikitext(quantityText[2]):done()
		:tag('td'):wikitext(quantityText[3]):done()
		:tag('td'):wikitext(quantityText[4]):done()

	return ret:done()
end
return p

--[[ debug:
mw.log(p._main({name='Blaze Rod'}))
--]]