Esempio n. 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()))
Esempio n. 2
0
 def test_container_contains(self):
     bag = Container("bag")
     key = Item("key")
     self.assertEqual(0, len(bag.inventory))
     self.assertEqual(0, bag.inventory_size)
     npc = NPC("julie", "f")
     bag.insert(key, npc)
     self.assertTrue(key in bag)
     self.assertEqual(1, bag.inventory_size)
     bag.remove(key, npc)
     self.assertEqual(0, bag.inventory_size)
     self.assertFalse(key in bag)
     with self.assertRaises(KeyError):
         bag.remove("not_existing", npc)
Esempio n. 3
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))
Esempio n. 4
0
 def test_allowance(self):
     bag = Container("bag")
     key = Item("key")
     player = Player("julie", "f")
     with self.assertRaises(Exception):
         bag.insert(None, player)
     bag.insert(key, player)
     with self.assertRaises(KeyError):
         bag.remove(None, player)
     bag.remove(key, player)
     bag.allow_item_move(player)
     with self.assertRaises(ActionRefused):
         key.insert(bag, player)
     with self.assertRaises(ActionRefused):
         key.remove(bag, player)
     self.assertFalse(key in bag)
     with self.assertRaises(ActionRefused):
         bag in key
Esempio n. 5
0
 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
     ])
Esempio n. 6
0
 def test_inventory(self):
     bag = Container("bag")
     key = Item("key")
     thing = Item("gizmo")
     player = Player("julie", "f")
     with self.assertRaises(ActionRefused):
         thing in key  # can't check for containment in an Item
     self.assertFalse(thing in bag)
     with self.assertRaises(ActionRefused):
         key.insert(thing, player)  # can't add stuf to an Item
     bag.insert(thing, player)
     self.assertTrue(thing in bag)
     self.assertTrue(isinstance(bag.inventory, (set, frozenset)))
     self.assertEqual(1, bag.inventory_size)
     with self.assertRaises(AttributeError):
         bag.inventory_size = 5
     with self.assertRaises(AttributeError):
         bag.inventory = None
     with self.assertRaises(AttributeError):
         bag.inventory.add(5)
Esempio n. 7
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)
Esempio n. 8
0
def make_item(vnum):
    """Create an instance of an item for the given vnum"""
    c_obj = objs[vnum]
    aliases = list(c_obj.aliases)
    name = aliases[0]
    aliases = set(aliases[1:])
    title = c_obj.shortdesc
    if title.startswith("the ") or title.startswith("The "):
        title = title[4:]
    if title.startswith("a ") or title.startswith("A "):
        title = title[2:]
    if vnum in circle_bulletin_boards:
        # it's a bulletin board
        item = BulletinBoard(name, title, short_description=c_obj.longdesc)
        item.storage_file = circle_bulletin_boards[
            vnum]  # note that some instances reuse the same board
        item.load()
        # remove the item name from the extradesc
        c_obj.extradesc = [
            ed for ed in c_obj.extradesc if item.name not in ed["keywords"]
        ]
    elif c_obj.type == "container":
        if c_obj.typespecific.get("closeable"):
            item = Boxlike(name, title, short_description=c_obj.longdesc)
            item.opened = True
            if "closed" in c_obj.typespecific:
                item.opened = not c_obj.typespecific["closed"]
        else:
            item = Container(name, title, short_description=c_obj.longdesc)
    elif c_obj.type == "weapon":
        item = Weapon(name, title, short_description=c_obj.longdesc)
        # @todo weapon attrs
    elif c_obj.type == "armor":
        item = Armour(name, title, short_description=c_obj.longdesc)
        # @todo armour attrs
    elif c_obj.type == "key":
        item = Key(name, title, short_description=c_obj.longdesc)
        item.key_for(code=vnum)  # the key code is just the item's vnum
    elif c_obj.type == "note":  # doesn't yet occur in the obj files though
        item = Note(name, title, short_description=c_obj.longdesc)
    elif c_obj.type == "food":
        item = Food(name, title, short_description=c_obj.longdesc)
        item.affect_fullness = c_obj.typespecific["filling"]
        item.poisoned = c_obj.typespecific.get("ispoisoned", False)
    elif c_obj.type == "light":
        item = Light(name, title, short_description=c_obj.longdesc)
        item.capacity = c_obj.typespecific["capacity"]
    elif c_obj.type == "scroll":
        item = Scroll(name, title, short_description=c_obj.longdesc)
        item.spell_level = c_obj.typespecific["level"]
        item.spells.add(c_obj.typespecific["spell1"])
        if "spell2" in c_obj.typespecific:
            item.spells.add(c_obj.typespecific["spell2"])
        if "spell3" in c_obj.typespecific:
            item.spells.add(c_obj.typespecific["spell3"])
    elif c_obj.type in ("staff", "wand"):
        item = MagicItem(name, title, short_description=c_obj.longdesc)
        item.level = c_obj.typespecific["level"]
        item.capacity = c_obj.typespecific["capacity"]
        item.remaining = c_obj.typespecific["remaining"]
        item.spell = c_obj.typespecific["spell"]
    elif c_obj.type == "trash":
        item = Trash(name, title, short_description=c_obj.longdesc)
    elif c_obj.type == "drinkcontainer":
        item = Drink(name, title, short_description=c_obj.longdesc)
        item.capacity = c_obj.typespecific["capacity"]
        item.quantity = c_obj.typespecific["remaining"]
        item.contents = c_obj.typespecific["drinktype"]
        drinktype = Drink.drinktypes[item.contents]
        item.affect_drunkness = drinktype.drunkness
        item.affect_fullness = drinktype.fullness
        item.affect_thirst = drinktype.thirst
        item.poisoned = c_obj.typespecific.get("ispoisoned", False)
    elif c_obj.type == "potion":
        item = Potion(name, title, short_description=c_obj.longdesc)
        item.spell_level = c_obj.typespecific["level"]
        item.spells.add(c_obj.typespecific["spell1"])
        if "spell2" in c_obj.typespecific:
            item.spells.add(c_obj.typespecific["spell2"])
        if "spell3" in c_obj.typespecific:
            item.spells.add(c_obj.typespecific["spell3"])
    elif c_obj.type == "money":
        item = Money(name, title, short_description=c_obj.longdesc)
        item.value = c_obj.typespecific["amount"]
    elif c_obj.type == "boat":
        item = Boat(name, title, short_description=c_obj.longdesc)
    elif c_obj.type == "worn":
        item = Wearable(name, title, short_description=c_obj.longdesc)
        # @todo worn attrs
    elif c_obj.type == "fountain":
        item = Fountain(name, title, short_description=c_obj.longdesc)
        item.capacity = c_obj.typespecific["capacity"]
        item.quantity = c_obj.typespecific["remaining"]
        item.contents = c_obj.typespecific["drinktype"]
        item.poisoned = c_obj.typespecific.get("ispoisoned", False)
    elif c_obj.type in ("treasure", "other"):
        item = Item(name, title, short_description=c_obj.longdesc)
    else:
        raise ValueError("invalid obj type: " + c_obj.type)
    for ed in c_obj.extradesc:
        item.add_extradesc(ed["keywords"], ed["text"])
    item.vnum = vnum  # keep the vnum
    item.aliases = aliases
    item.value = c_obj.cost
    item.rent = c_obj.rent
    item.weight = c_obj.weight
    # @todo: affects, effects, wear
    converted_items.add(vnum)
    return item