From Dark and Darker Wiki
m (row1 should actually be slot_headers not enchant_name_headers) |
m (add enchant iteration back with error handling) |
||
Line 12: | Line 12: | ||
if base_or_gem ~= "base" and base_or_gem ~= "gem" then return "1st parameter 'base_or_gem' must be either 'base' or 'gem'." end | if base_or_gem ~= "base" and base_or_gem ~= "gem" then return "1st parameter 'base_or_gem' must be either 'base' or 'gem'." end | ||
local slot_headers = | local slot_headers = '<th></th><th rowspan="2">Enchantments</th>' | ||
local min_max_headers = | local min_max_headers = '<th></th><th></th>' | ||
-- Create enchant_name_headers (row1) | -- Create enchant_name_headers (row1) | ||
Line 20: | Line 20: | ||
slot_headers = slot_headers .. '<th colspan="2">' .. slot_name .. '</th>' | slot_headers = slot_headers .. '<th colspan="2">' .. slot_name .. '</th>' | ||
min_max_headers = min_max_headers .. '<th>Min</th>' .. '<th>Max</th>' | min_max_headers = min_max_headers .. '<th>Min</th>' .. '<th>Max</th>' | ||
end | |||
local enchant_rows = "" | |||
for i, enchant_group_name in ipairs(enchantments_data["enchant_group_order"]) do | |||
local enchants_in_group = enchantments_data["enchant_order"][enchant_group_name] | |||
if enchants_in_group == nil then return "Error: " .. enchant_group_name .. " not found in \"enchant_order\"" end | |||
-- Iterate enchants in the group | |||
for i, enchant_name in ipairs(enchants_in_group) do | |||
-- Get that enchant's data | |||
local slots_data = enchantments_data["enchant_rolls"][enchant_name] | |||
if slots_data == nil then return "Error: " .. enchant_name .. " not found in \"enchant_rolls\"" end | |||
-- Iterate each slot in the enchant | |||
for slot_name, slot_data in pairs(slots_data) do | |||
local roll_data = slot_data[base_or_gem] | |||
if roll_data == nil then return "Error: " .. base_or_gem .. " not found in \"enchant_rolls\"." .. enchant_name .. "." .. slot_name end | |||
local min_roll = slot_data["min"] | |||
local max_roll = slot_data["max"] | |||
end | |||
end | |||
end | end | ||
Revision as of 02:19, 23 February 2025
Overview
Functions for Enchantments. Data comes from Data:Enchantments.json.
Functions
draw_roll_range_table
Create's a table of enchants for the Enchantments page
Parameters
- base_or_gem - List 'base' (traditional) or 'gem' enchant roll ranges?
Examples
{{#invoke:Enchantments|draw_roll_range_table|gem}}
Script error: The function "draw_roll_range_table" does not exist.
draw_socket_cost_table
Create's a table of socket's cost per rarity for the Enchantments page
Parameters
none
Examples
{{#invoke:Enchantments|draw_socket_cost_table}}
Script error: The function "draw_socket_cost_table" does not exist.
local enchantments_data = mw.loadJsonData("Data:Enchantments.json")
local p = {}
function p.draw_table(base_or_gem)
-- Handle based on how it was called
if type(base_or_gem) == "table" and base_or_gem.args then -- if called via wikitext instead of lua
local frame = base_or_gem
base_or_gem = frame.args[1]
end
-- Validate
if base_or_gem ~= "base" and base_or_gem ~= "gem" then return "1st parameter 'base_or_gem' must be either 'base' or 'gem'." end
local slot_headers = '<th></th><th rowspan="2">Enchantments</th>'
local min_max_headers = '<th></th><th></th>'
-- Create enchant_name_headers (row1)
-- Iterate enchant groups
for i, slot_name in ipairs(enchantments_data["slot_order"]) do
slot_headers = slot_headers .. '<th colspan="2">' .. slot_name .. '</th>'
min_max_headers = min_max_headers .. '<th>Min</th>' .. '<th>Max</th>'
end
local enchant_rows = ""
for i, enchant_group_name in ipairs(enchantments_data["enchant_group_order"]) do
local enchants_in_group = enchantments_data["enchant_order"][enchant_group_name]
if enchants_in_group == nil then return "Error: " .. enchant_group_name .. " not found in \"enchant_order\"" end
-- Iterate enchants in the group
for i, enchant_name in ipairs(enchants_in_group) do
-- Get that enchant's data
local slots_data = enchantments_data["enchant_rolls"][enchant_name]
if slots_data == nil then return "Error: " .. enchant_name .. " not found in \"enchant_rolls\"" end
-- Iterate each slot in the enchant
for slot_name, slot_data in pairs(slots_data) do
local roll_data = slot_data[base_or_gem]
if roll_data == nil then return "Error: " .. base_or_gem .. " not found in \"enchant_rolls\"." .. enchant_name .. "." .. slot_name end
local min_roll = slot_data["min"]
local max_roll = slot_data["max"]
end
end
end
local slot_headers = "<tr>" .. slot_headers .. "</tr>"
local min_max_headers = "<tr>" .. min_max_headers .. "</tr>"
local table_str = "<table>" .. slot_headers .. min_max_headers .. "</table>"
return table_str
end
return p