Toggle menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Module:Sandbox/User:Habblet/excq

From Minigame Madness Wiki

Documentation for this module may be created at Module:Sandbox/User:Habblet/excq/doc

local dpl = require('Module:DPLlua')

local p = {}

local soils = {
	['Everlight Dig Site'] = 'Saltwater mud',
	['Infernal Source Dig Site'] = 'Fiery brimstone',
	['Kharid-et Dig Site'] = 'Ancient gravel',
	['Orthen Dig Site'] = 'Volcanic ash',
	['Senntisten Dig Site'] = 'Ancient gravel',
	['Stormguard Citadel Dig Site'] = 'Aerated sediment',
	['Warforge Dig Site'] = 'Earthen clay'
}

local ignore = {
	['Barricade (Archaeology)'] = true,
	['Fort debris'] = true,
	['Centurion remains'] = true,
	['Dragonkin remains (Desperate Measures)'] = true,
	['Orthen rubble (Desperate Measures)'] = true,
	['Forum entrance'] = true,
}

function p.main()
	-- SMW query for materials
	local materials = {}
	qmats = mw.smw.ask{
		'[[:+]]',
		'[[Category:Items]]',
		'[[Category:Archaeology materials]]',
		'?#-',
		limit = 500
	}
	for _,v in ipairs(qmats) do
		materials[ v[1] ] = true
	end
	---- mw.logObject(materials)
	
	-- DPL query for hotspots and artefact restore XP
	local qhots, qarts = dpl.ask( {
		    namespace = '',
			uses = 'Template:Infobox Excavation hotspot',
			include = '{Infobox Excavation hotspot}:name:digsite:archlevel:successxp:failxp:artefactxp:hitpoints',
			count = 500
		},{
			namespace = '',
			category = 'Artefacts',
			uses = 'Template:Infobox Recipe',
			include = '{Infobox Recipe}:skillXP',
			count = 500
		} )
	local hots = {}
	local arts = {}
	for _,v in ipairs(qhots) do
		if not ignore[ v['title'] ] then
			local info = v['include']['Infobox Excavation hotspot']
			hots[ v['title'] ] = {
				artefacts = {},
				artefactxp = tonumber ( info['artefactxp'] ),
				failxp = tonumber( info['failxp'] ),
				hitpoints = tonumber( info['hitpoints'] ),
				materials = {},
				soil = soils[ info['digsite'] ],
				successxp = tonumber( info['successxp'] ),
				level = tonumber( info['archlevel'] )
			}
		end
	end
	for _,v in ipairs(qarts) do
		arts[ v['title'] ] = tonumber( v['include']['Infobox Recipe']['skillXP'] )
	end
	-- mw.logObject(hots)
	-- mw.logObject(arts)
	
	-- SMW query for material rarities
	local qrarities = mw.smw.ask{
		'[[Category:Excavation hotspots]]',
		'?#-',
		'?Has subobject.Dropped item#-',
		'?Has subobject.Drop JSON',
		limit = 500
	}
	-- mw.logObject(arts)
	for _,v in ipairs(qrarities) do
		local spot = v[1]
		if hots[spot] then
			for itn,w in ipairs( v["Dropped item"] ) do
				-- mw.log(arts[w])
				if materials[w] then
					local drop_json = mw.text.jsonDecode(v["Drop JSON"][itn])
					local numstr = string.gsub( drop_json["Rarity"], '/.*', '' )
					table.insert( hots[spot].materials, {w, (tonumber(numstr) or 1) * 1000 } )
				else
					local restname = string.gsub(w, ' ?%(damaged%)', '')
					-- mw.log(arts[restname])
					if arts[restname] then
						table.insert( hots[spot].artefacts, {w, 10} ) --arts[restname]}
					end
				end
			end
		end
	end
	-- mw.logObject(qrarities)
	-- mw.logObject(hots)
	
	--local div = mw.html.create('div')
	--div:attr('id', 'excdump')
	--div:wikitext( mw.dumpObject(hots) )
	
	-- dump and clean the table
	local dump_str = mw.dumpObject(hots)
	local ret = mw.ustring.gsub(dump_str, 'table#%d* ', '')
	ret = mw.ustring.gsub(ret, '%["(%w+)"%]', '%1')
	ret = mw.ustring.gsub(ret, '(",)\n%s+(%d+),', '%1 %2' )
    ret = mw.ustring.gsub(ret, '(%d+)\n%s+(},\n%s+{)\n%s+', '%1%2' )
    ret = mw.ustring.gsub(ret, '(= {\n%s+{)\n%s+(")', '%1%2' )
    ret = mw.ustring.gsub(ret, '(%d)\n%s+(},\n%s+},)', '%1%2' )
	--ret = mw.ustring.gsub(ret, '(",)\n%s+(")', '%1 %2' )
	-- ret = mw.ustring.gsub(ret, ' = {.-soil', '')
	
	return '<pre>' .. ret .. '</pre>'
end

return p
Cookies help us deliver our services. By using our services, you agree to our use of cookies.