Skip to content

Commit

Permalink
fix pc.xp_needed property
Browse files Browse the repository at this point in the history
  • Loading branch information
mmacy committed Nov 27, 2023
1 parent c35f1be commit f928a22
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 6 deletions.
5 changes: 3 additions & 2 deletions osrgame/osrgame/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def compose(self) -> ComposeResult:
def on_mount(self) -> None:
"""Perform actions when the widget is mounted."""
table = self.query_one(DataTable)
table.add_columns("Name", "Class", "Level", "HP", "AC")
table.add_columns("Name", "Class", "Level", "HP", "AC", "XP")

def update_table(self):
party = self.app.adventure.active_party
Expand All @@ -104,8 +104,9 @@ def update_table(self):
pc.name,
pc.character_class.class_type.value,
Text(str(pc.level), justify="center"),
Text(f"{str(pc.hit_points)}/{str(pc.character_class.max_hp)}", justify="center"),
Text(f"{str(pc.hit_points)}/{str(pc.max_hit_points)}", justify="center"),
Text(str(pc.armor_class), justify="center"),
Text(str(pc.xp) + "/" + str(pc.xp_needed_for_next_level), justify="center"),
]
table.add_row(*row_data, key=pc.name)

Expand Down
2 changes: 1 addition & 1 deletion osrgame/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 17 additions & 2 deletions osrlib/osrlib/player_character.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ def __str__(self):
)
return (
f"{self.name} ({self.character_class} {self.level}) "
f"HP: {self.hit_points}/{self.character_class.max_hp} "
f"HP: {self.hit_points}/{self.max_hit_points} "
f"AC: {self.armor_class} "
f"XP: {self.character_class.xp}/{self.character_class.xp_needed_for_next_level}"
f"XP: {self.xp}/{self.xp_needed_for_next_level}"
)

@property
Expand All @@ -96,6 +96,11 @@ def level(self):
def hit_points(self):
return self.character_class.hp

@property
def max_hit_points(self) -> int:
"""Get the maximum hit points of the character."""
return self.character_class.max_hp

@property
def armor_class(self):
"""Get the armor class of the character."""
Expand All @@ -108,6 +113,16 @@ def armor_class(self):
)
return armor_class

@property
def xp(self) -> int:
"""Get the character's current XP total."""
return self.character_class.xp

@property
def xp_needed_for_next_level(self) -> int:
"""Get the amount of XP needed for the character to reach the next level."""
return self.character_class.xp_needed_for_next_level

def get_ability_roll(self):
"""Rolls a 4d6 and returns the sum of the three highest rolls."""
roll = roll_dice("4d6", drop_lowest=True)
Expand Down
2 changes: 1 addition & 1 deletion osrlib/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "osrlib"
version = "0.1.24"
version = "0.1.27"
description = "Turn-based dungeon-crawler game engine for OSR-style RPGs."
authors = ["Marsh Macy <[email protected]>"]
license = "MIT"
Expand Down

0 comments on commit f928a22

Please sign in to comment.