Fixed a bug where skill names with spaces were not recognized as proficient.

This commit is contained in:
Mark Wolfman
2021-06-13 17:50:53 -05:00
parent 5a037d3c98
commit 57cb094d2e
2 changed files with 15 additions and 1 deletions
+11 -1
View File
@@ -1,6 +1,7 @@
import math
from collections import namedtuple
from math import ceil
import logging
from dungeonsheets.armor import Armor, HeavyArmor, NoArmor, NoShield, Shield
from dungeonsheets.features import (
@@ -27,6 +28,9 @@ from dungeonsheets.features import (
from dungeonsheets.weapons import Weapon
log = logging.getLogger(__name__)
def mod_str(modifier):
"""Converts a modifier to a string, eg 2 -> '+2'."""
return "{:+d}".format(modifier)
@@ -85,10 +89,14 @@ class Skill:
self.character = entity
def __get__(self, entity, owner):
log.debug("Getting skill '%s' for '%s'",
self.skill_name, entity.name)
ability = getattr(entity, self.ability_name)
modifier = ability.modifier
# Check for proficiency
is_proficient = self.skill_name in entity.skill_proficiencies
proficiencies = [p.replace("_", " ") for p in entity.skill_proficiencies]
is_proficient = self.skill_name in proficiencies
log.debug("%s is proficient in %s: %s", entity.name, self.skill_name, is_proficient)
if is_proficient:
modifier += entity.proficiency_bonus
elif entity.has_feature(JackOfAllTrades):
@@ -101,6 +109,8 @@ class Skill:
is_expert = self.skill_name in entity.skill_expertise
if is_expert:
modifier += entity.proficiency_bonus
log.debug("'%s' modifier for '%s': %d",
self.skill_name, entity.name, modifier)
return modifier
+4
View File
@@ -72,6 +72,7 @@ class TestStats(TestCase):
class MyClass(character.Character):
dexterity = stats.Ability(14)
acrobatics = stats.Skill(ability="dexterity")
sleight_of_hand = stats.Skill(ability="dexterity")
skill_proficiencies = []
proficiency_bonus = 2
@@ -80,3 +81,6 @@ class TestStats(TestCase):
# Check for a proficiency
my_class.skill_proficiencies = ["acrobatics"]
self.assertEqual(my_class.acrobatics, 4)
# Check for a proficiency with spaces in the name
my_class.skill_proficiencies = ["sleight_of_hand"]
self.assertEqual(my_class.sleight_of_hand, 4)