Jump to content
Toggle menu
  • 3.1K articles
  • 4.4K files
  • 18 users
  • 91.5K edits
Ashenzari's Archive
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Module:Species

From Ashenzari's Archive
Revision as of 22:45, 5 May 2016 by imported>Edsrzf (Initial module)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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 species_plural(species)

 if species == "Mummy" then
   return "Mummies"
 elseif species == "Deep Elf" or species == "High Elf" or species == "Deep Dwarf" then
   return species:sub(1, -2) .. "ves"
 elseif species == "Naga" or species == "Demonspawn" or species == "Tengu" or species == "Merfolk" then
   return species
 end
 return species .. "s"

end

function p.preferred_backgrounds(frame)

 local name = name_arg(frame)
 local species = data[name]
 local categories = {{}, {}, {}, {}, {}}
 local cat_names = {"Warriors", "Adventurers", "Zealots", "Warrior-mages", "Mages"}
 for _, bg in pairs(species.Backgrounds) do
   local cat = categories[5]
   if bg == "Fighter" or bg == "Gladiator" or bg == "Monk" or bg == "Hunter" or bg == "Assassin" then
     cat = categories[1]
   elseif bg == "Artificer" or bg == "Wanderer" then
     cat = categories[2]
   elseif bg == "Berserker" or bg == "Abyssal Knight" or bg == "Chaos Knight" then
     cat = categories[3]
   elseif bg == "Skald" or bg == "Transmuter" or bg == "Warper" or bg == "Arcane Marksman" or bg == "Enchanter" then
     cat = categories[4]
   end
   table.insert(cat, "" .. bg .. "")
 end
 local result = "==Preferred Backgrounds==\n"
 for i, cat in pairs(categories) do
   if #cat > 0 then
     result = result .. "*" .. cat_names[i] .. ": " .. table.concat(cat, ", ") .. "\n"
   end
 end
 return result

end

function p.base_stats(frame)

 local name = name_arg(frame)
 local species = data[name]
 local result = ("%s have a base Strength of %d, Intelligence of %d, and Dexterity of %d (before Background modifiers)."):format(species_plural(name), species.Strength, species.Intelligence, species.Dexterity)
 if species.MP ~= 0 then
   result = result .. (" They have %+d to base magic points."):format(species.MP)
 end
 return result

end

local function mr_gain(species)

 if name == "Draconian" then
   return ("+%d magic resistance per level (+%d for purple Draconians)."):format(species.MR, data["Purple Draconian"].MR)
 else
   return ("+%d magic resistance per level."):format(species.MR)
 end

end

local function hp_apt(species)

 if species.HP < 0 then
   return ("%d%% less HP than average."):format(-species.HP*10)
 elseif species.HP == 0 then
   return "Average hit points."
 else
   return ("%d%% more HP than average."):format(species.HP*10)
 end

end

function p.level_bonuses(frame)

 local name = name_arg(frame)
 local species = data[name]
 return ([[* %s
  • %s

]]):format(mr_gain(species), hp_apt(species)) end

return p