diff --git a/components/ai.py b/components/ai.py index ca158cc..eb8e5f8 100644 --- a/components/ai.py +++ b/components/ai.py @@ -4,6 +4,7 @@ from typing import List, Optional, Tuple, TYPE_CHECKING import actor_factories import color +import tile_types import numpy as np # type: ignore import tcod from actions import ( @@ -12,6 +13,7 @@ EnergyAction, MeleeAction, MovementAction, + OpenDoorAction, PickupAction, PounceAction, RangedAttackAction, @@ -149,6 +151,17 @@ def get_action(self) -> Optional[Action]: # Restore the AI if we see an enemy to avoid dying. self.entity.restore_ai() + # Open the door action if the tile you have to move to is a door + + if ( + self.engine.game_map.tiles[self.dest_x, self.dest_y] + in tile_types.door_tiles + and distance <= 1 + ): + print(f"Opening door at {self.dest_x}, {self.dest_y}.") + self.entity.restore_ai() + return OpenDoorAction(self.entity, self.dest_x, self.dest_y) + actor = self.engine.game_map.get_actor_at_location(self.dest_x, self.dest_y) if distance <= 1 and actor and actor is not self.entity: return MeleeAction(self.entity, dx, dy) diff --git a/event_handlers/main_game_event_handler.py b/event_handlers/main_game_event_handler.py index 3417d9a..90b0615 100644 --- a/event_handlers/main_game_event_handler.py +++ b/event_handlers/main_game_event_handler.py @@ -1,6 +1,8 @@ from __future__ import annotations from typing import Optional, TYPE_CHECKING + +import tile_types import tcod.event import color import actions @@ -35,7 +37,10 @@ def ev_mousebuttondown( self.engine.game_map.in_bounds(event.tile.x, event.tile.y) and game_map.explored[event.tile.x, event.tile.y] ): - if game_map.tiles["walkable"][event.tile.x, event.tile.y]: + if ( + game_map.tiles["walkable"][event.tile.x, event.tile.y] + or game_map.tiles[event.tile.x, event.tile.y] in tile_types.door_tiles + ): return MoveToTileAction(self.engine.player, event.tile.x, event.tile.y) return action