From Dark and Darker Wiki

No edit summary
(Testing tab toggles)
Line 1: Line 1:
local p = {}
local p = {}


function round(number, decimalPlaces)
local line_divider = '\n<div class="line" style="margin:5px 0px 5px 0px; background-image:linear-gradient(to right,#0A0A0A,#646464,#0A0A0A)"></div>'
  return tonumber(string.format("%." .. (decimalPlaces or 0) .. "f", number))
 
local function create_tab_toggle(tab_id, tab_number, title, content, selected)
if selected then
return '<div class="selected-tab tab-toggle tab" data-tabid="'..tab_id..'" data-tab="'..tab_number..'" title="'..title..'">'..content..'</div>'
else
return '<div class="tab-toggle tab" data-tabid="'..tab_id..'" data-tab="'..tab_number..'" title="'..title..'">'..content..'</div>'
end
end
end


function p.create_droprate_table(frame)
local function create_tabs_from_list(tab_list, tab_number)
local tab_toggles_html = ''
for i,mode in ipairs(tab_list) do
if i == 1 then
tab_toggles_html = tab_toggles_html..create_tab_toggle(mode, tab_number, mode, mode, true)
else
tab_toggles_html = tab_toggles_html..create_tab_toggle(mode, tab_number, mode, mode, false)
end
end
return tab_toggles_html
end
 
local function dungeongrade_translate(dungeongrade)
local code = {"Default","Default"}
 
if string.find(dungeongrade, "40") then
code[1] = "HR 225+"
elseif string.find(dungeongrade, "30") then
code[1] = "HR 0-224"
elseif string.find(dungeongrade, "20") then
code[1] = "LR"
elseif string.find(dungeongrade, "10") then
code[1] = "PvE"
end
 
if string.find(dungeongrade, "001") then
code[2] = "Goblin Caves"
elseif string.find(dungeongrade, "011") then
code[2] = "Ice Caverns"
elseif string.find(dungeongrade, "012") then
code[2] = "Ice Abyss"
elseif string.find(dungeongrade, "021") then
code[2] = "Ruins"
elseif string.find(dungeongrade, "022") then
code[2] = "Crypts"
elseif string.find(dungeongrade, "023") then
code[2] = "Inferno"
end
 
return code
end
 
local function round(number, decimalPlaces)
return tonumber(string.format("%."..(decimalPlaces or 0).."f", number))
end
 
local function create_droprate_table(droprate_data, lootdrop_data, dungeongrade, resulting_table)
-- Table header
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>'
 
-- Table body
for _, 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_data["luckgrade"][luckgrade]
if item_count == nil then return "item_count for '"..luckgrade.."' not found in lootdrop data." end
 
-- Table row
resulting_table = resulting_table.."<tr class='cr"..luckgrade.."'><td><b>"..luckgrade.."</b></td><td><b>"..100*probability.."%</b></td><td><b>"..round(100*probability/item_count,4).."%</b></td><td><b>"..item_count.."</b></td></tr>"
end
 
return resulting_table..'</table></div>'
end
 
function p.create_droprate_tables(frame)
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"


-- Load lootdrop_filename
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
-- Check if lootdrop_data is nil, if so return an error message
local lootdrop_item_counts = lootdrop_data["luckgrade"]
if lootdrop_data == nil then return "Lootdrop data file '"..lootdrop_filename.."' could not be found." end


-- Load droprate_filename
local droprate_data = mw.loadJsonData(droprate_filename)
local droprate_data = mw.loadJsonData(droprate_filename)
if droprate_data == nil then return "Droprate data file '" .. droprate_filename .. "' could not be found." end
-- Check if droprate_data is nil, if so return an error message
if droprate_data == nil then return "Droprate data file '"..droprate_filename.."' could not be found." end


local resulting_table = ''
local resulting_table = ''


for i, dungeongrade in ipairs(droprate_data["dungeongrade_order"]) do
-- The following nested code creates a series of divs with respective tab toggles for the different modes, maps, and lootdrops in the droprate data.
-- The outermost div is for the entire table, and the innermost div is for each specific dungeongrade.
 
-- Create the tabs for the modes in mode_order
resulting_table = resulting_table..create_tabs_from_list(droprate_data["mode_order"],0)
-- Create a div for each specific mode
for i,mode in ipairs(droprate_data["mode_order"]) do -- 4 nodes
resulting_table = resulting_table..'<div class="'.. mode ..'-data">'


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>'
-- Create the tabs for the maps in in map_order
resulting_table = resulting_table..create_tabs_from_list(droprate_data["map_order"][mode],i)
-- Create div for each specific map
for j,map in ipairs(droprate_data["map_order"][mode]) do -- 1 to 6 nodes
resulting_table = resulting_table..'<div class="'.. map ..'-data">'


for j, luckgrade in ipairs(droprate_data[tonumber(dungeongrade)]["luckgrade_order"]) do
-- Create the tabs for the lootdrop in lootdrop_order
local probability = droprate_data[tonumber(dungeongrade)]["luckgrade"][luckgrade]
resulting_table = resulting_table..create_tabs_from_list(droprate_data["lootdrop_order"][mode][map],j)
if probability == nil then return "probability for '" .. luckgrade .. "' not found in droprate data for luckgrade dictionary." end
-- Create a div for each specific dungeongrade
for _,dungeongrade in ipairs(droprate_data["lootdrop_order"][mode][map]) do -- 1 to 6 nodes, example data only has 1 node atm
resulting_table = resulting_table..'<div class="'..dungeongrade..'-data">'


local item_count = lootdrop_item_counts[luckgrade]
-- Create the droprate table for the specific dungeongrade
if item_count == nil then return "item_count for '" .. luckgrade .. "' not found in lootdrop data." end
resulting_table = resulting_table..create_droprate_table(droprate_data, lootdrop_data, dungeongrade, resulting_table)


resulting_table = resulting_table .. "<tr class='cr"..luckgrade.."'>"
resulting_table = resulting_table..'</div>'
.."<td><b>" .. luckgrade .. "</b></td>"
end
.."<td><b>" .. 100 * probability .. "%</b></td>"
resulting_table = resulting_table..'</div>'
.."<td><b>" .. round(100 * probability / item_count, 4) .. "%</b></td>"
.."<td><b>" .. item_count .. "</b></td></tr>"
end
end
resulting_table = resulting_table..'</div>'
end


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


return p
return p

Revision as of 00:08, 8 May 2025

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


local p = {}

local line_divider = '\n<div class="line" style="margin:5px 0px 5px 0px; background-image:linear-gradient(to right,#0A0A0A,#646464,#0A0A0A)"></div>'

local function create_tab_toggle(tab_id, tab_number, title, content, selected)
	if selected then
		return '<div class="selected-tab tab-toggle tab" data-tabid="'..tab_id..'" data-tab="'..tab_number..'" title="'..title..'">'..content..'</div>'
	else
		return '<div class="tab-toggle tab" data-tabid="'..tab_id..'" data-tab="'..tab_number..'" title="'..title..'">'..content..'</div>'
	end
end

local function create_tabs_from_list(tab_list, tab_number)
	local tab_toggles_html = ''
	for i,mode in ipairs(tab_list) do
		if i == 1 then
			tab_toggles_html = tab_toggles_html..create_tab_toggle(mode, tab_number, mode, mode, true)
		else
			tab_toggles_html = tab_toggles_html..create_tab_toggle(mode, tab_number, mode, mode, false)
		end
	end
	return tab_toggles_html
end

local function dungeongrade_translate(dungeongrade)
	local code = {"Default","Default"}

	if string.find(dungeongrade, "40") then
		code[1] = "HR 225+"
	elseif string.find(dungeongrade, "30") then
		code[1] = "HR 0-224"
	elseif string.find(dungeongrade, "20") then
		code[1] = "LR"
	elseif string.find(dungeongrade, "10") then
		code[1] = "PvE"
	end

	if string.find(dungeongrade, "001") then
		code[2] = "Goblin Caves"
	elseif string.find(dungeongrade, "011") then
		code[2] = "Ice Caverns"
	elseif string.find(dungeongrade, "012") then
		code[2] = "Ice Abyss"
	elseif string.find(dungeongrade, "021") then
		code[2] = "Ruins"
	elseif string.find(dungeongrade, "022") then
		code[2] = "Crypts"
	elseif string.find(dungeongrade, "023") then
		code[2] = "Inferno"
	end

	return code
end

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

local function create_droprate_table(droprate_data, lootdrop_data, dungeongrade, resulting_table)
	-- Table header
	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>'

	-- Table body
	for _, 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_data["luckgrade"][luckgrade]
		if item_count == nil then return "item_count for '"..luckgrade.."' not found in lootdrop data." end

		-- Table row
		resulting_table = resulting_table.."<tr class='cr"..luckgrade.."'><td><b>"..luckgrade.."</b></td><td><b>"..100*probability.."%</b></td><td><b>"..round(100*probability/item_count,4).."%</b></td><td><b>"..item_count.."</b></td></tr>"
	end

	return resulting_table..'</table></div>'
end

function p.create_droprate_tables(frame)
	local droprate_filename = "Data:Droprate Monsters Bosses.json"
	local lootdrop_filename = "Data:Lootdrop GhostKing.json"

	-- Load lootdrop_filename
	local lootdrop_data = mw.loadJsonData(lootdrop_filename)
	-- Check if lootdrop_data is nil, if so return an error message
	if lootdrop_data == nil then return "Lootdrop data file '"..lootdrop_filename.."' could not be found." end

	-- Load droprate_filename
	local droprate_data = mw.loadJsonData(droprate_filename)
	-- Check if droprate_data is nil, if so return an error message
	if droprate_data == nil then return "Droprate data file '"..droprate_filename.."' could not be found." end

	local resulting_table = ''

	-- The following nested code creates a series of divs with respective tab toggles for the different modes, maps, and lootdrops in the droprate data.
	-- The outermost div is for the entire table, and the innermost div is for each specific dungeongrade.

	-- Create the tabs for the modes in mode_order
	resulting_table = resulting_table..create_tabs_from_list(droprate_data["mode_order"],0)
	-- Create a div for each specific mode
	for i,mode in ipairs(droprate_data["mode_order"]) do -- 4 nodes
		resulting_table = resulting_table..'<div class="'.. mode ..'-data">'

		-- Create the tabs for the maps in in map_order
		resulting_table = resulting_table..create_tabs_from_list(droprate_data["map_order"][mode],i)
		-- Create div for each specific map
		for j,map in ipairs(droprate_data["map_order"][mode]) do -- 1 to 6 nodes
			resulting_table = resulting_table..'<div class="'.. map ..'-data">'

			-- Create the tabs for the lootdrop in lootdrop_order
			resulting_table = resulting_table..create_tabs_from_list(droprate_data["lootdrop_order"][mode][map],j)
			-- Create a div for each specific dungeongrade
			for _,dungeongrade in ipairs(droprate_data["lootdrop_order"][mode][map]) do -- 1 to 6 nodes, example data only has 1 node atm
				resulting_table = resulting_table..'<div class="'..dungeongrade..'-data">'

				-- Create the droprate table for the specific dungeongrade
				resulting_table = resulting_table..create_droprate_table(droprate_data, lootdrop_data, dungeongrade, resulting_table)

				resulting_table = resulting_table..'</div>'
			end
			resulting_table = resulting_table..'</div>'
		end
		resulting_table = resulting_table..'</div>'
	end

	return resulting_table
end

return p