From Dark and Darker Wiki

Revision as of 20:52, 19 May 2025 by Sur (talk | contribs) (fix)


Common


local utils = require("Module:Utilities")
local p = {}
local monsters_data = mw.loadJsonData("Data:Monster.json")
local monster_localized_names = monsters_data["monster_localized_names"] --nickname
local monster_ids = monsters_data["monster_ids"] --nickname
local monster_grades = {"Common", "Elite", "Nightmare"} --array used just for ordering them

function p.create_loot_table(droprate_id, lootdrop_id)
	if type(droprate_id) == "table" and droprate_id.args then -- if called via wikitext instead of lua
        local frame = droprate_id
        droprate_id = frame.args[1]
        lootdrop_id = frame.args[2]
	end

	droprate_id = "Droprate Monsters Bosses"
	lootdrop_id = "Lootdrop GhostKing"
	
	local droprate_filename = "Data:" .. droprate_id .. ".json"
	local lootdrop_filename = "Data:" .. lootdrop_id .. ".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 resulting_table = ""
	resulting_table = resulting_table .. '<table cellspacing="0" class="loottable stripedtable sortable jquery-tablesorter mw-collapsible" style="width:100%">'
	resulting_table = resulting_table .. '	<caption>Loot Table at 0 Luck</caption>'
	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>'
	
	-- Create body of table
	-- Item name, luck grade, rarity, item count
	for i, item_name in ipairs(lootdrop_data["item_order"]) do
		-- Get the item's data
		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
		
		-- Iterate each record in the item data
		local num_records = 0 --used for determining rowspan
		for j, item_record in ipairs(item_data) do
			num_records = num_records+1
		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
	
	resulting_table = resulting_table .. '</table><br>'
	
	return resulting_table
end

function p.create_monster_loot_tables(frame)
	local monster_localized_name = frame.args[1] -- Ghost King
	
	local my_monster_ids = monster_localized_names[monster_localized_name] -- {Common: id of Common monster, }
	if my_monster_ids == nil then return "Monster '" .. monster_localized_name .. "' was not found in monsters_data." end
	
	local outputted_string = ""
	for i, monster_grade_key in ipairs(monster_grades) do --mgk of --Elite
		-- Get the monster 
		if 2==2 then return monster_grade_key end
		monster_grade_id = my_monster_ids[monster_grade_key] --Id_Monster_GhostKing_Elite
		if monster_grade_id ~= nil then
			if 1==1 then return 'success' end
			spawner_ids = monster_ids[monster_grade_id]["spawner_ids"] -- {"Id_Spawner_New_Monster_GhostKing": true}
			for spawner_id, b in pairs(spawner_ids) do
				outputted_string = outputted_string .. create_spawner_loot_table(spawner_id)
			end
		end
	end
	
	return outputted_string
end

function create_spawner_loot_tables(spawner_id)
	if type(spawner_id) == "table" and spawner_id.args then -- if called via wikitext instead of lua
        local frame = spawner_id
        spawner_id = frame.args[1]
	end
	
	return "Cool" .. spawner_id
end

return p