Пример #1
0
def create_message_for_hint(
    hint: Hint,
    all_patches: Dict[int, GamePatches],
    players_config: PlayersConfiguration,
    hint_name_creator: LocationHintCreator,
    location_formatters: Dict[HintLocationPrecision, LocationFormatter],
    world_list: WorldList,
) -> str:
    if hint.hint_type == HintType.JOKE:
        return color_text(TextColor.JOKE, hint_name_creator.create_joke_hint())

    elif hint.hint_type == HintType.RED_TEMPLE_KEY_SET:
        return create_temple_key_hint(all_patches, players_config.player_index,
                                      hint.dark_temple, world_list)

    else:
        assert hint.hint_type == HintType.LOCATION
        patches = all_patches[players_config.player_index]
        determiner, pickup_name = _calculate_pickup_hint(
            patches.pickup_assignment, world_list, hint.precision.item,
            patches.pickup_assignment.get(hint.target))
        return location_formatters[hint.precision.location].format(
            Determiner(determiner),
            color_text(TextColor.ITEM, pickup_name),
            hint,
        )
Пример #2
0
def create_message_for_hint(
    hint: Hint,
    all_patches: Dict[int, GamePatches],
    players_config: PlayersConfiguration,
    hint_name_creator: LocationHintCreator,
    location_formatters: Dict[HintLocationPrecision, LocationFormatter],
    world_list: WorldList,
) -> str:
    if hint.hint_type == HintType.JOKE:
        return color_text(TextColor.JOKE, hint_name_creator.create_joke_hint())

    elif hint.hint_type == HintType.RED_TEMPLE_KEY_SET:
        return create_temple_key_hint(all_patches, players_config.player_index,
                                      hint.dark_temple, world_list)

    else:
        assert hint.hint_type == HintType.LOCATION
        patches = all_patches[players_config.player_index]
        pickup_target = patches.pickup_assignment.get(hint.target)
        determiner, pickup_name = _calculate_pickup_hint(
            patches.pickup_assignment, world_list, hint.precision.item,
            pickup_target, players_config)

        use_title_formatting = True
        if hint.precision.include_owner and len(
                players_config.player_names) > 1:
            target_player = pickup_target.player if pickup_target is not None else players_config.player_index
            determiner = f"{players_config.player_names[target_player]}'s "
            use_title_formatting = False

        return location_formatters[hint.precision.location].format(
            Determiner(determiner, use_title_formatting),
            color_text(TextColor.ITEM, pickup_name),
            hint,
        )
Пример #3
0
def create_temple_key_hint(
    all_patches: Dict[int, GamePatches],
    player_index: int,
    temple: HintDarkTemple,
    world_list: WorldList,
) -> str:
    """
    Creates the text for .
    :param all_patches:
    :param player_index:
    :param temple:
    :param world_list:
    :return:
    """
    all_world_names = set()

    _TEMPLE_NAMES = ["Dark Agon Temple", "Dark Torvus Temple", "Hive Temple"]
    temple_index = [
        HintDarkTemple.AGON_WASTES, HintDarkTemple.TORVUS_BOG,
        HintDarkTemple.SANCTUARY_FORTRESS
    ].index(temple)
    keys = echoes_items.DARK_TEMPLE_KEY_ITEMS[temple_index]

    index_to_node = {
        node.pickup_index: node
        for node in world_list.all_nodes if isinstance(node, PickupNode)
    }

    for patches in all_patches.values():
        for pickup_index, target in patches.pickup_assignment.items():
            if target.player != player_index:
                continue

            resources = resource_info.convert_resource_gain_to_current_resources(
                target.pickup.resource_gain({}))
            for resource, quantity in resources.items():
                if quantity < 1 or resource.index not in keys:
                    continue

                pickup_node = index_to_node[pickup_index]
                all_world_names.add(
                    world_list.world_name_from_node(pickup_node, True))

    temple_name = color_text(TextColor.ITEM, _TEMPLE_NAMES[temple_index])
    names_sorted = [
        color_text(TextColor.LOCATION, world)
        for world in sorted(all_world_names)
    ]
    if len(names_sorted) == 0:
        return f"The keys to {temple_name} are nowhere to be found."
    elif len(names_sorted) == 1:
        return f"The keys to {temple_name} can all be found in {names_sorted[0]}."
    else:
        last = names_sorted.pop()
        front = ", ".join(names_sorted)
        return f"The keys to {temple_name} can be found in {front} and {last}."
Пример #4
0
 def format(self, determiner: Determiner, pickup: str, hint: Hint) -> str:
     node_name = color_text(TextColor.LOCATION, self.hint_name_creator.index_node_name(
         hint.target,
         hint.precision.location == HintLocationPrecision.WORLD_ONLY
     ))
     return self.template.format(determiner=determiner,
                                 pickup=pickup,
                                 node=node_name)
Пример #5
0
def create_hints(
    patches: GamePatches,
    world_list: WorldList,
    hide_area: bool,
) -> list:
    """
    Creates the string patches entries that changes the Sky Temple Gateway hint scans with hints for where
    the STK actually are.
    :param patches:
    :param world_list:
    :param hide_area: Should the hint include only the world?
    :return:
    """
    location_hint_creator = LocationHintCreator(world_list)
    sky_temple_key_hints = {}

    for pickup_index, pickup in patches.pickup_assignment.items():
        resources = resource_info.convert_resource_gain_to_current_resources(
            pickup.resource_gain({}))

        for resource, quantity in resources.items():
            if quantity < 1:
                continue

            try:
                key_number = echoes_items.SKY_TEMPLE_KEY_ITEMS.index(
                    resource.index) + 1
            except ValueError:
                continue

            assert resource.index not in sky_temple_key_hints

            sky_temple_key_hints[
                resource.index] = "{} is located in {}.".format(
                    _sky_temple_key_name(key_number),
                    color_text(
                        TextColor.LOCATION,
                        location_hint_creator.index_node_name(
                            pickup_index, hide_area),
                    ),
                )

    for starting_resource, quantity in patches.starting_items.items():
        if quantity < 1:
            continue
        try:
            key_number = echoes_items.SKY_TEMPLE_KEY_ITEMS.index(
                starting_resource.index) + 1
        except ValueError:
            continue

        assert starting_resource.index not in sky_temple_key_hints
        sky_temple_key_hints[
            starting_resource.index] = "{} has no need to be located.".format(
                _sky_temple_key_name(key_number), )

    if len(sky_temple_key_hints) != len(echoes_items.SKY_TEMPLE_KEY_ITEMS):
        raise ValueError(
            "Expected to find {} Sky Temple Keys between pickup placement and starting items, found {}"
            .format(len(echoes_items.SKY_TEMPLE_KEY_ITEMS),
                    len(sky_temple_key_hints)))

    return [
        create_simple_logbook_hint(_SKY_TEMPLE_KEY_SCAN_ASSETS[key_number],
                                   sky_temple_key_hints[key_index]) for
        key_number, key_index in enumerate(echoes_items.SKY_TEMPLE_KEY_ITEMS)
    ]
Пример #6
0
def _sky_temple_key_name(key_number: int) -> str:
    return color_text(TextColor.ITEM, f"Sky Temple Key {key_number}")
Пример #7
0
 def format(self, determiner: Determiner, pickup: str, hint: Hint) -> str:
     guardian = color_text(TextColor.GUARDIAN,
                           self._GUARDIAN_NAMES[hint.target])
     return f"{guardian} is guarding {determiner}{pickup}."
Пример #8
0
def create_hints(patches: GamePatches,
                 world_list: WorldList,
                 rng: Random,
                 ) -> list:
    """
    Creates the string patches entries that changes the Lore scans in the game for item pickups
    :param patches:
    :param world_list:
    :param rng:
    :return:
    """

    hint_name_creator = LocationHintCreator(world_list)
    joke_items = sorted(set(_PRIME_1_ITEMS) | set(_PRIME_3_ITEMS))
    joke_locations = sorted(set(_PRIME_1_LOCATIONS) | set(_PRIME_3_LOCATIONS))
    joke_hints = sorted(_JOKE_HINTS)

    rng.shuffle(joke_items)
    rng.shuffle(joke_locations)
    rng.shuffle(joke_hints)

    hints_for_asset: Dict[int, str] = {}

    for asset, hint in patches.hints.items():
        if hint.precision.is_joke:
            if not joke_hints:
                joke_hints = sorted(_JOKE_HINTS)
                rng.shuffle(joke_hints)
            message = color_text(TextColor.JOKE, joke_hints.pop())

        else:
            target = patches.pickup_assignment.get(hint.target)

            # Determine location name
            if hint.hint_type is HintType.GUARDIAN:
                node_name = color_text(TextColor.GUARDIAN, _GUARDIAN_NAMES[hint.target])
            elif hint.location_precision == HintLocationPrecision.WRONG_GAME:
                node_name = color_text(TextColor.JOKE, "{} (?)".format(joke_locations.pop())
                                       if joke_locations else "an unknown location")
            else:
                node_name = color_text(TextColor.LOCATION, hint_name_creator.index_node_name(
                    hint.target,
                    hint.location_precision != HintLocationPrecision.DETAILED
                ))

            # Determine pickup name
            if target is not None:
                is_joke, determiner, pickup_name = _calculate_pickup_hint(
                    hint.item_precision,
                    _calculate_determiner(patches.pickup_assignment, target.pickup),
                    target.pickup,
                    joke_items,
                )
            else:
                is_joke = False
                determiner = "the " if len(patches.pickup_assignment) == 118 else "an "
                pickup_name = "Energy Transfer Module"

            if hint.hint_type is HintType.LOCATION:
                determiner = determiner.title()

            pickup_name = color_text(TextColor.JOKE if is_joke else TextColor.ITEM, pickup_name)
            message = _HINT_MESSAGE_TEMPLATES[hint.hint_type].format(determiner=determiner,
                                                                     pickup=pickup_name,
                                                                     node=node_name)
        hints_for_asset[asset.asset_id] = message

    return [
        create_simple_logbook_hint(
            logbook_node.string_asset_id,
            hints_for_asset.get(logbook_node.string_asset_id, "Someone forgot to leave a message."),
        )
        for logbook_node in world_list.all_nodes
        if isinstance(logbook_node, LogbookNode)
    ]