Skip to content

Commit

Permalink
Merge pull request #32 from mmacy/move-enums-to-enums
Browse files Browse the repository at this point in the history
move remaining enums to enums.py
  • Loading branch information
mmacy committed Dec 9, 2023
2 parents f26a25a + 87f4ea8 commit 0693db9
Show file tree
Hide file tree
Showing 17 changed files with 235 additions and 249 deletions.
228 changes: 114 additions & 114 deletions osrgame/poetry.lock

Large diffs are not rendered by default.

15 changes: 1 addition & 14 deletions osrlib/osrlib/ability.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,8 @@
"""Defines player character abilities."""

from abc import ABC, abstractmethod
from enum import Enum

from osrlib.enums import CharacterClassType
from osrlib.combat import ModifierType


class AbilityType(Enum):
"""Enum representing the types of abilities."""

STRENGTH = "Strength"
INTELLIGENCE = "Intelligence"
WISDOM = "Wisdom"
DEXTERITY = "Dexterity"
CONSTITUTION = "Constitution"
CHARISMA = "Charisma"
from osrlib.enums import AbilityType, CharacterClassType, ModifierType


class Ability(ABC):
Expand Down
24 changes: 0 additions & 24 deletions osrlib/osrlib/combat.py

This file was deleted.

2 changes: 2 additions & 0 deletions osrlib/osrlib/constants.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""Constants for use in random character and dungeon generation."""

FIGHTER_NAMES = [
"Alistair Goldleaf",
"Anya Steelgaze",
Expand Down
80 changes: 75 additions & 5 deletions osrlib/osrlib/enums.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,39 @@
from enum import Enum

class CharacterClassType(Enum):
"""Specifies the class, or profession, of a player character or NPC."""

class AbilityType(Enum):
STRENGTH = "Strength"
INTELLIGENCE = "Intelligence"
WISDOM = "Wisdom"
DEXTERITY = "Dexterity"
CONSTITUTION = "Constitution"
CHARISMA = "Charisma"


class AttackType(Enum):
MELEE = "Meelee"
RANGED = "Ranged"
DEATH_RAY_POISON = "Death ray or poison"
MAGIC_WANDS = "Magic wands"
PARALYSIS_TURN_TO_STONE = "Paralysis or turn to stone"
DRAGON_BREATH = "Dragon breath"
RODS_STAVES_SPELLS = "Rods, staves, or spells"


class ModifierType(Enum):
TO_HIT = "To hit"
DAMAGE = "Damage"
OPEN_DOORS = "Open doors"
LANGUAGES = "Languages"
SAVING_THROWS = "Magic-based saving throws"
AC = "AC"
INITIATIVE = "Initiative"
HP = "HP"
REACTION = "Monster and NPC reactions"
XP = "XP"


class CharacterClassType(Enum):
CLERIC = "Cleric"
DWARF = "Dwarf"
ELF = "Elf"
Expand All @@ -13,8 +44,19 @@ class CharacterClassType(Enum):
COMMONER = "Commoner"


class ItemType(Enum):
ARMOR = ("Armor", "Armor, helmet, gloves, or boots")
WEAPON = ("Weapon", "Bladed, blunt, or ranged weapon")
SPELL = ("Spell", "Spell or scroll")
EQUIPMENT = ("Equipment", "Piece of adventurers' equipment")
MAGIC_ITEM = (
"Magic item",
"Potion, ring, or other item imbued with magical properties",
)
ITEM = ("Normal item", "Normal (non-magical) item")


class OpenAIModelVersion(Enum):
"""Specifies the version of the OpenAI model to use."""
DEFAULT = "gpt-3.5-turbo-1106"
GPT35 = "gpt-3.5"
GPT35TURBO = "gpt-3.5-turbo-1106"
Expand All @@ -23,9 +65,37 @@ class OpenAIModelVersion(Enum):


class PartyReaction(Enum):
"""Specifies the reaction of a PC or monster party at the start of an encounter."""

FIGHT = "Fight"
RUN = "Run"
TALK = "Talk"
PASS = "Pass"


class TreasureType(Enum):
NONE = "None"
A = "A"
B = "B"
C = "C"
D = "D"
E = "E"
F = "F"
G = "G"
H = "H"
I = "I"
J = "J"
K = "K"
L = "L"
M = "M"
N = "N"
O = "O"
P = "P"
Q = "Q"
R = "R"
S = "S"
T = "T"
U = "U"
V = "V"
W = "W"
X = "X"
Y = "Y"
Z = "Z"
2 changes: 1 addition & 1 deletion osrlib/osrlib/inventory.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from collections import defaultdict
from typing import List

from osrlib.enums import ItemType
from osrlib.item import (
Item,
ItemAlreadyHasOwnerError,
Expand All @@ -9,7 +10,6 @@
ItemNotEquippedError,
ItemNotInInventoryError,
ItemNotUsableError,
ItemType,
Armor,
Weapon,
Spell
Expand Down
20 changes: 1 addition & 19 deletions osrlib/osrlib/item.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,7 @@
from enum import Enum
from typing import Optional, Set

from osrlib.enums import CharacterClassType


class ItemType(Enum):
"""Enumerates the types of items in the game.
The item type determines whether the item can be used by a player character (PC) and, if so, whether it can be
equipped by the PC.
"""

ARMOR = ("Armor", "Armor, helmet, gloves, or boots")
WEAPON = ("Weapon", "Bladed, blunt, or ranged weapon")
SPELL = ("Spell", "Spell or scroll")
EQUIPMENT = ("Equipment", "Piece of adventurers' equipment")
MAGIC_ITEM = (
"Magic item",
"Potion, ring, or other item imbued with magical properties",
)
ITEM = ("Normal item", "Normal (non-magical) item")
from osrlib.enums import CharacterClassType, ItemType


class ItemAlreadyHasOwnerError(Exception):
Expand Down
4 changes: 2 additions & 2 deletions osrlib/osrlib/item_factories.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from osrlib.item import Armor, Item, ItemType, Weapon
from osrlib.enums import CharacterClassType
from osrlib.item import Armor, Item, Weapon
from osrlib.enums import CharacterClassType, ItemType

_armor_combat_classes = {
CharacterClassType.CLERIC,
Expand Down
3 changes: 1 addition & 2 deletions osrlib/osrlib/monster.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
from typing import List
from osrlib.dice_roller import roll_dice, DiceRoll
from osrlib.enums import CharacterClassType
from osrlib.enums import CharacterClassType, TreasureType
from osrlib.player_character import Alignment
from osrlib.treasure import TreasureType
from osrlib.saving_throws import get_saving_throws_for_class_and_level
from osrlib.game_manager import logger

Expand Down
3 changes: 1 addition & 2 deletions osrlib/osrlib/monster_manual.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from osrlib.monster import MonsterStatsBlock
from osrlib.enums import CharacterClassType
from osrlib.enums import CharacterClassType, TreasureType
from osrlib.player_character import Alignment
from osrlib.treasure import TreasureType

berserker_stats = MonsterStatsBlock(
name="Berserker",
Expand Down
32 changes: 19 additions & 13 deletions osrlib/osrlib/player_character.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,15 @@
import datetime, json
import osrlib.ability
from osrlib.ability import (
AbilityType,
Charisma,
Constitution,
Dexterity,
Intelligence,
ModifierType,
Strength,
Wisdom,
)
from osrlib.character_classes import (
CharacterClass,
CharacterClassType,
)
from osrlib.character_classes import CharacterClass
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
Expand Down Expand Up @@ -136,7 +132,9 @@ def get_initiative_roll(self) -> int:
ModifierType.INITIATIVE
]
roll = roll_dice("1d6", modifier_value)
logger.debug(f"{self.name} ({self.character_class.class_type.value}) rolled {roll} for initiative and got {roll.total_with_modifier}.")
logger.debug(
f"{self.name} ({self.character_class.class_type.value}) rolled {roll} for initiative and got {roll.total_with_modifier}."
)
return roll.total_with_modifier

def get_attack_roll(self) -> DiceRoll:
Expand All @@ -151,8 +149,12 @@ def get_attack_roll(self) -> DiceRoll:
# - TODO: Melee: Strength modifier, enchanted/cursed weapon adjustment, buffs/curses
# - TODO: Ranged: Dexterity modifier, enchanted/cursed weapon adjustment, buffs/curses

melee_attack_modifier = self.abilities[AbilityType.STRENGTH].modifiers[ModifierType.TO_HIT]
ranged_attack_modifier = self.abilities[AbilityType.DEXTERITY].modifiers[ModifierType.TO_HIT]
melee_attack_modifier = self.abilities[AbilityType.STRENGTH].modifiers[
ModifierType.TO_HIT
]
ranged_attack_modifier = self.abilities[AbilityType.DEXTERITY].modifiers[
ModifierType.TO_HIT
]
return roll_dice("1d20", melee_attack_modifier)

def get_damage_roll(self) -> DiceRoll:
Expand All @@ -162,7 +164,9 @@ def get_damage_roll(self) -> DiceRoll:
DiceRoll: The result of the damage roll.
"""
weapon = self.inventory.get_equipped_weapon()
melee_damage_modifier = self.abilities[AbilityType.STRENGTH].modifiers[ModifierType.DAMAGE]
melee_damage_modifier = self.abilities[AbilityType.STRENGTH].modifiers[
ModifierType.DAMAGE
]
return roll_dice(weapon.damage_die, melee_damage_modifier)

def apply_damage(self, hit_points_damage: int):
Expand Down Expand Up @@ -199,7 +203,9 @@ def _set_prime_requisite_xp_adjustment(self):
if all(score >= 13 for score in prime_requisites_scores):
self.xp_adjustment_percentage = 10

logger.debug(f"XP adjustment percentage set to: {self.xp_adjustment_percentage}%")
logger.debug(
f"XP adjustment percentage set to: {self.xp_adjustment_percentage}%"
)

def set_character_class(
self, character_class_type: CharacterClassType, level: int = 1
Expand Down Expand Up @@ -329,7 +335,7 @@ def save_character(self, file_path: str = None) -> str:

if file_path is None:
now = datetime.datetime.now()
timestamp = now.strftime("%Y%m%d_%H%M%S") # YYYYMMDD_HHMMSS
timestamp = now.strftime("%Y%m%d_%H%M%S") # YYYYMMDD_HHMMSS
filename = f"{self.name}_{timestamp}.json".replace(" ", "_").lower()
save_dir = get_data_dir_path("osrlib") / "characters"
create_dir_tree_if_not_exist(save_dir)
Expand All @@ -343,4 +349,4 @@ def save_character(self, file_path: str = None) -> str:
logger.error(f"Failed to save character to {file_path}: {e}")
raise

return str(file_path)
return str(file_path)
3 changes: 1 addition & 2 deletions osrlib/osrlib/saving_throws.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from osrlib.enums import CharacterClassType
from osrlib.combat import AttackType
from osrlib.enums import CharacterClassType, AttackType
from osrlib.game_manager import logger

saving_throws = {
Expand Down
35 changes: 2 additions & 33 deletions osrlib/osrlib/treasure.py
Original file line number Diff line number Diff line change
@@ -1,37 +1,6 @@
from enum import Enum
from osrlib.dice_roller import roll_dice
from osrlib.item import Item, ItemType, Weapon, Armor

class TreasureType(Enum):
"""Represents the treasure type of a treasure."""

NONE = "None"
A = "A"
B = "B"
C = "C"
D = "D"
E = "E"
F = "F"
G = "G"
H = "H"
I = "I"
J = "J"
K = "K"
L = "L"
M = "M"
N = "N"
O = "O"
P = "P"
Q = "Q"
R = "R"
S = "S"
T = "T"
U = "U"
V = "V"
W = "W"
X = "X"
Y = "Y"
Z = "Z"
from osrlib.enums import ItemType, TreasureType
from osrlib.item import Item, Weapon, Armor

def get_treasure(treasure_type: TreasureType):
"""Get a collection of items appropriate for the specified treasure type.
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.46"
version = "0.1.47"
description = "Turn-based dungeon-crawler game engine for OSR-style RPGs."
authors = ["Marsh Macy <[email protected]>"]
license = "MIT"
Expand Down
Loading

0 comments on commit 0693db9

Please sign in to comment.