Added weapons, weapon proficiencies, and equipment.

This commit is contained in:
Mark Wolfman
2018-03-28 01:29:41 -05:00
parent 2790296a7c
commit e44bb9203b
12 changed files with 655 additions and 21 deletions
+32
View File
@@ -3,6 +3,7 @@
from unittest import TestCase
from dungeonsheets.character import Character
from dungeonsheets.weapons import Weapon, Shortsword
class TestCharacter(TestCase):
@@ -22,6 +23,37 @@ class TestCharacter(TestCase):
char = Character()
char.set_attrs(name='Inara')
self.assertEqual(char.name, 'Inara')
# Check that the weapons get loaded as objects not string
char.set_attrs(weapons=['shortsword'])
self.assertEqual(len(char.weapons), 1)
self.assertTrue(isinstance(char.weapons[0], Shortsword))
def test_wield_weapon(self):
char = Character()
char.strength = 14
char.weapon_proficienies = [Shortsword]
# Add a weapon
char.wield_weapon('shortsword')
self.assertEqual(len(char.weapons), 1)
sword = char.weapons[0]
self.assertTrue(isinstance(sword, Weapon))
self.assertTrue(isinstance(sword, Shortsword))
self.assertEqual(sword.attack_bonus, 4) # str + prof
self.assertEqual(sword.bonus_damage, 2) # str
# Check if dexterity is used if it's higher (Finesse weapon)
char.weapons = []
char.dexterity = 16
char.wield_weapon('shortsword')
sword = char.weapons[0]
self.assertEqual(sword.attack_bonus, 5) # dex + prof
def test_proficiencies_text(self):
char = Character()
char._proficiencies_text = ('hello', 'world')
self.assertEqual(char.proficiencies_text, 'Hello, world.')
# Check for extra proficiencies
char.proficiencies_extra = ("it's", "me")
self.assertEqual(char.proficiencies_text, "Hello, world, it's, me.")
def test_proficiency_bonus(self):
char = Character()
+1 -2
View File
@@ -10,7 +10,7 @@ class CharacterFileTestCase(unittest.TestCase):
def test_load_character_file(self):
charfile = CHARFILE
result = make_sheets.load_character_file(charfile)
self.assertEqual(result['strength'], 10)
self.assertEqual(result['strength'], 8)
class FDFTestCase(unittest.TestCase):
def tearDown(self):
@@ -22,4 +22,3 @@ class FDFTestCase(unittest.TestCase):
char = character.Character()
make_sheets.create_fdf(char, fdfname=fdfname)
self.assertTrue(os.path.exists(fdfname))
+17
View File
@@ -70,3 +70,20 @@ class TestStats(TestCase):
# Check for a proficiency
my_class.skill_proficiencies = ['acrobatics']
self.assertEqual(my_class.acrobatics, 4)
def test_findattr(self):
"""Check if the function can find attributes."""
class TestClass():
my_attr = 47
YourAttr = 53
test_class = TestClass()
# Direct access
self.assertEqual(stats.findattr(test_class, 'my_attr'),
test_class.my_attr)
self.assertEqual(stats.findattr(test_class, 'YourAttr'),
test_class.YourAttr)
# Swapping spaces for capitalization
self.assertEqual(stats.findattr(test_class, 'my attr'),
test_class.my_attr)
self.assertEqual(stats.findattr(test_class, 'your attr'),
test_class.YourAttr)
+12
View File
@@ -0,0 +1,12 @@
import unittest
from dungeonsheets.weapons import Weapon
class WeaponTestCase(unittest.TestCase):
def test_weapon_damage(self):
weapon = Weapon()
weapon.base_damage = '1d6'
self.assertEqual(weapon.damage, '1d6')
# Now add some bonus damage
weapon.bonus_damage = 2
self.assertEqual(weapon.damage, '1d6 +2')