From Dark and Darker Wiki

m (remove extra line)
No edit summary
Tag: Reverted
Line 1: Line 1:
local utils = require("Module:Utilities")
local p = {}
local p = {}


Line 5: Line 4:
local droprate_filename = "Data:Droprate Monsters Bosses.json"
local droprate_filename = "Data:Droprate Monsters Bosses.json"
local lootdrop_filename = "Data:Lootdrop GhostKing.json"
local lootdrop_filename = "Data:Lootdrop GhostKing.json"
 
local lootdrop_data = mw.loadJsonData(lootdrop_filename)
local lootdrop_data = mw.loadJsonData(lootdrop_filename)
if lootdrop_data == nil then return "Lootdrop data file '" .. lootdrop_filename .. "' could not be found." end
if lootdrop_data == nil then return "Lootdrop data file '" .. lootdrop_filename .. "' could not be found." end
local lootdrop_item_counts = lootdrop_data["luckgrade"]
local resulting_table = ""
 
resulting_table = resulting_table .. '<table cellspacing="0" class="loottable stripedtable sortable jquery-tablesorter mw-collapsible" style="width:100%">'
local droprate_data = mw.loadJsonData(droprate_filename)
resulting_table = resulting_table .. ' <caption>Loot Table at 0 Luck</caption>'
if droprate_data == nil then return "Droprate data file '" .. droprate_filename .. "' could not be found." end
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>"'
 
local 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>"'
-- Create body of table
 
-- Item name, luck grade, rarity, item count
for i, luckgrade in ipairs(droprate_data["4023"]["luckgrade_order"]) do
for i, item_name in ipairs(lootdrop_data["item_order"]) do
local probability = droprate_data["4023"]["luckgrade"][luckgrade]
-- Get the item's data
if probability == nil then return "probability for '" .. luckgrade .. "' not found in droprate data for luckgrade dictionary." end
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
local item_count = lootdrop_item_counts[luckgrade]
if item_count == nil then return "item_count for '" .. luckgrade .. "' not found in lootdrop data." end
-- Iterate each record in the item data
 
local num_records = 0 --used for determining rowspan
local probability_per_item = probability / item_count
for j, item_record in ipairs(item_data) do
 
num_records = num_records+1
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
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
end
 
resulting_table = resulting_table .. '</table><br>'
resulting_table = resulting_table .. '</table><br>'
 
return resulting_table
return resulting_table
end
end


return p
return p

Revision as of 04:10, 5 May 2025


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


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 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 = '<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["4023"]["luckgrade_order"]) do
		local probability = droprate_data["4023"]["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 = probability / item_count

		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>'

	return resulting_table
end

return p