Module:StatsTable

local p = {}

-- Builds the table on the /Stats subpage function p.stats_table(frame) -- Name input for convenience local in_args = frame:getParent.args local int_wis = frame.args.int_wis -- Set up variables for building the table local tbl_width = "60%" local col_width = "13%" local stats = {"HP", "TP", "STR", "TEC", "VIT", "AGI", "LUC"} -- If the game has the INT/WIS split (EO5 on), adjust for that if int_wis ~= nil then tbl_width = "70%" col_width = "11.375%" stats = {"HP", "TP", "STR", "INT", "VIT", "WIS", "AGI", "LUC"} end

-- Start building the output table out_table = mw.html.create("table") :addClass("wikitable"):css("width", tbl_width) :tag("tr") :tag("th"):css("width", "9%"):wikitext("Lv."):done for i = 1, #stats do   	out_table:tag("th"):css("width", col_width):wikitext(stats[i]):done end out_table:done -- Loop for each level to add the stats to the table for i = 1, 99 do   	local tr = out_table:tag("tr") :tag("th"):wikitext(i):done for s = 1, #stats do   		tr:tag("td"):wikitext(in_args[s + (#stats * (i - 1))]):done end tr:done -- Show the headings again after every 10 levels, makes it easier to read if i % 10 == 0 then tr = out_table:tag("tr") :tag("th"):css("width", "9%"):wikitext("Lv."):done for i = 1, #stats do		   	tr:tag("th"):css("width", col_width):wikitext(stats[i]):done end tr:done end end return out_table:done end

-- Builds the shorter (every 10 levels) table used on class pages function p.short(frame) -- Name input for convenience local in_args = frame:getParent.args local game = in_args.game or in_args[1] local class = in_args.class or in_args[2] local max_lv = in_args.max_level or in_args[3] or 99 local min_lv = in_args.min_level or in_args[4] or 1 local cargo = mw.ext.cargo -- Set up variables for building the table local tbl_width = "60%" local col_width = "13%" local stats = {"HP", "TP", "STR", "TEC", "VIT", "AGI", "LUC"} local cq_fields = {"level", "hp", "tp", "strength", "technique", "vitality", "agility", "luck"} -- If the game has the INT/WIS split (EO5 on), adjust for that if game == "EO5" or game == "EON" then tbl_width = "70%" col_width = "11.375%" stats = {"HP", "TP", "STR", "INT", "VIT", "WIS", "AGI", "LUC"} cq_fields = {"level", "hp", "tp", "strength", "intellect", "vitality", "wisdom", "agility", "luck"} end

-- In EO5 legendary titles' stats are modifiers; -- this appends a + sign to the value if the class being called is a legendary title local add_plus = "" if game == "EO5" and not (class == "Earthlain" or class == "Celestrian" or class == "Therian" or class == "Brouni" or class == "Hawk" or class == "Hound" or class == "Wraith") then add_plus = "+" end -- Cargo query arguments: -- limit: cut off at the specified max level -- offset: start at the specified min level (only relevant for EO5 legendary titles) local cq_args = { where = "class_name = '" .. class .. "' and (level = 1 or (level % 10 = 0) or level = " .. max_lv .. ")", limit = 1 + math.ceil(tonumber(max_lv) / 10), offset = math.floor(tonumber(min_lv) / 10) }	local cq_result = cargo.query("ClassStats_" .. game, table.concat(cq_fields, ","), cq_args) -- Start building the output table out_table = mw.html.create("table") :addClass("wikitable"):css("width", tbl_width) :tag("tr") :tag("th"):css("width", "9%"):wikitext("Lv."):done for i = 1, #stats do   	out_table:tag("th"):css("width", col_width):wikitext(stats[i]):done end out_table:done -- Loop through the returned values to build the table for i, v in ipairs(cq_result) do		local tr = out_table:tag("tr") :tag("th"):wikitext(v.level):done -- Start at 2 because 1 is level, which is already done for s = 2, #cq_fields do tr:tag("td"):wikitext(add_plus .. v[cq_fields[s]]):done end tr:done end return out_table:done end

function p.short_eo5(frame) -- Name input for convenience local in_args = frame:getParent.args local title = in_args.class or in_args[2] local race = frame.args.race local cargo = mw.ext.cargo -- Set up variables for building the table tbl_width = "70%" col_width = "11.375%" stats = {"HP", "TP", "STR", "INT", "VIT", "WIS", "AGI", "LUC"} cq_fields = {"level", "hp", "tp", "strength", "intellect", "vitality", "wisdom", "agility", "luck"} -- Cargo query arguments local title_args = { where = "class_name = '" .. title .. "' and (level = 1 or (level % 10 = 0) or level = 99)", offset = 2 }	local race_args = { where = "class_name = '" .. race .. "' and (level = 1 or (level % 10 = 0) or level = 99)", offset = 2 }	local title_result = cargo.query("ClassStats_EO5", table.concat(cq_fields, ","), title_args) local race_result = cargo.query("ClassStats_EO5", table.concat(cq_fields, ","), race_args) -- Start building the output table out_table = mw.html.create("table") :addClass("wikitable"):css("width", tbl_width) :tag("tr") :tag("th"):css("width", "9%"):wikitext("Lv."):done for i = 1, #stats do   	out_table:tag("th"):css("width", col_width):wikitext(stats[i]):done end out_table:done -- Loop through the returned values to build the table for i, v in ipairs(title_result) do		local tr = out_table:tag("tr") :tag("th"):wikitext(v.level):done -- Start at 2 because 1 is level, which is already done for s = 2, #cq_fields do   		tr:tag("td"):wikitext(tonumber(race_result[i][cq_fields[s]]) + tonumber(v[cq_fields[s]])):done end tr:done end return out_table:done end

return p