Skip to content

Commit

Permalink
new option: game medley game selection
Browse files Browse the repository at this point in the history
  • Loading branch information
nbrochu committed Jan 10, 2025
1 parent 235d509 commit d237dba
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 4 deletions.
22 changes: 21 additions & 1 deletion worlds/keymasters_keep/game_objective_generator.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import logging

from random import Random
from typing import Any, List, Tuple, Type, Union

Expand All @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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]
Expand Down
29 changes: 26 additions & 3 deletions worlds/keymasters_keep/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
"""
Expand All @@ -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.
Expand Down Expand Up @@ -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.
"""
Expand Down Expand Up @@ -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.
"""
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -408,6 +430,7 @@ class KeymastersKeepOptions(PerGameCommonOptions, GameArchipelagoOptions):
HintsRevealObjectives,
GameMedleyMode,
GameMedleyPercentageChance,
GameMedleyGameSelection,
MetagameSelection,
GameSelection,
ModdedGameSelection,
Expand Down
3 changes: 3 additions & 0 deletions worlds/keymasters_keep/world.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit d237dba

Please sign in to comment.