Exemplo n.º 1
0
def read_database(database_data: Dict, game: RandovaniaGame) -> ItemDatabase:
    """
    :param database_data:
    :param game:
    :return:
    """
    migrations.migrate_current(database_data)

    item_categories = {
        name: ItemCategory.from_json(name, value)
        for name, value in database_data["item_categories"].items()
    }

    major_items = {
        name: MajorItem.from_json(name, value, game, item_categories)
        for name, value in database_data["items"].items()
    }

    ammo = {
        name: Ammo.from_json(name, value, game, item_categories)
        for name, value in database_data["ammo"].items()
    }

    default_items = {
        item_categories[category_name]:
        tuple(major_items[item_name] for item_name in value)
        for category_name, value in database_data["default_items"].items()
    }

    return ItemDatabase(item_categories, major_items, ammo, default_items)
Exemplo n.º 2
0
def read_database(
    major_items_data: Dict,
    ammo_data: Dict,
) -> ItemDatabase:
    """

    :param major_items_data:
    :param ammo_data:
    :return:
    """
    major_items = {
        name: MajorItem.from_json(name, value)
        for name, value in major_items_data["items"].items()
    }

    ammo = {
        name: Ammo.from_json(name, value)
        for name, value in ammo_data.items()
    }

    default_items = {
        ItemCategory(category_name):
        tuple(major_items[item_name] for item_name in value)
        for category_name, value in major_items_data["default_items"].items()
    }

    return ItemDatabase(major_items, ammo, default_items)
Exemplo n.º 3
0
def test_create_pickup_for(percentage: bool, echoes_resource_database):
    # Setup
    item_a = echoes_resource_database.get_item(10)
    item_b = echoes_resource_database.get_item(15)
    item_c = echoes_resource_database.get_item(18)
    ammo_a = echoes_resource_database.get_item(40)
    ammo_b = echoes_resource_database.get_item(42)

    major_item = MajorItem(
        name="The Item",
        item_category=ItemCategory.MORPH_BALL,
        broad_category=ItemCategory.MORPH_BALL_RELATED,
        model_name="SuperModel",
        progression=(10, 15, 18),
        ammo_index=(40, 42),
        required=False,
        original_index=None,
        probability_offset=5,
    )
    state = MajorItemState(
        include_copy_in_original_location=False,
        num_shuffled_pickups=0,
        num_included_in_starting_items=0,
        included_ammo=(10, 20),
    )

    if percentage:
        extra_resources = (
            (ammo_a, 10),
            (ammo_b, 20),
            (echoes_resource_database.item_percentage, 1),
        )
    else:
        extra_resources = (
            (ammo_a, 10),
            (ammo_b, 20),
        )

    # Run
    result = randovania.generator.item_pool.pickup_creator.create_major_item(major_item, state, percentage,
                                                                             echoes_resource_database,
                                                                             None, False)

    # Assert
    assert result == PickupEntry(
        name="The Item",
        model=PickupModel(echoes_resource_database.game_enum, "SuperModel"),
        progression=(
            (item_a, 1),
            (item_b, 1),
            (item_c, 1),
        ),
        extra_resources=extra_resources,
        item_category=ItemCategory.MORPH_BALL,
        broad_category=ItemCategory.MORPH_BALL_RELATED,
        probability_offset=5,
        respects_lock=False,
    )
Exemplo n.º 4
0
def _state_with_data(request):
    item = MajorItem(
        name="Item Name",
        item_category=ItemCategory(request.param.get("category", "visor")),
        model_index=0,
        progression=(),
        ammo_index=request.param.get("ammo_index", ()),
        required=True,
        original_index=None,
        probability_offset=0,
    )
    return item, request.param["encoded"], MajorItemState.from_json(request.param["json"])
Exemplo n.º 5
0
def read_database(major_items_data: Dict,
                  ammo_data: Dict,
                  ) -> ItemDatabase:
    """

    :param major_items_data:
    :param ammo_data:
    :return:
    """
    major_items = {
        name: MajorItem.from_json(name, value)
        for name, value in major_items_data.items()
    }

    ammo = {
        name: Ammo.from_json(name, value)
        for name, value in ammo_data.items()
    }

    return ItemDatabase(major_items, ammo)
Exemplo n.º 6
0
def _major_item_state(request, echoes_item_database, generic_item_category):
    encoded: bytes = request.param["encoded"]

    item = MajorItem(
        game=RandovaniaGame.METROID_PRIME_ECHOES,
        name="Item Name",
        item_category=generic_item_category,
        broad_category=generic_item_category,
        model_name="Model Name",
        progression=(request.param.get("progression", "Power"),),
        default_starting_count=0,
        default_shuffled_count=1,
        ammo_index=request.param.get("ammo_index", ()),
        must_be_starting=True,
        original_index=None,
        probability_offset=0,
    )
    included_ammo = tuple(0 for _ in request.param["json"].get("included_ammo", []))
    reference = MajorItemState(included_ammo=included_ammo)
    return item, encoded, request.param["bit_count"], MajorItemState.from_json(request.param["json"]), reference
def test_create_pickup_for(percentage: bool, has_convert: bool,
                           echoes_resource_database):
    # Setup
    item_a = echoes_resource_database.get_by_type_and_index(
        ResourceType.ITEM, 10)
    item_b = echoes_resource_database.get_by_type_and_index(
        ResourceType.ITEM, 15)
    item_c = echoes_resource_database.get_by_type_and_index(
        ResourceType.ITEM, 18)
    ammo_a = echoes_resource_database.get_by_type_and_index(
        ResourceType.ITEM, 40)
    ammo_b = echoes_resource_database.get_by_type_and_index(
        ResourceType.ITEM, 42)
    temporary_a = echoes_resource_database.get_by_type_and_index(
        ResourceType.ITEM, 71)
    temporary_b = echoes_resource_database.get_by_type_and_index(
        ResourceType.ITEM, 72)

    major_item = MajorItem(
        name="The Item",
        item_category=ItemCategory.MORPH_BALL,
        model_index=1337,
        progression=(10, 15, 18),
        ammo_index=(40, 42),
        converts_indices=(71, 72) if has_convert else (),
        required=False,
        original_index=None,
        probability_offset=5,
    )
    state = MajorItemState(
        include_copy_in_original_location=False,
        num_shuffled_pickups=0,
        num_included_in_starting_items=0,
        included_ammo=(10, 20),
    )

    def _create_resources(item):
        if percentage:
            return (
                (item, 1),
                (ammo_a, 10),
                (ammo_b, 20),
                (echoes_resource_database.item_percentage, 1),
            )
        else:
            return (
                (item, 1),
                (ammo_a, 10),
                (ammo_b, 20),
            )

    # Run
    result = randovania.generator.item_pool.pickup_creator.create_major_item(
        major_item, state, percentage, echoes_resource_database, None, False)

    # Assert
    assert result == PickupEntry(
        name="The Item",
        model_index=1337,
        resources=(
            ConditionalResources(
                name="Dark Visor",
                item=None,
                resources=_create_resources(item_a),
            ),
            ConditionalResources(
                name="Morph Ball",
                item=item_a,
                resources=_create_resources(item_b),
            ),
            ConditionalResources(
                name="Morph Ball Bomb",
                item=item_b,
                resources=_create_resources(item_c),
            ),
        ),
        convert_resources=(
            ResourceConversion(source=temporary_a, target=ammo_a),
            ResourceConversion(source=temporary_b, target=ammo_b),
        ) if has_convert else (),
        item_category=ItemCategory.MORPH_BALL,
        probability_offset=5,
    )
Exemplo n.º 8
0
def test_create_pickup_for(percentage: bool, echoes_item_database,
                           echoes_resource_database, generic_item_category):
    # Setup
    item_a = echoes_resource_database.get_item("DarkVisor")
    item_b = echoes_resource_database.get_item("MorphBall")
    item_c = echoes_resource_database.get_item("Bombs")
    ammo_a = echoes_resource_database.get_item("EnergyTank")
    ammo_b = echoes_resource_database.get_item("DarkAmmo")

    less_generic_item_category = ItemCategory(name="the_category",
                                              long_name="The Category",
                                              hint_details=("a ",
                                                            " wonderful item"),
                                              is_major=True)

    major_item = MajorItem(
        game=echoes_resource_database.game_enum,
        name="The Item",
        item_category=less_generic_item_category,
        broad_category=generic_item_category,
        model_name="SuperModel",
        progression=("DarkVisor", "MorphBall", "Bombs"),
        default_starting_count=0,
        default_shuffled_count=1,
        ammo_index=("EnergyTank", "DarkAmmo"),
        must_be_starting=False,
        original_index=None,
        probability_offset=5,
    )
    state = MajorItemState(
        include_copy_in_original_location=False,
        num_shuffled_pickups=0,
        num_included_in_starting_items=0,
        included_ammo=(10, 20),
    )

    if percentage:
        extra_resources = (
            (ammo_a, 10),
            (ammo_b, 20),
            (echoes_resource_database.item_percentage, 1),
        )
    else:
        extra_resources = (
            (ammo_a, 10),
            (ammo_b, 20),
        )

    # Run
    result = pickup_creator.create_major_item(major_item, state, percentage,
                                              echoes_resource_database, None,
                                              False)

    # Assert
    assert result == PickupEntry(
        name="The Item",
        model=PickupModel(echoes_resource_database.game_enum, "SuperModel"),
        progression=(
            (item_a, 1),
            (item_b, 1),
            (item_c, 1),
        ),
        extra_resources=extra_resources,
        item_category=less_generic_item_category,
        broad_category=generic_item_category,
        probability_offset=5,
        respects_lock=False,
    )