Example #1
0
def state_with_pickup(state: State,
                      pickup: PickupEntry,
                      ) -> State:
    """
    Returns a new State that follows the given State and also has the resource gain of the given pickup
    :param state:
    :param pickup:
    :return:
    """
    new_state = state.copy()
    new_state.previous_state = state
    add_resource_gain_to_state(new_state, pickup.resource_gain())
    return new_state
Example #2
0
def _create_pickup(original_index: PickupIndex, pickup: PickupEntry) -> dict:
    return {
        "pickup_index":
        original_index.index,
        # "model": 1234,
        "scan":
        pickup.name,
        "resources":
        [{
            "index": resource.index,
            "amount": quantity
        } for resource, quantity in pickup.resource_gain()
         if quantity > 0 and resource.resource_type == ResourceType.ITEM]
    }
Example #3
0
    def assign_pickup_to_index(self, index: PickupIndex, pickup: PickupEntry) -> "State":
        new_patches = self.patches.assign_new_pickups([(index, pickup)])
        new_resources = copy.copy(self.resources)

        if index in self.resources:
            add_resource_gain_to_current_resources(pickup.resource_gain(), new_resources)

        return State(
            new_resources,
            self.node,
            new_patches,
            self,
            self.resource_database
        )
Example #4
0
def test_remove_pickup_entry_from_list():
    # Setup
    items = (
        PickupEntry("Item A", tuple(), "", 0),
        PickupEntry("Item B", tuple(), "", 0),
        PickupEntry("Item A", tuple(), "", 0),
        PickupEntry("Item C", tuple(), "", 0),
    )

    # Run
    filtered_item_pool = item_pool.remove_pickup_entry_from_list(
        items, PickupEntry("Item A", tuple(), "", 0))

    # Assert
    assert filtered_item_pool == (
        PickupEntry("Item B", tuple(), "", 0),
        PickupEntry("Item A", tuple(), "", 0),
        PickupEntry("Item C", tuple(), "", 0),
    )
Example #5
0
def test_sky_temple_key_distribution_logic_vanilla_used_location(dataclass_test_lib,
                                                                 sky_temple_keys,
                                                                 empty_patches):
    # Setup
    permalink = dataclass_test_lib.mock_dataclass(Permalink)
    permalink.layout_configuration.sky_temple_keys = LayoutSkyTempleKeyMode.VANILLA
    initial_pickup_assignment = {
        generator._FLYING_ING_CACHES[0]: PickupEntry("Other Item", tuple(), "other", 0)
    }
    patches = empty_patches.assign_new_pickups(initial_pickup_assignment.items())

    # Run
    with pytest.raises(GenerationFailure) as exp:
        generator._sky_temple_key_distribution_logic(permalink, patches, [sky_temple_keys[0]])

    assert exp.value == GenerationFailure(
        "Attempted to place '{}' in PickupIndex 45, but there's already 'Pickup Other Item' there".format(
            sky_temple_keys[0]
        ), permalink)
Example #6
0
def read_pickup_database(
        data: Dict, resource_database: ResourceDatabase) -> PickupDatabase:
    pickups = {
        name: PickupEntry(
            name,
            read_resource_gain_tuple(item["resources"], resource_database),
            item["item_category"],
            item["probability_offset"],
        )
        for name, item in data["pickups"].items()
    }
    original_pickup_mapping = {
        PickupIndex(i): pickups[name]
        for i, name in enumerate(data["original_indices"])
    }
    useless_pickup = pickups[data["useless_pickup"]]

    return PickupDatabase(pickups=pickups,
                          original_pickup_mapping=original_pickup_mapping,
                          useless_pickup=useless_pickup)
Example #7
0
def sample_sky_temple_keys():
    return [
        PickupEntry("Test Sky Temple Key {}".format(i), tuple(), "sky_temple_key", 0)
        for i in range(1, 10)
    ]
Example #8
0
def test_create_pickup_list(empty_patches):
    # Setup
    useless_resource = SimpleResourceInfo(0, "Useless", "Useless",
                                          ResourceType.ITEM)
    resource_a = SimpleResourceInfo(1, "A", "A", ResourceType.ITEM)
    resource_b = SimpleResourceInfo(2, "B", "B", ResourceType.ITEM)
    pickup_a = PickupEntry("A", ((resource_a, 1), ), "", 0)

    useless_pickup = PickupEntry("Useless", ((useless_resource, 1), ), "", 0)
    pickup_database = PickupDatabase(pickups={},
                                     original_pickup_mapping={
                                         PickupIndex(i): useless_pickup
                                         for i in range(4)
                                     },
                                     useless_pickup=useless_pickup)
    patches = empty_patches.assign_pickup_assignment({
        PickupIndex(0):
        pickup_a,
        PickupIndex(2):
        PickupEntry("B", ((resource_b, 1), (resource_a, 1)), "", 0),
        PickupIndex(3):
        pickup_a,
    })

    # Run
    result = patcher_file._create_pickup_list(patches, pickup_database)

    # Assert
    assert result == [
        {
            "pickup_index": 0,
            "scan": "A",
            "resources": [{
                "index": 1,
                "amount": 1
            }]
        },
        {
            "pickup_index": 1,
            "scan": "Useless",
            "resources": [{
                "index": 0,
                "amount": 1
            }]
        },
        {
            "pickup_index": 2,
            "scan": "B",
            "resources": [{
                "index": 2,
                "amount": 1
            }, {
                "index": 1,
                "amount": 1
            }]
        },
        {
            "pickup_index": 3,
            "scan": "A",
            "resources": [{
                "index": 1,
                "amount": 1
            }]
        },
    ]