Skip to content

Commit d5afb44

Browse files
committed
Add support for roll formulas with spell info
You can now use "1d20 + your Wizard spell save DC" for example Fixes kakaroto#118
1 parent 4fa88d4 commit d5afb44

8 files changed

+150
-138
lines changed

src/dndbeyond.pyj

+1-1
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ class Character(CharacterBase):
383383
not isObjectEqual(self._spell_saves, self.getSetting("spell_saves", {})):
384384
console.log("New Spell information")
385385
update = True
386-
elif self.getSetting("spell_info", None):
386+
else:
387387
self._spell_modifiers = self.getSetting("spell_modifiers", {})
388388
self._spell_saves = self.getSetting("spell_saves", {})
389389
self._spell_attacks = self.getSetting("spell_attacks", {})

src/dndbeyond_character.js

+120-107
Large diffs are not rendered by default.

src/dndbeyond_character.pyj

+24-25
Original file line numberDiff line numberDiff line change
@@ -622,35 +622,34 @@ def findModifiers(character, custom_roll):
622622
while text_len != len(text):
623623
# If text length changes, we can check again for another modifier
624624
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
627629
if text.toLowerCase().startsWith(mod_string):
628630
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
636632
text = text.substring(len(mod_string))
637633

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)
654653

655654
sibling.textContent = text
656655
img.attr("x-beyond20-roll", roll_formula)

src/dndbeyond_encounter.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -10404,7 +10404,7 @@ return this.__repr__();
1040410404
console.log("New Spell information");
1040510405
update = true;
1040610406
}
10407-
} else if (self.getSetting("spell_info", null)) {
10407+
} else {
1040810408
self._spell_modifiers = self.getSetting("spell_modifiers", {});
1040910409
self._spell_saves = self.getSetting("spell_saves", {});
1041010410
self._spell_attacks = self.getSetting("spell_attacks", {});

src/dndbeyond_items.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -10404,7 +10404,7 @@ return this.__repr__();
1040410404
console.log("New Spell information");
1040510405
update = true;
1040610406
}
10407-
} else if (self.getSetting("spell_info", null)) {
10407+
} else {
1040810408
self._spell_modifiers = self.getSetting("spell_modifiers", {});
1040910409
self._spell_saves = self.getSetting("spell_saves", {});
1041010410
self._spell_attacks = self.getSetting("spell_attacks", {});

src/dndbeyond_monster.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -10404,7 +10404,7 @@ return this.__repr__();
1040410404
console.log("New Spell information");
1040510405
update = true;
1040610406
}
10407-
} else if (self.getSetting("spell_info", null)) {
10407+
} else {
1040810408
self._spell_modifiers = self.getSetting("spell_modifiers", {});
1040910409
self._spell_saves = self.getSetting("spell_saves", {});
1041010410
self._spell_attacks = self.getSetting("spell_attacks", {});

src/dndbeyond_spell.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -10404,7 +10404,7 @@ return this.__repr__();
1040410404
console.log("New Spell information");
1040510405
update = true;
1040610406
}
10407-
} else if (self.getSetting("spell_info", null)) {
10407+
} else {
1040810408
self._spell_modifiers = self.getSetting("spell_modifiers", {});
1040910409
self._spell_saves = self.getSetting("spell_saves", {});
1041010410
self._spell_attacks = self.getSetting("spell_attacks", {});

src/dndbeyond_vehicle.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -10404,7 +10404,7 @@ return this.__repr__();
1040410404
console.log("New Spell information");
1040510405
update = true;
1040610406
}
10407-
} else if (self.getSetting("spell_info", null)) {
10407+
} else {
1040810408
self._spell_modifiers = self.getSetting("spell_modifiers", {});
1040910409
self._spell_saves = self.getSetting("spell_saves", {});
1041010410
self._spell_attacks = self.getSetting("spell_attacks", {});

0 commit comments

Comments
 (0)