Add room entry auto-triggers, player input, and more

* When you teleport to a room, the teleport auto-triggers fire.
* Rooms have auto-triggers. None by default. They are run every time you
  teleport to a room, and when the game starts. Gate behavior behind a
  variable.
* PlayerInputAction waits for player input (and potentially write it
  into a variable)

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
2021-11-18 20:32:02 -08:00
parent b67034d2fa
commit 2f86df2930
7 changed files with 119 additions and 16 deletions

View File

@@ -11,8 +11,9 @@ __all__ = (
"Action",
"SleepAction",
"PrintAction",
"TeleportAction",
"PrintRoomAction",
"PlayerInputAction",
"TeleportAction",
"GetAction",
"CheckInvItemsAction",
"CheckRoomItemsAction",
@@ -73,6 +74,35 @@ class PrintAction(Action):
game.say(line)
@dataclasses.dataclass
class PrintRoomAction(Action):
"""
Prints the current room.
"""
def act(self, game: "Game"):
game.say("", "." * 70, "")
game.print_room()
@dataclasses.dataclass
class PlayerInputAction(Action):
"""
Waits for a user to press a key, or press enter, or whatever.
"""
prompt: str = "Press enter to continue..."
store_var_id: Optional[str] = None
def act(self, game: "Game"):
line = input(self.prompt)
if self.store_var_id:
assert (
self.store_var_id in game.vars
), f"could not find var with id {self.store_var_id}"
game.vars[self.store_var_id] = line
@dataclasses.dataclass
class TeleportAction(Action):
"""
@@ -90,22 +120,12 @@ class TeleportAction(Action):
assert (
self.room_id in game.database.rooms
), f"could not find room with id {self.room_id}"
game.room = game.database.rooms[self.room_id]
game.teleport(game.database.rooms[self.room_id])
if self.announce:
game.say("", "." * 70, "")
game.print_room()
class PrintRoomAction(Action):
"""
Prints the current room.
"""
def act(self, game: "Game"):
game.say("", "." * 70, "")
game.print_room()
@dataclasses.dataclass
class GetAction(Action):
"""