From 05d2ba44e480a4abe5ac3a62efcb276eca5d9075 Mon Sep 17 00:00:00 2001 From: Faris Date: Wed, 24 Apr 2024 19:07:14 -0500 Subject: [PATCH] Updating to a post-LttP main.py --- worlds/tracker/TrackerClient.py | 137 +++++++++++++------------------- 1 file changed, 55 insertions(+), 82 deletions(-) diff --git a/worlds/tracker/TrackerClient.py b/worlds/tracker/TrackerClient.py index d9d1be2f6d05..b93384520471 100644 --- a/worlds/tracker/TrackerClient.py +++ b/worlds/tracker/TrackerClient.py @@ -278,7 +278,6 @@ def run_generator(self): logger.error(tb) def TMain(self, args, seed=None, baked_server_options: Optional[Dict[str, object]] = None): - if not baked_server_options: baked_server_options = get_settings().server_options.as_dict() assert isinstance(baked_server_options, dict) @@ -286,57 +285,33 @@ def TMain(self, args, seed=None, baked_server_options: Optional[Dict[str, object os.makedirs(args.outputpath, exist_ok=True) output_path.cached_path = args.outputpath + start = time.perf_counter() - # initialize the world - world = MultiWorld(args.multi) + # initialize the multiworld + multiworld = MultiWorld(args.multi) ### # Tracker Specific change to allow for worlds to know they aren't real ### - world.generation_is_fake = True + multiworld.generation_is_fake = True if self.re_gen_passthrough is not None: - world.re_gen_passthrough = self.re_gen_passthrough + multiworld.re_gen_passthrough = self.re_gen_passthrough logger = logging.getLogger() - world.set_seed(seed, args.race, str(args.outputname) if args.outputname else None) - world.plando_options = args.plando_options - - world.shuffle = args.shuffle.copy() - world.logic = args.logic.copy() - world.mode = args.mode.copy() - world.difficulty = args.difficulty.copy() - world.item_functionality = args.item_functionality.copy() - world.timer = args.timer.copy() - world.goal = args.goal.copy() - world.boss_shuffle = args.shufflebosses.copy() - world.enemy_health = args.enemy_health.copy() - world.enemy_damage = args.enemy_damage.copy() - world.beemizer_total_chance = args.beemizer_total_chance.copy() - world.beemizer_trap_chance = args.beemizer_trap_chance.copy() - world.countdown_start_time = args.countdown_start_time.copy() - world.red_clock_time = args.red_clock_time.copy() - world.blue_clock_time = args.blue_clock_time.copy() - world.green_clock_time = args.green_clock_time.copy() - world.dungeon_counters = args.dungeon_counters.copy() - world.triforce_pieces_available = args.triforce_pieces_available.copy() - world.triforce_pieces_required = args.triforce_pieces_required.copy() - world.shop_shuffle = args.shop_shuffle.copy() - world.shuffle_prizes = args.shuffle_prizes.copy() - world.sprite_pool = args.sprite_pool.copy() - world.dark_room_logic = args.dark_room_logic.copy() - world.plando_items = args.plando_items.copy() - world.plando_texts = args.plando_texts.copy() - world.plando_connections = args.plando_connections.copy() - world.required_medallions = args.required_medallions.copy() - world.game = args.game.copy() - world.player_name = args.name.copy() - world.sprite = args.sprite.copy() - world.glitch_triforce = args.glitch_triforce # This is enabled/disabled globally, no per player option. - - world.set_options(args) - world.set_item_links() - world.state = CollectionState(world) - logger.info('Archipelago Version %s - Seed: %s\n', __version__, world.seed) + multiworld.set_seed(seed, args.race, str(args.outputname) if args.outputname else None) + multiworld.plando_options = args.plando_options + multiworld.plando_items = args.plando_items.copy() + multiworld.plando_texts = args.plando_texts.copy() + multiworld.plando_connections = args.plando_connections.copy() + multiworld.game = args.game.copy() + multiworld.player_name = args.name.copy() + multiworld.sprite = args.sprite.copy() + multiworld.sprite_pool = args.sprite_pool.copy() + + multiworld.set_options(args) + multiworld.set_item_links() + multiworld.state = CollectionState(multiworld) + logger.info('Archipelago Version %s - Seed: %s\n', __version__, multiworld.seed) logger.info(f"Found {len(AutoWorld.AutoWorldRegister.world_types)} World Types:") longest_name = max(len(text) for text in AutoWorld.AutoWorldRegister.world_types) @@ -351,8 +326,7 @@ def TMain(self, args, seed=None, baked_server_options: Optional[Dict[str, object item_digits = len(str(max_item)) location_digits = len(str(max_location)) item_count = len(str(max(len(cls.item_names) for cls in AutoWorld.AutoWorldRegister.world_types.values()))) - location_count = len( - str(max(len(cls.location_names) for cls in AutoWorld.AutoWorldRegister.world_types.values()))) + location_count = len(str(max(len(cls.location_names) for cls in AutoWorld.AutoWorldRegister.world_types.values()))) del max_item, max_location for name, cls in AutoWorld.AutoWorldRegister.world_types.items(): @@ -368,72 +342,71 @@ def TMain(self, args, seed=None, baked_server_options: Optional[Dict[str, object # This assertion method should not be necessary to run if we are not outputting any multidata. if not args.skip_output: - AutoWorld.call_stage(world, "assert_generate") + AutoWorld.call_stage(multiworld, "assert_generate") - AutoWorld.call_all(world, "generate_early") + AutoWorld.call_all(multiworld, "generate_early") logger.info('') - for player in world.player_ids: - for item_name, count in world.worlds[player].options.start_inventory.value.items(): + for player in multiworld.player_ids: + for item_name, count in multiworld.worlds[player].options.start_inventory.value.items(): for _ in range(count): - world.push_precollected(world.create_item(item_name, player)) + multiworld.push_precollected(multiworld.create_item(item_name, player)) - for item_name, count in world.start_inventory_from_pool.setdefault(player, - StartInventoryPool({})).value.items(): + for item_name, count in getattr(multiworld.worlds[player].options, + "start_inventory_from_pool", + StartInventoryPool({})).value.items(): for _ in range(count): - world.push_precollected(world.create_item(item_name, player)) + multiworld.push_precollected(multiworld.create_item(item_name, player)) # remove from_pool items also from early items handling, as starting is plenty early. - early = world.early_items[player].get(item_name, 0) + early = multiworld.early_items[player].get(item_name, 0) if early: - world.early_items[player][item_name] = max(0, early - count) - remaining_count = count - early + multiworld.early_items[player][item_name] = max(0, early-count) + remaining_count = count-early if remaining_count > 0: - local_early = world.early_local_items[player].get(item_name, 0) + local_early = multiworld.early_local_items[player].get(item_name, 0) if local_early: - world.early_items[player][item_name] = max(0, local_early - remaining_count) + multiworld.early_items[player][item_name] = max(0, local_early - remaining_count) del local_early del early - logger.info('Creating World.') - AutoWorld.call_all(world, "create_regions") + logger.info('Creating MultiWorld.') + AutoWorld.call_all(multiworld, "create_regions") logger.info('Creating Items.') - AutoWorld.call_all(world, "create_items") + AutoWorld.call_all(multiworld, "create_items") logger.info('Calculating Access Rules.') - for player in world.player_ids: + for player in multiworld.player_ids: # items can't be both local and non-local, prefer local - world.worlds[player].options.non_local_items.value -= world.worlds[player].options.local_items.value - world.worlds[player].options.non_local_items.value -= set(world.local_early_items[player]) + multiworld.worlds[player].options.non_local_items.value -= multiworld.worlds[player].options.local_items.value + multiworld.worlds[player].options.non_local_items.value -= set(multiworld.local_early_items[player]) - AutoWorld.call_all(world, "set_rules") + AutoWorld.call_all(multiworld, "set_rules") - for player in world.player_ids: - exclusion_rules(world, player, world.worlds[player].options.exclude_locations.value) - world.worlds[player].options.priority_locations.value -= world.worlds[ - player].options.exclude_locations.value - for location_name in world.worlds[player].options.priority_locations.value: + for player in multiworld.player_ids: + exclusion_rules(multiworld, player, multiworld.worlds[player].options.exclude_locations.value) + multiworld.worlds[player].options.priority_locations.value -= multiworld.worlds[player].options.exclude_locations.value + for location_name in multiworld.worlds[player].options.priority_locations.value: try: - location = world.get_location(location_name, player) + location = multiworld.get_location(location_name, player) except KeyError as e: # failed to find the given location. Check if it's a legitimate location - if location_name not in world.worlds[player].location_name_to_id: - raise Exception( - f"Unable to prioritize location {location_name} in player {player}'s world.") from e + if location_name not in multiworld.worlds[player].location_name_to_id: + raise Exception(f"Unable to prioritize location {location_name} in player {player}'s world.") from e else: location.progress_type = LocationProgressType.PRIORITY # Set local and non-local item rules. - if world.players > 1: - locality_rules(world) + if multiworld.players > 1: + locality_rules(multiworld) else: - world.worlds[1].options.non_local_items.value = set() - world.worlds[1].options.local_items.value = set() - - AutoWorld.call_all(world, "generate_basic") + multiworld.worlds[1].options.non_local_items.value = set() + multiworld.worlds[1].options.local_items.value = set() + + AutoWorld.call_all(multiworld, "generate_basic") - self.multiworld = world + self.multiworld = multiworld return