예제 #1
0
    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)
예제 #2
0
 def test_move(self):
     hall = Location("hall")
     person = Living("person", "m", race="human")
     monster = NPC("dragon", "f", race="dragon")
     monster.aggressive = True
     key = Item("key")
     stone = Item("stone")
     hall.init_inventory([person, key])
     stone.move(hall, person)
     wiretap = Wiretap(hall)
     self.assertTrue(person in hall)
     self.assertTrue(key in hall)
     key.contained_in = person  # hack to force move to actually check the source container
     with self.assertRaises(KeyError):
         key.move(person, person)
     key.contained_in = hall  # put it back as it was
     key.move(person, person)
     self.assertFalse(key in hall)
     self.assertTrue(key in person)
     self.assertEqual([], wiretap.msgs, "item.move() should be silent")
     with self.assertRaises(ActionRefused) as x:
         key.move(monster, person)  # aggressive monster should fail
     self.assertTrue("not a good idea" in str(x.exception))
     monster.aggressive = False
     key.move(monster, person)  # non-aggressive should be ok
예제 #3
0
 def test_move(self):
     hall = Location("hall")
     person = Living("person", "m", race="human")
     monster = NPC("dragon", "f", race="dragon")
     monster.aggressive = True
     key = Item("key")
     stone = Item("stone")
     hall.init_inventory([person, key])
     stone.move(hall, person)
     wiretap = Wiretap(hall)
     self.assertTrue(person in hall)
     self.assertTrue(key in hall)
     key.contained_in = person   # hack to force move to actually check the source container
     with self.assertRaises(KeyError):
         key.move(person, person)
     key.contained_in = hall   # put it back as it was
     key.move(person, person)
     self.assertFalse(key in hall)
     self.assertTrue(key in person)
     self.assertEqual([], wiretap.msgs, "item.move() should be silent")
     with self.assertRaises(ActionRefused) as x:
         key.move(monster, person)  # aggressive monster should fail
     self.assertTrue("not a good idea" in str(x.exception))
     monster.aggressive = False
     key.move(monster, person)   # non-aggressive should be ok
예제 #4
0
파일: npcs.py 프로젝트: irmen/Tale
 def do_buy_pills(self, actor: Living, pills: Item, price: float) -> None:
     if actor.money < price:
         raise ActionRefused("You don't have enough money!")
     actor.money -= price
     self.money += price
     pills.move(actor, self)
     price_str = mud_context.driver.moneyfmt.display(price)
     actor.tell("After handing %s the %s, %s gives you the %s." % (self.objective, price_str, self.subjective, pills.title))
     self.tell_others("{Actor} says: \"Here's your medicine, now get out of here!\"")
예제 #5
0
파일: npcs.py 프로젝트: shawnantonucci/Tale
 def do_buy_ammo(self, actor: Living, ammo: Item, price: float) -> None:
     if actor.money < price:
         raise ActionRefused("You don't have enough money!")
     actor.money -= price
     self.money += price
     ammo.move(actor, self)
     price_str = mud_context.driver.moneyfmt.display(price)
     actor.tell("After handing %s the %s, %s gives you the %s." % (self.objective, price_str, self.subjective, ammo.title))
     self.tell_others("{Actor} says: \"Here's your ammo, now get out of here!\"")
예제 #6
0
 def test_title(self):
     bag = Container("bag", "leather bag", "a small leather bag")
     stone = Item("stone")
     player = Player("julie", "f")
     self.assertEqual("bag", bag.name)
     self.assertEqual("leather bag", bag.title)
     self.assertEqual("a small leather bag", bag.description)
     bag.move(player, player)
     self.assertEqual("bag", bag.name)
     self.assertEqual("leather bag", strip_text_styles(bag.title))
     self.assertEqual("a small leather bag", strip_text_styles(bag.description))
     stone.move(bag, player)
     self.assertEqual("bag", bag.name)
     self.assertEqual("leather bag", strip_text_styles(bag.title))
     self.assertEqual("a small leather bag", strip_text_styles(bag.description))
예제 #7
0
 def test_title(self):
     bag = Container("bag", "leather bag", "a small leather bag")
     stone = Item("stone")
     player = Player("julie", "f")
     self.assertEqual("bag", bag.name)
     self.assertEqual("leather bag", bag.title)
     self.assertEqual("a small leather bag", bag.description)
     bag.move(player, player)
     self.assertEqual("bag", bag.name)
     self.assertEqual("leather bag", strip_text_styles(bag.title))
     self.assertEqual("a small leather bag",
                      strip_text_styles(bag.description))
     stone.move(bag, player)
     self.assertEqual("bag", bag.name)
     self.assertEqual("leather bag", strip_text_styles(bag.title))
     self.assertEqual("a small leather bag",
                      strip_text_styles(bag.description))
예제 #8
0
 def test_with_key(self):
     player = Player("julie", "f")
     key = Item("key", "door key")
     key.door_code = 12345
     hall = Location("hall")
     door = Door("north", hall, "a locked door", locked=True, opened=False)
     with self.assertRaises(ActionRefused):
         door.unlock(player)
     with self.assertRaises(ActionRefused):
         door.unlock(player, key)
     door.door_code = 12345
     self.assertTrue(door.locked)
     door.unlock(player, key)
     self.assertFalse(door.locked)
     door.locked = True
     with self.assertRaises(ActionRefused):
         door.unlock(player)
     key.move(player, player)
     door.unlock(player)
     self.assertFalse(door.locked)
     door.lock(player)
     self.assertTrue(door.locked)
예제 #9
0
 def test_location(self):
     thingy = Item("thing")
     with self.assertRaises(TypeError):
         thingy.location = "foobar"
     hall = Location("hall")
     thingy.location = hall
     self.assertEqual(hall, thingy.contained_in)
     self.assertEqual(hall, thingy.location)
     person = Living("person", "m", race="human")
     key = Item("key")
     backpack = Container("backpack")
     person.insert(backpack, person)
     self.assertIsNone(key.contained_in)
     self.assertIsNone(key.location)
     self.assertTrue(backpack in person)
     self.assertEqual(person, backpack.contained_in)
     self.assertEqual(_limbo, backpack.location)
     hall.init_inventory([person, key])
     self.assertEqual(hall, key.contained_in)
     self.assertEqual(hall, key.location)
     self.assertEqual(hall, backpack.location)
     key.move(backpack, person)
     self.assertEqual(backpack, key.contained_in)
     self.assertEqual(hall, key.location)
예제 #10
0
 def test_location(self):
     thingy = Item("thing")
     with self.assertRaises(TypeError):
         thingy.location = "foobar"
     hall = Location("hall")
     thingy.location = hall
     self.assertEqual(hall, thingy.contained_in)
     self.assertEqual(hall, thingy.location)
     person = Living("person", "m", race="human")
     key = Item("key")
     backpack = Container("backpack")
     person.insert(backpack, person)
     self.assertIsNone(key.contained_in)
     self.assertIsNone(key.location)
     self.assertTrue(backpack in person)
     self.assertEqual(person, backpack.contained_in)
     self.assertEqual(_Limbo, backpack.location)
     hall.init_inventory([person, key])
     self.assertEqual(hall, key.contained_in)
     self.assertEqual(hall, key.location)
     self.assertEqual(hall, backpack.location)
     key.move(backpack, person)
     self.assertEqual(backpack, key.contained_in)
     self.assertEqual(hall, key.location)