From 82cd51f5f40b2acda9be5e96c70016ff76fb5175 Mon Sep 17 00:00:00 2001 From: espeon65536 Date: Sat, 22 May 2021 10:57:13 -0500 Subject: [PATCH] structure plando for Minecraft --- Mystery.py | 11 +++++++++++ worlds/minecraft/Regions.py | 15 ++++++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/Mystery.py b/Mystery.py index 12758173..a80872b8 100644 --- a/Mystery.py +++ b/Mystery.py @@ -564,6 +564,17 @@ def roll_settings(weights: dict, plando_options: typing.Set[str] = frozenset(("b setattr(ret, option_name, option.from_any(get_choice(option_name, weights))) else: setattr(ret, option_name, option(option.default)) + # bad hardcoded behavior to make this work for now + ret.plando_connections = [] + if "connections" in plando_options: + options = weights.get("plando_connections", []) + for placement in options: + if roll_percentage(get_choice("percentage", placement, 100)): + ret.plando_connections.append(PlandoConnection( + get_choice("entrance", placement), + get_choice("exit", placement), + get_choice("direction", placement, "both") + )) else: raise Exception(f"Unsupported game {ret.game}") return ret diff --git a/worlds/minecraft/Regions.py b/worlds/minecraft/Regions.py index e3cc53b0..2475e038 100644 --- a/worlds/minecraft/Regions.py +++ b/worlds/minecraft/Regions.py @@ -38,12 +38,25 @@ def link_minecraft_structures(world: MultiWorld, player: int): return False def set_pair(exit, struct): + try: + assert exit in exits + assert struct in structs + except AssertionError as e: + raise Exception(f"Invalid connection: {exit} => {struct} for player {player}") pairs[exit] = struct exits.remove(exit) structs.remove(struct) # Plando stuff. Remove any utilized exits/structs from the lists. # Raise error if trying to put Nether Fortress in the End. + if world.plando_connections[player]: + for connection in world.plando_connections[player]: + try: + if connection.entrance == 'The End Structure' and connection.exit == 'Nether Fortress': + raise Exception(f"Cannot place Nether Fortress in the End for player {player}") + set_pair(connection.entrance, connection.exit) + except Exception as e: + raise Exception(f"Could not connect using {connection}") from e if world.shuffle_structures[player]: # Can't put Nether Fortress in the End @@ -51,7 +64,7 @@ def link_minecraft_structures(world: MultiWorld, player: int): try: end_struct = world.random.choice([s for s in structs if s != 'Nether Fortress']) set_pair('The End Structure', end_struct) - except IndexError as e: + except IndexError as e: # should only happen if structs is emptied by plando raise Exception(f"Plando forced Nether Fortress in the End for player {player}") from e world.random.shuffle(structs) for exit, struct in zip(exits[:], structs[:]):