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

@@ -1,6 +1,6 @@
import dataclasses
import textwrap
from typing import Any, MutableMapping, List, Match, Optional, Sequence
from typing import Any, MutableMapping, List, Match, Optional, Sequence, Union
from agame.action import Action
from agame.color import colorize
from agame.item import Item, ItemInst
@@ -98,6 +98,17 @@ class Game:
for action in actions:
action.act(self)
def do_teleport_actions(self):
"Executes the teleport actions for the current room."
self.do_actions(self.room.teleport_actions)
def teleport(self, room: Union[str, Room]):
if isinstance(room, str):
assert room in self.database.rooms, f"could not find room with id {room}"
room = self.database.rooms[room]
self.room = room
self.do_teleport_actions()
def print_room(self):
"Prints this room's description."
self.say(f"(({self.room.name}))")