From d237dbaab1ae26648bd404e3bf380eb6454e1f24 Mon Sep 17 00:00:00 2001 From: Nicholas Brochu Date: Fri, 10 Jan 2025 17:00:23 -0500 Subject: [PATCH] new option: game medley game selection --- .../game_objective_generator.py | 22 +++++++++++++- worlds/keymasters_keep/options.py | 29 +++++++++++++++++-- worlds/keymasters_keep/world.py | 3 ++ 3 files changed, 50 insertions(+), 4 deletions(-) diff --git a/worlds/keymasters_keep/game_objective_generator.py b/worlds/keymasters_keep/game_objective_generator.py index b043e5b04e60..b4dcc89ba01b 100644 --- a/worlds/keymasters_keep/game_objective_generator.py +++ b/worlds/keymasters_keep/game_objective_generator.py @@ -1,3 +1,5 @@ +import logging + from random import Random from typing import Any, List, Tuple, Type, Union @@ -18,11 +20,14 @@ class GameObjectiveGeneratorException(Exception): class GameObjectiveGenerator: games: List[Type[Game]] + games_medley: List[Type[Game]] + archipelago_options: Any def __init__( self, allowable_games: List[str] = None, + allowable_games_medley: List[str] = None, include_adult_only_or_unrated_games: bool = False, include_modern_console_games: bool = False, include_difficult_objectives: bool = False, @@ -42,6 +47,21 @@ def __init__( if not len(self.games): raise GameObjectiveGeneratorException("No games are left after game / objective filtering") + self.games_medley = self._filter_games( + allowable_games_medley, + include_adult_only_or_unrated_games, + include_modern_console_games, + include_difficult_objectives, + include_time_consuming_objectives, + ) + + if not len(self.games_medley): + logging.warning( + "Keymaster's Keep: No medley games are left after game / objective filtering. Using all games." + ) + + self.games_medley = self.games[:] + def generate_from_plan( self, plan: List[int] = None, @@ -83,7 +103,7 @@ def generate_from_plan( game: GameMedleyGame = game_class( random=random, archipelago_options=self.archipelago_options, - game_selection=self.games, + game_selection=self.games_medley, ) optional_constraints: List[str] diff --git a/worlds/keymasters_keep/options.py b/worlds/keymasters_keep/options.py index 0ede84c9d338..5bca41c0731e 100644 --- a/worlds/keymasters_keep/options.py +++ b/worlds/keymasters_keep/options.py @@ -191,7 +191,7 @@ class AreaTrialsMaximum(Range): class GameMedleyMode(Toggle): """ If true, a percentage of keep areas will feature Game Medley as their game, with each trial sourced randomly from - the pool of available games. + a separate, dedicated pool of games. Activating Game Medley Mode will disable optional game conditions for keep areas assigned to Game Medley. """ @@ -212,6 +212,27 @@ class GameMedleyPercentageChance(Range): default = 100 +class GameMedleyGameSelection(OptionSet): + """ + Defines the game pool that will be used to generate Game Medley trials. + + Only game names originally listed in 'game_selection', 'metagame_selection' and 'modded_game_selection' are accepted. + + You are allowed to place games that already appear in other selection options here. + + If this is left empty, all games from other selection options will be used as a default. + """ + + display_name: str = "Game Medley Game Selection" + valid_keys = ( + sorted(AutoGameRegister.games.keys()) + + sorted(AutoGameRegister.metagames.keys()) + + sorted(AutoGameRegister.modded_games.keys()) + ) + + default = list() + + class MetagameSelection(OptionSet): """ Defines the metagame pool to select from. @@ -287,7 +308,7 @@ class ExcludedGamesDifficultObjectives(OptionSet): """ When 'include_difficult_objectives' is enabled, this option allows you to still exclude specific games. - Only game names from 'game_selection' and 'metagame_selection' are accepted. + Only game names originally listed in 'game_selection', 'metagame_selection' and 'modded_game_selection' are accepted. If a game specified here only offers difficult objectives, this option will have no effect for it. """ @@ -318,7 +339,7 @@ class ExcludedGamesTimeConsumingObjectives(OptionSet): """ When 'include_time_consuming_objectives' is enabled, this option allows you to still exclude specific games. - Only game names from 'game_selection' and 'metagame_selection' are accepted. + Only game names originally listed in 'game_selection', 'metagame_selection' and 'modded_game_selection' are accepted. If a game specified here only offers time-consuming objectives, this option will have no effect for it. """ @@ -359,6 +380,7 @@ class KeymastersKeepOptions(PerGameCommonOptions, GameArchipelagoOptions): area_trials_maximum: AreaTrialsMaximum game_medley_mode: GameMedleyMode game_medley_percentage_chance: GameMedleyPercentageChance + game_medley_game_selection: GameMedleyGameSelection metagame_selection: MetagameSelection game_selection: GameSelection modded_game_selection: ModdedGameSelection @@ -408,6 +430,7 @@ class KeymastersKeepOptions(PerGameCommonOptions, GameArchipelagoOptions): HintsRevealObjectives, GameMedleyMode, GameMedleyPercentageChance, + GameMedleyGameSelection, MetagameSelection, GameSelection, ModdedGameSelection, diff --git a/worlds/keymasters_keep/world.py b/worlds/keymasters_keep/world.py index 1f836757a33a..d3a198d9fb2b 100644 --- a/worlds/keymasters_keep/world.py +++ b/worlds/keymasters_keep/world.py @@ -117,6 +117,7 @@ class KeymastersKeepWorld(World): excluded_games_difficult_objectives: List[str] excluded_games_time_consuming_objectives: List[str] filler_item_names: List[str] = item_groups()["Filler"] + game_medley_game_selection: List[str] game_medley_mode: bool game_medley_percentage_chance: int game_selection: List[str] @@ -234,6 +235,7 @@ def generate_early(self) -> None: self.game_medley_mode = bool(self.options.game_medley_mode) self.game_medley_percentage_chance = self.options.game_medley_percentage_chance.value + self.game_medley_game_selection = list(self.options.game_medley_game_selection.value) self.game_selection = list(self.options.game_selection.value) self.metagame_selection = list(self.options.metagame_selection.value) @@ -616,6 +618,7 @@ def _generate_game_objective_data(self) -> None: generator: GameObjectiveGenerator = GameObjectiveGenerator( game_selection, + self.game_medley_game_selection, self.include_adult_only_or_unrated_games, self.include_modern_console_games, self.include_difficult_objectives,