Skip to content

Commit

Permalink
Allow auto-calculation of proficiency-bonus (rpgtex#319)
Browse files Browse the repository at this point in the history
Specifying no `proficiency-bonus` with no value or the special value `*`
will calculate the proficiency bonus from the challenge rating.

Co-authored-by: I Reyes <4106546+Darkade@users.noreply.github.com>
  • Loading branch information
kbriggs and Darkade committed Sep 2, 2021
1 parent d7b3e6d commit 6510377
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 3 deletions.
2 changes: 1 addition & 1 deletion example.tex
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ \chapter{Monsters and NPCs}
senses = {darkvision 60 ft., passive Perception 10},
languages = {Common, Goblin, Undercommon},
challenge = 1,
proficiency-bonus = +2,
proficiency-bonus, % = +2
]
% Traits
\DndMonsterAction{Innate Spellcasting}
Expand Down
55 changes: 53 additions & 2 deletions lib/dndmonster.sty
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,53 @@
{ #1 }
}

%% Monster CR/PB helper
% \l_tmpa_tl - CR
% \l_tmpb_tl - PB
\cs_new_protected_nopar:Npn \__dnd_cr_pb:N #1
{
\tl_set:Nn \l_tmpa_tl {#1}
\str_case_e:nnTF {#1}
{
{0} { \tl_set:Nn \l_tmpb_tl {+2} }
{1/8} { \tl_set:Nn \l_tmpb_tl {+2} }
{1/4} { \tl_set:Nn \l_tmpb_tl {+2} }
{1/2} { \tl_set:Nn \l_tmpb_tl {+2} }
{1} { \tl_set:Nn \l_tmpb_tl {+2} }
{2} { \tl_set:Nn \l_tmpb_tl {+2} }
{3} { \tl_set:Nn \l_tmpb_tl {+2} }
{4} { \tl_set:Nn \l_tmpb_tl {+2} }
{5} { \tl_set:Nn \l_tmpb_tl {+3} }
{6} { \tl_set:Nn \l_tmpb_tl {+3} }
{7} { \tl_set:Nn \l_tmpb_tl {+3} }
{8} { \tl_set:Nn \l_tmpb_tl {+3} }
{9} { \tl_set:Nn \l_tmpb_tl {+4} }
{10} { \tl_set:Nn \l_tmpb_tl {+4} }
{11} { \tl_set:Nn \l_tmpb_tl {+4} }
{12} { \tl_set:Nn \l_tmpb_tl {+4} }
{13} { \tl_set:Nn \l_tmpb_tl {+5} }
{14} { \tl_set:Nn \l_tmpb_tl {+5} }
{15} { \tl_set:Nn \l_tmpb_tl {+5} }
{16} { \tl_set:Nn \l_tmpb_tl {+5} }
{17} { \tl_set:Nn \l_tmpb_tl {+6} }
{18} { \tl_set:Nn \l_tmpb_tl {+6} }
{19} { \tl_set:Nn \l_tmpb_tl {+6} }
{20} { \tl_set:Nn \l_tmpb_tl {+6} }
{21} { \tl_set:Nn \l_tmpb_tl {+7} }
{22} { \tl_set:Nn \l_tmpb_tl {+7} }
{23} { \tl_set:Nn \l_tmpb_tl {+7} }
{24} { \tl_set:Nn \l_tmpb_tl {+7} }
{25} { \tl_set:Nn \l_tmpb_tl {+8} }
{26} { \tl_set:Nn \l_tmpb_tl {+8} }
{27} { \tl_set:Nn \l_tmpb_tl {+8} }
{28} { \tl_set:Nn \l_tmpb_tl {+8} }
{29} { \tl_set:Nn \l_tmpb_tl {+9} }
{30} { \tl_set:Nn \l_tmpb_tl {+9} }
}
{ \numprint {\l_tmpb_tl} }
{ #1 }
}

%% Monster details
\keys_define:nn { dnd / monster / details }
{
Expand Down Expand Up @@ -269,7 +316,8 @@
challenge .initial:n = 1,
challenge .value_required:n = true,
proficiency-bonus .tl_set:N = \l__proficiency_tl,
proficiency-bonus .value_required:n = true,
proficiency-bonus .value_required:n = false,
proficiency-bonus .default:n = *,
proficiencybonus .meta:n = { proficiency-bonus = {#1} },
}

Expand All @@ -288,7 +336,10 @@
\tl_if_empty:NF {\l__proficiency_tl}
{
{\enit@svlabel{\enit@format{\pbonname}}}
\hskip \labelsep \l__proficiency_tl
\hskip \labelsep
\str_if_eq:VnTF \l__proficiency_tl *
{\__dnd_cr_pb:N {\l__challenge_tl}}
{\l__proficiency_tl}
}
\end {__dnd_monster_attributes}
}
Expand Down

0 comments on commit 6510377

Please sign in to comment.