Pillars of Eternity Wiki
Advertisement
Pillars of Eternity Wiki
Template-info.png Module documentation

Handles some of the more complicated logic used in the display of ability-related data

Functions[]

BuildTypeString[]

Used by the template {{Infobox ability poe2}} in order to create game-like class ability descriptors to be used on Pillars of Eternity II: Deadfire ability pages, for example "3rd Level Wizard Ability".

This takes some infobox parameters into account, properly linking the first part "nth Level" to the appropriate table row on the class ability page, and the second part "<class> Ability" to the appropriate section on the class ability page.


-- Module:Ability
-- Description: Handles some of the more complicated logic used in the display of ability-related data
local p = {}
local c = require("Module:Common")

-- This function builds a string, which in its most simplified form returns "nth Level <class> Ability"
-- properly linking the first part "nth Level" to the appropriate sub-header on the ability page, and the second part
-- "<class> Ability" to the root class ability page
function p.BuildTypeString(frame)
	
	-- Get specific args
	local args = { }
	local frameArgs = frame:getParent().args
	
	args["activation"] = frameArgs["activation"]
	args["class"] = frameArgs["class"]
	args["ability_type"] = frameArgs["ability_type"]
	args["ability_level"] = frameArgs["ability_level"]
	
	return p._BuildTypeString(args)
	
end

function p._BuildTypeString(args)

	-- Lower-case all args so we don't have to do so later
	for k, v in pairs(args) do
		if (type(v) == "string") then
			args[k] = string.lower(v)
		end
	end
	
	-- For all class-based abilities
	if (c.isNotNilOrEmpty(args["class"])) then
		
		-- Get some useful variables
		local hasMultipleClasses = string.match(args["class"], ";") ~= nil
		local isPassive = args["activation"] == "passive"
		local isActive = args["activation"] == "active"
		local isClassAbility = args["class"] ~= nil
		local isGenericAbility = c.isNilOrEmpty(args["ability_type"]) or args["ability_type"] == "ability" or args["ability_type"] == "spell"
		local abilityLevel = tonumber(args["ability_level"])
	
		-- First define the base ability page link
		-- This is a link to, say, Barbarian abilities (Deadfire)
		local classAbilityPage = hasMultipleClasses and "" or c.upperCaseFirst(args["class"]).." abilities (Deadfire)"
		
		-- Define the first part of the string,
		-- 0 = "Core", otherwise 1st/2nd/3rd Level
		local typeStringFirst = ""
		if (abilityLevel ~= nil and abilityLevel > 0) then
			typeStringFirst = c.stringAddOrdinal(abilityLevel).." Level"
		elseif (abilityLevel == 0)  then
			typeStringFirst = "Core"
		end
		
		-- Define the second part of the string
		-- This is just the class name
		local typeStringSecond = hasMultipleClasses and "" or c.upperCaseFirst(args["class"])
		
		-- Define the third part of the string
		-- This is the type of ability, be it just "Ability", or "Passive", or other stuff like "Invocation"
		local typeStringThird = ""
		
		-- For generic spells and abilities, regardless of the activation, and by default
		if (isGenericAbility) then
			
			-- For active abilities (or undefined activation)
    		-- Show the ability_type (e.g. Spell/Ability) - default to "Ability"
			if (isActive or c.isNilOrEmpty(args["activation"])) then
				typeStringThird = c.default(c.upperCaseFirst(args["ability_type"]), "Ability")
			-- ...otherwise show the activation (e.g. "Modal", "Passive")
			else 
				typeStringThird = c.upperCaseFirst(args["activation"])
			end
			
		-- For other types of abilities, just use the type
		else
			typeStringThird = c.upperCaseFirst(args["ability_type"])
		end
		
		-- Finally, build the link
		if (not hasMultipleClasses) then
			-- Link first part (e.g. "1st Level") to abilities page with anchor to the associated row in table (e.g. Barbarian abilities (Deadfire)#level-1-abilities)
			local abilityLevelLink = "[["..classAbilityPage.."#level-"..tostring(abilityLevel).."-"..c.ternary(isPassive, "passives", "abilities").."|"..typeStringFirst.."]]"
			
			-- Link second part (e.g. Barbarian Passive) to passive section, or specific type section (e.g. Invocation, Phrase)
			local abilityTypeLink = "[["..classAbilityPage..c.ternary(isPassive, "#Passive abilities", c.ternary(isGenericAbility, "", "#"..c.upperCaseFirst(args["ability_type"]))).."|"..typeStringSecond.." "..typeStringThird.."]]"
		
			return abilityLevelLink.." "..abilityTypeLink
			
		-- For multiple classes, don't link
		else
			return typeStringFirst.." "..typeStringThird
		end
		
	-- For non class-based abilities
	else
		-- If the type isn't set, default it to "ability"
		local abilityType = c.default(args["ability_type"], "ability")
		
		local switch =
		{
			ability = "[[Pillars of Eternity II: Deadfire abilities|Ability]]",
			proficiency = "[[Pillars of Eternity II: Deadfire abilities#Proficiencies|Proficiency]]",
			default = c.upperCaseFirst(abilityType)
		}
		
		return switch[abilityType] or switch["default"]
	end
	
	return ""
end

return p
Advertisement