square = Location( "Town square", "The old town square of the village. It is not much really, " "and narrow streets quickly lead away from the small fountain in the center." ) lane = Location( "Lane of Magicks", "A long straight road leading to the horizon. Apart from a nearby small tower, " "you can't see any houses or other landmarks. The road seems to go on forever though." ) Exit.connect(square, ["north", "lane"], "A long straight lane leads north towards the horizon.", None, lane, "south", "The town square lies to the south.", None) paper = newspaper.clone() paper.aliases = {"paper"} paper.short_description = "Last day's newspaper lies on the floor." # add a bulletin board to the town, with some initial messages board = bulletinboard.clone() board.storage_file = "boards/board.json" board.posts = [ { "author": "irmen", "date": "2015-05-23", "subject": "hello and welcome to this world", "text": "Hello all who read this! Welcome to this world."
from tale.items.basic import Money from tale.errors import ParseError, ActionRefused, StoryCompleted from tale.util import call_periodically, Context from tale import mud_context north_street = Location("Rose Street", "The northern part of Rose Street.") south_street = Location("Rose Street", "The southern part of Rose Street.") crossing = Location("Crossing", "Town Crossing.") crossing.add_exits([ Exit("west", "magnolia_st.street2", "Westwards lies Magnolia Street."), Exit("east", "magnolia_st.street3", "Magnolia Street extends to the east, eventually leading towards the factory."), ]) Exit.connect(crossing, "north", "A part of Rose Street lies to the north.", None, north_street, ["south", "crossing"], "The street goes south towards the crossing.", None) Exit.connect(crossing, "south", "Rose Street continues to the south.", None, south_street, ["north", "crossing"], "The crossing is back towards the north.", None) playground = Location("Playground", "Children's playground. You see a rusty merry-go-round, and a little swing. " "To the west, a house is visible.") playground.add_extradesc({"west", "house"}, "You can see your house from here!") playground.add_exits([ Door("fence", _limbo, "On the north end of the playground is a sturdy looking padlocked fence.", locked=True, opened=False, key_code="999999999"), # this door is never meant to be opened ]) Exit.connect(playground, ["east", "street"], "Rose Street is back east.", None, north_street, ["west", "playground"], "The children's playground is to the west.", None)
kitchen = Location( "Kitchen", "A small but well supplied kitchen. Rather than ordering take-away, " "you prefer cooking your own meals -- unlike most of the other people you know in town. " "A window lets you look outside.") kitchen.add_extradesc({ "window", "outside" }, "Through the kitchen window you can see your small garden and behind that, the children's playground." ) kitchen.init_inventory([Money("cash", 8.0, title="small amount of cash") ]) # not enough, player needs to find more Exit.connect( livingroom, "kitchen", "Your kitchen is adjacent to this room.", "You can see your kitchen. The previous house owners had a door there but you removed it.", kitchen, ["living room", "livingroom", "back"], "The living room is back the way you entered.", None) # ----------------- Neighbours House, Bedroom, Garden ------------------------- neighbors_house = Location("Neighbor's House", "The house of your neighbors across the street.") # exit to street is defined in the street zone module bedroom = Location( "Bedroom", "A rather untidy little bedroom. There's clothes lying all over the place. The window is open!" ) bedroom.add_extradesc({"clothes"}, "A pile of clothes lies on the floor.") bedroom.add_extradesc({
drone = Drone("drone", "n", race="bot", title="mindless drone", descr="A stupid metallic drone. It just hovers here with no apparent reason. It has a little label attached to it.") drone.add_extradesc({"label"}, "The label reads: \"Wall-E was my cousin\".") drone.aggressive = True hall.init_inventory([table, key, drone]) attic = Location("Tower attic", "The dark and dusty attic of the wizard tower. There are piles of old scrolls " "and assorted stuff here of which you assume it once held great magical power. " "All of it is now covered with a thick layer of dust.") attic.add_extradesc({"dust", "stuff", "scrolls"}, "The scrolls look ancient. One looks like a spell!") attic.add_extradesc({"spell"}, "The scroll looks like it contains a spell, but on closer inspection, " "it has become too faded to be understood anymore.") kitchen = Location("Tower kitchen", "A cozy little kitchen for hungry wizards. " "Magically conjured food often tastes like cardboard, so even wizards need to prepare " "their meals the old-fashioned way. The kitchen looks small but tidy.") Exit.connect(hall, ["up", "ladder"], "A small ladder leads up through a hole in the ceiling.", None, attic, ["down", "ladder"], "A small ladder leads back down to the hall.", None) Exit.connect(hall, ["north", "kitchen"], "A door to the north leads to the kitchen.", None, kitchen, ["south", "hall"], "A door to the south leads back to the hall.", None) hall.add_exits([ Exit(["door", "east"], "town.lane", "A heavy wooden door to the east blocks the noises from the street outside."), ])
# define the exits that connect the locations door = Door( ["garden", "door"], outside, "A door leads to the garden.", "There's a heavy door here that leads to the garden outside the house.", locked=True, opened=False, key_code="1" ) # oneway door, once outside you're finished, so no reason to go back in door.enter_msg = "You step through your garden door into the great unknown that is the outside." livingroom.add_exits([door]) Exit.connect(livingroom, "closet", "There's a small closet in your house.", "", closet, ["living room", "back"], "You can see the living room where you came from.", "") # define items and NPCs class Cat(Living): def init(self) -> None: self.aliases = {"cat"} @call_periodically(5, 20) def do_purr(self, ctx: Context) -> None: if random.random() > 0.7: self.location.tell("%s purrs happily." % capital(self.title)) else: self.location.tell("%s yawns sleepily." % capital(self.title))
"and assorted stuff here of which you assume it once held great magical power. " "All of it is now covered with a thick layer of dust.") attic.add_extradesc({"dust", "stuff", "scrolls"}, "The scrolls look ancient. One looks like a spell!") attic.add_extradesc( {"spell"}, "The scroll looks like it contains a spell, but on closer inspection, " "it has become too faded to be understood anymore.") kitchen = Location( "Tower kitchen", "A cozy little kitchen for hungry wizards. " "Magically conjured food often tastes like cardboard, so even wizards need to prepare " "their meals the old-fashioned way. The kitchen looks small but tidy.") Exit.connect(hall, ["up", "ladder"], "A small ladder leads up through a hole in the ceiling.", None, attic, ["down", "ladder"], "A small ladder leads back down to the hall.", None) Exit.connect(hall, ["north", "kitchen"], "A door to the north leads to the kitchen.", None, kitchen, ["south", "hall"], "A door to the south leads back to the hall.", None) hall.add_exits([ Exit( ["door", "east"], "town.lane", "A heavy wooden door to the east blocks the noises from the street outside." ), ])
# player has entered, and thus the story ends player.tell("\n") player.tell("\n") player.tell("<bright>Congratulations on escaping the house!</> Someone else has to look after the parakeet now though...") raise StoryCompleted # Rooms livingroom = Location("Living room", "The living room in your home in the outskirts of the city.") bedroom = Location("Bed room", "A small bedroom with a single bed an a T.V in the corner.") closet = Location("Closet", "A small room.") # outside = Location("Outside", "Outside is Lake drive.") # define the exits that connect the locations Exit.connect(livingroom, "closet", "There's a small closet in your house.", None, closet, ["living room", "back"], "You can see the living room where you came from.", None) Exit.connect(livingroom, "bedroom", "There is a bedroom to your left", None, bedroom, ["living room", "back"], "The living room is where you came from", None) # define items and NPCs class Bird(Living): def init(self) -> None: self.aliases = {"bird"} @call_periodically(1, 50) def do_birdaction(self, ctx: Context) -> None: if random.random() > 0.7: self.location.tell("%s chirps." % capital(self.title)) else:
livingroom = Location("Living room", "The living room in your home in the outskirts of the city.") closet = Location("Closet", "A small room.") outside = GameEnd("Outside", "It is beautiful weather outside.") # define the exits that connect the locations door = Door( ["garden", "door"], outside, "A door leads to the garden.", "There's a heavy door here that leads to the garden outside the house.", locked=True, opened=False, key_code="1") # oneway door, once outside you're finished, so no reason to go back in livingroom.add_exits([door]) Exit.connect(livingroom, "closet", "There's a small closet in your house.", None, closet, ["living room", "back"], "You can see the living room where you came from.", None) # define items and NPCs class Cat(Living): def init(self) -> None: self.aliases = {"cat"} @call_periodically(5, 20) def do_purr(self, ctx: Context) -> None: if random.random() > 0.7: self.location.tell("%s purrs happily." % capital(self.title)) else: self.location.tell("%s yawns sleepily." % capital(self.title)) # it's possible to stop the periodical calling by setting: call_periodically(0)(Cat.do_purr)
"The rest of the town lies eastwards.") street2 = Location("Magnolia Street", "Another part of the street.") street3 = Location("Magnolia Street (east)", "The eastern part of Magnolia Street.") Door.connect(houses.livingroom, ["door", "outside", "street"], "Your front door leads outside, to the street.", "There's a heavy front door here that leads to the streets outside.", street1, ["house", "north", "inside"], "You can go back inside your house.", "It's your house, on the north side of the street.") pharmacy = Location("Pharmacy", "A pharmacy. It is completely empty, all medicine seems gone.") Exit.connect(pharmacy, ["east", "outside", "street"], "Magnolia street is outside towards the east.", None, street1, ["pharmacy", "west"], "The west end of the street leads to the pharmacy.", None) class Factory(Location): @call_periodically(30, 60) def spawn_wanderer(self, ctx: Context) -> None: w = Wanderer("blankly staring person", random.choice("mf"), descr="A person staring blankly somewhere.") w.aliases = {"person", "staring person"} w.move(self) factory = Factory("ArtiGrow factory", "This area is the ArtiGrow fertilizer factory.") Exit.connect(factory, ["west", "street"], "You can leave the factory to the west, back to Magnolia Street.", None, street3, ["factory", "east"], "Eastwards you'll enter the ArtiGrow factory area.", None)
lot = Location("Parking Lot", "A small parking lot with a few cars parked in it.") Door.connect( house.livingroom, ["door", "outside", "street"], "Your front door leads outside, to the street.\n", "There's a heavy front door here that leads to the streets outside.", street1, ["house", "door", "inside"], "You can go back inside your house.", "It's your house, on the north side of the street.") deli = Location( "Deli", "A deli. It is completely empty, all the food and items seem to be gone.") Exit.connect(deli, ["lake drive", "outside", "street", "back"], "Lake drive is the street you came from.", None, street1, ["deli", "east"], "The east end of the street leads to a deli.", None) Exit.connect(lot, ["back"], "Go back home.", None, street1, ["lot", "parking"], "There is a parking lot next to the deli.", None) zombie = w = Zombie("zombie", random.choice("mf"), descr="A bloody zombie lingering around.") street1.insert(zombie, None) trader = Trader("Creepy Trader", "m", title="Creepy Trader") trader.extra_desc[ "bullets"] = "It is a a box of rounds with 5 bullets in it for your gun." trader.extra_desc["ammo"] = trader.extra_desc["bullets"] trader.aliases.add("trader")
from tale.player import Player def init(driver: Driver) -> None: # called when zone is first loaded board.load() board.save() # make sure the storage file exists square = Location("Town square", "The old town square of the village. It is not much really, " "and narrow streets quickly lead away from the small fountain in the center.") lane = Location("Lane of Magicks", "A long straight road leading to the horizon. Apart from a nearby small tower, " "you can't see any houses or other landmarks. The road seems to go on forever though.") Exit.connect(square, ["north", "lane"], "A long straight lane leads north towards the horizon.", None, lane, "south", "The town square lies to the south.", None) paper = newspaper.clone() paper.aliases = {"paper"} paper.short_description = "Last day's newspaper lies on the floor." # add a bulletin board to the town, with some initial messages board = bulletinboard.clone() board.storage_file = "boards/board.json" board.posts = [ { "author": "irmen", "date": "2015-05-23", "subject": "hello and welcome to this world", "text": "Hello all who read this! Welcome to this world." },
street3 = Location("Magnolia Street (east)", "The eastern part of Magnolia Street.") Door.connect( houses.livingroom, ["door", "outside", "street"], "Your front door leads outside, to the street.", "There's a heavy front door here that leads to the streets outside.", street1, ["house", "north", "inside"], "You can go back inside your house.", "It's your house, on the north side of the street.") pharmacy = Location( "Pharmacy", "A pharmacy. It is completely empty, all medicine seems gone.") Exit.connect(pharmacy, ["east", "outside", "street"], "Magnolia street is outside towards the east.", None, street1, ["pharmacy", "west"], "The west end of the street leads to the pharmacy.", None) class Factory(Location): @call_periodically(30, 60) def spawn_wanderer(self, ctx: Context) -> None: w = Wanderer("blankly staring person", random.choice("mf"), descr="A person staring blankly somewhere.") w.aliases = {"person", "staring person"} w.move(self) factory = Factory("ArtiGrow factory", "This area is the ArtiGrow fertilizer factory.")