1
0

Update Items so they can be equippable, create factories for equippable items

This commit is contained in:
Timothy Warren 2022-02-08 09:49:48 -05:00
parent 159beb98b2
commit 142950e474
3 changed files with 42 additions and 4 deletions

View File

@ -79,6 +79,7 @@ class ItemAction(Action):
def perform(self) -> None:
"""Invoke the item's ability, this action will be given to provide context."""
if self.item.consumable:
self.item.consumable.activate(self)

View File

@ -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 = "<Unamed>",
consumable: Consumable,
consumable: Optional[Consumable] = None,
equippable: Optional[Equippable] = None,
):
super().__init__(
x=x,
@ -147,4 +149,11 @@ class Item(Entity):
)
self.consumable = consumable
if self.consumable:
self.consumable.parent = self
self.equippable = equippable
if self.equippable:
self.equippable.parent = self

View File

@ -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(),
)