示例#1
0
 def test_print_location(self):
     p = Player("julie", "f")
     key = Item("key")
     bag = Container("bag")
     room = Location("room")
     bag.insert(key, p)
     p.insert(bag, p)
     room.insert(p, p)
     with self.assertRaises(Exception):
         p.tell_object_location(None, None)
     p.tell_object_location(key, None)
     self.assertEqual(["(It's not clear where key is).\n"],
                      p.test_get_output_paragraphs())
     p.tell_object_location(key, None, print_parentheses=False)
     self.assertEqual(["It's not clear where key is.\n"],
                      p.test_get_output_paragraphs())
     p.tell_object_location(key, bag)
     result = "".join(p.test_get_output_paragraphs())
     self.assertTrue("in bag" in result and "in your inventory" in result)
     p.tell_object_location(key, room)
     self.assertTrue("in your current location" in "".join(
         p.test_get_output_paragraphs()))
     p.tell_object_location(bag, p)
     self.assertTrue(
         "in your inventory" in "".join(p.test_get_output_paragraphs()))
     p.tell_object_location(p, room)
     self.assertTrue("in your current location" in "".join(
         p.test_get_output_paragraphs()))
示例#2
0
 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)
示例#3
0
 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)
示例#4
0
文件: test_util.py 项目: irmen/Tale
 def test_print_location(self):
     p = Player("julie", "f")
     key = Item("key")
     bag = Container("bag")
     room = Location("room")
     bag.insert(key, p)
     p.insert(bag, p)
     room.insert(p, p)
     with self.assertRaises(Exception):
         p.tell_object_location(None, None)
     p.tell_object_location(key, None)
     self.assertEqual(["(It's not clear where key is).\n"], p.test_get_output_paragraphs())
     p.tell_object_location(key, None, print_parentheses=False)
     self.assertEqual(["It's not clear where key is.\n"], p.test_get_output_paragraphs())
     p.tell_object_location(key, bag)
     result = "".join(p.test_get_output_paragraphs())
     self.assertTrue("in bag" in result and "in your inventory" in result)
     p.tell_object_location(key, room)
     self.assertTrue("in your current location" in "".join(p.test_get_output_paragraphs()))
     p.tell_object_location(bag, p)
     self.assertTrue("in your inventory" in "".join(p.test_get_output_paragraphs()))
     p.tell_object_location(p, room)
     self.assertTrue("in your current location" in "".join(p.test_get_output_paragraphs()))
示例#5
0
文件: inn.py 项目: Ianax/Tale
sitting_foyer = Exit(
    directions=["foyer", "south"],
    target_location="inn.foyer",
    short_descr="The foyer is to the south.",
    long_descr=None,
)
sitting_dining = Exit(
    directions=["east", "dining"],
    target_location="inn.dining_room",
    short_descr="There appears to be a dinning room to the east.",
    long_descr="To the east you see a room with tables set to eat.",
)

sitting_room.add_exits([sitting_foyer, sitting_dining])

sarah = Sarah(name="Sarah", gender="f", descr=sarah_text['description'])
sitting_room.insert(sarah, None)

##### Dinning Room #####

dining_room = Location("Dining Room", room_descriptions['dining_room'])

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

dining_room.add_exits([dining_sitting])
示例#6
0
# 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))
        driver.defer(random.randint(5, 20), self, self.do_purr)

    def notify_action(self, parsed, actor):
        if parsed.verb in ("pet", "stroke", "tickle", "cuddle", "hug"):
            self.tell_others("{Title} curls up in a ball and purrs contently.")
        elif parsed.verb in ("hello", "hi", "greet"):
            self.tell_others("{Title} stares at you incomprehensibly.")
        else:
            message = (parsed.message or parsed.unparsed).lower()
            if self.name in message:
                self.tell_others("{Title} looks up at you.")


cat = Cat("garfield", "m", race="cat", description="A very obese cat, orange and black. It looks tired, but glances at you happily.")
livingroom.insert(cat, None)
key = Item("key", "small rusty key", "This key is small and rusty. It has a label attached, reading \"garden door\".")
key.door_code = 1
closet.insert(key, None)
示例#7
0
文件: rose_st.py 项目: irmen/Tale
                  short_descr="On the ground is a key, it's become quite rusty.")
parking_key.key_for(parking_gate)
parking_key.add_extradesc({"label"}, "The label says: `parking area gate'.")


class StorageRoom(Location):
    @call_periodically(5.0, 20.0)
    def shiver_from_cold(self, ctx: Context) -> None:
        # it's cold in the storage room, it makes people shiver
        if self.livings:
            living = random.choice(list(self.livings))
            living.do_socialize("shiver")


butcher = Location("Butcher shop", "The town's butcher shop. Usually there's quite a few people waiting in line, but now it is deserted.")
butcher.insert(parking_key, None)
Exit.connect(butcher, ["north", "street"], "Rose street is back to the north.", None,
             south_street, ["south", "butcher"], "The butcher shop is to the south.", None)

storage_room = StorageRoom("Storage room", "The butcher's meat storage room. Brrrrr, it is cold here!")

storage_room_door, _ = Door.connect(butcher, ["door", "storage"],
                                    "A door leads to the storage room.",
                                    "The meat storage is behind it. The door's locked with a security card instead of a key.",
                                    storage_room, ["door", "shop"], "The door leads back to the shop.", None,
                                    locked=True, key_code="butcher1")

friend = zones.npcs.Friend("Peter", "m", descr="It's your friend Peter, who works at the butcher shop.")
storage_room.insert(friend, None)

butcher_key = Key("card", "security card", descr="It is a security card, with a single word `storage' written on it.")
示例#8
0
文件: house.py 项目: zaghaghi/Tale
            self.tell_others("{Actor} stares at {target} incomprehensibly.",
                             target=actor)
        else:
            message = (parsed.message or parsed.unparsed).lower().split()
            if self.name in message or "cat" in message:
                self.tell_others(
                    "{Actor} looks up at {target} and wiggles %s tail." %
                    self.possessive,
                    target=actor)


cat = Cat(
    "garfield",
    "m",
    race="cat",
    descr=
    "A very obese cat, orange and black. It looks tired, but glances at you happily."
)
livingroom.insert(cat, None)
key = Key(
    "key",
    "small rusty key",
    descr=
    "This key is small and rusty. It has a label attached, reading \"garden door\"."
)
key.key_for(door)
closet.insert(key, None)

closet.insert(woodenYstick.clone(), None)
livingroom.insert(elastic_band.clone(), None)
示例#9
0
    "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
medicine.aliases = {"bottle", "medicine"}
apothecary.init_inventory([medicine])
pharmacy.insert(apothecary, None)
示例#10
0
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:
            self.location.tell("%s flys around the room." % capital(self.title))
        # it's possible to stop the periodical calling by setting:  call_periodically(0)(Cat.do_purr)

    def notify_action(self, parsed: ParseResult, actor: Living) -> None:
        if actor is self or parsed.verb in self.verbs:
            return  # avoid reacting to ourselves, or reacting to verbs we already have a handler for
        if parsed.verb in ("pet", "stroke", "tickle", "cuddle", "caress", "rub"):
            self.tell_others("{Actor} Gets excited and dances around chirping.")
        elif parsed.verb in AGGRESSIVE_VERBS:
            if self in parsed.who_info:   # only give aggressive response when directed at the cat.
                self.tell_others("{Actor} latches onto you and bites you. He backs away from you." % self.objective)
        elif parsed.verb in ("hello", "hi", "greet", "chirp"):
            self.tell_others("{Actor} stares at {target} incomprehensibly.", target=actor)
        else:
            message = (parsed.message or parsed.unparsed).lower().split()
            if self.name in message or "bird" in message:
                self.tell_others("{Actor} looks up at {target} and tilts %s tail." % self.possessive, target=actor)


bird = Bird("Parakeet", "m", race="bird", descr="A small bird flapping around the room.")
livingroom.insert(bird, None)
示例#11
0
文件: house_tpl.py 项目: irmen/Tale
        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)

    def notify_action(self, parsed: ParseResult, actor: Living) -> None:
        if actor is self or parsed.verb in self.verbs:
            return  # avoid reacting to ourselves, or reacting to verbs we already have a handler for
        if parsed.verb in ("pet", "stroke", "tickle", "cuddle", "hug", "caress", "rub"):
            self.tell_others("{Actor} curls up in a ball and purrs contently.")
        elif parsed.verb in AGGRESSIVE_VERBS:
            if self in parsed.who_info:   # only give aggressive response when directed at the cat.
                self.tell_others("{Actor} hisses! I wouldn't make %s angry if I were you!" % self.objective)
        elif parsed.verb in ("hello", "hi", "greet", "meow", "purr"):
            self.tell_others("{Actor} stares at {target} incomprehensibly.", target=actor)
        else:
            message = (parsed.message or parsed.unparsed).lower().split()
            if self.name in message or "cat" in message:
                self.tell_others("{Actor} looks up at {target} and wiggles %s tail." % self.possessive, target=actor)


cat = Cat("garfield", "m", race="cat", descr="A very obese cat, orange and black. It looks tired, but glances at you happily.")
livingroom.insert(cat, None)
key = Key("key", "small rusty key", descr="This key is small and rusty. It has a label attached, reading \"garden door\".")
key.key_for(door)
closet.insert(key, None)

closet.insert(woodenYstick.clone(), None)
livingroom.insert(elastic_band.clone(), None)
示例#12
0
文件: magnolia_st.py 项目: irmen/Tale
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
medicine.aliases = {"bottle", "medicine"}
apothecary.init_inventory([medicine])
pharmacy.insert(apothecary, None)
示例#13
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)
示例#14
0
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")

# ammo
ammo = Item("ammo",
            "5 pistol bullets",
            descr="It looks like the ammo for your gun.")
ammo.value = Trader.ammo_price
ammo.aliases = {"bullets", "ammo"}
trader.init_inventory([ammo])
deli.insert(trader, None)
示例#15
0
文件: house.py 项目: skirtap/Tale
            self.location.tell("%s purrs happily." % capital(self.title))
        else:
            self.location.tell("%s yawns sleepily." % capital(self.title))
        ctx.driver.defer(random.randint(5, 20), self.do_purr)

    def notify_action(self, parsed, actor):
        if parsed.verb in ("pet", "stroke", "tickle", "cuddle", "hug"):
            self.tell_others("{Title} curls up in a ball and purrs contently.")
        elif parsed.verb in ("hello", "hi", "greet"):
            self.tell_others("{Title} stares at you incomprehensibly.")
        else:
            message = (parsed.message or parsed.unparsed).lower()
            if self.name in message:
                self.tell_others("{Title} looks up at you.")


cat = Cat(
    "garfield",
    "m",
    race="cat",
    description=
    "A very obese cat, orange and black. It looks tired, but glances at you happily."
)
livingroom.insert(cat, None)
key = Key(
    "key", "small rusty key",
    "This key is small and rusty. It has a label attached, reading \"garden door\"."
)
key.key_for(door)
closet.insert(key, None)
示例#16
0
                  short_descr="On the ground is a key, it's become quite rusty.")
parking_key.key_for(parking_gate)
parking_key.add_extradesc({"label"}, "The label says: `parking area gate'.")


class StorageRoom(Location):
    @call_periodically(5.0, 20.0)
    def shiver_from_cold(self, ctx: Context) -> None:
        # it's cold in the storage room, it makes people shiver
        if self.livings:
            living = random.choice(list(self.livings))
            living.do_socialize("shiver")


butcher = Location("Butcher shop", "The town's butcher shop. Usually there's quite a few people waiting in line, but now it is deserted.")
butcher.insert(parking_key, None)
Exit.connect(butcher, ["north", "street"], "Rose street is back to the north.", None,
             south_street, ["south", "butcher"], "The butcher shop is to the south.", None)

storage_room = StorageRoom("Storage room", "The butcher's meat storage room. Brrrrr, it is cold here!")

storage_room_door, _ = Door.connect(butcher, ["door", "storage"],
    "A door leads to the storage room.", "The meat storage is behind it. The door's locked with a security card instead of a key.",
    storage_room, ["door", "shop"],
    "The door leads back to the shop.", None,
    locked=True, key_code="butcher1")

friend = zones.npcs.Friend("Peter", "m", descr="It's your friend Peter, who works at the butcher shop.")
storage_room.insert(friend, None)

butcher_key = Key("card", "security card", descr="It is a security card, with a single word `storage' written on it.")
示例#17
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)