Skip to content

Commit

Permalink
add game medley percentage chance option + add game medley options to…
Browse files Browse the repository at this point in the history
… seed information in gui
  • Loading branch information
nbrochu committed Jan 1, 2025
1 parent 1ed2b5c commit 25432c7
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 20 deletions.
4 changes: 4 additions & 0 deletions worlds/keymasters_keep/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ class KeymastersKeepContext(CommonClient.CommonContext):
artifacts_of_resolve_required: int
artifacts_of_resolve_total: int
completed_locations_queue: collections.deque
game_medley_mode: bool
game_medley_percentage_chance: int
goal: KeymastersKeepGoals
goal_completed: bool
goal_game: str
Expand Down Expand Up @@ -130,6 +132,8 @@ def on_package(self, cmd: str, _args: Any) -> None:
self.area_trials_minimum = _args["slot_data"]["area_trials_minimum"]
self.artifacts_of_resolve_required = _args["slot_data"]["artifacts_of_resolve_required"]
self.artifacts_of_resolve_total = _args["slot_data"]["artifacts_of_resolve_total"]
self.game_medley_mode = _args["slot_data"]["game_medley_mode"]
self.game_medley_percentage_chance = _args["slot_data"]["game_medley_percentage_chance"]
self.goal = KeymastersKeepGoals(_args["slot_data"]["goal"])
self.goal_game = _args["slot_data"]["goal_game"]
self.goal_game_optional_constraints = _args["slot_data"]["goal_game_optional_constraints"]
Expand Down
8 changes: 7 additions & 1 deletion worlds/keymasters_keep/client_gui/client_gui_layouts.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,11 @@ def __init__(self, ctx: KeymastersKeepContext):

lm: Dict[Any, str] = label_mapping

game_medley_mode_label: str = lm[self.ctx.game_medley_mode]

if self.ctx.game_medley_mode:
game_medley_mode_label += f" ({self.ctx.game_medley_percentage_chance}% chance)"

seed_information_content_label: Label = Label(
text=(
f"Keep Areas: [color=00FA9A]{len(self.ctx.area_trials)}[/color]\n"
Expand All @@ -349,14 +354,15 @@ def __init__(self, ctx: KeymastersKeepContext):
f"Lock Magic Keys (Maximum): [color=00FA9A]{self.ctx.lock_magic_keys_maximum}[/color]\n"
f"Area Trials (Minimum): [color=00FA9A]{self.ctx.area_trials_minimum}[/color]\n"
f"Area Trials (Maximum): [color=00FA9A]{self.ctx.area_trials_maximum}[/color]\n\n"
f"Game Medley Mode: [color=00FA9A]{game_medley_mode_label}[/color]\n\n"
f"Include 18+ / Unrated Games: [color=00FA9A]{lm[self.ctx.include_adult_only_or_unrated_games]}[/color]\n"
f"Include Difficult Objectives: [color=00FA9A]{lm[self.ctx.include_difficult_objectives]}[/color]\n"
f"Include Time Consuming Objectives: [color=00FA9A]{lm[self.ctx.include_time_consuming_objectives]}[/color]\n\n"
f"Hints Reveal Objectives: [color=00FA9A]{lm[self.ctx.hints_reveal_objectives]}[/color]"
),
markup=True,
size_hint_y=None,
height="260dp",
height="300dp",
halign="left",
valign="top",
)
Expand Down
27 changes: 16 additions & 11 deletions worlds/keymasters_keep/game_objective_generator.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from random import Random
from typing import Any, List, Tuple, Type
from typing import Any, List, Tuple, Type, Union

from .game import Game
from .games import AutoGameRegister
Expand Down Expand Up @@ -47,6 +47,7 @@ def generate_from_plan(
include_time_consuming: bool = False,
excluded_games_time_consuming: List[str] = None,
game_medley_mode: bool = False,
game_medley_percentage_chance: int = 100,
) -> GameObjectiveGeneratorData:
if plan is None or not len(plan):
return list()
Expand All @@ -56,22 +57,26 @@ def generate_from_plan(

game_selection: List[Type[Game]] = list()

if game_medley_mode:
game_selection = [GameMedleyGame for _ in range(plan_length)]
if plan_length <= len(self.games):
game_selection = random.sample(self.games, plan_length)
else:
if plan_length <= len(self.games):
game_selection = random.sample(self.games, plan_length)
else:
for _ in range(plan_length):
game_selection.append(random.choice(self.games))
for _ in range(plan_length):
game_selection.append(random.choice(self.games))

if game_medley_mode:
for i in range(len(game_selection)):
if random.randint(1, 100) <= game_medley_percentage_chance:
game_selection[i] = GameMedleyGame

data: GameObjectiveGeneratorData = list()

i: int
count: int
for i, count in enumerate(plan):
if game_medley_mode:
game: Game = game_selection[i](
game_class: Type[Union[Game, GameMedleyGame]] = game_selection[i]

if game_class == GameMedleyGame:
game: GameMedleyGame = game_class(
random=random,
archipelago_options=self.archipelago_options,
game_selection=self.games,
Expand All @@ -87,7 +92,7 @@ def generate_from_plan(

data.append((game, optional_constraints, objectives))
else:
game: Game = game_selection[i](random=random, archipelago_options=self.archipelago_options)
game: Game = game_class(random=random, archipelago_options=self.archipelago_options)

is_in_difficult_exclusions: bool = game.game_name_with_platforms() in excluded_games_difficult
include_difficult = include_difficult and not is_in_difficult_exclusions
Expand Down
20 changes: 18 additions & 2 deletions worlds/keymasters_keep/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,14 +181,28 @@ class AreaTrialsMaximum(Range):

class GameMedleyMode(Toggle):
"""
If true, keep areas will all have Game Medley as their game and each trial will be from a random game in the pool.
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.
Using Game Medley Mode will disable optional game conditions.
Activating Game Medley Mode will disable optional game conditions for keep areas assigned to Game Medley.
"""

display_name: str = "Game Medley Mode"


class GameMedleyPercentageChance(Range):
"""
Determines the percentage chance of a game medley being selected when Game Medley Mode is enabled.
"""

display_name: str = "Game Medley Percentage Chance"

range_start: int = 1
range_end: int = 100

default = 100


class GameSelection(OptionSet):
"""
Defines the game pool to select from.
Expand Down Expand Up @@ -302,6 +316,7 @@ class KeymastersKeepOptions(PerGameCommonOptions, GameArchipelagoOptions):
area_trials_minimum: AreaTrialsMinimum
area_trials_maximum: AreaTrialsMaximum
game_medley_mode: GameMedleyMode
game_medley_percentage_chance: GameMedleyPercentageChance
game_selection: GameSelection
metagame_selection: MetagameSelection
include_adult_only_or_unrated_games: IncludeAdultOnlyOrUnratedGames
Expand Down Expand Up @@ -347,6 +362,7 @@ class KeymastersKeepOptions(PerGameCommonOptions, GameArchipelagoOptions):
ExcludedGamesTimeConsumingObjectives,
HintsRevealObjectives,
GameMedleyMode,
GameMedleyPercentageChance,
MetagameSelection,
GameSelection,
],
Expand Down
13 changes: 7 additions & 6 deletions worlds/keymasters_keep/world.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ class KeymastersKeepWorld(World):
excluded_games_time_consuming_objectives: List[str]
filler_item_names: List[str] = item_groups()["Filler"]
game_medley_mode: bool
game_medley_percentage_chance: int
game_selection: List[str]
goal: KeymastersKeepGoals
goal_game: str
Expand Down Expand Up @@ -204,6 +205,7 @@ def generate_early(self) -> None:
self._generate_keep()

self.game_medley_mode = bool(self.options.game_medley_mode)
self.game_medley_percentage_chance = self.options.game_medley_percentage_chance.value

self.game_selection = list(self.options.game_selection.value)
self.metagame_selection = list(self.options.metagame_selection.value)
Expand Down Expand Up @@ -428,6 +430,7 @@ def fill_slot_data(self) -> Dict[str, Any]:
"artifacts_of_resolve_required": self.artifacts_of_resolve_required,
"artifacts_of_resolve_total": self.artifacts_of_resolve_total,
"game_medley_mode": self.game_medley_mode,
"game_medley_percentage_chance": self.game_medley_percentage_chance,
"goal": self.goal.value,
"goal_game": self.goal_game,
"goal_game_optional_constraints": self.goal_game_optional_constraints,
Expand Down Expand Up @@ -468,12 +471,9 @@ def extend_hint_information(self, hint_data: Dict[int, Dict[int, str]]):
for area, trial_locations in self.area_trials.items():
trial_location: KeymastersKeepLocationData
for trial_location in trial_locations:
if self.game_medley_mode:
data[trial_location.archipelago_id] = self.area_trial_game_objectives[trial_location.name]
else:
data[trial_location.archipelago_id] = (
f"{self.area_games[area.value]}: {self.area_trial_game_objectives[trial_location.name]}"
)
data[trial_location.archipelago_id] = (
f"{self.area_games[area.value]}: {self.area_trial_game_objectives[trial_location.name]}"
)

hint_data[self.player] = data

Expand Down Expand Up @@ -605,6 +605,7 @@ def _generate_game_objective_data(self) -> None:
self.include_time_consuming_objectives,
self.excluded_games_time_consuming_objectives,
self.game_medley_mode,
self.game_medley_percentage_chance,
)

self.area_games = dict()
Expand Down

0 comments on commit 25432c7

Please sign in to comment.