Beispiel #1
0
	def setup_items(self):
		self.book = self.book = Item(1043, 0x2, Labels("book", "a book", "a book of fairytales"), 2, "The Pied Piper", {})
		self.bread = Item(1109, 0x2, Labels("bread", "some bread", "a loaf of bread"), 2, None, {})
		self.items_by_id = {
			1043 : self.book,
			1044 : self.bread,
		}
Beispiel #2
0
	def setup_locations(self):
		self.lighthouse_location = Location(12, 0x1, Labels("Lighthouse", "at a lighthouse", " by the sea."))
		self.beach_location = Location(13, 0x1, Labels("Beach", "on a beach", " of black sand"))
		self.locations_by_id = {
			12 : self.lighthouse_location,
			13 : self.beach_location,
		}
	def setup_locations(self):
		self.initial_location = Location(9, 0x1, Labels("Lighthouse", "at a lighthouse", " by the sea."))
		self.beach_location = Location(13, 0x1, Labels("Beach", "on a beach", " of black sand"))
		self.data.get_location.side_effect = lambda x: {
			9 : self.initial_location,
			13 : self.beach_location,
		}.get(x)
Beispiel #4
0
    def setUp(self):

        self.inventory = Inventory(
            0, 0x1,
            Labels("Main Inventory", "in the main inventory",
                   ", where items live usually."), 3)
        self.book = Item(1105, 0x2,
                         Labels("book", "a book", "a book of fairytales"), 2,
                         "The Pied Piper", {})
        self.lamp = Item(1043, 0x10101A,
                         Labels("lamp", "a lamp", "a small lamp"), 2, None, {})
        self.coin = Item(1000, 0x2, Labels("coin", "a coin", "a silver coin"),
                         1, None, {})
        self.medal = Item(1001, 0x2, Labels("medal", "a medal",
                                            "a gold medal"), 1, None, {})
        self.suit = UsableItem(1046, 0x402,
                               Labels("suit", "a suit", "a space-suit"), 2,
                               None, {}, Item.ATTRIBUTE_GIVES_AIR)
        self.water = Item(1109, 0x22902,
                          Labels("water", "some water", "some water"), 1, None,
                          {})
        self.basket = ContainerItem(
            1107, 0x3, Labels("basket", "a basket", "a large basket"), 6, None,
            {})
        self.non_essential_drop_location = Location(
            12, 0x1, Labels("Lighthouse", "at a lighthouse", " by the sea."))
        self.essential_drop_location = Location(
            9, 0x0, Labels("Cave", "in a cave", ". It is dark"))
 def setup_locations(self):
     self.lighthouse_location = Location(
         12, 0x603, Labels("Lighthouse", "at a lighthouse", " by the sea."))
     self.beach_location = Location(
         13, 0x603, Labels("Beach", "on a beach", " of black sand"))
     self.locations_by_id = {}
     self.locations_by_id[12] = self.lighthouse_location
     self.locations_by_id[13] = self.beach_location
     self.location_collection = LocationCollection(self.locations_by_id)
	def setup_inventories(self):
		default_labels = Labels("Main Inventory", "in the main inventory", ", where items live usually.")
		self.default_inventory_template = Inventory(0, 0x1, default_labels, 13)
		non_default_labels = Labels("Special Inventory", "in the special inventory", ", where items live sometimes.")
		self.non_default_inventory_template = Inventory(1, 0x0, non_default_labels, 8, [37, 38, 39])

		self.data.get_inventory_template.side_effect = lambda x: {
			0 : self.default_inventory_template,
			1 : self.non_default_inventory_template,
		}.get(x)

		self.data.get_inventory_templates.return_value = [self.default_inventory_template, self.non_default_inventory_template]
	def setup_items(self):
		self.book = Item(1105, 0x2, Labels("book", "a book", "a book of fairytales"), 2, "The Pied Piper", {})
		self.box = ContainerItem(1106, 0x3, Labels("box", "a box", "a small box"), 3, None, {})
		lamp_switching_info = SwitchInfo(Item.ATTRIBUTE_GIVES_LIGHT, "off", "on")
		self.lamp = SwitchableItem(1043, 0x101A, Labels("lamp", "a lamp", "a small lamp"), 2, None, {}, lamp_switching_info)
		self.salt = Item(1110, 0x102, Labels("salt", "some salt", "some salt"), 1, None, {})

		self.data.get_item_list_by_name.side_effect = lambda x: {
			"book" : [self.book],
			"box" : [self.box],
			"lamp" : [self.lamp],
			"salt" : [self.salt],
		}.get(x)
Beispiel #8
0
 def setup_locations(self):
     self.beach_location = Location(
         13, 0x1, Labels("Beach", "on a beach", " of black sand"))
     self.cave_location = Location(
         9, 0x0, Labels("Cave", "in a cave", ". It is dark"))
     self.lighthouse_location = Location(
         12, 0x1, Labels("Lighthouse", "at a lighthouse", " by the sea."))
     self.mine_location = Location(
         11, 0x0,
         Labels("Mines", "in the mines",
                ". There are dark passages everywhere."))
     self.sun_location = Location(
         10, 0x11, Labels("Sun", "in the sun", ". It is hot."))
Beispiel #9
0
 def setUp(self):
     self.lighthouse_location = Location(
         12, 0x603, Labels("Lighthouse", "at a lighthouse", " by the sea."))
     self.beach_location = Location(
         13, 0x603, Labels("Beach", "on a beach", " of black sand"))
     self.cave_location = Location(
         9, 0x402, Labels("Cave", "in a cave", ". It is dark"))
     self.inventory = Inventory(
         0, 0x1,
         Labels("Main Inventory", "in the main inventory",
                ", where items live usually."), 13)
     self.player = Player(1, 0x3, self.lighthouse_location,
                          self.cave_location, self.beach_location,
                          self.cave_location, self.inventory)
 def setup_inventories(self):
     self.inventories_by_id = {}
     self.inventories_by_id[0] = Inventory(
         0, 0x1,
         Labels("Main Inventory", "in the main inventory",
                ", where items live usually."), 3)
     self.inventory_collection = InventoryCollection(self.inventories_by_id)
 def setup_items(self):
     self.bean = Item(1003, 0x2, Labels("bean", "a bean", "a magic bean"),
                      2, None, {})
     self.bottle = ContainerItem(
         1108, 0x203, Labels("bottle", "a bottle", "a small bottle"), 3,
         None, {})
     lamp_switching_info = SwitchInfo(Item.ATTRIBUTE_GIVES_LIGHT, "off",
                                      "on")
     self.lamp = SwitchableItem(1043, 0x101A,
                                Labels("lamp", "a lamp", "a small lamp"), 2,
                                None, {}, lamp_switching_info)
     self.potion = Item(
         1058, 0x800, Labels("potion", "some potion",
                             "some magical potion"), 1, None, {})
     self.wand = Item(1203, 0x2, Labels("wand", "a wand", "a magical wand"),
                      2, None, {})
Beispiel #12
0
	def setUp(self):
		extended_descriptions = [". The walls are dark and cold", ". The walls are glowing"]
		self.lighthouse_location = Location(12, 0x1, Labels("Lighthouse", "at a lighthouse", " by the sea."))
		self.mine_location = Location(11, 0x0, Labels("Mines", "in the mines", ". There are dark passages everywhere", extended_descriptions))
		self.lower_mine_location = Location(10, 0x200, Labels("Lower mines", "in the lower mines", ". This is the bottom of the mines", extended_descriptions))

		self.book = Item(1105, 2, Labels("book", "a book", "a book of fairytales"), 2, "The Pied Piper", {})
		self.desk = Item(1000, 0x20000, Labels("desk", "a desk", "a large mahogany desk"), 6, None, {})
		self.obstruction = Item(1000, 0x4, Labels("obstruction", "an obstruction", "an obstruction blocking you"), 8, None, {})
		self.basket = ContainerItem(1107, 0x3, Labels("basket", "a basket", "a large basket"), 6, None, {})
		self.box = ContainerItem(1108, 0x3, Labels("box", "a box", "a small box"), 3, None, {})
    def test_validate_inventory_non_default_shared_location(self):
        self.inventories_by_id[1] = Inventory(
            1, 0x0,
            Labels("Special Inventory", "in the special inventory",
                   ", where items live sometimes."), 3, [12])
        self.inventories_by_id[2] = Inventory(
            2, 0x0,
            Labels("Occasional Inventory", "in the occasional inventory",
                   ", where items live occasionally."), 3, [12])

        validation = self.validator.validate(self.data_collection)

        self.assertEqual(3, len(self.inventories_by_id))
        self.assertEqual(1, len(validation))
        validation_line = validation[0]
        self.assertEqual(
            "Non-default inventory {0} \"{1}\" references location with id {2}, but this location is referenced by at least one other inventory.",
            validation_line.template)
        self.assertEqual(Severity.ERROR, validation_line.severity)
        self.assertEqual((2, "Occasional Inventory", 12), validation_line.args)
Beispiel #14
0
    def test_run_item_args(self):
        resolver_functions = [
            self.arg_function_non_movement, self.vision_function,
            self.handler_function
        ]
        command_non_movement = Command(1, 0x9, 0x0, resolver_functions, [""],
                                       {})
        book = Item(1105, 2, Labels("book", "a book", "a book of fairytales"),
                    2, "The Pied Piper", {})

        result = self.runner.run(command_non_movement, None, [book])

        self.assertEqual("Action \"book\" successful.", result)
    def test_validate_item_below_min_size_negative(self):
        self.items_by_id[1111] = Item(
            1111, 0x2, Labels("pebble", "a pebble", "a small pebble"), -6,
            None, {}, None)

        validation = self.validator.validate(self.data_collection)

        self.assertEqual(1, len(validation))
        validation_line = validation[0]
        self.assertEqual(
            "Item {0} \"{1}\" has a size of {2}. The minimum possible is {3}.",
            validation_line.template)
        self.assertEqual(Severity.ERROR, validation_line.severity)
        self.assertEqual((1111, "pebble", -6, 1), validation_line.args)
Beispiel #16
0
    def parse_labels(self, item_input, validation, item_id):
        label_input = item_input["labels"]
        shortnames = label_input["shortnames"]
        extended_descriptions = label_input.get("extended_descriptions", [])

        primary_shortname = None
        if shortnames:
            primary_shortname = shortnames[0]
        else:
            validation.append(Message(Message.ITEM_NO_SHORTNAMES, (item_id, )))

        return Labels(primary_shortname, label_input["longname"],
                      label_input["description"],
                      extended_descriptions), shortnames
    def test_validate_item_usable_no_list_template_using(self):
        self.items_by_id[1118] = UsableItem(
            1118, 0x10002, Labels("raft", "a raft", "a rickety raft"), 6, None,
            {}, Item.ATTRIBUTE_GIVES_LAND)

        validation = self.validator.validate(self.data_collection)

        self.assertEqual(1, len(validation))
        validation_line = validation[0]
        self.assertEqual(
            "Mandatory list template \"using\" not found for usable item {0} \"{1}\".",
            validation_line.template)
        self.assertEqual(Severity.ERROR, validation_line.severity)
        self.assertEqual((1118, "raft"), validation_line.args)
    def test_validate_item_fragile_no_smash_command(self):
        self.items_by_id[1017] = Item(
            1017, 0xC203, Labels("vial", "a vial", "a small glass vial"), 2,
            None, {}, None)

        validation = self.validator.validate(self.data_collection)

        self.assertEqual(1, len(validation))
        validation_line = validation[0]
        self.assertEqual(
            "Fragile item(s) found, but no command specified with the handler \"smash\".",
            validation_line.template)
        self.assertEqual(Severity.ERROR, validation_line.severity)
        self.assertEqual((), validation_line.args)
    def test_validate_item_usable_liquid(self):
        self.items_by_id[1118] = UsableItem(
            1118, 0x10102, Labels("raft", "a raft", "a rickety raft"), 6, None,
            {ListTemplateType.USING, "(sailing) {0}"},
            Item.ATTRIBUTE_GIVES_LAND)

        validation = self.validator.validate(self.data_collection)

        self.assertEqual(1, len(validation))
        validation_line = validation[0]
        self.assertEqual("Usable item {0} \"{1}\" is marked as liquid.",
                         validation_line.template)
        self.assertEqual(Severity.ERROR, validation_line.severity)
        self.assertEqual((1118, "raft"), validation_line.args)
    def test_validate_location_no_floor_no_down(self):
        self.locations_by_id[17] = Location(
            17, 0x50F,
            Labels("Precipice", "on a precipice", ", high in the air"))

        validation = self.validator.validate(self.data_collection)

        self.assertEqual(1, len(validation))
        validation_line = validation[0]
        self.assertEqual(
            "Location {0} has no floor, but does not specify a link in direction {1}.",
            validation_line.template)
        self.assertEqual(Severity.ERROR, validation_line.severity)
        self.assertEqual((17, "DOWN"), validation_line.args)
    def test_validate_item_container_below_min_size(self):
        self.items_by_id[1111] = ContainerItem(
            1111, 0x3, Labels("locket", "a locket", "a small locket"), 1, None,
            {})

        validation = self.validator.validate(self.data_collection)

        self.assertEqual(1, len(validation))
        validation_line = validation[0]
        self.assertEqual(
            "Container item {0} \"{1}\" has a size of only {2}. As the minimum item size is {3}, nothing will be able to fit in it.",
            validation_line.template)
        self.assertEqual(Severity.WARN, validation_line.severity)
        self.assertEqual((1111, "locket", 1, 1), validation_line.args)
    def test_validate_item_liquid_container_not_liquid(self):
        water = Item(1111, 0x22902, Labels("water", "some water",
                                           "some water"), 1, None, {})
        water.add_container(self.basket)
        self.items_by_id[1111] = water

        validation = self.validator.validate(self.data_collection)

        self.assertEqual(1, len(validation))
        validation_line = validation[0]
        self.assertEqual(
            "Item {0} \"{1}\" is a liquid, but has container {2} \"{3}\", which is not a liquid container.",
            validation_line.template)
        self.assertEqual(Severity.ERROR, validation_line.severity)
        self.assertEqual((1111, "water", 1107, "basket"), validation_line.args)
    def test_validate_item_copyable_non_liquid(self):
        self.items_by_id[1042] = Item(
            1042, 0x2802,
            Labels("kohlrabi", "some kohlrabi",
                   "some kohlrabi, a cabbage cultivar"), 3, None, {})

        validation = self.validator.validate(self.data_collection)

        self.assertEqual(1, len(validation))
        validation_line = validation[0]
        self.assertEqual(
            "Item {0} \"{1}\" has been specified as both copyable and non-liquid. This is not supported.",
            validation_line.template)
        self.assertEqual(Severity.ERROR, validation_line.severity)
        self.assertEqual((1042, "kohlrabi"), validation_line.args)
    def test_validate_item_non_mobile_wearable(self):
        self.items_by_id[1046] = UsableItem(
            1046, 0x400, Labels("suit", "a suit", "a space-suit"), 2, None,
            {ListTemplateType.USING, "(wearing) {0}"},
            Item.ATTRIBUTE_GIVES_AIR)

        validation = self.validator.validate(self.data_collection)

        self.assertEqual(1, len(validation))
        validation_line = validation[0]
        self.assertEqual(
            "Item {0} \"{1}\" is marked as both non-mobile and wearable.",
            validation_line.template)
        self.assertEqual(Severity.ERROR, validation_line.severity)
        self.assertEqual((1046, "suit"), validation_line.args)
    def test_validate_item_fragile_no_smash_transformation(self):
        self.smash_command_ids.append(37)
        self.items_by_id[1017] = Item(
            1017, 0xC203, Labels("vial", "a vial", "a small glass vial"), 2,
            None, {}, None)

        validation = self.validator.validate(self.data_collection)

        self.assertEqual(1, len(validation))
        validation_line = validation[0]
        self.assertEqual(
            "Item {0} \"{1}\" is fragile, but does not have a \"smash\" command replacement.",
            validation_line.template)
        self.assertEqual(Severity.ERROR, validation_line.severity)
        self.assertEqual((1017, "vial"), validation_line.args)
    def test_validate_item_obstruction_non_location_container(self):
        self.items_by_id[1111] = Item(
            1111, 0x80006, Labels("lion", "a lion", "a ferocious lioness"), 4,
            None, {}, None)
        self.items_by_id[1111].add_container(self.basket)

        validation = self.validator.validate(self.data_collection)

        self.assertEqual(1, len(validation))
        validation_line = validation[0]
        self.assertEqual(
            "Obstruction item {0} \"{1}\" has a parent container that is not a location.",
            validation_line.template)
        self.assertEqual(Severity.ERROR, validation_line.severity)
        self.assertEqual((1111, "lion"), validation_line.args)
    def test_validate_item_liquid_non_copyable_container_location(self):
        water = Item(1111, 0x2102, Labels("water", "some water", "some water"),
                     1, None, {})
        water.add_container(self.lighthouse_location)
        self.items_by_id[1111] = water

        validation = self.validator.validate(self.data_collection)

        self.assertEqual(1, len(validation))
        validation_line = validation[0]
        self.assertEqual(
            "Item {0} \"{1}\" is a liquid, and has location container {2} \"{3}\". Liquids may only be contained at locations if they are copyable.",
            validation_line.template)
        self.assertEqual(Severity.ERROR, validation_line.severity)
        self.assertEqual((1111, "water", 12, "Lighthouse"),
                         validation_line.args)
    def test_validate_location_no_land_no_floor(self):
        mid_air_location = Location(
            19, 0x10F,
            Labels("Mid-air", "in mid-air", "; you are not sure how high"))
        mid_air_location.directions[Direction.DOWN] = self.lighthouse_location
        self.locations_by_id[19] = mid_air_location

        validation = self.validator.validate(self.data_collection)

        self.assertEqual(1, len(validation))
        validation_line = validation[0]
        self.assertEqual(
            "Location {0} has no land, but also no floor. Locations without land must have a floor.",
            validation_line.template)
        self.assertEqual(Severity.ERROR, validation_line.severity)
        self.assertEqual((19, ), validation_line.args)
    def test_validate_item_non_liquid_container_liquid(self):
        bottle = ContainerItem(
            1111, 0x203, Labels("bottle", "a bottle", "a small glass bottle"),
            3, None, {})
        self.book.add_container(bottle)
        self.items_by_id[1111] = bottle

        validation = self.validator.validate(self.data_collection)

        self.assertEqual(1, len(validation))
        validation_line = validation[0]
        self.assertEqual(
            "Item {0} \"{1}\" is non-liquid, but has container {2} \"{3}\", which is a liquid container.",
            validation_line.template)
        self.assertEqual(Severity.ERROR, validation_line.severity)
        self.assertEqual((1105, "book", 1111, "bottle"), validation_line.args)
    def test_validate_inventory_non_default_duplicate_location(self):
        self.inventories_by_id[1] = Inventory(
            1, 0x0,
            Labels("Special Inventory", "in the special inventory",
                   ", where items live sometimes."), 3, [12, 12])

        validation = self.validator.validate(self.data_collection)

        self.assertEqual(2, len(self.inventories_by_id))
        self.assertEqual(1, len(validation))
        validation_line = validation[0]
        self.assertEqual(
            "Non-default inventory {0} \"{1}\" references location with id {2} multiple times.",
            validation_line.template)
        self.assertEqual(Severity.WARN, validation_line.severity)
        self.assertEqual((1, "Special Inventory", 12), validation_line.args)