diff --git a/actions.py b/actions.py index 293bede..8330c90 100644 --- a/actions.py +++ b/actions.py @@ -79,7 +79,8 @@ class ItemAction(Action): def perform(self) -> None: """Invoke the item's ability, this action will be given to provide context.""" - self.item.consumable.activate(self) + if self.item.consumable: + self.item.consumable.activate(self) class DropItem(ItemAction): diff --git a/entity.py b/entity.py index 90b3690..8ca799b 100644 --- a/entity.py +++ b/entity.py @@ -9,6 +9,7 @@ from render_order import RenderOrder if TYPE_CHECKING: from components.ai import BaseAI from components.consumable import Consumable + from components.equippable import Equippable from components.fighter import Fighter from components.inventory import Inventory from components.level import Level @@ -134,7 +135,8 @@ class Item(Entity): char: str = "?", color: Tuple[int, int, int] = (255, 255, 255), name: str = "", - consumable: Consumable, + consumable: Optional[Consumable] = None, + equippable: Optional[Equippable] = None, ): super().__init__( x=x, @@ -147,4 +149,11 @@ class Item(Entity): ) self.consumable = consumable - self.consumable.parent = self + + if self.consumable: + self.consumable.parent = self + + self.equippable = equippable + + if self.equippable: + self.equippable.parent = self diff --git a/entity_factories.py b/entity_factories.py index b90d757..219b4f1 100644 --- a/entity_factories.py +++ b/entity_factories.py @@ -1,5 +1,5 @@ from components.ai import HostileEnemy -from components import consumable +from components import consumable, equippable from components.fighter import Fighter from components.inventory import Inventory from components.level import Level @@ -58,3 +58,31 @@ lightning_scroll = Item( name="Lightning Scroll", consumable=consumable.LightningDamageConsumable(damage=20, maximum_range=5), ) + +dagger = Item( + char="/", + color=(0, 191, 255), + name="Dagger", + equippable=equippable.Dagger(), +) + +sword = Item( + char="/", + color=(0, 191, 244), + name="Sword", + equippable=equippable.Sword(), +) + +leather_armor = Item( + char="[", + color=(139, 69, 19), + name="Leather Armor", + equippable=equippable.LeatherArmor(), +) + +chain_mail = Item( + char="[", + color=(139, 69, 19), + name="Chain Mail", + equippable=equippable.ChainMail(), +)