Update Items so they can be equippable, create factories for equippable items
This commit is contained in:
parent
159beb98b2
commit
142950e474
@ -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):
|
||||
|
13
entity.py
13
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 = "<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
|
||||
self.consumable.parent = self
|
||||
|
||||
if self.consumable:
|
||||
self.consumable.parent = self
|
||||
|
||||
self.equippable = equippable
|
||||
|
||||
if self.equippable:
|
||||
self.equippable.parent = self
|
||||
|
@ -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(),
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user