Skip to content

Commit

Permalink
item gen for treasure pt. 1
Browse files Browse the repository at this point in the history
  • Loading branch information
mmacy committed Feb 8, 2024
1 parent 00cb290 commit c750b81
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 17 deletions.
1 change: 0 additions & 1 deletion docs/reference/game_manager.md

This file was deleted.

1 change: 0 additions & 1 deletion mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ nav:
- dungeon_assistant: reference/dungeon_assistant.md
- encounter: reference/encounter.md
- enums: reference/enums.md
- game_manager: reference/game_manager.md
- inventory: reference/inventory.md
- item: reference/item.md
- item_factories: reference/item_factories.md
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.

8 changes: 3 additions & 5 deletions osrlib/osrlib/item_factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ class ArmorFactory:

@staticmethod
def create_armor(armor_name: str):
armor_info = armor_data.get(armor_name)
armor_info = (armor_data | magic_armor_data).get(armor_name)
if armor_info:
return Armor(
name=armor_name,
Expand Down Expand Up @@ -181,11 +181,11 @@ def create_item(item_name):


class WeaponFactory:
"""Factory class to create items of type ``Weapon``."""
"""Factory class to create items of type `Weapon`."""

@staticmethod
def create_weapon(weapon_name: str):
weapon_info = weapon_data.get(weapon_name)
weapon_info = (weapon_data| magic_weapon_data).get(weapon_name)
if weapon_info:
return Weapon(
name=weapon_name,
Expand All @@ -194,7 +194,6 @@ def create_weapon(weapon_name: str):
usable_by_classes=weapon_info["usable_by"],
range=weapon_info.get("range"),
)

else:
raise ItemDataNotFoundError(weapon_name)

Expand Down Expand Up @@ -340,6 +339,5 @@ def get_random_item(item_type: ItemType, magical: bool = False) -> Item:
data = magic_weapon_data if magical else weapon_data
item_name = random.choice(list(data.keys()))
return WeaponFactory.create_weapon(item_name)
# TODO: Add support for SPELL, EQUIPMENT, and MAGIC_ITEM
else:
raise ValueError(f"No item selection logic for {item_type}")
19 changes: 12 additions & 7 deletions osrlib/osrlib/treasure.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
categories to their respective contents. These categories represent different types of treasure the party might obtain,
each with specified probabilities and quantities of items like coins, gems, jewelry, and magical items.
"""
from typing import Dict, NamedTuple, Union
import random
from typing import Dict, Union, List
from dataclasses import dataclass
from osrlib.dice_roller import roll_dice
from osrlib.enums import ItemType, TreasureType, CoinType
from osrlib.item import Item, Weapon, Armor
from osrlib.item import Item
from osrlib.item_factories import get_random_item
from osrlib.utils import logger

from enum import Enum
Expand Down Expand Up @@ -74,6 +76,7 @@ class Treasure:
```
"""
items: Dict[Union[CoinType, ItemType], int]
magic_items: List[Item]

_treasure_types: Dict[
TreasureType, Dict[Union[CoinType, ItemType], TreasureDetail]
Expand All @@ -86,7 +89,8 @@ class Treasure:
CoinType.GOLD: TreasureDetail(chance=35, amount="2000d6"),
CoinType.PLATINUM: TreasureDetail(chance=25, amount="1000d2"),
ItemType.GEMS_JEWELRY: TreasureDetail(chance=50, amount="6d6"),
ItemType.MAGIC_ITEM: TreasureDetail(chance=30, amount="3", magical=True),
ItemType.ARMOR: TreasureDetail(chance=30, amount="1", magical=True),
ItemType.WEAPON: TreasureDetail(chance=30, amount="1", magical=True),
},
TreasureType.B: {
CoinType.COPPER: TreasureDetail(chance=50, amount="1000d8"),
Expand Down Expand Up @@ -207,6 +211,7 @@ class Treasure:

def __init__(self, treasure_type: TreasureType = TreasureType.NONE):
self.items = {}
self.magic_items = []
self._generate_treasure(treasure_type)
self.treasure_type = treasure_type

Expand Down Expand Up @@ -245,10 +250,10 @@ def _generate_treasure(self, treasure_type: TreasureType) -> None:
amount_roll = roll_dice(details.amount)
if isinstance(item_type, CoinType):
self.items[item_type] = amount_roll.total_with_modifier
else:
# TODO: Create the items and add them to a List[Item]
# For now, do the same as for coinage
self.items[item_type] = amount_roll.total_with_modifier
elif item_type == ItemType.ARMOR or item_type == ItemType.WEAPON:
magic_item = get_random_item(item_type, magical=True)
self.magic_items.append(magic_item)
logger.debug(f"Added {magic_item} to {treasure_type}")

@property
def total_gp_value(self) -> int:
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.81"
version = "0.1.83"
description = "Turn-based dungeon-crawler game engine for OSR-style RPGs."
authors = ["Marsh Macy <[email protected]>"]
license = "MIT"
Expand Down
2 changes: 1 addition & 1 deletion tests/test_unit_dungeon.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def test_random_dungeon():
description="The first level of the home of the ancient wizard lich Glofarnux, its "
"entrance hidden in a forgotten glade deep in the cursed Mystic Forest.",
num_locations=20,
openai_model=OpenAIModelVersion.DEFAULT,
openai_model=OpenAIModelVersion.NONE,
)

# Validate Dungeon
Expand Down

0 comments on commit c750b81

Please sign in to comment.