From Dark and Darker Wiki

Loot Table at 0 Luck
NameLuck GradeLuck Grades present on the graph but missing in the column below are associated with dropping nothing.RarityItem Count
1Poor1
2Common1
3Uncommon1
4Rare1
5Epic1
6Legend1
7Unique1
1Poor1
2Common1
3Uncommon1
4Rare1
5Epic1
6Legend1
7Unique1
3Uncommon1
4Rare1
5Epic1
6Legend1
7Unique1
1Poor1
2Common1
3Uncommon1
4Rare1
5Epic1
6Legend1
7Unique1
8Artifact1
3Uncommon1
4Rare1
5Epic1
6Legend1
7Unique1
1Poor1
2Common1
3Uncommon1
4Rare1
5Epic1
6Legend1
7Unique1
1Poor1
2Common1
3Uncommon1
4Rare1
5Epic1
6Legend1
7Unique1
1Poor1
2Common1
3Uncommon1
4Rare1
5Epic1
6Legend1
7Unique1
1Poor1
2Common1
3Uncommon1
4Rare1
5Epic1
6Legend1
7Unique1
1Poor1
2Common1
3Uncommon1
4Rare1
5Epic1
6Legend1
7Unique1
1Poor1
2Common1
3Uncommon1
4Rare1
5Epic1
6Legend1
7Unique1
1Poor1
2Common1
3Uncommon1
4Rare1
5Epic1
6Legend1
7Unique1
1Poor1
2Common1
3Uncommon1
4Rare1
5Epic1
6Legend1
7Unique1
8Artifact1
1Poor1
2Common1
3Uncommon1
4Rare1
5Epic1
6Legend1
7Unique1
1Poor1
2Common1
3Uncommon1
4Rare1
5Epic1
6Legend1
7Unique1
8Artifact1
1Poor1
2Common1
3Uncommon1
4Rare1
5Epic1
6Legend1
7Unique1
3Uncommon1
4Rare1
5Epic1
6Legend1
7Unique1
1Poor1
2Common1
3Uncommon1
4Rare1
5Epic1
6Legend1
7Unique1
3Uncommon1
4Rare1
5Epic1
6Legend1
7Unique1
1Poor1
2Common1
3Uncommon1
4Rare1
5Epic1
6Legend1
7Unique1
1Poor1
2Common1
3Uncommon1
4Rare1
5Epic1
6Legend1
7Unique1
1Poor1
2Common1
3Uncommon1
4Rare1
5Epic1
6Legend1
7Unique1
1Poor1
2Common1
3Uncommon1
4Rare1
5Epic1
6Legend1
7Unique1
8Artifact1
1Poor1
2Common1
3Uncommon1
4Rare1
5Epic1
6Legend1
7Unique1
1Poor1
2Common1
3Uncommon1
4Rare1
5Epic1
6Legend1
7Unique1
1Poor1
2Common1
3Uncommon1
4Rare1
5Epic1
6Legend1
7Unique1
3Uncommon1
4Rare1
5Epic1
6Legend1
7Unique1
1Poor1
2Common1
3Uncommon1
4Rare1
5Epic1
6Legend1
7Unique1
3Uncommon1
4Rare1
5Epic1
6Legend1
7Unique1
1Poor1
2Common1
3Uncommon1
4Rare1
5Epic1
6Legend1
7Unique1
1Poor1
2Common1
3Uncommon1
4Rare1
5Epic1
6Legend1
7Unique1
1Poor1
2Common1
3Uncommon1
4Rare1
5Epic1
6Legend1
7Unique1
1Poor1
2Common1
3Uncommon1
4Rare1
5Epic1
6Legend1
7Unique1
1Poor1
2Common1
3Uncommon1
4Rare1
5Epic1
6Legend1
7Unique1
3Uncommon1
4Rare1
5Epic1
6Legend1
7Unique1
3Uncommon1
4Rare1
5Epic1
6Legend1
7Unique1
1Poor1
2Common1
3Uncommon1
4Rare1
5Epic1
6Legend1
7Unique1
3Uncommon1
4Rare1
5Epic1
6Legend1
7Unique1
1Poor1
2Common1
3Uncommon1
4Rare1
5Epic1
6Legend1
7Unique1
3Uncommon1
4Rare1
5Epic1
6Legend1
7Unique1
1Poor1
2Common1
3Uncommon1
4Rare1
5Epic1
6Legend1
7Unique1
3Uncommon1
4Rare1
5Epic1
6Legend1
7Unique1
3Uncommon1
4Rare1
5Epic1
6Legend1
7Unique1
3Uncommon1
4Rare1
5Epic1
6Legend1
7Unique1
3Uncommon1
4Rare1
5Epic1
6Legend1
7Unique1
3Uncommon1
4Rare1
5Epic1
6Legend1
7Unique1
3Uncommon1
4Rare1
5Epic1
6Legend1
7Unique1
3Uncommon1
4Rare1
5Epic1
6Legend1
7Unique1
1Poor1
2Common1
3Uncommon1
4Rare1
5Epic1
6Legend1
7Unique1
1Poor1
2Common1
3Uncommon1
4Rare1
5Epic1
6Legend1
7Unique1
3Uncommon1
4Rare1
5Epic1
6Legend1
7Unique1
1Poor1
2Common1
3Uncommon1
4Rare1
5Epic1
6Legend1
7Unique1
8Artifact1
1Poor1
2Common1
3Uncommon1
4Rare1
5Epic1
6Legend1
7Unique1
1Poor1
2Common1
3Uncommon1
4Rare1
5Epic1
6Legend1
7Unique1
1Poor1
2Common1
3Uncommon1
4Rare1
5Epic1
6Legend1
7Unique1
1Poor1
2Common1
3Uncommon1
4Rare1
5Epic1
6Legend1
7Unique1
1Poor1
2Common1
3Uncommon1
4Rare1
5Epic1
6Legend1
7Unique1
3Uncommon1
4Rare1
5Epic1
6Legend1
7Unique1


local utils = require("Module:Utilities")
local p = {}

function p.create_loot_table(frame)
	local droprate_filename = "Data:Droprate Monsters Bosses.json"
	local lootdrop_filename = "Data:Lootdrop GhostKing.json"
	
	local lootdrop_data = mw.loadJsonData(lootdrop_filename)
	if lootdrop_data == nil then return "Lootdrop data file '" .. lootdrop_filename .. "' could not be found." end
	
	local resulting_table = ""
	resulting_table = resulting_table .. '<table cellspacing="0" class="loottable stripedtable sortable jquery-tablesorter mw-collapsible" style="width:100%">'
	resulting_table = resulting_table .. '	<caption>Loot Table at 0 Luck</caption>'
	resulting_table = resulting_table .. '	<tr><th style="width:5%">Name</th><th class="tooltip" style="width:5%"><u>Luck Grade</u><span class="tooltiptext-left" style="left:50%; transform:translate(-50%); bottom:66%; width:100%">Luck Grades present on the graph but missing in the column below are associated with dropping nothing.</span></th><th style="width:5%">Rarity</th><th style="width:5%">Item Count</th></tr>'
	
	-- Create body of table
	-- Item name, luck grade, rarity, item count
	for i, item_name in ipairs(lootdrop_data["item_order"]) do
		-- Get the item's data
		local item_data = lootdrop_data["item"][item_name]
		if item_data == nil then return "item_name '" .. item_name .. "' from item_order not found in lootdrop_data." end
		
		-- Iterate each record in the item data
		local num_records = 0 --used for determining rowspan
		for j, item_record in ipairs(item_data) do
			num_records = num_records+1
		end
		for j, item_record in ipairs(item_data) do
			local luck_grade = item_record[1] --lua is index1 based
			local rarity_num = item_record[2]
			local count = item_record[3]
			if luck_grade == nil then return "item_name '" .. item_name .. "' has a missing luck_grade." end
			if rarity_num == nil then return "item_name '" .. item_name .. "' has a missing rarity." end
			if count == nil then return "item_name '" .. item_name .. "' has a missing count." end
			
			local rarity_name = utils.rarity_num_to_name(rarity_num)
			if rarity_name == nil then return "rarity_num of '" .. rarity_num .. "' was converted to a nil rarity_name." end
			
			local rowspan_str = ""
			if j==1 and num_records > 1 then --if first record and there are multiple records; span all records
				rowspan_str = "<td rowspan='" .. num_records .. "'" .."><div class='iconbox'><div class='rarity2 rounded relative'>[[File:"..item_name..".png|x80px|link="..item_name.."]]</div>[[" .. item_name .. "]]</div>" .. "</td>"
			end
			
			resulting_table = resulting_table .. "<tr>"
			resulting_table = resulting_table ..     rowspan_str
			resulting_table = resulting_table ..     "<td class='cr"..luck_grade.."'><b>" .. luck_grade .. "</b></td>"
			resulting_table = resulting_table ..     "<td class='cr"..rarity_num.."'><b>" .. rarity_name .. "</b></td>"
			resulting_table = resulting_table ..     "<td>" .. count .. "</td>"
			resulting_table = resulting_table .. "</tr>"
		end
	end
	
	resulting_table = resulting_table .. '</table><br>'
	
	return resulting_table
end

return p