Add initial equipment, and allow equipping items. This completes the main tutorial
This commit is contained in:
parent
359258862d
commit
ceeaf22d2f
13
actions.py
13
actions.py
@ -82,9 +82,22 @@ class ItemAction(Action):
|
||||
|
||||
class DropItem(ItemAction):
|
||||
def perform(self) -> None:
|
||||
if self.entity.equipment.item_is_equipped(self.item):
|
||||
self.entity.equipment.toggle_equip(self.item)
|
||||
|
||||
self.entity.inventory.drop(self.item)
|
||||
|
||||
|
||||
class EquipAction(Action):
|
||||
def __init__(self, entity: Actor, item: Item):
|
||||
super().__init__(entity)
|
||||
|
||||
self.item = item
|
||||
|
||||
def perform(self) -> None:
|
||||
self.entity.equipment.toggle_equip(self.item)
|
||||
|
||||
|
||||
class WaitAction(Action):
|
||||
def perform(self) -> None:
|
||||
pass
|
||||
|
@ -1,15 +1,14 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
|
||||
from typing import overload, Callable, Optional, Tuple, TYPE_CHECKING, Union
|
||||
|
||||
import tcod.event
|
||||
|
||||
import actions
|
||||
from actions import Action, BumpAction, PickupAction, WaitAction
|
||||
import color
|
||||
import exceptions
|
||||
from actions import Action, BumpAction, PickupAction, WaitAction
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from engine import Engine
|
||||
@ -344,7 +343,15 @@ class InventoryEventHandler(AskUserEventHandler):
|
||||
if number_of_items_in_inventory > 0:
|
||||
for i, item in enumerate(self.engine.player.inventory.items):
|
||||
item_key = chr(ord("a") + i)
|
||||
console.print(x + 1, y + i + 1, f"({item_key}) {item.name}")
|
||||
|
||||
is_equipped = self.engine.player.equipment.item_is_equipped(item)
|
||||
|
||||
item_string = f"({item_key}) {item.name}"
|
||||
|
||||
if is_equipped:
|
||||
item_string = f"{item_string} (E)"
|
||||
|
||||
console.print(x + 1, y + i + 1, item_string)
|
||||
else:
|
||||
console.print(x + 1, y + 1, "(Empty)")
|
||||
|
||||
@ -375,8 +382,13 @@ class InventoryActivateHandler(InventoryEventHandler):
|
||||
TITLE = "Select an item to use"
|
||||
|
||||
def on_item_selected(self, item: Item) -> Optional[ActionOrHandler]:
|
||||
"""Return the action for the selected item."""
|
||||
if item.consumable:
|
||||
# Return the action for the selected item.
|
||||
return item.consumable.get_action(self.engine.player)
|
||||
elif item.equippable:
|
||||
return actions.EquipAction(self.engine.player, item)
|
||||
else:
|
||||
return None
|
||||
|
||||
|
||||
class InventoryDropHandler(InventoryEventHandler):
|
||||
|
@ -6,8 +6,8 @@ from typing import Dict, Iterator, List, Tuple, TYPE_CHECKING
|
||||
import tcod
|
||||
|
||||
import entity_factories
|
||||
from game_map import GameMap
|
||||
import tile_types
|
||||
from game_map import GameMap
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from engine import Engine
|
||||
@ -27,8 +27,8 @@ max_monsters_by_floor = [
|
||||
item_chances: Dict[int, List[Tuple[Entity, int]]] = {
|
||||
0: [(entity_factories.health_potion, 35)],
|
||||
2: [(entity_factories.confusion_scroll, 10)],
|
||||
4: [(entity_factories.lightning_scroll, 25)],
|
||||
6: [(entity_factories.fireball_scroll, 25)],
|
||||
4: [(entity_factories.lightning_scroll, 25), (entity_factories.sword, 5)],
|
||||
6: [(entity_factories.fireball_scroll, 25), (entity_factories.chain_mail, 15)],
|
||||
}
|
||||
|
||||
enemy_chances: Dict[int, List[Tuple[Entity, int]]] = {
|
||||
|
@ -10,10 +10,10 @@ from typing import Optional
|
||||
import tcod
|
||||
|
||||
import color
|
||||
from engine import Engine
|
||||
import entity_factories
|
||||
from game_map import GameWorld
|
||||
import input_handlers
|
||||
from engine import Engine
|
||||
from game_map import GameWorld
|
||||
|
||||
# Load the background image and remove the alpha channel.
|
||||
background_image = tcod.image.load("menu_background.png")[:, :, :3]
|
||||
@ -47,6 +47,18 @@ def new_game() -> Engine:
|
||||
"Hello and welcome, adventurer, to yet another dungeon!", color.welcome_text
|
||||
)
|
||||
|
||||
dagger = copy.deepcopy(entity_factories.dagger)
|
||||
leather_armor = copy.deepcopy(entity_factories.leather_armor)
|
||||
|
||||
dagger.parent = player.inventory
|
||||
leather_armor.parent = player.inventory
|
||||
|
||||
player.inventory.items.append(dagger)
|
||||
player.equipment.toggle_equip(dagger, add_message=False)
|
||||
|
||||
player.inventory.items.append(leather_armor)
|
||||
player.equipment.toggle_equip(leather_armor, add_message=False)
|
||||
|
||||
return engine
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user