Skip to content

Commit

Permalink
Change max_hd and current_hd in level.setter
Browse files Browse the repository at this point in the history
  • Loading branch information
tassaron committed Jul 12, 2023
1 parent 4d4a954 commit 42e196b
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
5 changes: 5 additions & 0 deletions dnd_character/character.py
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,11 @@ def level(self, new_level):
self.hd, new_level, self.constitution
)
self.max_hp = Character.maximum_hp(self.hd, new_level, self.constitution)
if self.current_hd == self.max_hd:
self.current_hd = new_level
self.max_hd = new_level
if self.current_hd > self.max_hd:
self.current_hd = self.max_hd
self.applyClassLevel()

def removeShields(self):
Expand Down
27 changes: 27 additions & 0 deletions tests/test_hit_dice.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from dnd_character.classes import Barbarian, Rogue, Sorcerer


def test_hd_for_barb_rogue_sorc():
barb = Barbarian()
rogue = Rogue()
sorc = Sorcerer()
assert barb.hd == 12
assert rogue.hd == 8
assert sorc.hd == 6


def test_max_hd_at_level_1():
barb = Barbarian(level=1)
assert barb.max_hd == 1


def test_max_hd_at_level_10():
barb = Barbarian(level=10)
assert barb.max_hd == 10


def test_current_hd_increases_at_level_up():
barb = Barbarian(level=1)
assert barb.current_hd == 1
barb.level = 2
assert barb.current_hd == 2

0 comments on commit 42e196b

Please sign in to comment.