Module:Apt: Difference between revisions
From Ashenzari's Archive
More actions
imported>Ge0ff m add Shapeshifting, mark it as obsolete for now |
imported>Ge0ff m test non-obsolete Sh |
||
| Line 20: | Line 20: | ||
local function is_obsolete_sk(skill) | local function is_obsolete_sk(skill) | ||
return | return skill == "Charms" or skill == "Slings" or skill == "Bows" or skill == "Crossbows" or skill == "Stabbing" or skill == "Traps" | ||
end | end | ||
Revision as of 13:52, 12 July 2023
local p = {}
local data = mw.loadData('Module:Table of species')
local function name_arg(frame)
local name = frame.args[1] if not name or name == "" then name = mw.title.getCurrentTitle().text end return name
end
local function is_colored_draconian(species)
return species:match(" Draconian$")
end
local function is_obsolete(species)
return data[species].Obsolete or false
end
local function is_obsolete_sk(skill)
return skill == "Charms" or skill == "Slings" or skill == "Bows" or skill == "Crossbows" or skill == "Stabbing" or skill == "Traps"
end
local function species_sorted(include_obsolete)
include_obsolete = include_obsolete or false
local species = {}
for sp in pairs(data) do
if not is_colored_draconian(sp) and (include_obsolete or not is_obsolete(sp)) then
table.insert(species, sp)
end
end
table.sort(species)
return species
end
local function skill_average(skill)
local count = 0
local sum = 0
for name, sp in pairs(data) do
if sp.Aptitudes[skill] and not is_colored_draconian(name) and name ~= "Gnoll" and (is_obsolete_sk(skill) or not is_obsolete(name)) then
count = count + 1
sum = sum + sp.Aptitudes[skill]
end
end
return string.format("%.3f", sum / count)
end
function p.aptitude(frame)
local sp = frame.args[1] local sk = frame.args[2] if not sp or not sk then return "" end if sp == "Average" then return skill_average(sk) else return data[sp].Aptitudes[sk] or "N/A" end
end
function p.skill_table(frame)
local browser_width = frame.args[2]
browser_width = tonumber(browser_width) or 50
local skill = name_arg(frame)
local headers = {}
local species = species_sorted(is_obsolete_sk(skill))
local sp_headers_1 = {}
local sp_headers_2 = {}
for i, sp in ipairs(species) do
local header = ("%s"):format(sp, data[sp].Abbrev)
if i<browser_width then
table.insert(sp_headers_1, header)
else
table.insert(sp_headers_2, header)
end
end
local sk_headers_1 = {}
local sk_headers_2 = {}
for i, sp in ipairs(species) do
local header = ("%s"):format(data[sp].Aptitudes[skill] or "N/A")
if i<browser_width then
table.insert(sk_headers_1, header)
else
table.insert(sk_headers_2, header)
end
end
local result = [[{| class="wikitable" border="1"
|- |]]
result = result .. table.concat(sp_headers_1, "\n|") result = result .. "\n|-\n| " result = result .. table.concat(sk_headers_1, "\n| ") if next(sp_headers_2) then result = result .. "\n|-\n|" result = result .. table.concat(sp_headers_2, "\n|") result = result .. "\n|-\n| " result = result .. table.concat(sk_headers_2, "\n| ") end result = result .. "\n|}" return result
end
function p.skill_draconian_exceptions(frame)
local skill = name_arg(frame)
local normal = data['Draconian'].Aptitudes[skill]
local result =
for name, species in pairs(data) do
if is_colored_draconian(name) and (is_obsolete_sk(skill) or not is_obsolete(name)) and species.Aptitudes[skill] ~= normal then
local col = name:match("^%a*")
result = result .. '* ' .. col .. ' draconians get ' .. species.Aptitudes[skill] .. '.\n'
end
end
return result
end
local function aptitude_chart(skills, header)
local result = header
-- constants used by sort_key
local a_ord = string.byte('a')
local z_ord = string.byte('z')
local aa_ord = string.byte('A')
-- generates the table keys
local function sort_key(i)
local result
if i > z_ord - a_ord then
i = i - (z_ord - a_ord) - 1
result = '!' .. string.char(aa_ord + i)
else
result = '"' .. string.char(a_ord + i)
end
return result
end
local i = 0
for _, sp in ipairs(species_sorted()) do
result = result .. '|' .. sp .. "\n"
for _, sk in ipairs(skills) do
result = result .. "||" .. (data[sp].Aptitudes[sk] or "N/A") .. "\n"
end
result = result .. "|-\n"
i = i + 1
end
result = result .. "|}"
return result
end
function p.aptitude_chart_general(frame)
local skills = {'Armour', 'Dodging', 'Stealth',
'Shields', 'Invocations', 'Evocations', 'Hit Points', 'Magic Points', 'Experience'}
local header = [=[
]=]
return aptitude_chart(skills, header)
end
function p.aptitude_chart_combat(frame)
local skills = {'Fighting', 'Short Blades', 'Long Blades', 'Maces & Flails',
'Axes', 'Polearms', 'Staves', 'Unarmed Combat', 'Throwing', 'Ranged Weapons'}
local header = [=[
| Species | Arm | Ddg | Sth | Shd | Inv | Evo | HP | MP | Exp |
|---|
| Species | Fgt | SBl | LBl | M&F | Axs | Pla | Stv | UC | Thr | RW |
|---|
| Species | Spc | Coj | Hex | Sum | Nec | Trl | Trm | Fir | Ice | Air | Ear | Poi |
|---|