Added armor and shields to calculate armor class.

This commit is contained in:
Mark Wolfman
2018-04-14 01:25:56 -05:00
parent 9ff160eb59
commit c9bcaac18d
11 changed files with 290 additions and 35 deletions
+28
View File
@@ -5,6 +5,7 @@ from unittest import TestCase
from dungeonsheets import race
from dungeonsheets.character import Character, Wizard
from dungeonsheets.weapons import Weapon, Shortsword
from dungeonsheets.armor import Armor, LightLeatherArmor, Shield
class TestCharacter(TestCase):
@@ -28,6 +29,10 @@ class TestCharacter(TestCase):
char.set_attrs(weapons=['shortsword'])
self.assertEqual(len(char.weapons), 1)
self.assertTrue(isinstance(char.weapons[0], Shortsword))
# Check that armor and shield gets set_attrs
char.set_attrs(armor='light leather armor', shield='shield')
self.assertFalse(isinstance(char.armor, str))
self.assertFalse(isinstance(char.shield, str))
# Check that race gets set to an object
char.set_attrs(race='high elf')
self.assertIsInstance(char.race, race.HighElf)
@@ -125,3 +130,26 @@ class TestCharacter(TestCase):
self.assertEqual(char.spell_slots(spell_level=0), 3)
self.assertEqual(char.spell_slots(spell_level=1), 3)
self.assertEqual(char.spell_slots(spell_level=2), 0)
def test_equip_armor(self):
char = Character(dexterity=16)
char.wear_armor('light leather armor')
self.assertTrue(isinstance(char.armor, Armor))
# Now make sure the armor class is correct
self.assertEqual(char.armor_class, 14)
# Try passing an Armor object directly
char.wear_armor(LightLeatherArmor)
self.assertEqual(char.armor_class, 14)
# Test equipped armor with max dexterity mod_str
char.armor.dexterity_mod_max = 1
self.assertEqual(char.armor_class, 12)
def test_wield_shield(self):
char = Character(dexterity=16)
char.wield_shield('shield')
self.assertTrue(isinstance(char.shield, Shield), msg=char.shield)
# Now make sure the armor class is correct
self.assertEqual(char.armor_class, 15)
# Try passing an Armor object directly
char.wield_shield(Shield)
self.assertEqual(char.armor_class, 15)
+11 -8
View File
@@ -10,10 +10,8 @@ class TestStats(TestCase):
self.assertEqual(stats.mod_str(2), '+2')
def test_saving_throw(self):
stat = stats.Ability(14)
self.assertEqual(stat.saving_throw, 2)
# Now try it with an ST proficiency
class MyClass():
# Try it with an ST proficiency
class MyClass(character.Character):
saving_throw_proficiencies = ['strength']
proficiency_bonus = 2
strength = stats.Ability(14)
@@ -21,6 +19,11 @@ class TestStats(TestCase):
self.assertEqual(my_class.strength.saving_throw, 4)
def test_modifier(self):
class MyCharacter(character.Character):
saving_throw_proficiencies = ['strength']
proficiency_bonus = 2
strength = stats.Ability(14)
my_char = MyCharacter()
ranges = [
((1,), -5),
((2, 3), -4),
@@ -40,17 +43,17 @@ class TestStats(TestCase):
((30,), 10),
]
# Test the values for each modifier range
stat = stats.Ability()
for range_, target in ranges:
for value in range_:
stat.value = value
my_char.strength = value
stat = my_char.strength
msg = f"Stat {value} doesn't produce modifier {target} ({stat.modifier})"
self.assertEqual(stat.modifier, target, msg)
def test_setter(self):
"""Verify that this class works as a data descriptor."""
# Set up a dummy class
class MyCharacter():
class MyCharacter(character.Character):
stat = stats.Ability()
char = MyCharacter()
# Check that the stat works as expected once set
@@ -60,7 +63,7 @@ class TestStats(TestCase):
def test_skill(self):
"""Test for a skill, that depends on another ability."""
class MyClass():
class MyClass(character.Character):
dexterity = stats.Ability(14)
acrobatics = stats.Skill(ability='dexterity')
skill_proficiencies = []