Ejemplo n.º 1
0
def test_simple_echoes_damage(echoes_resource_database):
    db = echoes_resource_database
    req = ResourceRequirement.create(
        db.get_by_type_and_index(ResourceType.DAMAGE, "DarkWorld1"),
        50,
        False,
    )
    d_suit = db.get_item_by_name("Dark Suit")
    l_suit = db.get_item_by_name("Light Suit")

    assert req.damage(_empty_col(), db) == 50
    assert req.damage(_col_for(db, d_suit), db) == 11
    assert req.damage(_col_for(db, l_suit), db) == 0
Ejemplo n.º 2
0
def test_list_dangerous_resources(database, input_data, output_data):
    # setup
    req_list = RequirementList(
        (ResourceRequirement.create(database.resource_by_index[item[0]], 1,
                                    item[1]) for item in input_data))

    expected_result = {
        database.resource_by_index[item]
        for item in output_data
    }

    # run
    result = set(req_list.dangerous_resources)

    # assert
    assert result == expected_result
Ejemplo n.º 3
0
def test_requirement_list_constructor(echoes_resource_database):
    def item(name):
        return search.find_resource_info_with_long_name(
            echoes_resource_database.item, name)

    req_list = RequirementList([
        ResourceRequirement.simple(item("Dark Visor")),
        ResourceRequirement.create(item("Missile"), 5, False),
        ResourceRequirement.simple(item("Seeker Launcher")),
    ])
    extract = [(req.resource.long_name, req.amount)
               for req in req_list.values()]

    assert sorted(extract) == [
        ("Dark Visor", 1),
        ("Missile", 5),
        ("Seeker Launcher", 1),
    ]
Ejemplo n.º 4
0
def _unsatisfied_item_requirements_in_list(
        alternative: RequirementList, state: State,
        uncollected_resources: set[ResourceInfo]):
    possible = True
    items = []
    damage = []

    for individual in alternative.values():
        if individual.negate:
            possible = False
            break

        if individual.resource.resource_type == ResourceType.DAMAGE:
            damage.append(individual)
            continue

        if individual.satisfied(state.resources, state.energy,
                                state.resource_database):
            continue

        if individual.resource.resource_type != ResourceType.ITEM:
            if individual.resource not in uncollected_resources:
                possible = False
                break

        items.append(individual)

    if not possible:
        return

    sum_damage = sum(
        req.damage(state.resources, state.resource_database) for req in damage)
    if state.energy < sum_damage:
        tank_count = (sum_damage -
                      state.energy) // state.game_data.energy_per_tank
        yield items + [
            ResourceRequirement.create(state.resource_database.energy_tank,
                                       tank_count + 1, False)
        ]
        # FIXME: get the required items for reductions (aka suits)
    else:
        yield items
Ejemplo n.º 5
0
    def current_requirement(self) -> ResourceRequirement:
        resource_type = self.resource_type

        # Quantity
        if resource_type == ResourceType.TRICK:
            quantity: int = self.amount_combo.currentData()
        elif resource_type == ResourceType.EVENT:
            quantity = 1
        else:
            quantity = int(self.amount_edit.text())

        # Negate flag
        if resource_type == ResourceType.ITEM:
            negate: bool = self.negate_combo.currentData()
        elif resource_type == ResourceType.EVENT:
            negate = self.negate_check.isChecked()
        else:
            negate = False

        return ResourceRequirement.create(
            self.resource_name_combo.currentData(), quantity, negate)
Ejemplo n.º 6
0
def test_requirement_set_constructor(echoes_resource_database):
    item = echoes_resource_database.get_item_by_name

    req_set = RequirementSet([
        RequirementList([
            ResourceRequirement.simple(item("Dark Visor")),
            ResourceRequirement.create(item("Missile"), 5, False),
            ResourceRequirement.simple(item("Seeker Launcher")),
        ]),
        RequirementList([
            ResourceRequirement.simple(item("Screw Attack")),
            ResourceRequirement.simple(item("Space Jump Boots")),
        ]),
        RequirementList([
            ResourceRequirement.simple(item("Power Bomb")),
            ResourceRequirement.simple(item("Boost Ball")),
        ]),
    ])
    extract = [
        sorted((req.resource.long_name, req.amount)
               for req in req_list.values())
        for req_list in req_set.alternatives
    ]

    assert sorted(extract) == [
        [
            ("Boost Ball", 1),
            ("Power Bomb", 1),
        ],
        [
            ("Dark Visor", 1),
            ("Missile", 5),
            ("Seeker Launcher", 1),
        ],
        [
            ("Screw Attack", 1),
            ("Space Jump Boots", 1),
        ],
    ]
 def current_individual(self) -> ResourceRequirement:
     return ResourceRequirement.create(
         self.resource_name_combo.currentData(),
         int(self.amount_edit.text()), self.negate_combo.currentData())