<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">% 
%  __  __             _      
% |  \/  | __ _  __ _(_) ___ 
% | |\/| |/ _` |/ _` | |/ __|
% | |  | | (_| | (_| | | (__ 
% |_|  |_|\__,_|\__, |_|\___|
%               |___/        


\newcounter{spellCost}
\setcounter{spellCost}{1}

\newcommand\spellName{}
\newcommand\spellEnhancements{}
\newcommand\spellAction{}
\newcommand\spellSphere{}
\newcommand\spellResistance{}
\newcommand\spellSum{}
\newcommand\spellNotes{}

\newcommand\calcSpell[7]{%
  \renewcommand\spellName{#1}%
  \setcounter{spellCost}{1}%
  \foreach \d in {#2}{%
    \stepcounter{spellCost}%
  }%
  \renewcommand\spellEnhancements{#2}%
  \renewcommand\spellAction{#3}%
  \renewcommand\spellSphere{#4}%
  \renewcommand\spellResistance{#5}
  \renewcommand\spellSum{#6}
  \renewcommand\spellNotes{#7}
}


\newcommand\fullSpell{%
  \paragraph{\spellName}

  Cost: \arabic{spellCost},
  \spellEnhancements,
  \spellAction~
  \spellSphere

  Resisted by: \spellResistance

  \spellSum \ 
  \spellNotes
}


\newcommand\spellIndex{\index[spells]{\textbf{\spellName} Cost: \arabic{spellCost}, \spellEnhancements, \spellAction~\spellSphere Resisted by: \detokenize{\spellResistance} \spellSum \spellNotes }}


\newcommand\shortSpell{%
  \paragraph{\spellName}

  Cost: \arabic{spellCost},
  \spellEnhancements,
  \spellAction~
  \spellSphere

  Resisted by: \spellResistance

  \spellSum \ 
  \spellNotes
}


% We use spellPotency to track spell effects which are typically larger than the spell's level.
\newcounter{spellPotency}

% spellResTN is the TN to resist spells, used only in specified spells beneath creatures. For example, if someone had Air 2, resisting their spells would be TN (7 + 2) 9.
\newcounter{spellResTN}


\newcommand\mFate{%
  Fate%
  \global\settoggle{insubstantial}{true}%
  \ifnum\value{spellResTN}&lt;8%
    \addtocounter{spellResTN}{\value{Fate}}%
  \fi%
}
\newcommand\mEarth{%
  Earth%
  \ifnum\value{spellResTN}&lt;8%
    \addtocounter{spellResTN}{\value{Earth}}%
  \fi%
}
\newcommand\mAir{%
  Air%
  \global\settoggle{insubstantial}{true}%
  \ifnum\value{spellResTN}&lt;8%
    \addtocounter{spellResTN}{\value{Air}}%
  \fi%
}
\newcommand\mFire{%
  Fire%
  \ifnum\value{spellResTN}&lt;8%
    \addtocounter{spellResTN}{\value{Fire}}%
  \fi%
  \addtocounter{spellPotency}{-1}%
}
\newcommand\mWater{%
  Water%
  \ifnum\value{spellResTN}&lt;8%
    \addtocounter{spellResTN}{\value{Water}}%
  \fi%
}

% 1 = Name
% 2 = Spheres
% 3 = Action
% 4 = Enhancements
% 5 = Resistance
% 6 = Description
% 7 = Longer notes

\newcommand{\spell}[7]{
  \global\settoggle{distant}{false}%
  \global\settoggle{duplicated}{false}%
  \global\settoggle{insubstantial}{false}%
  \setcounter{spelllevel}{1}%
  \foreach \s in {#4}{%
    \stepcounter{spelllevel}%
  }%
  \setcounter{spellPotency}{\value{spelllevel}}%
    \addtocounter{spellPotency}{3}%
  \setcounter{spellResTN}{7}%
  \iftoggle{genExamples}{
    \subsubsection{#1}%
    \label{#1}%

    {\sffamily(#4%
    \ifnum\value{spelllevel}&gt;1~\fi #3
    #2)}
    \gls{mp} Cost:~\arabic{spelllevel},
    Resisted by: #5,
    \setRange%
    Range:~\spellRange
    \setArea%
    \iftoggle{duplicated}{%
      \ignorespaces, Targets:~\spellArea, %
    }{}%

    \afterparnoindent
    #7

    \vphantom{\dmg{spellPotency}}
    \index[spells]{\textbf{#1}: #6 (Cost: \arabic{spelllevel}, Range:~\spellRange, Resisted by: #5\iftoggle{duplicated}{, Targets: \spellArea}{})|needspace{2em} --- Page }
  }{
    \item[\textbf{#1}]%
    \vphantom{\dmg{spellPotency}}%
    \vphantom{#4}%
    \vphantom{#2}%
    \setArea%
    \setRange%
    \ifdefparam{#5}{%
      Roll #5, \tn[\arabic{spellResTN}], or #6.
    }{
      \MakeUppercase#6.
    }
    (Spheres:~#2, Cost:~\arabic{spelllevel}, Range:~\spellRange\iftoggle{duplicated}{, Targets:~\spellArea}{})
  }
}

\newcommand\spellRange{}
\newcommand\setRange{%
  \iftoggle{distant}%
    {%
      \ifcase\value{spelllevel}\relax%
      \renewcommand\spellRange{Error}%
      \or%
      \renewcommand\spellRange{Error}%
      \or%
        \renewcommand\spellRange{throwing distance}%
      \or%
        \renewcommand\spellRange{shouting distance}%
      \or%
        \renewcommand\spellRange{horizon}%
      \else%
        \renewcommand\spellRange{line of sight}%
      \fi%
    }%
    {%
      \setcounter{track}{20}%
      \Repeat{\arabic{spelllevel}}{\addtocounter{track}{-4}}%
      \ifnum\value{track}&lt;1%
        \renewcommand\spellRange{touch}%
      \else%
        \renewcommand\spellRange{\arabic{track}~steps}%
      \fi%
    }%
}


%%%
\newcommand\spellArea{}
\newcounter{spellArea}

\newcommand\setArea{%
  \setcounter{spellArea}{\value{spelllevel}}%
  \multiply\value{spellArea} by \value{spelllevel}%
  \iftoggle{insubstantial}{%
    \multiply\value{spellArea} by \value{spelllevel}%
    \addtocounter{spellArea}{0}%
  }{}%
  \renewcommand\spellArea{%
    \arabic{spellArea}%
  }%
}

%%%

\newtoggle{insubstantial}
  \settoggle{insubstantial}{false}
\newtoggle{distant}
  \settoggle{distant}{false}
\newtoggle{duplicated}
  \settoggle{duplicated}{false}

\newcommand\detailed{Detailed}

\newcommand\duplicated{%
  \global\settoggle{duplicated}{true}%
  Duplicated%
}

\newcommand\divergent{Divergent}

\newcommand\distant{%
  \global\settoggle{distant}{true}%
  Distant%
}

\newcommand\rollConv{\arabic{numberofdice}D6\ifnum\value{damagebonus}&lt;0\arabic{damagebonus}\else\ifnum\value{damagebonus}&gt;0+\arabic{damagebonus}\fi\fi}

\newcommand\magicItem[7]{
  \global\settoggle{distant}{false}%
  \global\settoggle{duplicated}{false}%
  \global\settoggle{insubstantial}{false}%
  \setcounter{spelllevel}{1}%
  \foreach \s in {#3}{%
    \stepcounter{spelllevel}%
  }%
  \setcounter{spellPotency}{\value{spelllevel}}%
    \addtocounter{spellPotency}{3}%
  \setcounter{spellResTN}{7}%
  \vphantom{\dmg{spellPotency}}%
  \vphantom{#3}%
  \setArea%
  \setRange%
  \needspace{3em}
  {\center\decoone~\textbf{\large #1}~\decoone}
  \noindent
  \begin{description}
    \item[Item:] #7
    \item[Activation:]
      When #3,
      #6
    \raggedright
    \item[Stats:]
      Potence:~\arabic{spelllevel}, Range: \spellRange\iftoggle{duplicated}{, Targets: \spellArea}{}
      \item[Resisted~by:]
      #4
  \end{description}

}

\newcommand{\magicitem}[7]{%
  \vspace{1em}\needspace{1em}\noindent\textbf{#1}%
  \index{Magical Item!#1}

  \noindent
  \textit{Spells: #2, }%
  \textit{Path: #3, }%
  \textit{Duration: #4, }%
  \textit{Type: #5, }%
  \textit{Potency: +#6, }%
  \textit{MP: #7}%
  % Type can be 'Pocket Spell', 'Talisman', or 'Artefact'.
  \needspace{2em}%
}

\newcommand{\manalake}[8]{
  \subsection{#1 (Level #8)}

  \textit{Spells: #2, }\textit{Path: #3, }\textit{Duration: #4, }\textit{Type: #5, }\textit{Potence: #6, }\textit{#7 MP}% Type can be 'pocket spell', 'magical item', or 'artefact'.
  \index{Mana Lakes!#1}
  \vspace{.3em}
}

\newcommand\creatureSpells[2][]{
  \begin{description}
    \settoggle{genExamples}{false}
    #1
    \foreach \s in {#2}{
      \IfFileExists{config/spells/\s.tex}{
        \input{config/spells/\s.tex}
      }{}
    }
  \end{description}
}

\newcommand\showStdSpells{
  \setcounter{enc}{0}
  \begin{description}
    \settoggle{genExamples}{false}
    \foreach\n in {3,2,1}{
      \ifnum\value{enc}&lt;3
        \foreach \s in {Earth,Air,Fire,Water,Fate}{
          \ifnumcomp{\value{\s}}{=}{\n}{
              \input{config/spells/\s\n.tex}
              \stepcounter{enc}
          }{}
        }
      \fi
    }
  \end{description}
  \textcolor{\pageSideColor}{\hrulefill\raisebox{-3pt}{\npcsymbol}}
}

\newcommand\showSpells[1]{
  \needspace{3em}
  \settoggle{genExamples}{true}
  \foreach \s in {#1}{
    \input{config/spells/\s.tex}
  }
}

</pre></body></html>