@@ -622,35 +622,34 @@ def findModifiers(character, custom_roll):
622
622
while text_len != len(text):
623
623
# If text length changes, we can check again for another modifier
624
624
text_len = len(text)
625
- for ability in character._abilities:
626
- mod_string = " + your " + ability[0].toLowerCase() + " modifier"
625
+
626
+ find_static_modifier = def(name, value):
627
+ nonlocal text, roll_formula, strong
628
+ mod_string = " + your " + name
627
629
if text.toLowerCase().startsWith(mod_string):
628
630
strong.append(text.substring(0, len(mod_string)))
629
- roll_formula += ability[3]
630
- text = text.substring(len(mod_string))
631
- for class_name in character._classes:
632
- mod_string = " + your " + class_name.toLowerCase() + " level"
633
- if text.toLowerCase().startsWith(mod_string):
634
- strong.append(text.substring(0, len(mod_string)))
635
- roll_formula += " + " + character._classes[class_name]
631
+ roll_formula += " + " + value
636
632
text = text.substring(len(mod_string))
637
633
638
- mod_string = " + your proficiency bonus"
639
- if text.toLowerCase().startsWith(mod_string):
640
- strong.append(text.substring(0, len(mod_string)))
641
- roll_formula += " + " + character._proficiency
642
- text = text.substring(len(mod_string))
643
-
644
- mod_string = " + your ac"
645
- if text.toLowerCase().startsWith(mod_string):
646
- strong.append(text.substring(0, len(mod_string)))
647
- roll_formula += " + " + character._ac
648
- text = text.substring(len(mod_string))
649
- mod_string = " + your armor class"
650
- if text.toLowerCase().startsWith(mod_string):
651
- strong.append(text.substring(0, len(mod_string)))
652
- roll_formula += " + " + character._ac
653
- text = text.substring(len(mod_string))
634
+ for ability in character._abilities:
635
+ find_static_modifier(ability[0].toLowerCase() + " modifier", ability[3])
636
+ for class_name in character._classes:
637
+ find_static_modifier(class_name.toLowerCase() + " level", character._classes[class_name])
638
+ find_static_modifier("proficiency bonus", character._proficiency)
639
+ find_static_modifier("ac", character._ac)
640
+ find_static_modifier("armor class", character._ac)
641
+
642
+ find_spell_modifier = def(suffix, obj):
643
+ default_spell_mod = None
644
+ for class_name in obj:
645
+ default_spell_mod = obj[class_name] if default_spell_mod is None else default_spell_mod
646
+ find_static_modifier(class_name.toLowerCase() + " " + suffix, obj[class_name])
647
+ if default_spell_mod:
648
+ find_static_modifier(suffix, default_spell_mod)
649
+ find_spell_modifier("spell modifier", character._spell_modifiers)
650
+ find_spell_modifier("spell attack", character._spell_attacks)
651
+ find_spell_modifier("spell save dc", character._spell_saves)
652
+ find_spell_modifier("save dc", character._spell_saves)
654
653
655
654
sibling.textContent = text
656
655
img.attr("x-beyond20-roll", roll_formula)
0 commit comments