The Aether Project Wiki has officially launched! With your help, this wiki can be made a comprehensive source of information about the Aether Project.

Module:Get drop info

From Aether Project Wiki
Jump to navigation Jump to search
This is the documentation page. It will be transcluded into the main module page. See Template:Documentation for more information

Usage

Called by {{Drop sources}}


-- Copied from Minecraft wiki: 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]
	local smwItemName
	
	if not itemName then
		itemName = mw.title.getCurrentTitle().text
	end
	smwItemName = itemName
	
	local query = {
		'[[Item name::' .. smwItemName .. ']]',
		'?Drop JSON',
		limit = 500
	}
	
	local smwdata = mw.smw.ask(query)
	
	local retTable = {}
	if smwdata then
		for i,v in ipairs(smwdata) do
			if type(v['Drop JSON']) == "table" then -- if a page has a drop happening multiple times it is returned in a table instead of a string
				for j,k in ipairs(v['Drop JSON']) do
					local dropJSON = mw.text.jsonDecode(v['Drop JSON'][j] or '{}')
					table.insert(retTable, makeDropLine(itemName, dropJSON))
				end
			else
				local dropJSON = mw.text.jsonDecode(v['Drop JSON'] or '{}')
				table.insert(retTable, makeDropLine(itemName, dropJSON))
			end
		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'}))
--]]