Module:Mazunki/Monsters: Difference between revisions

From Melvor Idle
(copypasted falter's tailored table)
(No difference)

Revision as of 16:34, 30 January 2022

Documentation for this module may be created at Module:Mazunki/Monsters/doc

function p.getMonsterTable(frame)
	--Generates a plaintext table for Mazunki's use for spreadsheet generation
	local result = '{|'
	result = result..'\r\n!ID!!Name!!Price!!Combat Obtainable!!Monster Drop Chances'
	local rows = {}
	
	local itemList = Items.getItems(function(item) return true end)
	table.sort(itemList, function(a, b) return a.id < b.id end)
	
	local monsterSourceColumns = { 'id', 'dropWt', 'totalWt', 'minQty', 'maxQty' }
	
	local itemID = 0
	local item = Items.getItemByID(itemID)
	while item ~= nil and itemID < 2000 do
		local rowTxt = '|-\r\n'
		rowTxt = rowTxt..'|'..item.id..'||'..item.name..'||'..item.sellsFor
		local monsterData = SourceTables._getItemMonsterSources(item)
		if(Shared.tableCount(monsterData) > 0) then
			local monsterColData = {}
			for i, colName in pairs(monsterSourceColumns) do
				monsterColData[colName] = {}
			end
			
			rowTxt = rowTxt..'||true||'
			for j, mData in pairs(monsterData) do
				for k, colName in pairs(monsterSourceColumns) do
					table.insert(monsterColData[colName], mData[colName])
				end
			end
			local colTxtArray = {}
			for j, colName in pairs(monsterSourceColumns) do
				table.insert(colTxtArray, 'monster_'..colName..' = '..table.concat(monsterColData[colName], ','))
			end
			rowTxt = rowTxt..table.concat(colTxtArray, '<br/>')
		else
			rowTxt = rowTxt..'||false||'
		end
		table.insert(rows, rowTxt)
		itemID = itemID + 1
		item = Items.getItemByID(itemID)
	end
	
	result = result..'\r\n'..table.concat(rows, '\r\n')..'\r\n|}'
	return result
end