Skip to content

Commit

Permalink
pytest logging + char_class_type fixture cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
mmacy committed Feb 7, 2024
1 parent b8e7adf commit 00cb290
Show file tree
Hide file tree
Showing 30 changed files with 221 additions and 258 deletions.
6 changes: 3 additions & 3 deletions osrgame/osrgame/osrgame.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
from osrlib.constants import ADVENTURE_NAMES, DUNGEON_NAMES
from osrlib.dungeon import Dungeon
from osrlib.dungeon_assistant import DungeonAssistant
from osrlib.game_manager import logger
from osrlib.party import get_default_party
from osrlib.utils import logger
from osrlib.party import Party
from osrlib.enums import OpenAIModelVersion


Expand Down Expand Up @@ -86,7 +86,7 @@ def set_active_adventure(self, adventure: Adventure = None) -> None:

default_adventure.add_dungeon(dungeon)
default_adventure.set_active_dungeon(dungeon)
default_adventure.set_active_party(get_default_party())
default_adventure.set_active_party(Party.get_default_party())
self.adventure = default_adventure

def start_session(self) -> str:
Expand Down
2 changes: 1 addition & 1 deletion osrlib/osrlib/adventure.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
DungeonAlreadyExistsError: Raised for duplicate dungeon additions.
"""
import json, os, datetime
from osrlib.game_manager import logger
from osrlib.utils import logger
from osrlib.dungeon import Dungeon
from osrlib.party import Party
from osrlib.quest import Quest
Expand Down
2 changes: 1 addition & 1 deletion osrlib/osrlib/character_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from osrlib.dice_roller import DiceRoll, roll_dice
from osrlib.enums import CharacterClassType
from osrlib.saving_throws import get_saving_throws_for_class_and_level
from osrlib.game_manager import logger
from osrlib.utils import logger


class ClassLevel:
Expand Down
2 changes: 1 addition & 1 deletion osrlib/osrlib/dungeon.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import random, json, uuid
from openai import OpenAI
from osrlib.enums import Direction, OpenAIModelVersion
from osrlib.game_manager import logger
from osrlib.utils import logger
from osrlib.encounter import Encounter
from osrlib.dice_roller import roll_dice

Expand Down
3 changes: 1 addition & 2 deletions osrlib/osrlib/dungeon_assistant.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
"""The `dungeon_assistant` module contains the `DungeonAssistant` class that interfaces with the OpenAI API and performs the duties of the game's referee and guide (*game master* or *dungeon master* in some tabletop RPGs)."""

import asyncio
from openai import OpenAI
from osrlib.adventure import Adventure
from osrlib.enums import OpenAIModelVersion
from osrlib.game_manager import logger
from osrlib.utils import logger


dm_init_message = (
Expand Down
2 changes: 1 addition & 1 deletion osrlib/osrlib/encounter.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from osrlib.party import Party
from osrlib.monster import MonsterParty
from osrlib.monster_manual import monster_stats_blocks
from osrlib.game_manager import logger, last_message_handler as pylog
from osrlib.utils import logger, last_message_handler as pylog
from osrlib.dice_roller import roll_dice
from osrlib.treasure import Treasure, TreasureType

Expand Down
51 changes: 0 additions & 51 deletions osrlib/osrlib/game_manager.py

This file was deleted.

92 changes: 46 additions & 46 deletions osrlib/osrlib/item.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,51 +5,6 @@
from osrlib.enums import CharacterClassType, ItemType


class ItemAlreadyHasOwnerError(Exception):
"""Exception raised when an item already has an owner."""

pass


class ItemAlreadyInInventoryError(Exception):
"""Exception raised when trying to add an item to a player character's (PC) inventory already in the inventory."""

pass


class ItemEquippedError(Exception):
"""Exception raised when trying to equip an item the player character (PC) already has equipped."""

pass


class ItemNotEquippedError(Exception):
"""Exception raised when trying to unequip an item the player character (PC) doesn't have equipped."""

pass


class ItemNotInInventoryError(Exception):
"""Exception raised when trying to remove an item from a player character's (PC) inventory that's not in the inventory."""

pass


class ItemNotUsableError(Exception):
"""Exception raised when trying to use an item that the player character (PC) can't use.
The inability to use an item is typically due to a character class restriction. For example, a magic user can't use
a sword and a thief can't wear plate mail armor."""

pass


class ItemAlreadyInQuestError(Exception):
"""Exception raised when trying to assign an item to a quest that's already been assigned to a quest."""

pass


class Item:
"""An item represents a piece of equipment, a weapon, spell, quest piece, any other item that can be owned by a player character (PC).
Expand All @@ -71,7 +26,7 @@ class Item:
Example:
```python
# Create an item that is a sword usable by fighters and thieves
# Create a sword usable by Fighters and Thieves
usable_by = {CharacterClassType.FIGHTER, CharacterClassType.THIEF}
item = Item("Sword", ItemType.WEAPON, usable_by, max_equipped=1, gp_value=10)
```
Expand Down Expand Up @@ -410,3 +365,48 @@ def from_dict(cls, spell_dict: dict) -> "Spell":
max_equipped=base_item.max_equipped,
gp_value=base_item.gp_value,
)


class ItemAlreadyHasOwnerError(Exception):
"""Exception raised when an item already has an owner."""

pass


class ItemAlreadyInInventoryError(Exception):
"""Exception raised when trying to add an item to a player character's (PC) inventory already in the inventory."""

pass


class ItemEquippedError(Exception):
"""Exception raised when trying to equip an item the player character (PC) already has equipped."""

pass


class ItemNotEquippedError(Exception):
"""Exception raised when trying to unequip an item the player character (PC) doesn't have equipped."""

pass


class ItemNotInInventoryError(Exception):
"""Exception raised when trying to remove an item from a player character's (PC) inventory that's not in the inventory."""

pass


class ItemNotUsableError(Exception):
"""Exception raised when trying to use an item that the player character (PC) can't use.
The inability to use an item is typically due to a character class restriction. For example, a magic user can't use
a sword and a thief can't wear plate mail armor."""

pass


class ItemAlreadyInQuestError(Exception):
"""Exception raised when trying to assign an item to a quest that's already been assigned to a quest."""

pass
2 changes: 1 addition & 1 deletion osrlib/osrlib/monster.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from osrlib.enums import CharacterClassType, TreasureType
from osrlib.player_character import Alignment
from osrlib.saving_throws import get_saving_throws_for_class_and_level
from osrlib.game_manager import logger
from osrlib.utils import logger
from osrlib.treasure import Treasure

monster_xp = {
Expand Down
38 changes: 20 additions & 18 deletions osrlib/osrlib/party.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from typing import List

from osrlib.player_character import PlayerCharacter
from osrlib.game_manager import logger
from osrlib.utils import logger
from osrlib.enums import CharacterClassType
from osrlib.item_factories import equip_party
from osrlib.dice_roller import roll_dice
Expand Down Expand Up @@ -63,6 +63,7 @@ class NoMembersInPartyError(Exception):

pass


class Party:
"""Manages a collection of player characters (PCs) that comprise an adventuring party.
Expand Down Expand Up @@ -528,21 +529,22 @@ def from_dict(cls, party_dict: dict) -> "Party":
party.set_active_character(party.members[0])
return party

def get_default_party(party_name: str = "Default Party") -> Party: # pragma: no cover
"""Get a party of six (6) first-level characters: a Fighter, Elf, Dwarf, Thief, Halfling, and Magic User.
@staticmethod
def get_default_party(party_name: str = "Default Party") -> "Party": # pragma: no cover
"""Get a party of first-level characters of each class: a Fighter, Elf, Cleric, Dwarf, Thief, Halfling, and Magic User.
Returns:
Party: A party with six (6) player characters at first level (zero experience points).
"""
party = Party(party_name)
party.create_character(random.choice(FIGHTER_NAMES), CharacterClassType.FIGHTER, 1)
party.create_character(random.choice(ELF_NAMES), CharacterClassType.ELF, 1)
party.create_character(random.choice(CLERIC_NAMES), CharacterClassType.CLERIC, 1)
party.create_character(random.choice(DWARF_NAMES), CharacterClassType.DWARF, 1)
party.create_character(random.choice(THIEF_NAMES), CharacterClassType.THIEF, 1)
party.create_character(random.choice(HALFLING_NAMES), CharacterClassType.HALFLING, 1)
party.create_character(random.choice(MAGIC_USER_NAMES), CharacterClassType.MAGIC_USER, 1)

equip_party(party)

return party
Returns:
Party: A party of first-level player characters in each character class.
"""
party = Party(party_name)
party.create_character(random.choice(FIGHTER_NAMES), CharacterClassType.FIGHTER, 1)
party.create_character(random.choice(ELF_NAMES), CharacterClassType.ELF, 1)
party.create_character(random.choice(CLERIC_NAMES), CharacterClassType.CLERIC, 1)
party.create_character(random.choice(DWARF_NAMES), CharacterClassType.DWARF, 1)
party.create_character(random.choice(THIEF_NAMES), CharacterClassType.THIEF, 1)
party.create_character(random.choice(HALFLING_NAMES), CharacterClassType.HALFLING, 1)
party.create_character(random.choice(MAGIC_USER_NAMES), CharacterClassType.MAGIC_USER, 1)

equip_party(party)

return party
6 changes: 4 additions & 2 deletions osrlib/osrlib/player_character.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from osrlib.enums import AbilityType, CharacterClassType, ModifierType
from osrlib.inventory import Inventory
from osrlib.dice_roller import roll_dice, DiceRoll
from osrlib.game_manager import logger
from osrlib.utils import logger
from osrlib.utils import get_data_dir_path, create_dir_tree_if_not_exist


Expand All @@ -34,7 +34,9 @@ class PlayerCharacter:
abilities (dict): A dictionary of the character's abilities.
character_class (CharacterClass): The character's class.
inventory (Inventory): The character's inventory.
xp_adjustment_percentage (int): The character's XP adjustment based on the scores of ability their prime requisite(s). This value is set when the character's class is set, or when restoring a saved character.
xp_adjustment_percentage (int): The character's XP adjustment based on the scores of ability their prime
requisite(s). This value is set when the character's class is set, or when
restoring a saved character.
"""

def __init__(
Expand Down
2 changes: 1 addition & 1 deletion osrlib/osrlib/saving_throws.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from osrlib.enums import CharacterClassType, AttackType
from osrlib.game_manager import logger
from osrlib.utils import logger

saving_throws = {
CharacterClassType.CLERIC: {
Expand Down
Loading

0 comments on commit 00cb290

Please sign in to comment.