11from __future__ import annotations
22
3- from typing import TYPE_CHECKING , Optional
3+ from typing import TYPE_CHECKING , Optional , Union
44
5- from game .actions import Action , ItemAction
6- from game .color import health_recovered
7- from game .components .ai import ConfusedEnemy
8- from game .components .base_component import BaseComponent
9- from game .components .inventory import Inventory
10- from game .entity import Actor , Item
11- from game .exceptions import Impossible
12- from game .input_handlers import ActionOrHandler , AreaRangedAttackHandler , SingleRangedAttackHandler
5+ import game .actions
6+ import game .color
7+ import game .components .ai
8+ import game .components .base_component
9+ import game .exceptions
10+ import game .input_handlers
1311
1412if TYPE_CHECKING :
15- import game .actions
13+ import game .entity
1614
1715
18- class Consumable (BaseComponent ):
19- parent : Item
16+ class Consumable (game . components . base_component . BaseComponent ):
17+ parent : game . entity . Item
2018
21- def get_action (self , consumer : Actor ) -> Optional [Action ]:
19+ def get_action (
20+ self , consumer : game .entity .Actor
21+ ) -> Optional [Union [game .actions .Action , game .input_handlers .BaseEventHandler ]]:
2222 """Try to return the action for this item."""
23- return ItemAction (consumer , self .parent )
23+ return game . actions . ItemAction (consumer , self .parent )
2424
25- def activate (self , action : ItemAction ) -> None :
25+ def activate (self , action : game . actions . ItemAction ) -> None :
2626 """Invoke this items ability.
2727
2828 `action` is the context for this activation.
@@ -33,28 +33,28 @@ def consume(self) -> None:
3333 """Remove the consumed item from its containing inventory."""
3434 entity = self .parent
3535 inventory = entity .parent
36- if isinstance (inventory , Inventory ):
36+ if isinstance (inventory , game . components . inventory . Inventory ):
3737 inventory .items .remove (entity )
3838
3939
4040class HealingConsumable (Consumable ):
4141 def __init__ (self , amount : int ):
4242 self .amount = amount
4343
44- def activate (self , action : ItemAction ) -> None :
44+ def activate (self , action : game . actions . ItemAction ) -> None :
4545 # Type check to ensure consumer is an Actor
46- assert isinstance (action .entity , Actor ), "Consumer must be an Actor"
46+ assert isinstance (action .entity , game . entity . Actor ), "Consumer must be an Actor"
4747 consumer = action .entity
4848 amount_recovered = consumer .fighter .heal (self .amount )
4949
5050 if amount_recovered > 0 :
5151 self .engine .message_log .add_message (
5252 f"You consume the { self .parent .name } , and recover { amount_recovered } HP!" ,
53- health_recovered ,
53+ game . color . health_recovered ,
5454 )
5555 self .consume ()
5656 else :
57- raise Impossible ("Your health is already full." )
57+ raise game . exceptions . Impossible ("Your health is already full." )
5858
5959
6060class LightningDamageConsumable (Consumable ):
@@ -89,9 +89,9 @@ class ConfusionConsumable(Consumable):
8989 def __init__ (self , number_of_turns : int ):
9090 self .number_of_turns = number_of_turns
9191
92- def get_action (self , consumer : Actor ) -> Optional [ActionOrHandler ]:
92+ def get_action (self , consumer : game . entity . Actor ) -> Optional [game . input_handlers . ActionOrHandler ]:
9393 self .engine .message_log .add_message ("Select a target location." , game .color .needs_target )
94- return SingleRangedAttackHandler (
94+ return game . input_handlers . SingleRangedAttackHandler (
9595 self .engine ,
9696 callback = lambda xy : game .actions .ItemAction (consumer , self .parent , xy ),
9797 )
@@ -111,7 +111,7 @@ def activate(self, action: game.actions.ItemAction) -> None:
111111 f"The eyes of the { target .name } look vacant, as it starts to stumble around!" ,
112112 game .color .status_effect_applied ,
113113 )
114- target .ai = ConfusedEnemy (
114+ target .ai = game . components . ai . ConfusedEnemy (
115115 entity = target ,
116116 previous_ai = target .ai ,
117117 turns_remaining = self .number_of_turns ,
@@ -124,9 +124,9 @@ def __init__(self, damage: int, radius: int):
124124 self .damage = damage
125125 self .radius = radius
126126
127- def get_action (self , consumer : Actor ) -> Optional [ActionOrHandler ]:
127+ def get_action (self , consumer : game . entity . Actor ) -> Optional [game . input_handlers . ActionOrHandler ]:
128128 self .engine .message_log .add_message ("Select a target location." , game .color .needs_target )
129- return AreaRangedAttackHandler (
129+ return game . input_handlers . AreaRangedAttackHandler (
130130 self .engine ,
131131 radius = self .radius ,
132132 callback = lambda xy : game .actions .ItemAction (consumer , self .parent , xy ),
0 commit comments