From Dark and Darker Wiki
m (Needs to be a string now?) |
mNo edit summary |
||
Line 18: | Line 18: | ||
local resulting_table = '' | local resulting_table = '' | ||
for i, dungeongrade in ipairs(droprate_data | 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>' | 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>' |
Revision as of 23:54, 7 May 2025
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 j, luckgrade in ipairs(droprate_data[tostring(dungeongrade)]["luckgrade_order"]) do
local probability = droprate_data[tostring(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
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
resulting_table = resulting_table .. '</table><br>'
end
return resulting_table
end
return p