Exemplo n.º 1
0
 def test_socialize(self):
     player = Player("fritz", "m")
     attic = Location("Attic", "A dark attic.")
     julie = NPC("julie", "f")
     julie.move(attic)
     player.move(attic)
     parsed = player.parse("wave all")
     self.assertEqual("wave", parsed.verb)
     self.assertEqual([julie], parsed.who_order)
     who, playermsg, roommsg, targetmsg = player.soul.process_verb_parsed(
         player, parsed)
     self.assertEqual({julie}, who)
     self.assertEqual("You wave happily at julie.", playermsg)
     with self.assertRaises(tale.soul.UnknownVerbException):
         player.parse("befrotzificate all and me")
     with self.assertRaises(NonSoulVerb) as x:
         player.parse("befrotzificate all and me",
                      external_verbs={"befrotzificate"})
     parsed = x.exception.parsed
     self.assertEqual("befrotzificate", parsed.verb)
     self.assertEqual([julie, player], parsed.who_order)
     attic.add_exits([Exit("south", "target", "door")])
     try:
         player.parse("push south")
         self.fail(
             "push south should throw a parse error because of the exit that is used"
         )
     except ParseError:
         pass
     with self.assertRaises(NonSoulVerb):
         player.parse("fart south")
     parsed = player.parse("hug julie")
     player.validate_socialize_targets(parsed)
Exemplo n.º 2
0
 def test_socialize(self):
     player = Player("fritz", "m")
     attic = Location("Attic", "A dark attic.")
     julie = NPC("julie", "f")
     julie.move(attic)
     player.move(attic)
     parsed = player.parse("wave all")
     self.assertEqual("wave", parsed.verb)
     self.assertEqual([julie], parsed.who_order)
     who, playermsg, roommsg, targetmsg = player.soul.process_verb_parsed(player, parsed)
     self.assertEqual({julie}, who)
     self.assertEqual("You wave happily at julie.", playermsg)
     with self.assertRaises(tale.soul.UnknownVerbException):
         player.parse("befrotzificate all and me")
     with self.assertRaises(NonSoulVerb) as x:
         player.parse("befrotzificate all and me", external_verbs={"befrotzificate"})
     parsed = x.exception.parsed
     self.assertEqual("befrotzificate", parsed.verb)
     self.assertEqual([julie, player], parsed.who_order)
     attic.add_exits([Exit("south", "target", "door")])
     try:
         player.parse("push south")
         self.fail("push south should throw a parse error because of the exit that is used")
     except ParseError:
         pass
     with self.assertRaises(NonSoulVerb):
         player.parse("fart south")
     parsed = player.parse("hug julie")
     player.validate_socialize_targets(parsed)
Exemplo n.º 3
0
 def test_custom_verbs(self):
     player = Player("julie", "f")
     player.verbs["xywobble"] = "p1"
     monster = NPC("snake", "f")
     monster.verbs["snakeverb"] = "s1"
     room = Location("room")
     chair1 = Item("chair1")
     chair1.verbs["frobnitz"] = "c1"
     chair2 = Item("chair2")
     chair2.verbs["frobnitz"] = "c2"
     chair_in_inventory = Item("chair3")
     chair_in_inventory.verbs["kowabooga"] = "c3"
     box_in_inventory = Item("box")
     box_in_inventory.verbs["boxverb"] = "c4"
     player.init_inventory([box_in_inventory, chair_in_inventory])
     exit = Exit("e", "dummy", None, None)
     exit.verbs["exitverb"] = "c5"
     room.init_inventory([chair1, player, chair2, monster])
     room.add_exits([exit])
     custom_verbs = mud_context.driver.current_custom_verbs(player)
     all_verbs = mud_context.driver.current_verbs(player)
     self.assertEqual(
         {
             "xywobble", "snakeverb", "frobnitz", "kowabooga", "boxverb",
             "exitverb"
         }, set(custom_verbs))
     self.assertEqual(set(), set(custom_verbs) - set(all_verbs))
Exemplo n.º 4
0
    def test_door_pair(self):
        loc1 = Location("room1", "room one")
        loc2 = Location("room2", "room two")
        key = Key("key")
        door_one_two = Door("two", loc2, "door to room two", locked=True, opened=False)
        door_two_one = door_one_two.reverse_door("one", loc1, "door to room one", reverse_open_msg="door one open", reverse_close_msg="door one close",
                                                 this_open_msg="door two open", this_close_msg="door two close")
        loc1.add_exits([door_one_two])
        loc2.add_exits([door_two_one])
        door_one_two.key_code = 555
        key.key_for(door_one_two)
        pubsub1 = PubsubCollector()
        pubsub2 = PubsubCollector()
        loc1.get_wiretap().subscribe(pubsub1)
        loc2.get_wiretap().subscribe(pubsub2)
        self.assertTrue(door_two_one.locked)
        self.assertFalse(door_two_one.opened)
        lucy = Living("lucy", "f")

        door_two_one.unlock(lucy, item=key)
        self.assertFalse(door_one_two.locked)
        door_two_one.open(lucy)
        self.assertTrue(door_one_two.opened)
        pubsub.sync()
        self.assertEqual(["door one open"], pubsub1.messages)
        self.assertEqual([], pubsub2.messages)
        door_one_two.close(lucy)
        door_one_two.lock(lucy, item=key)
        self.assertTrue(door_two_one.locked)
        self.assertFalse(door_two_one.opened)
        pubsub1.clear()
        pubsub2.clear()
        pubsub.sync()
        self.assertEqual([], pubsub1.messages)
        self.assertEqual(["door two close"], pubsub2.messages)
Exemplo n.º 5
0
 def test_exits(self):
     hall = Location("hall")
     attic = Location("attic")
     exit1 = Exit("ladder1", attic, "The first ladder leads to the attic.")
     exit2 = Exit("up", attic, "Second ladder to attic.")
     exit3 = Exit("ladder3", attic, "Third ladder to attic.")
     exit4 = Exit("window", attic, "A window.",
                  "A window, maybe if you open it you can get out?")
     hall.add_exits([exit1, exit2, exit3, exit4])
     self.assertTrue(hall.exits["up"] is exit2)
     self.assertTrue(hall.exits["ladder3"] is exit3)
     self.assertTrue(hall.exits["window"] is exit4)
     self.assertEqual([
         '[hall]',
         'The first ladder leads to the attic. Third ladder to attic. Second ladder to attic. A window.'
     ], strip_text_styles(hall.look()))
     self.assertEqual("Third ladder to attic.", exit3.description)
     self.assertEqual("A window, maybe if you open it you can get out?",
                      exit4.description)
     with self.assertRaises(ActionRefused):
         exit1.activate(None)
     with self.assertRaises(ActionRefused):
         exit1.deactivate(None)
     with self.assertRaises(ActionRefused):
         exit1.close(None, None)
     with self.assertRaises(ActionRefused):
         exit1.open(None, None)
     with self.assertRaises(ActionRefused):
         exit1.lock(None, None)
     with self.assertRaises(ActionRefused):
         exit1.unlock(None, None)
     with self.assertRaises(ActionRefused):
         exit1.manipulate("frobnitz", None)
     with self.assertRaises(ActionRefused):
         exit1.read(None)
Exemplo n.º 6
0
 def test_exits(self):
     hall = Location("hall")
     attic = Location("attic")
     exit1 = Exit("ladder1", attic, "The first ladder leads to the attic.")
     exit2 = Exit("up", attic, "Second ladder to attic.")
     exit3 = Exit("ladder3", attic, "Third ladder to attic.")
     exit4 = Exit("window", attic, "A window.", "A window, maybe if you open it you can get out?")
     hall.add_exits([exit1, exit2, exit3, exit4])
     self.assertTrue(hall.exits["up"] is exit2)
     self.assertTrue(hall.exits["ladder3"] is exit3)
     self.assertTrue(hall.exits["window"] is exit4)
     self.assertEqual(['[hall]', 'The first ladder leads to the attic. Third ladder to attic. Second ladder to attic. A window.'], strip_text_styles(hall.look()))
     self.assertEqual("Third ladder to attic.", exit3.description)
     self.assertEqual("A window, maybe if you open it you can get out?", exit4.description)
     with self.assertRaises(ActionRefused):
         exit1.activate(None)
     with self.assertRaises(ActionRefused):
         exit1.deactivate(None)
     with self.assertRaises(ActionRefused):
         exit1.close(None, None)
     with self.assertRaises(ActionRefused):
         exit1.open(None, None)
     with self.assertRaises(ActionRefused):
         exit1.lock(None, None)
     with self.assertRaises(ActionRefused):
         exit1.unlock(None, None)
     with self.assertRaises(ActionRefused):
         exit1.manipulate("frobnitz", None)
     with self.assertRaises(ActionRefused):
         exit1.read(None)
Exemplo n.º 7
0
 def test_aliases(self):
     loc = Location("hall", "empty hall")
     exit = Exit("up", "attic", "ladder to attic")
     door = Door("door", "street", "door to street")
     exit2 = Exit(["down", "hatch", "manhole"], "underground", "hatch to underground")
     door2 = Door(["east", "garden"], "garden", "door east to garden")
     self.assertEqual("up", exit.name)
     self.assertEqual("door", door.name)
     loc.add_exits([exit, door, exit2, door2])
     self.assertEqual({"up", "door", "down", "hatch", "manhole", "east", "garden"}, set(loc.exits.keys()))
     self.assertEqual(loc.exits["down"], loc.exits["hatch"])
Exemplo n.º 8
0
 def test_message_nearby_location(self):
     plaza = Location("plaza")
     road = Location("road")
     house = Location("house")
     attic = Location("attic")
     plaza.add_exits([Exit("north", road, "road leads north"), Exit("door", house, "door to a house")])
     road.add_exits([Exit("south", plaza, "plaza to the south")])
     house.add_exits([Exit("door", plaza, "door to the plaza"), Exit("ladder", attic, "dusty attic")])
     attic.add_exits([Exit("ladder", house, "the house")])
     wiretap_plaza = Wiretap(plaza)
     wiretap_road = Wiretap(road)
     wiretap_house = Wiretap(house)
     wiretap_attic = Wiretap(attic)
     util.message_nearby_locations(plaza, "boing")
     pubsub.sync()
     self.assertEqual([], wiretap_plaza.msgs, "the plaza doesnt receive tells")
     self.assertEqual([], wiretap_attic.msgs, "the attic is too far away to receive msgs")
     self.assertTrue(("road", "boing") in wiretap_road.msgs)
     self.assertTrue(
         ("road", "The sound is coming from the south.") in wiretap_road.msgs, "road should give sound direction"
     )
     self.assertTrue(("house", "boing") in wiretap_house.msgs)
     self.assertTrue(
         ("house", "You can't hear where the sound is coming from.") in wiretap_house.msgs,
         "in the house you can't locate the sound direction",
     )
Exemplo n.º 9
0
 def test_message_nearby_location(self):
     plaza = Location("plaza")
     road = Location("road")
     house = Location("house")
     attic = Location("attic")
     plaza.add_exits([
         Exit("north", road, "road leads north"),
         Exit("door", house, "door to a house")
     ])
     road.add_exits([Exit("south", plaza, "plaza to the south")])
     house.add_exits([
         Exit("door", plaza, "door to the plaza"),
         Exit("ladder", attic, "dusty attic")
     ])
     attic.add_exits([Exit("ladder", house, "the house")])
     wiretap_plaza = Wiretap(plaza)
     wiretap_road = Wiretap(road)
     wiretap_house = Wiretap(house)
     wiretap_attic = Wiretap(attic)
     plaza.message_nearby_locations("boing")
     pubsub.sync()
     self.assertEqual([], wiretap_plaza.msgs,
                      "the plaza doesnt receive tells")
     self.assertEqual([], wiretap_attic.msgs,
                      "the attic is too far away to receive msgs")
     self.assertTrue(("road", "boing") in wiretap_road.msgs)
     self.assertTrue(("road", "The sound is coming from the south.")
                     in wiretap_road.msgs,
                     "road should give sound direction")
     self.assertTrue(("house", "boing") in wiretap_house.msgs)
     self.assertTrue(
         ("house", "You can't hear where the sound is coming from.")
         in wiretap_house.msgs,
         "in the house you can't locate the sound direction")
Exemplo n.º 10
0
 def test_aliases(self):
     loc = Location("hall", "empty hall")
     exit = Exit("up", "attic", "ladder to attic")
     door = Door("door", "street", "door to street")
     exit2 = Exit(["down", "hatch", "manhole"], "underground",
                  "hatch to underground")
     door2 = Door(["east", "garden"], "garden", "door east to garden")
     self.assertEqual("up", exit.name)
     self.assertEqual("door", door.name)
     loc.add_exits([exit, door, exit2, door2])
     self.assertEqual(
         {"up", "door", "down", "hatch", "manhole", "east", "garden"},
         set(loc.exits.keys()))
     self.assertEqual(loc.exits["down"], loc.exits["hatch"])
Exemplo n.º 11
0
    def test_door_pair(self):
        loc1 = Location("room1", "room one")
        loc2 = Location("room2", "room two")
        key = Key("key")
        door_one_two = Door("two",
                            loc2,
                            "door to room two",
                            locked=True,
                            opened=False)
        door_two_one = door_one_two.reverse_door(
            "one",
            loc1,
            "door to room one",
            reverse_open_msg="door one open",
            reverse_close_msg="door one close",
            this_open_msg="door two open",
            this_close_msg="door two close")
        loc1.add_exits([door_one_two])
        loc2.add_exits([door_two_one])
        door_one_two.key_code = 555
        key.key_for(door_one_two)
        pubsub1 = PubsubCollector()
        pubsub2 = PubsubCollector()
        loc1.get_wiretap().subscribe(pubsub1)
        loc2.get_wiretap().subscribe(pubsub2)
        self.assertTrue(door_two_one.locked)
        self.assertFalse(door_two_one.opened)
        lucy = Living("lucy", "f")

        door_two_one.unlock(lucy, item=key)
        self.assertFalse(door_one_two.locked)
        door_two_one.open(lucy)
        self.assertTrue(door_one_two.opened)
        pubsub.sync()
        self.assertEqual(["door one open"], pubsub1.messages)
        self.assertEqual([], pubsub2.messages)
        door_one_two.close(lucy)
        door_one_two.lock(lucy, item=key)
        self.assertTrue(door_two_one.locked)
        self.assertFalse(door_two_one.opened)
        pubsub1.clear()
        pubsub2.clear()
        pubsub.sync()
        self.assertEqual([], pubsub1.messages)
        self.assertEqual(["door two close"], pubsub2.messages)
Exemplo n.º 12
0
 def test_destroy_loc(self):
     ctx = Context(None, None, None, None)
     loc = Location("loc")
     i = Item("item")
     liv = Living("rat", "n", race="rodent")
     loc.add_exits([Exit("north", "somewhere", "exit to somewhere")])
     player = Player("julie", "f")
     player.privileges = {"wizard"}
     player.create_wiretap(loc)
     loc.init_inventory([i, liv, player])
     self.assertTrue(len(loc.exits) > 0)
     self.assertTrue(len(loc.items) > 0)
     self.assertTrue(len(loc.livings) > 0)
     self.assertEqual(loc, player.location)
     self.assertEqual(loc, liv.location)
     loc.destroy(ctx)
     self.assertTrue(len(loc.exits) == 0)
     self.assertTrue(len(loc.items) == 0)
     self.assertTrue(len(loc.livings) == 0)
     self.assertEqual(_limbo, player.location)
     self.assertEqual(_limbo, liv.location)
Exemplo n.º 13
0
 def test_destroy_loc(self):
     ctx = Context()
     loc = Location("loc")
     i = Item("item")
     liv = Living("rat", "n", race="rodent")
     loc.add_exits([Exit("north", "somewhere", "exit to somewhere")])
     player = Player("julie", "f")
     player.privileges = {"wizard"}
     player.create_wiretap(loc)
     loc.init_inventory([i, liv, player])
     self.assertTrue(len(loc.exits) > 0)
     self.assertTrue(len(loc.items) > 0)
     self.assertTrue(len(loc.livings) > 0)
     self.assertEqual(loc, player.location)
     self.assertEqual(loc, liv.location)
     loc.destroy(ctx)
     self.assertTrue(len(loc.exits) == 0)
     self.assertTrue(len(loc.items) == 0)
     self.assertTrue(len(loc.livings) == 0)
     self.assertEqual(_Limbo, player.location)
     self.assertEqual(_Limbo, liv.location)
Exemplo n.º 14
0
 def test_nearby(self):
     plaza = Location("plaza")
     road = Location("road")
     house = Location("house")
     alley = Location("alley")  # no exits
     attic = Location("attic")
     plaza.add_exits([Exit("north", road, "road leads north"), Exit("door", house, "door to a house"),
                      Exit("west", alley, "small alleywith no way back")])
     road.add_exits([Exit("south", plaza, "plaza to the south")])
     house.add_exits([Exit("door", plaza, "door to the plaza"), Exit("ladder", attic, "dusty attic")])
     attic.add_exits([Exit("ladder", house, "the house")])
     adj = set(plaza.nearby())
     self.assertSetEqual({road, house}, adj)
     adj = set(plaza.nearby(no_traps=False))
     self.assertSetEqual({road, house, alley}, adj)
Exemplo n.º 15
0
 def test_custom_verbs(self):
     player = Player("julie", "f")
     player.verbs["xywobble"] = "p1"
     monster = NPC("snake", "f")
     monster.verbs["snakeverb"] = "s1"
     room = Location("room")
     chair1 = Item("chair1")
     chair1.verbs["frobnitz"] = "c1"
     chair2 = Item("chair2")
     chair2.verbs["frobnitz"] = "c2"
     chair_in_inventory = Item("chair3")
     chair_in_inventory.verbs["kowabooga"] = "c3"
     box_in_inventory = Item("box")
     box_in_inventory.verbs["boxverb"] = "c4"
     player.init_inventory([box_in_inventory, chair_in_inventory])
     exit = Exit("e", "dummy", None, None)
     exit.verbs["exitverb"] = "c5"
     room.init_inventory([chair1, player, chair2, monster])
     room.add_exits([exit])
     custom_verbs = mud_context.driver.current_custom_verbs(player)
     all_verbs = mud_context.driver.current_verbs(player)
     self.assertEqual({"xywobble", "snakeverb", "frobnitz", "kowabooga", "boxverb", "exitverb"}, set(custom_verbs))
     self.assertEqual(set(), set(custom_verbs) - set(all_verbs))
Exemplo n.º 16
0
 def test_nearby(self):
     plaza = Location("plaza")
     road = Location("road")
     house = Location("house")
     alley = Location("alley")  # no exits
     attic = Location("attic")
     plaza.add_exits([
         Exit("north", road, "road leads north"),
         Exit("door", house, "door to a house"),
         Exit("west", alley, "small alleywith no way back")
     ])
     road.add_exits([Exit("south", plaza, "plaza to the south")])
     house.add_exits([
         Exit("door", plaza, "door to the plaza"),
         Exit("ladder", attic, "dusty attic")
     ])
     attic.add_exits([Exit("ladder", house, "the house")])
     adj = set(plaza.nearby())
     self.assertSetEqual({road, house}, adj)
     adj = set(plaza.nearby(no_traps=False))
     self.assertSetEqual({road, house, alley}, adj)
Exemplo n.º 17
0
import zones.houses
import zones.npcs

from tale.base import Location, Exit, Door, Key, Living, ParseResult, _limbo
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
])
Exemplo n.º 18
0
    "Neighbor's Garden", "The garden of your neighbor across the street. "
    "Behind some trees to the south you see what appears to be a storage building of a shop."
)
garden.add_extradesc({"ladder"}, "It leads up towards a window.")
garden.add_extradesc({
    "trees", "south", "building"
}, "The building behind the trees could very well be the meat storage room of the butcher shop in town."
                     )

Exit.connect(
    garden, ["ladder", "up"],
    "A ladder leads up towards a window in the house.", None, bedroom,
    ["ladder", "down"],
    "The ladder that is placed outside of the window provides access down to the garden below.",
    None)

Exit.connect(garden, ["house", "doors"],
             "The garden doors are open and lead back to the house.", None,
             neighbors_house, ["garden", "doors"],
             "The garden doors are open and lead to... the garden.", None)

Exit.connect(neighbors_house, ["up", "stairs"],
             "Up the stairs is the bedroom.", None, bedroom, "stairs",
             "Stairs lead back to the rest of the house.", None)

# oneway route to get back on the street from the garden:
garden.add_exits([
    Exit(["fence", "street"], "magnolia_st.street2",
         "You can step over a low fence back onto the street if you wish."),
])
Exemplo n.º 19
0
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
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:
Exemplo n.º 20
0

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."),
])
Exemplo n.º 21
0
        # but for the game ending, we require an immediate response.
        # So instead we hook into the direct arrival of something in this location.
        super(GameEnd, self).insert(obj, actor)
        try:
            obj.story_completed()   # player arrived! Great Success!
        except AttributeError:
            pass


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("north", north_street, "A part of Rose Street lies to the north."),
    Exit("south", south_street, "Rose Street continues to the south.")
])

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),  # this door is never meant to be opened
    Exit(["east", "street"], north_street, "Rose Street is back east."),
    zones.magnolia_st.street_gate
])

carpark = Location("Car Parking", "There are a few cars still parked over here. Their owners are nowhere to be seen. "
                                  "One yellow car grabs your attention.")
carpark.add_extradesc({"cars"}, "They look abandoned, but their doors are all locked.")
Exemplo n.º 22
0
#                 raise ActionRefused("You could try to unlock the door with it instead.")
#             else:
#                 raise ActionRefused("You could try to lock the door with it instead.")
#         raise ActionRefused("The %s doesn't fit." % item.title)


go_north = Hazard(
    directions=["north", "n"], target_location=north_hallway, short_description="The hallway continues to the north."
)

south_hallway.add_exits(
    [
        go_north,
        Exit(
            ["south", "s"],
            "athletics.gym",
            "The gymnasium is to the south.",
            "A door to the south of you opens into the Parsely High gymnasium.",
        ),
        Exit(["east", "e"], nurses_office, "The school nurse's office is to the east."),
    ]
)

room112 = Door(
    ["room 112", "door 112", "english class", "east", "e"],
    "classrooms.english",
    short_description="To the east is the door leading to your English class.",
    long_description="To the east is the door leading to your English Class. You see Mr. Bushel giving a lecture on last night's homework. Oops.",
    locked=False,
    opened=True,
)
Exemplo n.º 23
0
garden_door = Door(
    directions=["garden", "door"],
    target_location="house.outside",
    short_descr="A door leads to the garden.",
    long_descr=
    "There's a heavy door here that leads to the garden outside the house.",
    locked=True,
    opened=False,
    key_code="1")

lr_closet = Exit(directions="closet",
                 target_location="house.closet",
                 short_descr="There is a small closet in your house.",
                 long_descr=None)

livingroom.add_exits([garden_door, lr_closet])

# Insert items & npcs
livingroom.insert(cat, None)
livingroom.insert(elastic_band.clone(), None)

##### Closet #####
closet = Location("Closet", "A small room.")

closet_lr = Exit(
    directions=["living room", "back", "livingroom"],
    target_location="house.livingroom",
    short_descr="You can see the living room where you came from.",
    long_descr=None)

closet.add_exits([closet_lr])
Exemplo n.º 24
0
    "magnolia_st.street1",
    "Your front door leads outside, to the street.",
    "There's a heavy front door here that leads to the streets outside.",
    opened=False)
house_door = front_door.reverse_door(
    ["house", "north", "inside"],
    livingroom,
    "You can go back inside your house.",
    "It's your house, on the north side of the street.",
    reverse_open_msg="Someone outside opens the door.",
    reverse_close_msg="Someone outside closes the door.",
    this_open_msg="Someone in the house opens the door.",
    this_close_msg="Someone in the house closes the door.")
livingroom.add_exits([
    Exit(
        "kitchen", 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."
    ), front_door
])

kitchen.add_exits([
    Exit(["living room", "livingroom", "back"], livingroom,
         "The living room is back the way you entered.")
])

# ----------------- Neighbours House, Bedroom, Garden  -------------------------

neighbors_house = Location("Neighbor's House",
                           "The house of your neighbors across the street.")

bedroom = Location(
    "Bedroom",
Exemplo n.º 25
0

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)
door.door_code = 1
closet_exit = Exit("closet", closet, "There's a small closet in your house.")
livingroom.add_exits([door, closet_exit])
closet.add_exits([Exit("living room", livingroom, "You can see the living room.")])


# define items and NPCs

class Cat(NPC):
    def init(self):
        self.aliases={"cat"}
        mud_context.driver.defer(4, self, self.do_purr)

    def do_purr(self, driver):
        if random.random() > 0.5:
            self.location.tell("%s purrs happily." % capital(self.title))
        else:
            self.location.tell("%s yawns sleepily." % capital(self.title))
Exemplo n.º 26
0
class TestLocations(unittest.TestCase):
    def setUp(self):
        mud_context.driver = DummyDriver()
        self.hall = Location("Main hall", "A very large hall.")
        self.attic = Location("Attic", "A dark attic.")
        self.street = Location("Street", "An endless street.")
        e1 = Exit("up", self.attic, "A ladder leads up.")
        e2 = Exit(["door", "east"], self.street, "A heavy wooden door to the east blocks the noises from the street outside.")
        self.hall.add_exits([e1, e2])
        self.table = Item("table", "oak table", "a large dark table with a lot of cracks in its surface")
        self.key = Item("key", "rusty key", "an old rusty key without a label", short_description="Someone forgot a key.")
        self.magazine = Item("magazine", "university magazine")
        self.rat = NPC("rat", "n", race="rodent")
        self.fly = NPC("fly", "n", race="insect", short_description="A fly buzzes around your head.")
        self.julie = NPC("julie", "f", title="attractive Julie", description="She's quite the looker.")
        self.julie.aliases = {"chick"}
        self.player = Player("player", "m")
        self.pencil = Item("pencil", title="fountain pen")
        self.pencil.aliases = {"pen"}
        self.bag = Container("bag")
        self.notebook_in_bag = Item("notebook")
        self.bag.insert(self.notebook_in_bag, self.player)
        self.player.insert(self.pencil, self.player)
        self.player.insert(self.bag, self.player)
        self.hall.init_inventory([self.table, self.key, self.magazine, self.rat, self.julie, self.player, self.fly])

    def test_names(self):
        loc = Location("The Attic", "A dusty attic.")
        self.assertEqual("The Attic", loc.name)
        self.assertEqual("A dusty attic.", loc.description)

    def test_contains(self):
        self.assertTrue(self.julie in self.hall)
        self.assertTrue(self.magazine in self.hall)
        self.assertFalse(self.pencil in self.hall)
        self.assertFalse(self.magazine in self.attic)
        self.assertFalse(self.julie in self.attic)

    def test_look(self):
        expected = ["[Main hall]", "A very large hall.",
                    "A heavy wooden door to the east blocks the noises from the street outside. A ladder leads up.",
                    "Someone forgot a key. You see a university magazine and an oak table. Player, attractive Julie, and rat are here. A fly buzzes around your head."]
        self.assertEqual(expected, strip_text_styles(self.hall.look()))
        expected = ["[Main hall]", "A very large hall.",
                    "A heavy wooden door to the east blocks the noises from the street outside. A ladder leads up.",
                    "Someone forgot a key. You see a university magazine and an oak table. Attractive Julie and rat are here. A fly buzzes around your head."]
        self.assertEqual(expected, strip_text_styles(self.hall.look(exclude_living=self.player)))
        expected = ["[Attic]", "A dark attic."]
        self.assertEqual(expected, strip_text_styles(self.attic.look()))

    def test_look_short(self):
        expected = ["[Attic]"]
        self.assertEqual(expected, strip_text_styles(self.attic.look(short=True)))
        expected = ["[Main hall]", "Exits: door, east, up", "You see: key, magazine, table", "Present: fly, julie, player, rat"]
        self.assertEqual(expected, strip_text_styles(self.hall.look(short=True)))
        expected = ["[Main hall]", "Exits: door, east, up", "You see: key, magazine, table", "Present: fly, julie, rat"]
        self.assertEqual(expected, strip_text_styles(self.hall.look(exclude_living=self.player, short=True)))

    def test_search_living(self):
        self.assertEqual(None, self.hall.search_living("<notexisting>"))
        self.assertEqual(None, self.attic.search_living("<notexisting>"))
        self.assertEqual(self.rat, self.hall.search_living("rat"))
        self.assertEqual(self.julie, self.hall.search_living("Julie"))
        self.assertEqual(self.julie, self.hall.search_living("attractive julie"))
        self.assertEqual(self.julie, self.hall.search_living("chick"))
        self.assertEqual(None, self.hall.search_living("bloke"))

    def test_search_item(self):
        # almost identical to locate_item so only do a few basic tests
        self.assertEqual(None, self.player.search_item("<notexisting>"))
        self.assertEqual(self.pencil, self.player.search_item("pencil"))

    def test_locate_item(self):
        item, container = self.player.locate_item("<notexisting>")
        self.assertEqual(None, item)
        self.assertEqual(None, container)
        item, container = self.player.locate_item("pencil")
        self.assertEqual(self.pencil, item)
        self.assertEqual(self.player, container)
        item, container = self.player.locate_item("fountain pen")
        self.assertEqual(self.pencil, item, "need to find the title")
        item, container = self.player.locate_item("pen")
        self.assertEqual(self.pencil, item, "need to find the alias")
        item, container = self.player.locate_item("pencil", include_inventory=False)
        self.assertEqual(None, item)
        self.assertEqual(None, container)
        item, container = self.player.locate_item("key")
        self.assertEqual(self.key, item)
        self.assertEqual(self.hall, container)
        item, container = self.player.locate_item("key", include_location=False)
        self.assertEqual(None, item)
        self.assertEqual(None, container)
        item, container = self.player.locate_item("KEY")
        self.assertEqual(self.key, item, "should work case-insensitive")
        self.assertEqual(self.hall, container, "should work case-insensitive")
        item, container = self.player.locate_item("notebook")
        self.assertEqual(self.notebook_in_bag, item)
        self.assertEqual(self.bag, container, "should search in bags in inventory")
        item, container = self.player.locate_item("notebook", include_containers_in_inventory=False)
        self.assertEqual(None, item)
        self.assertEqual(None, container, "should not search in bags in inventory")

    def test_tell(self):
        rat = MsgTraceNPC("rat", "n", "rodent")
        self.assertTrue(rat._init_called, "init() must be called from __init__")
        julie = MsgTraceNPC("julie", "f", "human")
        hall = Location("hall")
        hall.livings = [rat, julie]
        hall.tell("roommsg")
        self.assertEqual(["roommsg"], rat.messages)
        self.assertEqual(["roommsg"], julie.messages)
        rat.clearmessages()
        julie.clearmessages()
        hall.tell("roommsg", rat, [julie], "juliemsg")
        self.assertEqual([], rat.messages)
        self.assertEqual(["juliemsg"], julie.messages)

    def test_verbs(self):
        room = Location("room")
        room.verbs["smurf"] = ""
        self.assertTrue("smurf" in room.verbs)
        del room.verbs["smurf"]
        self.assertFalse("smurf" in room.verbs)

    def test_enter_leave(self):
        hall = Location("hall")
        rat1 = NPC("rat1", "n")
        rat2 = NPC("rat2", "n")
        julie = NPC("julie", "f")
        with self.assertRaises(TypeError):
            hall.insert(12345, julie)
        self.assertEqual(_Limbo, rat1.location)
        self.assertFalse(rat1 in hall.livings)
        wiretap = Wiretap(hall)
        hall.insert(rat1, julie)
        self.assertEqual(hall, rat1.location)
        self.assertTrue(rat1 in hall.livings)
        self.assertEqual([], wiretap.msgs, "insert shouldn't produce arrival messages")
        hall.insert(rat2, julie)
        self.assertTrue(rat2 in hall.livings)
        self.assertEqual([], wiretap.msgs, "insert shouldn't produce arrival messages")
        # now test leave
        wiretap.clear()
        hall.remove(rat1, julie)
        self.assertFalse(rat1 in hall.livings)
        self.assertIsNone(rat1.location)
        self.assertEqual([], wiretap.msgs, "remove shouldn't produce exit message")
        hall.remove(rat2, julie)
        self.assertFalse(rat2 in hall.livings)
        self.assertEqual([], wiretap.msgs, "remove shouldn't produce exit message")
        # test random leave
        hall.remove(rat1, julie)
        hall.remove(12345, julie)

    def test_custom_verbs(self):
        player = Player("julie", "f")
        player.verbs["xywobble"] = "p1"
        room = Location("room")
        chair1 = Item("chair1")
        chair1.verbs["frobnitz"] = "c1"
        chair2 = Item("chair2")
        chair2.verbs["frobnitz"] = "c2"
        chair_in_inventory = Item("chair3")
        chair_in_inventory.verbs["kowabooga"] = "c3"
        room.init_inventory([chair1, player, chair2])

        # check inventory NOT affecting player custom verbs, but DOES affect location verbs
        self.assertEqual({"xywobble": "p1"}, player.verbs)
        self.assertEqual({"frobnitz": "c2", "xywobble": "p1"}, room.verbs)
        player.insert(chair_in_inventory, player)
        self.assertEqual({"xywobble": "p1"}, player.verbs)
        self.assertEqual({"frobnitz": "c2", "xywobble": "p1", "kowabooga": "c3"}, room.verbs)
        player.remove(chair_in_inventory, player)
        self.assertEqual({"frobnitz": "c2", "xywobble": "p1"}, room.verbs)

        player.insert(chair_in_inventory, player)
        self.assertEqual({"frobnitz": "c2", "xywobble": "p1", "kowabooga": "c3" }, room.verbs)
        room2 = Location("room2")
        self.assertEqual({}, room2.verbs)
        chair1.move(room2, player)
        self.assertEqual({"xywobble": "p1", "kowabooga": "c3" }, room.verbs)
        self.assertEqual({"frobnitz": "c1"}, room2.verbs)
        chair2.move(room2, player)
        self.assertEqual({"xywobble": "p1", "kowabooga": "c3"}, room.verbs)
        self.assertEqual({"frobnitz": "c2"}, room2.verbs)
        player.move(room2)
        self.assertEqual({}, room.verbs)
        self.assertEqual({"frobnitz": "c2", "xywobble": "p1", "kowabooga": "c3"}, room2.verbs)

    def test_notify(self):
        room = Location("room")
        room2 = Location("room2")
        player = Player("julie", "f")
        room.notify_player_arrived(player, room2)
        room.notify_player_left(player, room2)
        room.notify_npc_arrived(player, room2)
        room.notify_npc_left(player, room2)
        parsed = ParseResult("verb")
        room.notify_action(parsed, player)
Exemplo n.º 27
0
    """
    The gymnasium is where the Parsely Greens have their home games.
    It's currently empty of sweaty athletes and cheering fans.
    """)

locker_room = Location("Locker Room",
    """
    You are in a stereotypical high school locker room.
    It smells of dirty athletic socks and despair.
    """)

gym.add_exits([
    Exit(["east", "locker room", "e"],
        locker_room,
        "You smell a locker room to the east.",
        "A door in the eastern wall of the gym says 'Locker Room'."),
    Exit(["north", "hall", "n"], 
        "hallways.south_hallway",
        "Parsely High is to the north",
        "A door in the north wall of the gym leads to the rest of the school.")
])

locker_room.add_exits([
    Exit(["exit", "out", "west", "door", "w"],
        gym,
        "The gym is to the west.",
        "To the west you can see Parsely High's gymnasium.")
])


class GlassesCase(Boxlike):
    def init(self):
Exemplo n.º 28
0
        player.tell("<bright>Congratulations on escaping the house!</> Someone else has to look after Garfield now though...")
        raise StoryCompleted


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))
Exemplo n.º 29
0
# create the Olde Shoppe and its owner
shopinfo = ShopBehavior()
toothpick = Item("toothpick", "pointy wooden toothpick")
toothpick.value = 0.12
shopinfo.forsale.add(toothpick)
shopinfo.banks_money = True
shopkeeper = Shopkeeper(
    "Lucy",
    "f",
    short_description=
    "Lucy, the shop owner, is looking happily at her newly arrived customer.")
shopkeeper.money = 14000
shop = Location("Curiosity Shoppe", "A weird little shop. It sells odd stuff.")
shop.insert(shopkeeper, shop)
shop.add_exits([
    Exit(["door", "out"], "town.lane",
         "A fancy door provides access back to the lane outside.")
])

# provide some items in the shop
clock = clone(gameclock)
clock.value = 500
paper = clone(newspaper)
gem2 = clone(diamond)
gem2.value = 80000
gem3 = clone(gem)
gem3.value = 9055
shopkeeper.init_inventory([gem2, gem3, toothpick])
shopkeeper.set_shop(shopinfo)
shop.insert(clock, shop)
shop.insert(paper, shop)
lamp = Item("lamp", "rather small lamp")
Exemplo n.º 30
0
             "The street extends to the west, where your house is.", None)

Door.connect(
    street2, ["north", "gate", "playground"],
    "To the north there is a small gate that connects to the children's playground.",
    None, rose_st.playground, ["gate", "south"],
    "The gate that leads back to Magnolia Street is south.", None)

Exit.connect(
    street2, ["south", "house", "neighbors"],
    "You can see the house from the neighbors across the street, to the south.",
    None, houses.neighbors_house, ["street", "north"],
    "The street is back north.", None)

street2.add_exits([
    Exit(["east", "crossing"], "rose_st.crossing",
         "There's a crossing to the east."),
])

street3.add_exits([
    Exit(["west", "crossing"], "rose_st.crossing",
         "There's a crossing to the west.")
])

apothecary = Apothecary("carla", "f", title="apothecary Carla")
apothecary.extra_desc[
    "bottle"] = "It is a small bottle of the pills that your friend Peter needs for his illness."
apothecary.extra_desc["pills"] = apothecary.extra_desc["bottle"]
apothecary.aliases.add("apothecary")

# the medicine Peter needs
medicine = Item(
Exemplo n.º 31
0
class TestLocations(unittest.TestCase):
    def setUp(self):
        mud_context.driver = TestDriver()
        mud_context.config = DemoStory()._get_config()
        self.hall = Location("Main hall", "A very large hall.")
        self.attic = Location("Attic", "A dark attic.")
        self.street = Location("Street", "An endless street.")
        e1 = Exit("up", self.attic, "A ladder leads up.")
        e2 = Exit(
            ["door", "east"], self.street,
            "A heavy wooden door to the east blocks the noises from the street outside."
        )
        self.hall.add_exits([e1, e2])
        self.table = Item(
            "table", "oak table",
            "a large dark table with a lot of cracks in its surface")
        self.key = Item("key",
                        "rusty key",
                        "an old rusty key without a label",
                        short_description="Someone forgot a key.")
        self.magazine = Item("magazine", "university magazine")
        self.magazine2 = Item("magazine", "university magazine")
        self.rat = NPC("rat", "n", race="rodent")
        self.rat2 = NPC("rat", "n", race="rodent")
        self.fly = NPC("fly",
                       "n",
                       race="insect",
                       short_description="A fly buzzes around your head.")
        self.julie = NPC("julie",
                         "f",
                         title="attractive Julie",
                         description="She's quite the looker.")
        self.julie.aliases = {"chick"}
        self.player = Player("player", "m")
        self.pencil = Item("pencil", title="fountain pen")
        self.pencil.aliases = {"pen"}
        self.bag = Container("bag")
        self.notebook_in_bag = Item("notebook")
        self.bag.insert(self.notebook_in_bag, self.player)
        self.player.insert(self.pencil, self.player)
        self.player.insert(self.bag, self.player)
        self.hall.init_inventory([
            self.table, self.key, self.magazine, self.magazine2, self.rat,
            self.rat2, self.julie, self.player, self.fly
        ])

    def test_names(self):
        loc = Location("The Attic", "A dusty attic.")
        self.assertEqual("The Attic", loc.name)
        self.assertEqual("A dusty attic.", loc.description)

    def test_contains(self):
        self.assertTrue(self.julie in self.hall)
        self.assertTrue(self.magazine in self.hall)
        self.assertFalse(self.pencil in self.hall)
        self.assertFalse(self.magazine in self.attic)
        self.assertFalse(self.julie in self.attic)

    def test_look(self):
        expected = [
            "[Main hall]", "A very large hall.",
            "A heavy wooden door to the east blocks the noises from the street outside. A ladder leads up.",
            "Someone forgot a key. You see two university magazines and an oak table. Player, attractive Julie, and two rats are here. A fly buzzes around your head."
        ]
        self.assertEqual(expected, strip_text_styles(self.hall.look()))
        expected = [
            "[Main hall]", "A very large hall.",
            "A heavy wooden door to the east blocks the noises from the street outside. A ladder leads up.",
            "Someone forgot a key. You see two university magazines and an oak table. Attractive Julie and two rats are here. A fly buzzes around your head."
        ]
        self.assertEqual(
            expected,
            strip_text_styles(self.hall.look(exclude_living=self.player)))
        expected = ["[Attic]", "A dark attic."]
        self.assertEqual(expected, strip_text_styles(self.attic.look()))

    def test_look_short(self):
        expected = ["[Attic]"]
        self.assertEqual(expected,
                         strip_text_styles(self.attic.look(short=True)))
        expected = [
            "[Main hall]", "Exits: door, east, up",
            "You see: key, two magazines, and table",
            "Present: fly, julie, player, and two rats"
        ]
        self.assertEqual(expected,
                         strip_text_styles(self.hall.look(short=True)))
        expected = [
            "[Main hall]", "Exits: door, east, up",
            "You see: key, two magazines, and table",
            "Present: fly, julie, and two rats"
        ]
        self.assertEqual(
            expected,
            strip_text_styles(
                self.hall.look(exclude_living=self.player, short=True)))

    def test_search_living(self):
        self.assertEqual(None, self.hall.search_living("<notexisting>"))
        self.assertEqual(None, self.attic.search_living("<notexisting>"))
        self.assertEqual(self.fly, self.hall.search_living("fly"))
        self.assertEqual(self.julie, self.hall.search_living("Julie"))
        self.assertEqual(self.julie,
                         self.hall.search_living("attractive julie"))
        self.assertEqual(self.julie, self.hall.search_living("chick"))
        self.assertEqual(None, self.hall.search_living("bloke"))

    def test_search_item(self):
        # almost identical to locate_item so only do a few basic tests
        self.assertEqual(None, self.player.search_item("<notexisting>"))
        self.assertEqual(self.pencil, self.player.search_item("pencil"))

    def test_locate_item(self):
        item, container = self.player.locate_item("<notexisting>")
        self.assertEqual(None, item)
        self.assertEqual(None, container)
        item, container = self.player.locate_item("pencil")
        self.assertEqual(self.pencil, item)
        self.assertEqual(self.player, container)
        item, container = self.player.locate_item("fountain pen")
        self.assertEqual(self.pencil, item, "need to find the title")
        item, container = self.player.locate_item("pen")
        self.assertEqual(self.pencil, item, "need to find the alias")
        item, container = self.player.locate_item("pencil",
                                                  include_inventory=False)
        self.assertEqual(None, item)
        self.assertEqual(None, container)
        item, container = self.player.locate_item("key")
        self.assertEqual(self.key, item)
        self.assertEqual(self.hall, container)
        item, container = self.player.locate_item("key",
                                                  include_location=False)
        self.assertEqual(None, item)
        self.assertEqual(None, container)
        item, container = self.player.locate_item("KEY")
        self.assertEqual(self.key, item, "should work case-insensitive")
        self.assertEqual(self.hall, container, "should work case-insensitive")
        item, container = self.player.locate_item("notebook")
        self.assertEqual(self.notebook_in_bag, item)
        self.assertEqual(self.bag, container,
                         "should search in bags in inventory")
        item, container = self.player.locate_item(
            "notebook", include_containers_in_inventory=False)
        self.assertEqual(None, item)
        self.assertEqual(None, container,
                         "should not search in bags in inventory")

    def test_tell(self):
        rat = MsgTraceNPC("rat", "n", "rodent")
        self.assertTrue(rat._init_called,
                        "init() must be called from __init__")
        julie = MsgTraceNPC("julie", "f", "human")
        hall = Location("hall")
        hall.livings = [rat, julie]
        hall.tell("roommsg")
        self.assertEqual(["roommsg"], rat.messages)
        self.assertEqual(["roommsg"], julie.messages)
        rat.clearmessages()
        julie.clearmessages()
        hall.tell("roommsg", rat, [julie], "juliemsg")
        self.assertEqual([], rat.messages)
        self.assertEqual(["juliemsg"], julie.messages)

    def test_message_nearby_location(self):
        plaza = Location("plaza")
        road = Location("road")
        house = Location("house")
        attic = Location("attic")
        plaza.add_exits([
            Exit("north", road, "road leads north"),
            Exit("door", house, "door to a house")
        ])
        road.add_exits([Exit("south", plaza, "plaza to the south")])
        house.add_exits([
            Exit("door", plaza, "door to the plaza"),
            Exit("ladder", attic, "dusty attic")
        ])
        attic.add_exits([Exit("ladder", house, "the house")])
        wiretap_plaza = Wiretap(plaza)
        wiretap_road = Wiretap(road)
        wiretap_house = Wiretap(house)
        wiretap_attic = Wiretap(attic)
        plaza.message_nearby_locations("boing")
        pubsub.sync()
        self.assertEqual([], wiretap_plaza.msgs,
                         "the plaza doesnt receive tells")
        self.assertEqual([], wiretap_attic.msgs,
                         "the attic is too far away to receive msgs")
        self.assertTrue(("road", "boing") in wiretap_road.msgs)
        self.assertTrue(("road", "The sound is coming from the south.")
                        in wiretap_road.msgs,
                        "road should give sound direction")
        self.assertTrue(("house", "boing") in wiretap_house.msgs)
        self.assertTrue(
            ("house", "You can't hear where the sound is coming from.")
            in wiretap_house.msgs,
            "in the house you can't locate the sound direction")

    def test_nearby(self):
        plaza = Location("plaza")
        road = Location("road")
        house = Location("house")
        alley = Location("alley")  # no exits
        attic = Location("attic")
        plaza.add_exits([
            Exit("north", road, "road leads north"),
            Exit("door", house, "door to a house"),
            Exit("west", alley, "small alleywith no way back")
        ])
        road.add_exits([Exit("south", plaza, "plaza to the south")])
        house.add_exits([
            Exit("door", plaza, "door to the plaza"),
            Exit("ladder", attic, "dusty attic")
        ])
        attic.add_exits([Exit("ladder", house, "the house")])
        adj = set(plaza.nearby())
        self.assertSetEqual({road, house}, adj)
        adj = set(plaza.nearby(no_traps=False))
        self.assertSetEqual({road, house, alley}, adj)

    def test_verbs(self):
        room = Location("room")
        room.verbs["smurf"] = ""
        self.assertTrue("smurf" in room.verbs)
        del room.verbs["smurf"]
        self.assertFalse("smurf" in room.verbs)

    def test_enter_leave(self):
        hall = Location("hall")
        rat1 = NPC("rat1", "n")
        rat2 = NPC("rat2", "n")
        julie = NPC("julie", "f")
        with self.assertRaises(TypeError):
            hall.insert(12345, julie)
        self.assertEqual(_limbo, rat1.location)
        self.assertFalse(rat1 in hall.livings)
        wiretap = Wiretap(hall)
        hall.insert(rat1, julie)
        self.assertEqual(hall, rat1.location)
        self.assertTrue(rat1 in hall.livings)
        self.assertEqual([], wiretap.msgs,
                         "insert shouldn't produce arrival messages")
        hall.insert(rat2, julie)
        self.assertTrue(rat2 in hall.livings)
        self.assertEqual([], wiretap.msgs,
                         "insert shouldn't produce arrival messages")
        # now test leave
        wiretap.clear()
        hall.remove(rat1, julie)
        self.assertFalse(rat1 in hall.livings)
        self.assertIsNone(rat1.location)
        self.assertEqual([], wiretap.msgs,
                         "remove shouldn't produce exit message")
        hall.remove(rat2, julie)
        self.assertFalse(rat2 in hall.livings)
        self.assertEqual([], wiretap.msgs,
                         "remove shouldn't produce exit message")
        # test random leave
        hall.remove(rat1, julie)
        hall.remove(12345, julie)

    def test_custom_verbs(self):
        player = Player("julie", "f")
        player.verbs["xywobble"] = "p1"
        monster = NPC("snake", "f")
        monster.verbs["snakeverb"] = "s1"
        room = Location("room")
        chair1 = Item("chair1")
        chair1.verbs["frobnitz"] = "c1"
        chair2 = Item("chair2")
        chair2.verbs["frobnitz"] = "c2"
        chair_in_inventory = Item("chair3")
        chair_in_inventory.verbs["kowabooga"] = "c3"
        box_in_inventory = Item("box")
        box_in_inventory.verbs["boxverb"] = "c4"
        player.init_inventory([box_in_inventory, chair_in_inventory])
        exit = Exit("e", "dummy", None, None)
        exit.verbs["exitverb"] = "c5"
        room.init_inventory([chair1, player, chair2, monster])
        room.add_exits([exit])
        custom_verbs = mud_context.driver.current_custom_verbs(player)
        all_verbs = mud_context.driver.current_verbs(player)
        self.assertEqual(
            {
                "xywobble", "snakeverb", "frobnitz", "kowabooga", "boxverb",
                "exitverb"
            }, set(custom_verbs))
        self.assertEqual(set(), set(custom_verbs) - set(all_verbs))

    def test_notify(self):
        room = Location("room")
        room2 = Location("room2")
        player = Player("julie", "f")
        room.notify_player_arrived(player, room2)
        room.notify_player_left(player, room2)
        room.notify_npc_arrived(player, room2)
        room.notify_npc_left(player, room2)
        parsed = ParseResult("verb")
        room.notify_action(parsed, player)
Exemplo n.º 32
0
from __future__ import absolute_import, print_function, division, unicode_literals
from tale.base import Location, Exit, Door

# define the locations


class GameEnd(Location):
    def init(self):
        pass

    def notify_player_arrived(self, player, previous_location):
        # player has entered!
        player.story_completed()

livingroom = Location("Living room", "The living room in your home in the outskirts of the city.")
room1 = Location("Small room", "A small room.")
room2 = Location("Large room", "A large room.")
outside = GameEnd("Outside", "You escaped the house.")


# define the exits that connect the locations

livingroom.add_exits([
    Exit("small room", room1, "There's a small room in your house."),
    Exit("large room", room2, "There's a large room in your house."),
    Door(["door", "garden"], outside, "A door leads to the garden.", "There's a heavy door here that leads to the garden outside the house.", opened=False)
])
room1.add_exits([Exit("living room", livingroom, "You can see the living room.")])
room2.add_exits([Exit("living room", livingroom, "You can see the living room.")])
Exemplo n.º 33
0
class TestLocations(unittest.TestCase):
    def setUp(self):
        mud_context.driver = TestDriver()
        mud_context.config = DemoStory()._get_config()
        self.hall = Location("Main hall", "A very large hall.")
        self.attic = Location("Attic", "A dark attic.")
        self.street = Location("Street", "An endless street.")
        e1 = Exit("up", self.attic, "A ladder leads up.")
        e2 = Exit(["door", "east"], self.street, "A heavy wooden door to the east blocks the noises from the street outside.")
        self.hall.add_exits([e1, e2])
        self.table = Item("table", "oak table", "a large dark table with a lot of cracks in its surface")
        self.key = Item("key", "rusty key", "an old rusty key without a label", short_description="Someone forgot a key.")
        self.magazine = Item("magazine", "university magazine")
        self.magazine2 = Item("magazine", "university magazine")
        self.rat = NPC("rat", "n", race="rodent")
        self.rat2 = NPC("rat", "n", race="rodent")
        self.fly = NPC("fly", "n", race="insect", short_description="A fly buzzes around your head.")
        self.julie = NPC("julie", "f", title="attractive Julie", description="She's quite the looker.")
        self.julie.aliases = {"chick"}
        self.player = Player("player", "m")
        self.pencil = Item("pencil", title="fountain pen")
        self.pencil.aliases = {"pen"}
        self.bag = Container("bag")
        self.notebook_in_bag = Item("notebook")
        self.bag.insert(self.notebook_in_bag, self.player)
        self.player.insert(self.pencil, self.player)
        self.player.insert(self.bag, self.player)
        self.hall.init_inventory([self.table, self.key, self.magazine, self.magazine2, self.rat, self.rat2, self.julie, self.player, self.fly])

    def test_names(self):
        loc = Location("The Attic", "A dusty attic.")
        self.assertEqual("The Attic", loc.name)
        self.assertEqual("A dusty attic.", loc.description)

    def test_contains(self):
        self.assertTrue(self.julie in self.hall)
        self.assertTrue(self.magazine in self.hall)
        self.assertFalse(self.pencil in self.hall)
        self.assertFalse(self.magazine in self.attic)
        self.assertFalse(self.julie in self.attic)

    def test_look(self):
        expected = ["[Main hall]", "A very large hall.",
                    "A heavy wooden door to the east blocks the noises from the street outside. A ladder leads up.",
                    "Someone forgot a key. You see two university magazines and an oak table. Player, attractive Julie, and two rats are here. A fly buzzes around your head."]
        self.assertEqual(expected, strip_text_styles(self.hall.look()))
        expected = ["[Main hall]", "A very large hall.",
                    "A heavy wooden door to the east blocks the noises from the street outside. A ladder leads up.",
                    "Someone forgot a key. You see two university magazines and an oak table. Attractive Julie and two rats are here. A fly buzzes around your head."]
        self.assertEqual(expected, strip_text_styles(self.hall.look(exclude_living=self.player)))
        expected = ["[Attic]", "A dark attic."]
        self.assertEqual(expected, strip_text_styles(self.attic.look()))

    def test_look_short(self):
        expected = ["[Attic]"]
        self.assertEqual(expected, strip_text_styles(self.attic.look(short=True)))
        expected = ["[Main hall]", "Exits: door, east, up", "You see: key, two magazines, and table", "Present: fly, julie, player, and two rats"]
        self.assertEqual(expected, strip_text_styles(self.hall.look(short=True)))
        expected = ["[Main hall]", "Exits: door, east, up", "You see: key, two magazines, and table", "Present: fly, julie, and two rats"]
        self.assertEqual(expected, strip_text_styles(self.hall.look(exclude_living=self.player, short=True)))

    def test_search_living(self):
        self.assertEqual(None, self.hall.search_living("<notexisting>"))
        self.assertEqual(None, self.attic.search_living("<notexisting>"))
        self.assertEqual(self.fly, self.hall.search_living("fly"))
        self.assertEqual(self.julie, self.hall.search_living("Julie"))
        self.assertEqual(self.julie, self.hall.search_living("attractive julie"))
        self.assertEqual(self.julie, self.hall.search_living("chick"))
        self.assertEqual(None, self.hall.search_living("bloke"))

    def test_search_item(self):
        # almost identical to locate_item so only do a few basic tests
        self.assertEqual(None, self.player.search_item("<notexisting>"))
        self.assertEqual(self.pencil, self.player.search_item("pencil"))

    def test_locate_item(self):
        item, container = self.player.locate_item("<notexisting>")
        self.assertEqual(None, item)
        self.assertEqual(None, container)
        item, container = self.player.locate_item("pencil")
        self.assertEqual(self.pencil, item)
        self.assertEqual(self.player, container)
        item, container = self.player.locate_item("fountain pen")
        self.assertEqual(self.pencil, item, "need to find the title")
        item, container = self.player.locate_item("pen")
        self.assertEqual(self.pencil, item, "need to find the alias")
        item, container = self.player.locate_item("pencil", include_inventory=False)
        self.assertEqual(None, item)
        self.assertEqual(None, container)
        item, container = self.player.locate_item("key")
        self.assertEqual(self.key, item)
        self.assertEqual(self.hall, container)
        item, container = self.player.locate_item("key", include_location=False)
        self.assertEqual(None, item)
        self.assertEqual(None, container)
        item, container = self.player.locate_item("KEY")
        self.assertEqual(self.key, item, "should work case-insensitive")
        self.assertEqual(self.hall, container, "should work case-insensitive")
        item, container = self.player.locate_item("notebook")
        self.assertEqual(self.notebook_in_bag, item)
        self.assertEqual(self.bag, container, "should search in bags in inventory")
        item, container = self.player.locate_item("notebook", include_containers_in_inventory=False)
        self.assertEqual(None, item)
        self.assertEqual(None, container, "should not search in bags in inventory")

    def test_tell(self):
        rat = MsgTraceNPC("rat", "n", "rodent")
        self.assertTrue(rat._init_called, "init() must be called from __init__")
        julie = MsgTraceNPC("julie", "f", "human")
        hall = Location("hall")
        hall.livings = [rat, julie]
        hall.tell("roommsg")
        self.assertEqual(["roommsg"], rat.messages)
        self.assertEqual(["roommsg"], julie.messages)
        rat.clearmessages()
        julie.clearmessages()
        hall.tell("roommsg", rat, [julie], "juliemsg")
        self.assertEqual([], rat.messages)
        self.assertEqual(["juliemsg"], julie.messages)

    def test_message_nearby_location(self):
        plaza = Location("plaza")
        road = Location("road")
        house = Location("house")
        attic = Location("attic")
        plaza.add_exits([Exit("north", road, "road leads north"), Exit("door", house, "door to a house")])
        road.add_exits([Exit("south", plaza, "plaza to the south")])
        house.add_exits([Exit("door", plaza, "door to the plaza"), Exit("ladder", attic, "dusty attic")])
        attic.add_exits([Exit("ladder", house, "the house")])
        wiretap_plaza = Wiretap(plaza)
        wiretap_road = Wiretap(road)
        wiretap_house = Wiretap(house)
        wiretap_attic = Wiretap(attic)
        plaza.message_nearby_locations("boing")
        pubsub.sync()
        self.assertEqual([], wiretap_plaza.msgs, "the plaza doesnt receive tells")
        self.assertEqual([], wiretap_attic.msgs, "the attic is too far away to receive msgs")
        self.assertTrue(("road", "boing") in wiretap_road.msgs)
        self.assertTrue(("road", "The sound is coming from the south.") in wiretap_road.msgs, "road should give sound direction")
        self.assertTrue(("house", "boing") in wiretap_house.msgs)
        self.assertTrue(("house", "You can't hear where the sound is coming from.") in wiretap_house.msgs, "in the house you can't locate the sound direction")

    def test_nearby(self):
        plaza = Location("plaza")
        road = Location("road")
        house = Location("house")
        alley = Location("alley")  # no exits
        attic = Location("attic")
        plaza.add_exits([Exit("north", road, "road leads north"), Exit("door", house, "door to a house"),
                         Exit("west", alley, "small alleywith no way back")])
        road.add_exits([Exit("south", plaza, "plaza to the south")])
        house.add_exits([Exit("door", plaza, "door to the plaza"), Exit("ladder", attic, "dusty attic")])
        attic.add_exits([Exit("ladder", house, "the house")])
        adj = set(plaza.nearby())
        self.assertSetEqual({road, house}, adj)
        adj = set(plaza.nearby(no_traps=False))
        self.assertSetEqual({road, house, alley}, adj)

    def test_verbs(self):
        room = Location("room")
        room.verbs["smurf"] = ""
        self.assertTrue("smurf" in room.verbs)
        del room.verbs["smurf"]
        self.assertFalse("smurf" in room.verbs)

    def test_enter_leave(self):
        hall = Location("hall")
        rat1 = NPC("rat1", "n")
        rat2 = NPC("rat2", "n")
        julie = NPC("julie", "f")
        with self.assertRaises(TypeError):
            hall.insert(12345, julie)
        self.assertEqual(_limbo, rat1.location)
        self.assertFalse(rat1 in hall.livings)
        wiretap = Wiretap(hall)
        hall.insert(rat1, julie)
        self.assertEqual(hall, rat1.location)
        self.assertTrue(rat1 in hall.livings)
        self.assertEqual([], wiretap.msgs, "insert shouldn't produce arrival messages")
        hall.insert(rat2, julie)
        self.assertTrue(rat2 in hall.livings)
        self.assertEqual([], wiretap.msgs, "insert shouldn't produce arrival messages")
        # now test leave
        wiretap.clear()
        hall.remove(rat1, julie)
        self.assertFalse(rat1 in hall.livings)
        self.assertIsNone(rat1.location)
        self.assertEqual([], wiretap.msgs, "remove shouldn't produce exit message")
        hall.remove(rat2, julie)
        self.assertFalse(rat2 in hall.livings)
        self.assertEqual([], wiretap.msgs, "remove shouldn't produce exit message")
        # test random leave
        hall.remove(rat1, julie)
        hall.remove(12345, julie)

    def test_custom_verbs(self):
        player = Player("julie", "f")
        player.verbs["xywobble"] = "p1"
        monster = NPC("snake", "f")
        monster.verbs["snakeverb"] = "s1"
        room = Location("room")
        chair1 = Item("chair1")
        chair1.verbs["frobnitz"] = "c1"
        chair2 = Item("chair2")
        chair2.verbs["frobnitz"] = "c2"
        chair_in_inventory = Item("chair3")
        chair_in_inventory.verbs["kowabooga"] = "c3"
        box_in_inventory = Item("box")
        box_in_inventory.verbs["boxverb"] = "c4"
        player.init_inventory([box_in_inventory, chair_in_inventory])
        exit = Exit("e", "dummy", None, None)
        exit.verbs["exitverb"] = "c5"
        room.init_inventory([chair1, player, chair2, monster])
        room.add_exits([exit])
        custom_verbs = mud_context.driver.current_custom_verbs(player)
        all_verbs = mud_context.driver.current_verbs(player)
        self.assertEqual({"xywobble", "snakeverb", "frobnitz", "kowabooga", "boxverb", "exitverb"}, set(custom_verbs))
        self.assertEqual(set(), set(custom_verbs) - set(all_verbs))

    def test_notify(self):
        room = Location("room")
        room2 = Location("room2")
        player = Player("julie", "f")
        room.notify_player_arrived(player, room2)
        room.notify_player_left(player, room2)
        room.notify_npc_arrived(player, room2)
        room.notify_npc_left(player, room2)
        parsed = ParseResult("verb")
        room.notify_action(parsed, player)
Exemplo n.º 34
0
from npcs.town_creatures import TownCrier, VillageIdiot, WalkingRat


square = Location("Essglen Town square",
    """
    The old town square of Essglen. 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.
    """)

square.add_exits([Exit(["north", "lane"], lane, "A long straight lane leads north towards the horizon.")])

paper = clone(newspaper)
paper.aliases = {"paper"}
paper.short_description = "Last day's newspaper lies on the floor."


class CursedGem(Item):
    def move(self, target, actor, silent=False, is_player=False, verb="move"):
        if self.contained_in is actor and not "wizard" in actor.privileges:
            raise ActionRefused("The gem is cursed! It sticks to your hand, you can't get rid of it!")
        super(CursedGem, self).move(target, actor, verb=verb)


class InsertOnlyBox(Container):
    def remove(self, item, actor):
Exemplo n.º 35
0
                              "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.")

#  Exits

front_door = Door(["door", "outside", "street"], "magnolia_st.street1", "Your front door leads outside, to the street.",
                  "There's a heavy front door here that leads to the streets outside.", opened=False)
house_door = front_door.reverse_door(["house", "north", "inside"], livingroom,
                                     "You can go back inside your house.", "It's your house, on the north side of the street.",
                                     reverse_open_msg="Someone outside opens the door.",
                                     reverse_close_msg="Someone outside closes the door.",
                                     this_open_msg="Someone in the house opens the door.",
                                     this_close_msg="Someone in the house closes the door.")
livingroom.add_exits([
    Exit("kitchen", 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."),
    front_door
])

kitchen.add_exits([
    Exit(["living room", "livingroom", "back"], livingroom, "The living room is back the way you entered.")
])


# ----------------- Neighbours House, Bedroom, Garden  -------------------------

neighbors_house = Location("Neighbor's House", "The house of your neighbors across the street.")

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. The back pocket of some trousers draw your attention.")
bedroom.add_extradesc({"window"}, "The bedroom window is open and you see a ladder leading down to the garden.")
Exemplo n.º 36
0

def init(driver):
    # called when zone is first loaded
    pass


street1 = Location("Magnolia Street", "Your house is on Magnolia Street, one of the larger streets in town. "
                                      "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.")


pharmacy = Location("Pharmacy", "A pharmacy.")
pharmacy.add_exits([
    Exit(["east", "outside", "street"], street1, "Magnolia street is outside towards the east.")
])

factory = Location("ArtiGrow factory", "This area is the ArtiGrow fertilizer factory.")
factory.add_exits([
    Exit(["west", "street"], street3, "You can leave the factory to the west, back to Magnolia Street.")
])


street1.add_exits([
    houses.house_door,
    Exit(["pharmacy", "west"], pharmacy, "The west end of the street leads to the pharmacy."),
    Exit(["town", "east"], street2, "The street extends eastwards, towards the rest of the town.")
])

playground_gate = Door(["north", "gate", "playground"], "rose_st.playground", "To the north there is a small gate that connects to the children's playground.", opened=False)
Exemplo n.º 37
0
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)
door.key_code = 1
# use an exit with an unbound target (string), the driver will link this up:
closet_exit = Exit("closet", "house.closet",
                   "There's a small closet in your house.")
livingroom.add_exits([door, closet_exit])
# use another exit with a bound target (object):
closet.add_exits(
    [Exit("living room", livingroom, "You can see the living room.")])

# define items and NPCs


class Cat(NPC):
    def init(self):
        self.aliases = {"cat"}
        mud_context.driver.defer(4, self.do_purr)

    def do_purr(self, ctx):
        if random.random() > 0.5:
            self.location.tell("%s purrs happily." % capital(self.title))
Exemplo n.º 38
0
Exit.connect(street1, ["town", "east"], "The street extends eastwards, towards the rest of the town.", None,
             street2, "west", "The street extends to the west, where your house is.", None)

Door.connect(street2,
             ["north", "gate", "playground"],
             "To the north there is a small gate that connects to the children's playground.", None,
             rose_st.playground,
             ["gate", "south"],
             "The gate that leads back to Magnolia Street is south.", None)

Exit.connect(street2, ["south", "house", "neighbors"], "You can see the house from the neighbors across the street, to the south.", None,
             houses.neighbors_house, ["street", "north"], "The street is back north.", None)

street2.add_exits([
    Exit(["east", "crossing"], "rose_st.crossing", "There's a crossing to the east."),
])

street3.add_exits([
    Exit(["west", "crossing"], "rose_st.crossing", "There's a crossing to the west.")
])


apothecary = Apothecary("carla", "f", title="apothecary Carla")
apothecary.extra_desc["bottle"] = "It is a small bottle of the pills that your friend Peter needs for his illness."
apothecary.extra_desc["pills"] = apothecary.extra_desc["bottle"]
apothecary.aliases.add("apothecary")

# the medicine Peter needs
medicine = Item("pills", "bottle of pills", descr="It looks like the medicine your friend Peter needs for his illness.")
medicine.value = Apothecary.pills_price
Exemplo n.º 39
0
Arquivo: inn.py Projeto: Ianax/Tale
##### Lobby #####

foyer = Location(name="Foyer", descr=room_descriptions['foyer'])
# Build Exits
foyer_closet = Exit(directions="closet",
                    target_location="inn.foyer_closet",
                    short_descr="There is a small closet in the foyer.",
                    long_descr=None)

foyer_sitting = Exit(directions=["north", "sitting"],
                     target_location="inn.sitting_room",
                     short_descr="There is a sitting room to the north.",
                     long_descr="""Through the archway you can see a cozy
                                   room flickering to the light of a fire.""")

foyer.add_exits([foyer_closet, foyer_sitting])

# Insert items & npcs

##### Foyer Closet #####
foyer_closet = Location("Foyer Closet", "A small closet.")

closet_foyer = Exit(directions=["out", "back", "foyer"],
                    target_location="inn.foyer",
                    short_descr="You can see the foyer you came from.",
                    long_descr=None)

foyer_closet.add_exits([closet_foyer])

##### Sitting Room #####
Exemplo n.º 40
0
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.
    """)

hall.add_exits([
    Exit(["up", "ladder"], attic, "A small ladder leads up through a hole in the ceiling."),
    Exit(["door", "east"], "town.lane", "A heavy wooden door to the east blocks the noises from the street outside."),
    Exit("north", kitchen, "A door to the north leads to the kitchen.")
])

kitchen.add_exits([Exit("south", hall, "A door to the south leads back to the hall.")])
attic.add_exits([Exit(["down", "ladder"], hall, "A small ladder leads back down to the hall.")])
Exemplo n.º 41
0
import zones.houses
import zones.npcs

from tale.base import Location, Exit, Door, Key, Living, ParseResult, _limbo
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
])
Exemplo n.º 42
0
Arquivo: town.py Projeto: irmen/Tale
class RemoveOnlyBox(Container):
    def insert(self, item: Union[Living, Item], actor: Optional[Living]) -> None:
        raise ActionRefused("No matter how hard you try, you can't fit %s in the box." % item.title)


insertonly_box = InsertOnlyBox("box1", "box1 (a black box)")
removeonly_box = RemoveOnlyBox("box2", "box2 (a white box)")
normal_gem = gem.clone()
removeonly_box.init_inventory([normal_gem])

cursed_gem = CursedGem("black gem")
cursed_gem.aliases = {"gem"}
normal_gem = Item("blue gem")
normal_gem.aliases = {"gem"}
lane.add_exits([Exit(["shop", "north east", "northeast", "ne"], "shoppe.shop", "There's a curiosity shop to the north-east.")])


class WizardTowerEntry(Exit):
    def allow_passage(self, actor: Living) -> None:
        if "wizard" in actor.privileges:
            actor.tell("You pass through the force-field.", end=True)
        else:
            raise ActionRefused("You can't go that way, the force-field is impenetrable.")


lane.add_exits([WizardTowerEntry("west", "wizardtower.hall",
                                 "To the west is the wizard's tower. It seems to be protected by a force-field.")])

towncrier = TownCrier("laish", "f", title="Laish the town crier",
                      descr="The town crier is awfully quiet today. She seems rather preoccupied with something.")
Exemplo n.º 43
0
        raise ActionRefused(
            "No matter how hard you try, you can't fit %s in the box." %
            item.title)


insertonly_box = InsertOnlyBox("box1", "box1 (a black box)")
removeonly_box = RemoveOnlyBox("box2", "box2 (a white box)")
normal_gem = gem.clone()
removeonly_box.init_inventory([normal_gem])

cursed_gem = CursedGem("black gem")
cursed_gem.aliases = {"gem"}
normal_gem = Item("blue gem")
normal_gem.aliases = {"gem"}
lane.add_exits([
    Exit(["shop", "north east", "northeast", "ne"], "shoppe.shop",
         "There's a curiosity shop to the north-east.")
])


class WizardTowerEntry(Exit):
    def allow_passage(self, actor: Living) -> None:
        if "wizard" in actor.privileges:
            actor.tell("You pass through the force-field.", end=True)
        else:
            raise ActionRefused(
                "You can't go that way, the force-field is impenetrable.")


lane.add_exits([
    WizardTowerEntry(
        "west", "wizardtower.hall",
Exemplo n.º 44
0
    "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."
    ),
])
Exemplo n.º 45
0
library = Location(
    "Library",
    """
    You're in the library, where you usually spend your after-school time in detention.
    """,
)

hallway_door = Door(
    ["hallway", "hallway door", "south", "s", "out"],
    "hallways.north_hallway",
    short_description="An open door to the south leads back into the hallway.",
    locked=False,
    opened=True,
)

library.add_exits([hallway_door])

english.add_exits(
    [Exit(["w", "west"], "hallways.north_hallway", "The hallway to the west offers the possibility of escape.")]
)


class ForDummies(Note):
    def init(self):
        super(Note, self).init()
        self._text = """
        "Divide by 2" is scrawled in the margin of the book in your handwriting.
        """

    def read(self, actor):
        actor.tell(self.text)
Exemplo n.º 46
0
def init(driver):
    # called when zone is first loaded
    pass


# create the Olde Shoppe and its owner
shopinfo = ShopBehavior()
toothpick = Item("toothpick", "pointy wooden toothpick")
toothpick.value = 0.12
shopinfo.forsale.add(toothpick)
shopinfo.banks_money = True
shopkeeper = Shopkeeper("Lucy", "f", short_description="Lucy, the shop owner, is looking happily at her newly arrived customer.")
shopkeeper.money = 14000
shop = Location("Curiosity Shoppe", "A weird little shop. It sells odd stuff.")
shop.insert(shopkeeper, shop)
shop.add_exits([Exit(["door", "out"], "town.lane", "A fancy door provides access back to the lane outside.")])


# provide some items in the shop
clock = clone(gameclock)
clock.value = 500
paper = clone(newspaper)
gem2 = clone(diamond)
gem2.value = 80000
gem3 = clone(gem)
gem3.value = 9055
shopkeeper.init_inventory([gem2, gem3, toothpick])
shopkeeper.set_shop(shopinfo)
shop.insert(clock, shop)
shop.insert(paper, shop)
lamp = Item("lamp", "rather small lamp")