- name - Name of the object
- category - Monster, Prop, Loose Loot
The Dark and Darker Wiki is made by and for the players. Do you want to contribute?
From Dark and Darker Wiki
Functions for making loot table. Data comes from Loot:Monster.json, Loot:Prop.json, Loot:Loose Loot.json, and the Loot: namespace.
Creates a table of drops
{{#invoke:Droprate|loot_tables|name=Lich|category=Monster}}
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 translate_dungeon_codes(code)
local codes = {
[40] = "HR 225+",
[30] = "HR 0-224",
[20] = "LR",
[10] = "PvE",
[1] = "Goblin Caves",
[11] = "Ice Cavern",
[12] = "Ice Abyss",
[21] = "Ruins",
[22] = "Crypts",
[23] = "Inferno"
}
local found_dungeon = codes[code]
if found_dungeon == nil then
return code
else
return found_dungeon
end
end
local function create_div_tab(id, is_displayed)
if is_displayed then
return '<div class="'.. id ..'-data">'
else
return '<div class="'.. id ..'-data" style="display:none;">'
end
end
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_id)
if tab_list == nil then return '' end
local tab_toggles_html = ''
for i,tab in ipairs(tab_list) do
if i == 1 then
tab_toggles_html = tab_toggles_html..create_tab_toggle(tab_id, tab, tab, translate_dungeon_codes(tab), true)
else
tab_toggles_html = tab_toggles_html..create_tab_toggle(tab_id, tab, tab, translate_dungeon_codes(tab), false)
end
end
return tab_toggles_html
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)
if droprate_data[dungeongrade] == nil then return '' end
-- Table header
local droprate_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]
local item_count = lootdrop_data["luckgrade"][luckgrade]
-- Table row
droprate_table = droprate_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 droprate_table..'</table>'
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
-- 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
local resulting_table = create_tabs_from_list(droprate_data["mode_order"],"0")
for i,mode in ipairs(droprate_data["mode_order"]) do -- 4 nodes
-- Create a div and tabs for each specific mode
resulting_table = resulting_table..create_div_tab(mode, i == 1)..create_tabs_from_list(droprate_data["map_order"][mode],"1"..i)
for j,map in ipairs(droprate_data["map_order"][mode]) do -- 1 to 6 nodes
-- Create div and tabs for each specific map
resulting_table = resulting_table..create_div_tab(map, j == 1)..create_tabs_from_list(droprate_data["lootdrop_order"][mode][map],"2"..i..j)
for k,dungeongrade in ipairs(droprate_data["lootdrop_order"][mode][map]) do -- 1 to 6 nodes, example data only has 1 node atm
-- Create a div and table for each specific dungeongrade
resulting_table = resulting_table..create_div_tab(dungeongrade, k == 1)..create_droprate_table(droprate_data, lootdrop_data, dungeongrade)..'</div>'
end
resulting_table = resulting_table..'</div>'
end
resulting_table = resulting_table..'</div>'
end
return resulting_table
end
return p