Exemple #1
0
def add_ammo(
    resource_database: ResourceDatabase,
    ammo_configuration: AmmoConfiguration,
    included_ammo_for_item: Dict[int, int],
) -> Iterator[PickupEntry]:
    """
    Creates the necessary pickups for the given ammo_configuration.
    :param resource_database:
    :param ammo_configuration:
    :param included_ammo_for_item: How much of each item was provided based on the major items.
    :return:
    """

    previous_pickup_for_item = {}

    for ammo, state in ammo_configuration.items_state.items():
        if state.pickup_count == 0:
            continue

        if state.variance != 0:
            raise InvalidConfiguration(
                "Variance was configured for {0.name}, but it is currently NYI"
                .format(ammo))

        ammo_per_pickup = items_for_ammo(ammo, state, included_ammo_for_item,
                                         previous_pickup_for_item,
                                         ammo_configuration.maximum_ammo)

        for ammo_quantity in ammo_per_pickup:
            yield create_ammo_expansion(ammo, ammo_quantity,
                                        state.requires_major_item,
                                        resource_database)
Exemple #2
0
def test_pickup_data_for_pb_expansion_unlocked(echoes_item_database, echoes_resource_database):
    # Setup
    pickup = pickup_creator.create_ammo_expansion(
        echoes_item_database.ammo["Power Bomb Expansion"],
        [2],
        False,
        echoes_resource_database,
    )
    creator = pickup_exporter.PickupExporterSolo(patch_data_factory._simplified_memo_data())

    # Run
    details = creator.export(PickupIndex(0), PickupTarget(pickup, 0), pickup, PickupModelStyle.ALL_VISIBLE)
    result = patch_data_factory.echoes_pickup_details_to_patcher(details, MagicMock())

    # Assert
    assert result == {
        "pickup_index": 0,
        "scan": "Power Bomb Expansion. Provides 2 Power Bombs and 1 Item Percentage",
        "model": {"game": "prime2", "name": "PowerBombExpansion"},
        "hud_text": ["Power Bomb Expansion acquired!"],
        'resources': [{'amount': 2, 'index': 43},
                      {'amount': 1, 'index': 47}],
        "conditional_resources": [],
        "convert": [],
    }
def test_pickup_scan_for_ammo_expansion(echoes_item_database, echoes_resource_database, item, ammo, result):
    # Setup
    expansion = echoes_item_database.ammo[item]
    pickup = pickup_creator.create_ammo_expansion(expansion, ammo, False, echoes_resource_database)

    # Run
    result = patcher_file._pickup_scan(pickup)

    # Assert
    assert result == result
Exemple #4
0
def add_ammo(
    resource_database: ResourceDatabase,
    ammo_configuration: AmmoConfiguration,
) -> Iterator[PickupEntry]:
    """
    Creates the necessary pickups for the given ammo_configuration.
    :param resource_database:
    :param ammo_configuration:
    :return:
    """
    for ammo, state in ammo_configuration.items_state.items():
        for _ in range(state.pickup_count):
            yield create_ammo_expansion(ammo, state.ammo_count,
                                        state.requires_major_item,
                                        resource_database)
Exemple #5
0
def test_pickup_data_for_pb_expansion_locked(simplified, echoes_item_database, echoes_resource_database):
    # Setup
    pickup = pickup_creator.create_ammo_expansion(
        echoes_item_database.ammo["Power Bomb Expansion"],
        [2],
        True,
        echoes_resource_database,
    )
    if simplified:
        memo = patch_data_factory._simplified_memo_data()
        hud_text = [
            "Power Bomb Expansion acquired, but the main Power Bomb is required to use it.",
            "Power Bomb Expansion acquired!",
        ]
    else:
        memo = default_database.default_prime2_memo_data()
        hud_text = [
            "Power Bomb Expansion acquired! \n"
            "Without the main Power Bomb item, you are still unable to release Power Bombs.",
            "Power Bomb Expansion acquired! \nMaximum Power Bomb carrying capacity increased by 2.",
        ]

    creator = pickup_exporter.PickupExporterSolo(memo)

    # Run
    details = creator.export(PickupIndex(0), PickupTarget(pickup, 0), pickup, PickupModelStyle.ALL_VISIBLE)
    result = patch_data_factory.echoes_pickup_details_to_patcher(details, MagicMock())

    # Assert
    assert result == {
        "pickup_index": 0,
        "scan": "Power Bomb Expansion. Provides 2 Power Bombs and 1 Item Percentage",
        "model": {"game": "prime2", "name": "PowerBombExpansion"},
        "hud_text": hud_text,
        'resources': [{'amount': 2, 'index': 72},
                      {'amount': 1, 'index': 47}],
        "conditional_resources": [
            {'item': 43,
             'resources': [{'amount': 2, 'index': 43},
                           {'amount': 1, 'index': 47}]}
        ],
        "convert": [],
    }
Exemple #6
0
def test_create_ammo_expansion(requires_major_item: bool, echoes_item_database,
                               echoes_resource_database):
    # Setup
    primary_a = echoes_resource_database.get_item("MissileLauncher")
    ammo_a = echoes_resource_database.get_item("Missile")
    temporary_a = echoes_resource_database.get_item("Temporary1")

    ammo = Ammo(
        game=echoes_resource_database.game_enum,
        name="The Item",
        items=("Missile", ),
        broad_category=USELESS_ITEM_CATEGORY,
        unlocked_by="MissileLauncher",
        temporary="Temporary1",
        model_name="AmmoModel",
    )
    ammo_count = (11, 150)

    # Run
    result = pickup_creator.create_ammo_expansion(ammo, ammo_count,
                                                  requires_major_item,
                                                  echoes_resource_database)

    # Assert
    assert result == PickupEntry(
        name="The Item",
        model=PickupModel(echoes_resource_database.game_enum, "AmmoModel"),
        progression=tuple(),
        extra_resources=(
            (ammo_a, ammo_count[0]),
            (echoes_resource_database.item_percentage, 1),
        ),
        item_category=AMMO_ITEM_CATEGORY,
        broad_category=USELESS_ITEM_CATEGORY,
        probability_offset=0,
        respects_lock=requires_major_item,
        resource_lock=ResourceLock(
            locked_by=primary_a,
            temporary_item=temporary_a,
            item_to_lock=ammo_a,
        ),
    )
Exemple #7
0
def test_missile_expansion_before_launcher(include_before, echoes_item_database, echoes_resource_database):
    # Setup
    ammo = echoes_item_database.ammo["Missile Expansion"]
    major_item = echoes_item_database.major_items["Missile Launcher"]

    missile = echoes_resource_database.get_item(ammo.items[0])
    missile_launcher = echoes_resource_database.get_item(major_item.progression[0])
    temporary = echoes_resource_database.get_item(ammo.temporary)
    percent = echoes_resource_database.item_percentage

    # Run
    expansion = pickup_creator.create_ammo_expansion(ammo, [5], True, echoes_resource_database)
    launcher = pickup_creator.create_major_item(
        major_item, MajorItemState(included_ammo=(5,)),
        True, echoes_resource_database, ammo, True
    )

    resources = {}

    if include_before:
        # Ammo Expansion
        add_resource_gain_to_current_resources(expansion.resource_gain(resources, force_lock=True), resources)
        assert resources == {percent: 1, temporary: 5}

    # Add Launcher
    add_resource_gain_to_current_resources(launcher.resource_gain(resources, force_lock=True), resources)
    if include_before:
        assert resources == {percent: 2, temporary: 0, missile_launcher: 1, missile: 10}
    else:
        assert resources == {percent: 1, temporary: 0, missile_launcher: 1, missile: 5}

    # Ammo Expansion
    add_resource_gain_to_current_resources(expansion.resource_gain(resources, force_lock=True), resources)
    if include_before:
        assert resources == {percent: 3, temporary: 0, missile_launcher: 1, missile: 15}
    else:
        assert resources == {percent: 2, temporary: 0, missile_launcher: 1, missile: 10}