コード例 #1
0
ファイル: test_mudobjects.py プロジェクト: skirtap/Tale
 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))
コード例 #2
0
 def test_bind_exit(self):
     class ModuleDummy(object):
         pass
     zones = ModuleDummy()
     zones.town = ModuleDummy()
     zones.town.square = Location("square")
     exit = Exit("square", "town.square", "someplace")
     self.assertFalse(exit.bound)
     exit._bind_target(zones)
     self.assertTrue(exit.bound)
     self.assertTrue(zones.town.square is exit.target)
     exit._bind_target(zones)
コード例 #3
0
ファイル: test_mudobjects.py プロジェクト: skirtap/Tale
 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"])
コード例 #4
0
 def test_title_name(self):
     door = Door("north", "hall", "a locked door", locked=True, opened=False)
     self.assertEqual("north", door.name)
     self.assertEqual("Exit to <unbound:hall>", door.title)
     exit = Exit("outside", "town.square", "someplace")
     self.assertEqual("outside", exit.name)
     self.assertEqual("Exit to <unbound:town.square>", exit.title)
     class ModuleDummy(object):
         pass
     zones = ModuleDummy()
     zones.town = ModuleDummy()
     zones.town.square = Location("square")
     exit._bind_target(zones)
     self.assertEqual("Exit to square", exit.title)
     self.assertEqual("exit to square", exit.name)
コード例 #5
0
ファイル: test_player.py プロジェクト: skirtap/Tale
 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)
コード例 #6
0
ファイル: test_mudobjects.py プロジェクト: skirtap/Tale
 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
     ])
コード例 #7
0
ファイル: circle_locations.py プロジェクト: vtbassmatt/Tale
def make_exit(c_exit: SimpleNamespace) -> Exit:
    """Create an instance of a door or exit for the given circle exit"""
    if c_exit.type in ("normal", "pickproof"):  # @todo other door types? reverse doors? locks/keys?
        door = Door(c_exit.direction, make_location(c_exit.roomlink), c_exit.desc)
        door.aliases |= c_exit.keywords
        return door
    else:
        exit = Exit(c_exit.direction, make_location(c_exit.roomlink), c_exit.desc)
        exit.aliases |= c_exit.keywords
        return exit
コード例 #8
0
ファイル: __init__.py プロジェクト: skirtap/Tale
def make_exit(c_exit):
    """Create an instance of a door or exit for the given circle exit"""
    if c_exit.type in ("normal", "pickproof"):
        xt = Door(c_exit.direction, make_location(c_exit.roomlink),
                  c_exit.desc)
    else:
        xt = Exit(c_exit.direction, make_location(c_exit.roomlink),
                  c_exit.desc)
    xt.aliases |= c_exit.keywords
    return xt
コード例 #9
0
ファイル: test_mudobjects.py プロジェクト: skirtap/Tale
    def test_title_name(self):
        door = Door("north",
                    "hall",
                    "a locked door",
                    locked=True,
                    opened=False)
        self.assertEqual("north", door.name)
        self.assertEqual("Exit to <unbound:hall>", door.title)
        exit = Exit("outside", "town.square", "someplace")
        self.assertEqual("outside", exit.name)
        self.assertEqual("Exit to <unbound:town.square>", exit.title)

        class ModuleDummy(object):
            pass

        zones = ModuleDummy()
        zones.town = ModuleDummy()
        zones.town.square = Location("square")
        exit._bind_target(zones)
        self.assertEqual("Exit to square", exit.title)
        self.assertEqual("exit to square", exit.name)
コード例 #10
0
ファイル: test_mudobjects.py プロジェクト: skirtap/Tale
 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")
コード例 #11
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))
コード例 #12
0
ファイル: test_mudobjects.py プロジェクト: skirtap/Tale
    def test_bind_exit(self):
        class ModuleDummy(object):
            pass

        zones = ModuleDummy()
        zones.town = ModuleDummy()
        zones.town.square = Location("square")
        exit = Exit("square", "town.square", "someplace")
        self.assertFalse(exit.bound)
        exit._bind_target(zones)
        self.assertTrue(exit.bound)
        self.assertTrue(zones.town.square is exit.target)
        exit._bind_target(zones)
コード例 #13
0
ファイル: test_mudobjects.py プロジェクト: skirtap/Tale
 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)
コード例 #14
0
ファイル: test_mudobjects.py プロジェクト: skirtap/Tale
 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)
コード例 #15
0
ファイル: test_mudobjects.py プロジェクト: skirtap/Tale
    def test_actions(self):
        player = Player("julie", "f")
        hall = Location("hall")
        attic = Location("attic")
        unbound_exit = Exit("random", "foo.bar", "a random exit")
        with self.assertRaises(Exception):
            self.assertFalse(unbound_exit.allow_passage(
                player))  # should fail because not bound
        exit1 = Exit("ladder", attic, "first ladder to attic")
        exit1.allow_passage(player)

        door = Door("north",
                    hall,
                    "open unlocked door",
                    locked=False,
                    opened=True)
        with self.assertRaises(ActionRefused) as x:
            door.open(player)  # fail, it's already open
        self.assertEqual("It's already open.", str(x.exception))
        door.close(player)
        self.assertFalse(door.opened, "must be closed")
        with self.assertRaises(ActionRefused) as x:
            door.lock(player)  # default door can't be locked
        self.assertEqual("You don't seem to have the means to lock it.",
                         str(x.exception))
        with self.assertRaises(ActionRefused) as x:
            door.unlock(player)  # fail, it's not locked
        self.assertEqual("It's not locked.", str(x.exception))

        door = Door("north",
                    hall,
                    "open locked door",
                    locked=False,
                    opened=True)
        with self.assertRaises(ActionRefused) as x:
            door.open(player)  # fail, it's already open
        self.assertEqual("It's already open.", str(x.exception))
        door.close(player)
        door.locked = True
        with self.assertRaises(ActionRefused) as x:
            door.lock(player)  # it's already locked
        self.assertEqual("It's already locked.", str(x.exception))
        self.assertTrue(door.locked)
        with self.assertRaises(ActionRefused) as x:
            door.unlock(player)  # you can't unlock it
        self.assertEqual("You don't seem to have the means to unlock it.",
                         str(x.exception))
        self.assertTrue(door.locked)

        door = Door("north",
                    hall,
                    "closed unlocked door",
                    locked=False,
                    opened=False)
        door.open(player)
        self.assertTrue(door.opened)
        door.close(player)
        self.assertFalse(door.opened)
        with self.assertRaises(ActionRefused) as x:
            door.close(player)  # it's already closed
        self.assertEqual("It's already closed.", str(x.exception))

        door = Door("north",
                    hall,
                    "closed locked door",
                    locked=True,
                    opened=False)
        with self.assertRaises(ActionRefused) as x:
            door.open(player)  # can't open it, it's locked
        self.assertEqual("You try to open it, but it's locked.",
                         str(x.exception))
        with self.assertRaises(ActionRefused) as x:
            door.close(player)  # it's already closed
        self.assertEqual("It's already closed.", str(x.exception))

        door = Door("north", hall, "Some door.")
        self.assertEqual("Some door.", door.short_description)
        self.assertEqual("Some door. It is open and unlocked.",
                         door.description)
        self.assertTrue(door.opened)
        self.assertFalse(door.locked)
        door = Door("north", hall, "Some door.",
                    "This is a peculiar door leading north.")
        self.assertEqual("Some door.", door.short_description)
        self.assertEqual(
            "This is a peculiar door leading north. It is open and unlocked.",
            door.description)
コード例 #16
0
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")
コード例 #17
0
ファイル: magnolia_st.py プロジェクト: irmen/Tale
                                      "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)
コード例 #18
0
ファイル: shoppe.py プロジェクト: zaghaghi/Tale
toothpick.value = 0.12
shopinfo.forsale.add(toothpick)  # never run out of toothpicks
shopinfo.banks_money = True
shopkeeper = ShoppeShopkeeper(
    "Lucy",
    "f",
    short_descr=
    "Lucy, the shop owner, is looking happily at her newly arrived customer.")
shopkeeper.money = 14000
shop = Shoppe("Curiosity Shoppe", "A weird little shop. It sells odd stuff.")
shop.insert(shopkeeper, None)
shop.get_wiretap().subscribe(
    shopkeeper
)  # the shopkeeper wants to act on certain things happening in her 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 = gameclock.clone()
clock.value = 500
paper = newspaper.clone()
gem2 = diamond.clone()
gem2.value = 80000
gem3 = gem.clone()
gem3.value = 9055
stick = woodenYstick.clone()
elastic = elastic_band.clone()
shopkeeper.init_inventory([gem2, gem3, toothpick, stick, elastic])
shopkeeper.set_shop(shopinfo)
コード例 #19
0
ファイル: rose_st.py プロジェクト: irmen/Tale
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)

コード例 #20
0
    def test_actions(self):
        player = Player("julie", "f")
        hall = Location("hall")
        attic = Location("attic")
        unbound_exit = Exit("random", "foo.bar", "a random exit")
        with self.assertRaises(Exception):
            self.assertFalse(unbound_exit.allow_passage(player))  # should fail because not bound
        exit1 = Exit("ladder", attic, "first ladder to attic")
        exit1.allow_passage(player)

        door = Door("north", hall, "open unlocked door", locked=False, opened=True)
        with self.assertRaises(ActionRefused) as x:
            door.open(player)  # fail, it's already open
        self.assertEqual("It's already open.", str(x.exception))
        door.close(player)
        self.assertFalse(door.opened, "must be closed")
        with self.assertRaises(ActionRefused) as x:
            door.lock(player)  # default door can't be locked
        self.assertEqual("You don't seem to have the means to lock it.", str(x.exception))
        with self.assertRaises(ActionRefused) as x:
            door.unlock(player)  # fail, it's not locked
        self.assertEqual("It's not locked.", str(x.exception))

        door = Door("north", hall, "open locked door", locked=False, opened=True)
        with self.assertRaises(ActionRefused) as x:
            door.open(player)  # fail, it's already open
        self.assertEqual("It's already open.", str(x.exception))
        door.close(player)
        door.locked = True
        with self.assertRaises(ActionRefused) as x:
            door.lock(player)  # it's already locked
        self.assertEqual("It's already locked.", str(x.exception))
        self.assertTrue(door.locked)
        with self.assertRaises(ActionRefused) as x:
            door.unlock(player)  # you can't unlock it
        self.assertEqual("You don't seem to have the means to unlock it.", str(x.exception))
        self.assertTrue(door.locked)

        door = Door("north", hall, "closed unlocked door", locked=False, opened=False)
        door.open(player)
        self.assertTrue(door.opened)
        door.close(player)
        self.assertFalse(door.opened)
        with self.assertRaises(ActionRefused) as x:
            door.close(player)  # it's already closed
        self.assertEqual("It's already closed.", str(x.exception))

        door = Door("north", hall, "closed locked door", locked=True, opened=False)
        with self.assertRaises(ActionRefused) as x:
            door.open(player)  # can't open it, it's locked
        self.assertEqual("You try to open it, but it's locked.", str(x.exception))
        with self.assertRaises(ActionRefused) as x:
            door.close(player)  # it's already closed
        self.assertEqual("It's already closed.", str(x.exception))

        door = Door("north", hall, "Some door.")
        self.assertEqual("Some door.", door.short_description)
        self.assertEqual("Some door. It is open and unlocked.", door.description)
        self.assertTrue(door.opened)
        self.assertFalse(door.locked)
        door = Door("north", hall, "Some door.", "This is a peculiar door leading north.")
        self.assertEqual("Some door.", door.short_description)
        self.assertEqual("This is a peculiar door leading north. It is open and unlocked.", door.description)
コード例 #21
0
ファイル: house.py プロジェクト: Ianax/Tale
    "key",
    "small rusty key",
    descr=
    "This key is small and rusty. It has a label attached, reading \"garden door\"."
)

rooms = {
    'livingroom':  ####### Living Room
    {
        'location': {
            'name': "Living room",
            'descr': "The living room in your home in the new testing story."
        },
        'exits': [
            Exit(directions="closet",
                 target_location="house.closet",
                 short_descr="There's a small closet in your house.",
                 long_descr=None),
        ],
        'doors': [
            Door(directions=["garden", "door"],
                 target_location="house.outside",
                 short_descr="A door leads to the garden.",
                 long_descr="There's a heavy door in this test.",
                 locked=True,
                 opened=False,
                 key_code="1"),
            Door(
                directions=["bathroom"],
                target_location="house.bathroom",
                short_descr="A door leads to the bathroom.",
                long_descr=None,
コード例 #22
0
livingroom_descr = """
    The living room in your home in the outskirts of the city."""
livingroom = Location(name="Living room", descr=livingroom_descr)
# Build Exits
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.",
コード例 #23
0

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."
コード例 #24
0
ファイル: magnolia_st.py プロジェクト: skirtap/Tale

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)
コード例 #25
0
ファイル: rose_st.py プロジェクト: skirtap/Tale
        # Normally you would use notify_player_arrived() to trigger an action.
        # 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. "
コード例 #26
0
ファイル: house_tpl.py プロジェクト: irmen/Tale

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)
コード例 #27
0
ファイル: test_mudobjects.py プロジェクト: skirtap/Tale
 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)
コード例 #28
0
ファイル: houses.py プロジェクト: zaghaghi/Tale
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({
コード例 #29
0
ファイル: wizardtower.py プロジェクト: vtbassmatt/Tale
    "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."
    ),
])
コード例 #30
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)
コード例 #31
0
ファイル: house.py プロジェクト: shawnantonucci/Tale
        # 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:
コード例 #32
0
ファイル: house.py プロジェクト: skirtap/Tale
    "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.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:
コード例 #33
0
ファイル: inn.py プロジェクト: Ianax/Tale
Their pet cat is also here and you can interact with him a little.

The generated demo code below is provided for you to use or modify as you wish.
(it creates a trivial location similar to the built-in demo story of the Tale library itself)
"""

from tale.base import Location, Exit, Door
from zones.sarah import Sarah
from zones.descriptions import room_descriptions, sarah_text

##### 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.")
コード例 #34
0
ファイル: wizardtower.py プロジェクト: irmen/Tale

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."),
])
コード例 #35
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.")])
コード例 #36
0
ファイル: house.py プロジェクト: zaghaghi/Tale
# 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))
コード例 #37
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
])
コード例 #38
0
ファイル: town.py プロジェクト: irmen/Tale
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."
    },