Module:Feature page/how to learn

From bg3.wiki
Jump to navigation Jump to search

Renders the "How to learn" section of a feature page.

Examples

Markup

| class learns at level 6 = College of Lore:via [[Magical Secrets]]
| granted by features = Magic Initiate: Sorcerer, Magic Initiate: Wizard, Spell Sniper
| granted by items = Mourning Frost
| race learns at level 1 = High Elf, High Half-Elf
| class learns at level 1 = Sorcerer, Wizard
| class learns at level 3 = Eldritch Knight, Arcane Trickster
| class learns at level 10 = Bard:via [[Magical Secrets]]
| scribing = yes
Renders as

How to learn

Classes: Races: Granted by items: Granted by features: Other ways to learn:

Markup

| class learns at level 6 = College of Lore:via [[Magical Secrets]]
| class learns at level 5 = Sorcerer, Wizard, Circle of the Land:Arctic or Grassland, Warlock:via [[Pact of the Tome]] once per long rest
| class learns at level 9 = Oath of Vengeance
| granted by items = Darkfire Shortbow:Long Rest
| level = 3
| class learns at level 10 = Bard:via [[Magical Secrets]]
| scribing = yes
Renders as

How to learn

Classes: Granted by items: Other ways to learn:

Markup

| scribing scroll = Scroll of Enlarge
| granted by items = Sethan:Long Rest
| class learns at level 8 = Arcane Trickster, Eldritch Knight
| level = 2
| class learns at level 3 = Sorcerer, Wizard
| race learns at level 3 = Duergar
| scribing = yes
Renders as

How to learn

Classes: Races: Granted by items: Other ways to learn:

Markup

| used by creatures = Spectator
| granted by features = Legendary Action: Ocular Nightmare
Renders as

How to learn

Granted by features:


local getArgs = require("Module:Arguments").getArgs
local util = require("Module:Feature page/util")
local resource = require("Module:Resource").main
local p = {}

local function scribing(frame)
	local args = getArgs(frame)
	local scroll = frame:expandTemplate{
		title = "Rarity item",
		args = { args["scribing scroll"] or "Scroll of " .. frame:getTitle() }
	}
	local spell_level = tonumber(args["level"] or "0")
	local level_text = ""
	if spell_level > 1 then
		level_text = " with " .. resource(frame, {
			"level" .. spell_level, 
			["force plural"] = "yes"
		})
	end
	
	local scribing_text = {
		["yes"] = "<ul><li>" 
			.. "[[Wizard]]s" .. level_text 
			.. " can copy a " .. scroll 
			.. " to their spellbooks with [[Spell Scribing]].</li></ul>",
		["no"] = "<ul><li>"
			.. "[[Wizard]]s cannot copy a " .. scroll
			.. " to their spellbooks with [[Spell Scribing]]."
			.. "</li></ul>",
		["no scrolls"] = "<ul><li>" 
			.. "There are no scrolls available for [[Wizard]]s"
			.. " to copy to their spellbooks with [[Spell Scribing]]."
			.. "</li></ul>"
	}
	
	return scribing_text[args["scribing"]] or ""
end

function p.how_to_learn_content(frame)
	local args = getArgs(frame)
	
	local function progression(args, field, header, subheader, print_func)
		local result = ""
		for i = 1, 12 do
			local param = args[field .. " ".. i]
			if param then
				local parsed = util.parse_list(param)
				result = result 
				.. "<li>" .. subheader .. " " .. i .. ": " 
				.. util.print_prose_list(parsed, print_func)
				.. "</li>\n"
			end
		end
		if result ~= "" then
			return header .. ":<ul>\n" .. result .. "</ul>\n"
		else
			return ""
		end
	end
	
	local other_ways = (args["other ways to learn"] or "") .. scribing(frame)
	if other_ways ~= "" then
		other_ways = "Other ways to learn:<br>" .. other_ways
	end
	
	return progression(
		args, "class learns at level", "Classes", "Class level",
		function(class)
			local result = "[[" .. class[1] .. "]]"
			if class[2] ~= "" then
				result = result .. " (" .. class[2] .. ")"
			end
			return result
		end
	) .. progression(
		args, "race learns at level", "Races", "Character level",
		function(race)
			local result = "[[" .. race[1] .. "]]"
			if race[2] ~= "" then
				result = result .. " (" .. frame:expandTemplate{
					title = "Recharge",
					args = { race[2] }
				}.. ")"
			end
			return result
		end
	) .. util.print_bulleted_list(
		util.parse_list(args["granted by items"]),
		"Granted by items",
		function(elem)
			local result = frame:expandTemplate{
				title = "Rarity item",
				args = { elem[1], 30 }
			}
			if elem[2] ~= "" then
				result = result .. " (" .. frame:expandTemplate{
					title = "Recharge",
					args = { elem[2] }
				}.. ")"
			end
			return result
		end
	) .. util.print_bulleted_list(
		util.parse_list(args["granted by features"]),
		"Granted by features",
		function(elem)
			return frame:expandTemplate{
				title = "Pass",
				args = { elem[1], w=30 }
			}
		end
	) .. util.print_bulleted_list(
		util.parse_list(args["granted by spells"]),
		"Granted by spells",
		function(elem)
			return frame:expandTemplate{
				title = "SAI",
				args = { elem[1], w=30 }
			}
		end
	) .. other_ways
end

function p.how_to_learn(frame)
	local content = p.how_to_learn_content(frame)
	if content ~= nil and content ~= "" then
		return "<h2>How to learn</h2>"
		.. "<div class=\"bg3wiki-tooltip-box bg3wiki-tooltip-gradient-common\">"
		.. content
		.. "</div>"
	else
		return nil
	end
end

function p.examples()
	return util.print_examples(p.how_to_learn, {
		mw.getCurrentFrame():newChild{
			title="Ray of Frost",
			args={
				["class learns at level 1"] = "Sorcerer, Wizard",
				["class learns at level 3"] = "Eldritch Knight, Arcane Trickster",
				["class learns at level 6"] = "College of Lore:via [[Magical Secrets]]",
				["class learns at level 10"] = "Bard:via [[Magical Secrets]]",
				["race learns at level 1"] = "High Elf, High Half-Elf",
				["granted by features"] = "Magic Initiate: Sorcerer, Magic Initiate: Wizard, Spell Sniper",
				["granted by items"] = "Mourning Frost",
				["scribing"] = "yes"
			}
		},
		mw.getCurrentFrame():newChild{
			title="Haste",
			args={
				["level"] = "3",
				["class learns at level 5"] = "Sorcerer, Wizard, Circle of the Land:Arctic or Grassland, Warlock:via [[Pact of the Tome]] once per long rest",
				["class learns at level 6"] = "College of Lore:via [[Magical Secrets]]",
				["class learns at level 9"] = "Oath of Vengeance",
				["class learns at level 10"] = "Bard:via [[Magical Secrets]]",
				["granted by items"] = "Darkfire Shortbow:Long Rest",
				["scribing"] = "yes",
			}
			
		},
		mw.getCurrentFrame():newChild{
			title="Enlarge/Reduce",
			args={
				["level"] = "2",
				["class learns at level 3"] = "Sorcerer, Wizard",
				["class learns at level 8"] = "Arcane Trickster, Eldritch Knight",
				["race learns at level 3"] = "Duergar",
				["granted by items"] = "Sethan:Long Rest",
				["scribing"] = "yes",
				["scribing scroll"] = "Scroll of Enlarge"
			}
		},
		mw.getCurrentFrame():newChild{
			title="Ocular Nightmare",
			args={
				["used by creatures"] = "Spectator",
				["granted by features"] = "Legendary Action: Ocular Nightmare",
				
			}
		}
	})
end

return p