From Dark and Darker Wiki

Revision as of 21:20, 5 May 2025 by Raw Salad (talk | contribs)

Script error: The function "loot_tables" does not exist.


local p = {}

function round(number, decimalPlaces)
  return tonumber(string.format("%." .. (decimalPlaces or 0) .. "f", number))
end

function p.create_droprate_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 lootdrop_item_counts = lootdrop_data["luckgrade"]

	local droprate_data = mw.loadJsonData(droprate_filename)
	if droprate_data == nil then return "Droprate data file '" .. droprate_filename .. "' could not be found." end

	local resulting_table = ''

	for i, dungeongrade in ipairs(droprate_data["dungeon_grades"]) do
		
		resulting_table = resulting_table .. '<table cellspacing="0" class="loottable stripedtable sortable jquery-tablesorter mw-collapsible" style="width:100%"><caption>Drop rates</caption><tr><th style="width:5%">Luck grade</th><th style="width:5%">Probability</th><th style="width:5%">Probability per item</th><th style="width:5%">Item count</th></tr>'
		
		for i, luckgrade in ipairs(droprate_data[dungeongrade]["luckgrade_order"]) do
			local probability = droprate_data[dungeongrade]["luckgrade"][luckgrade]
			if probability == nil then return "probability for '" .. luckgrade .. "' not found in droprate data for luckgrade dictionary." end
			
			local item_count = lootdrop_item_counts[luckgrade]
			if item_count == nil then return "item_count for '" .. luckgrade .. "' not found in lootdrop data." end
			
			local probability_per_item = round(probability / item_count,4)
			
			resulting_table = resulting_table .. "<tr><td class='cr"
								..luckgrade.."'><b>" .. luckgrade .. "</b></td><td class='cr"
								..luckgrade.."'><b>" .. probability .. "</b></td><td class='cr"
								..luckgrade.."'><b>" .. probability_per_item .. "</b></td><td class='cr"
								..luckgrade.."'><b>" .. item_count .. "</b></td></tr>"
		end

		resulting_table = resulting_table .. '</table><br>'
	end
		
	return resulting_table
end

return p