Files
ages/examplegame/rooms.py

442 lines
15 KiB
Python
Raw Normal View History

from typing import Sequence
from agame.action import *
from agame.item import Item
from agame.room import Room
from agame.trigger import *
from . import database
LINEBREAK = "=" * 70
################################################################################
# Utility functions
################################################################################
def create_path_synonyms(direction: str) -> Sequence[str]:
return (
f"path to {direction}",
f"path to the {direction}",
f"path leading {direction}",
f"path leading {direction}ward",
f"{direction}",
f"{direction}ward",
f"{direction}ward path",
f"{direction} path",
f"{direction}ern path",
)
################################################################################
# Utility items
################################################################################
database.add_items(
Item(
id="ambiguous_path",
name="path",
room_desc=None,
triggers={
LOOK: [PrintAction("Which path?")],
USE: [PrintAction("Which path?")],
GO: [PrintAction("Which path?")],
},
),
)
################################################################################
# Prelude
################################################################################
database.add_room(
Room(
id="prelude",
name="Prelude",
desc="",
items={},
teleport_actions=[
PrintAction(
LINEBREAK,
#
"Many stories have been told about this place. Some are tall "
"tales and mostly contradictory. Some others, however, are true.",
#
"This is one of those stories.",
LINEBREAK,
),
WaitForAckAction(),
PrintAction(
LINEBREAK,
#
"There used to be trees here. Fifteen years ago, we were sitting "
"in the shade, telling stories about last summer and what we hope "
"would happen next, our laughter unable to break past the leaves "
"and branches around us.",
#
"It is now desolate. Only the wind shakes the dry branches of the "
"remaining trees. They chitter and clack; any other noise is a "
"long echo. Nothing else stands tall enough to block the sound.",
#
"No animals patrol the sky nor ground. Life has left this place.",
LINEBREAK,
),
WaitForAckAction(),
PrintAction(
LINEBREAK,
#
"It is because of the ((machine)).",
#
LINEBREAK,
),
WaitForAckAction(),
PrintAction(LINEBREAK),
SleepAction(0.75),
PrintAction("."),
SleepAction(0.75),
PrintAction(".."),
SleepAction(0.75),
PrintAction("..."),
SleepAction(0.75),
PrintAction("...."),
SleepAction(0.75),
PrintAction("....."),
SleepAction(0.75),
PrintAction("......"),
SleepAction(0.75),
PrintAction(LINEBREAK),
PrintAction("You awaken from a fitful sleep. Where are you again?"),
WaitForAckAction(),
PrintAction(LINEBREAK),
TeleportAction("cabin_inside"),
],
)
)
################################################################################
# Inside the cabin
################################################################################
database.add_items(
Item(
id="cabin_inside_door",
name="Cabin door",
room_desc="A door rests upon the south wall.",
synonyms=("door",),
triggers={
LOOK: [PrintAction("A strong, sturdy door leading outside.")],
GET: [PrintAction("The door is firmly attached to the wall.")],
# Don't actually worry about the door being open here. It's just a
# nice flavoring.
GO: [
PrintAction("You step outside."),
TeleportAction("cabin_outside"),
],
OPEN: [
CheckVarAction(
"cabin_door_open",
yes=PrintAction("The door is already open."),
no=[
PrintAction("You pull the cabin door open."),
SetVarAction("cabin_door_open", True),
],
)
],
CLOSE: [
CheckVarAction(
"cabin_door_open",
yes=[
PrintAction("You shut the door tight."),
SetVarAction("cabin_door_open", False),
],
no=PrintAction("The door is already closed."),
)
],
},
),
Item(
id="cabin_inside_bed",
name="Bed",
room_desc="A bed, freshly made, sits in the corner.",
triggers={
LOOK: [
PrintAction("It's a comfortable looking bed, but no time for rest now.")
],
GET: [PrintAction("Uh, no.")],
USE: [
PrintAction("You've only just woken up, now is not the time for rest.")
],
GO: [
PrintAction("You've only just woken up, now is not the time for rest.")
],
},
),
Item(
# The outside view, and also kind of a hack for the player to be allowed
# to say "go outside" and "look outside" without having an "outside"
# synonym for the door, so the player can't also do "open outside"
id="cabin_inside_outside",
name="Outside",
room_desc=None,
triggers={
LOOK: [PrintAction("It's brown and gray.")],
GO: [
PrintAction("You step outside."),
TeleportAction("cabin_outside"),
],
},
),
Item(
id="cabin_inside_window",
name="Window",
room_desc="A dull light pours in from the solitary window on the east wall.",
synonyms=("outside window", "out window", "out the window"),
triggers={
LOOK: [PrintAction("It's brown and gray.")],
OPEN: [
PrintAction(
"This window is simply a pane of glass in a fixed frame, it can be neither opened nor closed."
)
],
CLOSE: [
PrintAction(
"This window is simply a pane of glass in a fixed frame, it can be neither opened nor closed."
)
],
GO: [PrintAction("Try using the door instead.")],
},
),
)
database.add_room(
Room(
id="cabin_inside",
name="Inside the cabin",
desc="",
items=[
database.items["cabin_inside_door"].create_inst(),
database.items["cabin_inside_bed"].create_inst(),
database.items["cabin_inside_outside"].create_inst(),
database.items["cabin_inside_window"].create_inst(),
],
)
)
################################################################################
# Outside the cabin
################################################################################
ANJAS_LETTER = [
"Dear Juni!",
"If you are reading this message you have finally arrived at my cabin in the "
"West. Continue your journey further into the west - that is where the machine "
"resides. Turn it off, and this land will begin healing anew.",
"You are our only hope - we are counting on you!",
"- Anja",
]
database.add_items(
Item(
id="anjas_letter",
name="Anja's letter",
synonyms=("letter", "anjas letter", "anja's letter"),
triggers={
GET: [GetAction("anjas_letter")],
LOOK: [PrintAction(*ANJAS_LETTER)],
READ: [PrintAction(*ANJAS_LETTER)],
},
),
Item(
id="cabin_outside_mailbox",
name="Mailbox",
synonyms=("mailbox", "postbox", "rusty mailbox", "rusty postbox"),
room_desc="A rusty mailbox sits by the door to the cabin.",
triggers={
GET: [
PrintAction(
"The mailbox is firmly rooted in the ground. You don't have anywhere to put it, anyway."
)
],
LOOK: [
CheckVarAction(
var_id="mailbox_open",
yes=[
CheckRoomItemsAction(
item_ids="anjas_letter",
yes=PrintAction("A single letter sits in the mailbox."),
no=PrintAction("It's empty."),
)
],
no=[
PrintAction("A rusty mailbox sits atop its post. It is closed.")
],
)
],
OPEN: [
CheckVarAction(
var_id="mailbox_open",
yes=PrintAction("The mailbox is already open."),
no=[
PrintAction(
"You unlatch the lid to the mailbox, and it pops open."
),
SetVarAction("mailbox_open", True),
CheckRoomItemsAction(
item_ids="anjas_letter",
yes=[
PrintAction("A single letter sits inside."),
RevealItemAction("anjas_letter"),
],
),
],
)
],
CLOSE: [
CheckVarAction(
var_id="mailbox_open",
yes=[
PrintAction("The mailbox snaps shut."),
SetVarAction("mailbox_open", False),
CheckRoomItemsAction(
"anjas_letter", yes=[UnrevealItemAction("anjas_letter")]
),
],
no=PrintAction("It's already closed."),
)
],
},
),
Item(
id="cabin_outside_west_path",
name="Western path",
synonyms=create_path_synonyms("west"),
room_desc=(
"A path leads westward, where the sky loses its color and becomes a dark gray. "
"The land becomes more barren in this direction."
),
triggers={
LOOK: [
PrintAction(
"A dirt path extends towards a barren wasteland. At one "
"point it had become overgrown with disuse, but most anything "
"that was once alive is either long gone or a husk of its "
"former self."
)
],
GO: [PrintAction("You head west."), TeleportAction("west_fork")],
USE: [PrintAction("You head west."), TeleportAction("west_fork")],
},
),
Item(
id="cabin_outside_door",
name="Cabin door",
room_desc=None,
synonyms=("door",),
triggers={
LOOK: [
PrintAction("A strong, sturdy door leading to the inside of the cabin.")
],
OPEN: [
CheckVarAction(
var_id="cabin_door_open",
yes=PrintAction("The cabin door is already open."),
no=[
PrintAction("You push the cabin door open."),
SetVarAction("cabin_door_open", True),
],
)
],
CLOSE: [
CheckVarAction(
var_id="cabin_door_open",
yes=[
PrintAction("You shut the cabin door tight."),
SetVarAction("cabin_door_open", False),
],
no=PrintAction("The cabin door is already shut."),
)
],
GO: [
PrintAction("You step inside the cabin."),
TeleportAction("cabin_inside"),
],
USE: [
PrintAction("You step inside the cabin."),
TeleportAction("cabin_inside"),
],
},
),
Item(
id="cabin_outside_inside",
name="Cabin",
room_desc=None,
synonyms=("inside", "inside cabin"),
triggers={
LOOK: [PrintAction("The cabin is small, but sturdy. A door leads inside.")],
GO: [
PrintAction("You step inside the cabin."),
TeleportAction("cabin_inside"),
],
},
),
)
database.add_rooms(
Room(
id="cabin_outside",
name="Outside the cabin",
desc=[],
items=[
# Fixtures
database.items["cabin_outside_mailbox"].create_inst(),
database.items["cabin_outside_west_path"].create_inst(),
database.items["cabin_outside_door"].create_inst(),
database.items["cabin_outside_inside"].create_inst(),
# Items
database.items["anjas_letter"].create_inst(revealed=False),
],
),
)
################################################################################
# Western fork
################################################################################
database.add_items(
Item(
id="west_fork_east_path",
name="Eastern path",
room_desc="There is a path that leads eastward. Your cabin lies in this direction.",
synonyms=create_path_synonyms("east"),
triggers={
GO: [
PrintAction("You head east."),
TeleportAction("cabin_outside"),
],
USE: [
PrintAction("You head east."),
TeleportAction("cabin_outside"),
],
},
),
Item(
id="west_fork_south_path",
name="Southern path",
room_desc="There is a path that leads southward. The mountains lie in this direction.",
synonyms=create_path_synonyms("south"),
),
Item(
id="west_fork_west_path",
name="Western path",
room_desc="There is a path that leads westward. A desolate wasteland lies in this direction.",
synonyms=create_path_synonyms("west"),
),
)
database.add_rooms(
Room(
id="west_fork",
name="West fork",
desc="A fork in the path.",
items=[
database.items["west_fork_east_path"].create_inst(),
database.items["west_fork_west_path"].create_inst(),
database.items["west_fork_south_path"].create_inst(),
database.items["ambiguous_path"].create_inst(),
],
)
)