| 
									
										
										
										
											2023-04-06 03:48:30 -05:00
										 |  |  |  | import logging | 
					
						
							| 
									
										
										
										
											2024-04-18 11:59:30 -05:00
										 |  |  |  | from typing import Any, ClassVar, Dict, List, Optional, Set, TextIO | 
					
						
							| 
									
										
										
										
											2023-03-12 09:05:50 -05:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-11 17:23:41 -05:00
										 |  |  |  | from BaseClasses import CollectionState, Entrance, Item, ItemClassification, MultiWorld, Tutorial | 
					
						
							|  |  |  |  | from Options import Accessibility | 
					
						
							|  |  |  |  | from Utils import output_path | 
					
						
							|  |  |  |  | from settings import FilePath, Group | 
					
						
							| 
									
										
										
										
											2023-10-08 07:33:39 -05:00
										 |  |  |  | from worlds.AutoWorld import WebWorld, World | 
					
						
							| 
									
										
										
										
											2024-03-11 17:23:41 -05:00
										 |  |  |  | from worlds.LauncherComponents import Component, Type, components | 
					
						
							|  |  |  |  | from .client_setup import launch_game | 
					
						
							|  |  |  |  | from .connections import CONNECTIONS, RANDOMIZED_CONNECTIONS, TRANSITIONS | 
					
						
							| 
									
										
										
										
											2024-03-31 10:47:11 -05:00
										 |  |  |  | from .constants import ALL_ITEMS, ALWAYS_LOCATIONS, BOSS_LOCATIONS, FILLER, NOTES, PHOBEKINS, PROG_ITEMS, TRAPS, \ | 
					
						
							|  |  |  |  |     USEFUL_ITEMS | 
					
						
							| 
									
										
										
										
											2024-03-11 17:23:41 -05:00
										 |  |  |  | from .options import AvailablePortals, Goal, Logic, MessengerOptions, NotesNeeded, ShuffleTransitions | 
					
						
							|  |  |  |  | from .portals import PORTALS, add_closed_portal_reqs, disconnect_portals, shuffle_portals, validate_portals | 
					
						
							|  |  |  |  | from .regions import LEVELS, MEGA_SHARDS, LOCATIONS, REGION_CONNECTIONS | 
					
						
							| 
									
										
										
										
											2023-10-08 07:33:39 -05:00
										 |  |  |  | from .rules import MessengerHardRules, MessengerOOBRules, MessengerRules | 
					
						
							| 
									
										
										
										
											2024-03-11 17:23:41 -05:00
										 |  |  |  | from .shop import FIGURINES, PROG_SHOP_ITEMS, SHOP_ITEMS, USEFUL_SHOP_ITEMS, shuffle_shop_prices | 
					
						
							|  |  |  |  | from .subclasses import MessengerEntrance, MessengerItem, MessengerRegion, MessengerShopLocation | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | components.append( | 
					
						
							|  |  |  |  |     Component("The Messenger", component_type=Type.CLIENT, func=launch_game)#, game_name="The Messenger", supports_uri=True) | 
					
						
							|  |  |  |  | ) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | class MessengerSettings(Group): | 
					
						
							|  |  |  |  |     class GamePath(FilePath): | 
					
						
							|  |  |  |  |         description = "The Messenger game executable" | 
					
						
							|  |  |  |  |         is_exe = True | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     game_path: GamePath = GamePath("TheMessenger.exe") | 
					
						
							| 
									
										
										
										
											2023-03-12 09:05:50 -05:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | class MessengerWeb(WebWorld): | 
					
						
							|  |  |  |  |     theme = "ocean" | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-25 16:11:51 -05:00
										 |  |  |  |     bug_report_page = "https://github.com/alwaysintreble/TheMessengerRandomizerModAP/issues" | 
					
						
							| 
									
										
										
										
											2023-03-12 09:05:50 -05:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |     tut_en = Tutorial( | 
					
						
							| 
									
										
										
										
											2024-02-20 11:22:32 -05:00
										 |  |  |  |         "Multiworld Setup Guide", | 
					
						
							| 
									
										
										
										
											2023-03-12 09:05:50 -05:00
										 |  |  |  |         "A guide to setting up The Messenger randomizer on your computer.", | 
					
						
							|  |  |  |  |         "English", | 
					
						
							|  |  |  |  |         "setup_en.md", | 
					
						
							|  |  |  |  |         "setup/en", | 
					
						
							| 
									
										
										
										
											2023-04-03 19:27:36 -05:00
										 |  |  |  |         ["alwaysintreble"], | 
					
						
							| 
									
										
										
										
											2023-03-12 09:05:50 -05:00
										 |  |  |  |     ) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     tutorials = [tut_en] | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | class MessengerWorld(World): | 
					
						
							|  |  |  |  |     """
 | 
					
						
							|  |  |  |  |     As a demon army besieges his village, a young ninja ventures through a cursed world, to deliver a scroll paramount | 
					
						
							|  |  |  |  |     to his clan’s survival. What begins as a classic action platformer soon unravels into an expansive time-traveling | 
					
						
							|  |  |  |  |     adventure full of thrills, surprises, and humor. | 
					
						
							|  |  |  |  |     """
 | 
					
						
							|  |  |  |  |     game = "The Messenger" | 
					
						
							| 
									
										
										
										
											2023-10-10 15:30:20 -05:00
										 |  |  |  |     options_dataclass = MessengerOptions | 
					
						
							|  |  |  |  |     options: MessengerOptions | 
					
						
							| 
									
										
										
										
											2024-03-11 17:23:41 -05:00
										 |  |  |  |     settings_key = "messenger_settings" | 
					
						
							|  |  |  |  |     settings: ClassVar[MessengerSettings] | 
					
						
							| 
									
										
										
										
											2023-03-12 09:05:50 -05:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |     base_offset = 0xADD_000 | 
					
						
							|  |  |  |  |     item_name_to_id = {item: item_id | 
					
						
							|  |  |  |  |                        for item_id, item in enumerate(ALL_ITEMS, base_offset)} | 
					
						
							|  |  |  |  |     location_name_to_id = {location: location_id | 
					
						
							| 
									
										
										
										
											2023-04-06 03:48:30 -05:00
										 |  |  |  |                            for location_id, location in | 
					
						
							|  |  |  |  |                            enumerate([ | 
					
						
							|  |  |  |  |                                *ALWAYS_LOCATIONS, | 
					
						
							| 
									
										
										
										
											2023-06-29 07:33:37 -05:00
										 |  |  |  |                                *[shard for shards in MEGA_SHARDS.values() for shard in shards], | 
					
						
							| 
									
										
										
										
											2023-04-06 03:48:30 -05:00
										 |  |  |  |                                *BOSS_LOCATIONS, | 
					
						
							| 
									
										
										
										
											2023-06-29 07:33:37 -05:00
										 |  |  |  |                                *[f"The Shop - {shop_loc}" for shop_loc in SHOP_ITEMS], | 
					
						
							| 
									
										
										
										
											2023-06-27 18:39:52 -05:00
										 |  |  |  |                                *FIGURINES, | 
					
						
							|  |  |  |  |                                "Money Wrench", | 
					
						
							| 
									
										
										
										
											2023-04-06 03:48:30 -05:00
										 |  |  |  |                            ], base_offset)} | 
					
						
							| 
									
										
										
										
											2024-03-11 17:23:41 -05:00
										 |  |  |  |     item_name_groups = { | 
					
						
							|  |  |  |  |         "Notes": set(NOTES), | 
					
						
							|  |  |  |  |         "Keys": set(NOTES), | 
					
						
							|  |  |  |  |         "Crest": {"Sun Crest", "Moon Crest"}, | 
					
						
							|  |  |  |  |         "Phobe": set(PHOBEKINS), | 
					
						
							|  |  |  |  |         "Phobekin": set(PHOBEKINS), | 
					
						
							|  |  |  |  |     } | 
					
						
							|  |  |  |  |     location_name_groups = { | 
					
						
							|  |  |  |  |         "Notes": { | 
					
						
							|  |  |  |  |             "Autumn Hills - Key of Hope", | 
					
						
							|  |  |  |  |             "Searing Crags - Key of Strength", | 
					
						
							|  |  |  |  |             "Underworld - Key of Chaos", | 
					
						
							|  |  |  |  |             "Sunken Shrine - Key of Love", | 
					
						
							|  |  |  |  |             "Elemental Skylands - Key of Symbiosis", | 
					
						
							|  |  |  |  |             "Corrupted Future - Key of Courage", | 
					
						
							|  |  |  |  |         }, | 
					
						
							|  |  |  |  |         "Keys": { | 
					
						
							|  |  |  |  |             "Autumn Hills - Key of Hope", | 
					
						
							|  |  |  |  |             "Searing Crags - Key of Strength", | 
					
						
							|  |  |  |  |             "Underworld - Key of Chaos", | 
					
						
							|  |  |  |  |             "Sunken Shrine - Key of Love", | 
					
						
							|  |  |  |  |             "Elemental Skylands - Key of Symbiosis", | 
					
						
							|  |  |  |  |             "Corrupted Future - Key of Courage", | 
					
						
							|  |  |  |  |         }, | 
					
						
							|  |  |  |  |         "Phobe": { | 
					
						
							|  |  |  |  |             "Catacombs - Necro", | 
					
						
							|  |  |  |  |             "Bamboo Creek - Claustro", | 
					
						
							|  |  |  |  |             "Searing Crags - Pyro", | 
					
						
							|  |  |  |  |             "Cloud Ruins - Acro", | 
					
						
							|  |  |  |  |         }, | 
					
						
							|  |  |  |  |         "Phobekin": { | 
					
						
							|  |  |  |  |             "Catacombs - Necro", | 
					
						
							|  |  |  |  |             "Bamboo Creek - Claustro", | 
					
						
							|  |  |  |  |             "Searing Crags - Pyro", | 
					
						
							|  |  |  |  |             "Cloud Ruins - Acro", | 
					
						
							|  |  |  |  |         }, | 
					
						
							|  |  |  |  |     } | 
					
						
							| 
									
										
										
										
											2023-03-12 09:05:50 -05:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-31 10:47:11 -05:00
										 |  |  |  |     required_client_version = (0, 4, 4) | 
					
						
							| 
									
										
										
										
											2023-03-12 09:05:50 -05:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |     web = MessengerWeb() | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-06 03:48:30 -05:00
										 |  |  |  |     total_seals: int = 0 | 
					
						
							|  |  |  |  |     required_seals: int = 0 | 
					
						
							| 
									
										
										
										
											2024-03-11 17:23:41 -05:00
										 |  |  |  |     created_seals: int = 0 | 
					
						
							| 
									
										
										
										
											2023-10-08 07:33:39 -05:00
										 |  |  |  |     total_shards: int = 0 | 
					
						
							| 
									
										
										
										
											2023-06-27 18:39:52 -05:00
										 |  |  |  |     shop_prices: Dict[str, int] | 
					
						
							|  |  |  |  |     figurine_prices: Dict[str, int] | 
					
						
							| 
									
										
										
										
											2023-08-01 12:43:10 -05:00
										 |  |  |  |     _filler_items: List[str] | 
					
						
							| 
									
										
										
										
											2024-03-11 17:23:41 -05:00
										 |  |  |  |     starting_portals: List[str] | 
					
						
							|  |  |  |  |     plando_portals: List[str] | 
					
						
							|  |  |  |  |     spoiler_portal_mapping: Dict[str, str] | 
					
						
							|  |  |  |  |     portal_mapping: List[int] | 
					
						
							|  |  |  |  |     transitions: List[Entrance] | 
					
						
							|  |  |  |  |     reachable_locs: int = 0 | 
					
						
							| 
									
										
										
										
											2024-03-31 10:47:11 -05:00
										 |  |  |  |     filler: Dict[str, int] | 
					
						
							| 
									
										
										
										
											2023-06-27 18:39:52 -05:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-12 09:05:50 -05:00
										 |  |  |  |     def generate_early(self) -> None: | 
					
						
							| 
									
										
										
										
											2023-10-10 15:30:20 -05:00
										 |  |  |  |         if self.options.goal == Goal.option_power_seal_hunt: | 
					
						
							|  |  |  |  |             self.total_seals = self.options.total_seals.value | 
					
						
							| 
									
										
										
										
											2023-03-12 09:05:50 -05:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-11 17:23:41 -05:00
										 |  |  |  |         if self.options.limited_movement: | 
					
						
							|  |  |  |  |             self.options.accessibility.value = Accessibility.option_minimal | 
					
						
							|  |  |  |  |             if self.options.logic_level < Logic.option_hard: | 
					
						
							|  |  |  |  |                 self.options.logic_level.value = Logic.option_hard | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         if self.options.early_meditation: | 
					
						
							|  |  |  |  |             self.multiworld.early_items[self.player]["Meditation"] = 1 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-24 19:41:20 -05:00
										 |  |  |  |         self.shop_prices, self.figurine_prices = shuffle_shop_prices(self) | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-11 17:23:41 -05:00
										 |  |  |  |         starting_portals = ["Autumn Hills", "Howling Grotto", "Glacial Peak", "Riviere Turquoise", "Sunken Shrine", "Searing Crags"] | 
					
						
							|  |  |  |  |         self.starting_portals = [f"{portal} Portal" | 
					
						
							|  |  |  |  |                                  for portal in starting_portals[:3] + | 
					
						
							|  |  |  |  |                                  self.random.sample(starting_portals[3:], k=self.options.available_portals - 3)] | 
					
						
							| 
									
										
										
										
											2024-03-31 10:47:11 -05:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-11 17:23:41 -05:00
										 |  |  |  |         # super complicated method for adding searing crags to starting portals if it wasn't chosen | 
					
						
							| 
									
										
										
										
											2024-03-31 10:47:11 -05:00
										 |  |  |  |         # TODO add a check for transition shuffle when that gets added back in | 
					
						
							| 
									
										
										
										
											2024-03-11 17:23:41 -05:00
										 |  |  |  |         if not self.options.shuffle_portals and "Searing Crags Portal" not in self.starting_portals: | 
					
						
							|  |  |  |  |             self.starting_portals.append("Searing Crags Portal") | 
					
						
							| 
									
										
										
										
											2024-04-18 11:59:30 -05:00
										 |  |  |  |             portals_to_strip = [portal for portal in ["Riviere Turquoise Portal", "Sunken Shrine Portal"] | 
					
						
							|  |  |  |  |                                 if portal in self.starting_portals] | 
					
						
							| 
									
										
										
										
											2024-05-17 03:18:50 -05:00
										 |  |  |  |             if portals_to_strip: | 
					
						
							|  |  |  |  |                 self.starting_portals.remove(self.random.choice(portals_to_strip)) | 
					
						
							| 
									
										
										
										
											2024-03-11 17:23:41 -05:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-31 10:47:11 -05:00
										 |  |  |  |         self.filler = FILLER.copy() | 
					
						
							| 
									
										
										
										
											2024-04-18 11:59:30 -05:00
										 |  |  |  |         if self.options.traps: | 
					
						
							| 
									
										
										
										
											2024-03-31 10:47:11 -05:00
										 |  |  |  |             self.filler.update(TRAPS) | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-11 17:23:41 -05:00
										 |  |  |  |         self.plando_portals = [] | 
					
						
							|  |  |  |  |         self.portal_mapping = [] | 
					
						
							|  |  |  |  |         self.spoiler_portal_mapping = {} | 
					
						
							|  |  |  |  |         self.transitions = [] | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-12 09:05:50 -05:00
										 |  |  |  |     def create_regions(self) -> None: | 
					
						
							| 
									
										
										
										
											2023-11-10 22:49:55 -06:00
										 |  |  |  |         # MessengerRegion adds itself to the multiworld | 
					
						
							| 
									
										
										
										
											2024-03-11 17:23:41 -05:00
										 |  |  |  |         # create simple regions | 
					
						
							|  |  |  |  |         simple_regions = [MessengerRegion(level, self) for level in LEVELS] | 
					
						
							|  |  |  |  |         # create complex regions that have sub-regions | 
					
						
							|  |  |  |  |         complex_regions = [MessengerRegion(f"{parent} - {reg_name}", self, parent) | 
					
						
							|  |  |  |  |                            for parent, sub_region in CONNECTIONS.items() | 
					
						
							|  |  |  |  |                            for reg_name in sub_region] | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         for region in complex_regions: | 
					
						
							|  |  |  |  |             region_name = region.name.replace(f"{region.parent} - ", "") | 
					
						
							|  |  |  |  |             connection_data = CONNECTIONS[region.parent][region_name] | 
					
						
							|  |  |  |  |             for exit_region in connection_data: | 
					
						
							|  |  |  |  |                 region.connect(self.multiworld.get_region(exit_region, self.player)) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         # all regions need to be created before i can do these connections so we create and connect the complex first | 
					
						
							|  |  |  |  |         for region in [level for level in simple_regions if level.name in REGION_CONNECTIONS]: | 
					
						
							|  |  |  |  |             region.add_exits(REGION_CONNECTIONS[region.name]) | 
					
						
							| 
									
										
										
										
											2023-03-12 09:05:50 -05:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |     def create_items(self) -> None: | 
					
						
							| 
									
										
										
										
											2023-06-27 18:39:52 -05:00
										 |  |  |  |         # create items that are always in the item pool | 
					
						
							| 
									
										
										
										
											2024-03-11 17:23:41 -05:00
										 |  |  |  |         main_movement_items = ["Rope Dart", "Wingsuit"] | 
					
						
							| 
									
										
										
										
											2024-03-31 10:47:11 -05:00
										 |  |  |  |         precollected_names = [item.name for item in self.multiworld.precollected_items[self.player]] | 
					
						
							| 
									
										
										
										
											2023-10-10 15:30:20 -05:00
										 |  |  |  |         itempool: List[MessengerItem] = [ | 
					
						
							| 
									
										
										
										
											2023-06-27 18:39:52 -05:00
										 |  |  |  |             self.create_item(item) | 
					
						
							|  |  |  |  |             for item in self.item_name_to_id | 
					
						
							| 
									
										
										
										
											2024-03-31 10:47:11 -05:00
										 |  |  |  |             if item not in { | 
					
						
							| 
									
										
										
										
											2024-03-11 17:23:41 -05:00
										 |  |  |  |                 "Power Seal", *NOTES, *FIGURINES, *main_movement_items, | 
					
						
							| 
									
										
										
										
											2024-03-31 10:47:11 -05:00
										 |  |  |  |                 *precollected_names, *FILLER, *TRAPS, | 
					
						
							| 
									
										
										
										
											2024-03-11 17:23:41 -05:00
										 |  |  |  |             } | 
					
						
							| 
									
										
										
										
											2023-06-27 18:39:52 -05:00
										 |  |  |  |         ] | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-11 17:23:41 -05:00
										 |  |  |  |         if self.options.limited_movement: | 
					
						
							|  |  |  |  |             itempool.append(self.create_item(self.random.choice(main_movement_items))) | 
					
						
							|  |  |  |  |         else: | 
					
						
							|  |  |  |  |             itempool += [self.create_item(move_item) for move_item in main_movement_items] | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-10 15:30:20 -05:00
										 |  |  |  |         if self.options.goal == Goal.option_open_music_box: | 
					
						
							| 
									
										
										
										
											2023-06-27 18:39:52 -05:00
										 |  |  |  |             # make a list of all notes except those in the player's defined starting inventory, and adjust the | 
					
						
							|  |  |  |  |             # amount we need to put in the itempool and precollect based on that | 
					
						
							| 
									
										
										
										
											2024-03-31 10:47:11 -05:00
										 |  |  |  |             notes = [note for note in NOTES if note not in precollected_names] | 
					
						
							| 
									
										
										
										
											2023-07-02 05:50:14 -05:00
										 |  |  |  |             self.random.shuffle(notes) | 
					
						
							| 
									
										
										
										
											2023-06-27 18:39:52 -05:00
										 |  |  |  |             precollected_notes_amount = NotesNeeded.range_end - \ | 
					
						
							| 
									
										
										
										
											2024-03-11 17:23:41 -05:00
										 |  |  |  |                                         self.options.notes_needed - \ | 
					
						
							|  |  |  |  |                                         (len(NOTES) - len(notes)) | 
					
						
							| 
									
										
										
										
											2023-03-12 09:05:50 -05:00
										 |  |  |  |             if precollected_notes_amount: | 
					
						
							|  |  |  |  |                 for note in notes[:precollected_notes_amount]: | 
					
						
							|  |  |  |  |                     self.multiworld.push_precollected(self.create_item(note)) | 
					
						
							| 
									
										
										
										
											2023-06-27 18:39:52 -05:00
										 |  |  |  |                 notes = notes[precollected_notes_amount:] | 
					
						
							|  |  |  |  |             itempool += [self.create_item(note) for note in notes] | 
					
						
							| 
									
										
										
										
											2023-04-06 03:48:30 -05:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-10 15:30:20 -05:00
										 |  |  |  |         elif self.options.goal == Goal.option_power_seal_hunt: | 
					
						
							| 
									
										
										
										
											2023-04-06 03:48:30 -05:00
										 |  |  |  |             total_seals = min(len(self.multiworld.get_unfilled_locations(self.player)) - len(itempool), | 
					
						
							| 
									
										
										
										
											2023-10-10 15:30:20 -05:00
										 |  |  |  |                               self.options.total_seals.value) | 
					
						
							| 
									
										
										
										
											2023-04-06 03:48:30 -05:00
										 |  |  |  |             if total_seals < self.total_seals: | 
					
						
							| 
									
										
										
										
											2024-03-11 17:23:41 -05:00
										 |  |  |  |                 logging.warning( | 
					
						
							|  |  |  |  |                     f"Not enough locations for total seals setting " | 
					
						
							|  |  |  |  |                     f"({self.options.total_seals}). Adjusting to {total_seals}" | 
					
						
							|  |  |  |  |                 ) | 
					
						
							| 
									
										
										
										
											2023-04-06 03:48:30 -05:00
										 |  |  |  |                 self.total_seals = total_seals | 
					
						
							| 
									
										
										
										
											2023-10-10 15:30:20 -05:00
										 |  |  |  |             self.required_seals = int(self.options.percent_seals_required.value / 100 * self.total_seals) | 
					
						
							| 
									
										
										
										
											2023-04-06 03:48:30 -05:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |             seals = [self.create_item("Power Seal") for _ in range(self.total_seals)] | 
					
						
							|  |  |  |  |             itempool += seals | 
					
						
							| 
									
										
										
										
											2023-07-24 19:41:20 -05:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-11 17:23:41 -05:00
										 |  |  |  |         self.multiworld.itempool += itempool | 
					
						
							| 
									
										
										
										
											2023-06-29 07:33:37 -05:00
										 |  |  |  |         remaining_fill = len(self.multiworld.get_unfilled_locations(self.player)) - len(itempool) | 
					
						
							| 
									
										
										
										
											2023-08-01 12:43:10 -05:00
										 |  |  |  |         if remaining_fill < 10: | 
					
						
							|  |  |  |  |             self._filler_items = self.random.choices( | 
					
						
							| 
									
										
										
										
											2024-03-31 10:47:11 -05:00
										 |  |  |  |                 list(self.filler)[2:], | 
					
						
							|  |  |  |  |                 weights=list(self.filler.values())[2:], | 
					
						
							| 
									
										
										
										
											2024-03-11 17:23:41 -05:00
										 |  |  |  |                 k=remaining_fill | 
					
						
							| 
									
										
										
										
											2023-08-01 12:43:10 -05:00
										 |  |  |  |             ) | 
					
						
							| 
									
										
										
										
											2024-03-11 17:23:41 -05:00
										 |  |  |  |         filler = [self.create_filler() for _ in range(remaining_fill)] | 
					
						
							| 
									
										
										
										
											2023-03-12 09:05:50 -05:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-11 17:23:41 -05:00
										 |  |  |  |         self.multiworld.itempool += filler | 
					
						
							| 
									
										
										
										
											2023-03-12 09:05:50 -05:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |     def set_rules(self) -> None: | 
					
						
							| 
									
										
										
										
											2023-10-10 15:30:20 -05:00
										 |  |  |  |         logic = self.options.logic_level | 
					
						
							| 
									
										
										
										
											2023-03-21 15:21:27 -05:00
										 |  |  |  |         if logic == Logic.option_normal: | 
					
						
							| 
									
										
										
										
											2023-10-08 07:33:39 -05:00
										 |  |  |  |             MessengerRules(self).set_messenger_rules() | 
					
						
							| 
									
										
										
										
											2023-03-21 15:21:27 -05:00
										 |  |  |  |         elif logic == Logic.option_hard: | 
					
						
							| 
									
										
										
										
											2023-10-08 07:33:39 -05:00
										 |  |  |  |             MessengerHardRules(self).set_messenger_rules() | 
					
						
							| 
									
										
										
										
											2023-03-21 15:21:27 -05:00
										 |  |  |  |         else: | 
					
						
							| 
									
										
										
										
											2024-03-11 17:23:41 -05:00
										 |  |  |  |             raise ValueError(f"Somehow you have a logic option that's currently invalid." | 
					
						
							|  |  |  |  |                              f" {logic} for {self.multiworld.get_player_name(self.player)}") | 
					
						
							|  |  |  |  |         #     MessengerOOBRules(self).set_messenger_rules() | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         add_closed_portal_reqs(self) | 
					
						
							|  |  |  |  |         # i need portal shuffle to happen after rules exist so i can validate it | 
					
						
							|  |  |  |  |         attempts = 5 | 
					
						
							|  |  |  |  |         if self.options.shuffle_portals: | 
					
						
							|  |  |  |  |             self.portal_mapping = [] | 
					
						
							|  |  |  |  |             self.spoiler_portal_mapping = {} | 
					
						
							|  |  |  |  |             for _ in range(attempts): | 
					
						
							|  |  |  |  |                 disconnect_portals(self) | 
					
						
							|  |  |  |  |                 shuffle_portals(self) | 
					
						
							|  |  |  |  |                 if validate_portals(self): | 
					
						
							|  |  |  |  |                     break | 
					
						
							|  |  |  |  |             # failsafe mostly for invalid plandoed portals with no transition shuffle | 
					
						
							|  |  |  |  |             else: | 
					
						
							|  |  |  |  |                 raise RuntimeError("Unable to generate valid portal output.") | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     def write_spoiler_header(self, spoiler_handle: TextIO) -> None: | 
					
						
							|  |  |  |  |         if self.options.available_portals < 6: | 
					
						
							|  |  |  |  |             spoiler_handle.write(f"\nStarting Portals:\n\n") | 
					
						
							|  |  |  |  |             for portal in self.starting_portals: | 
					
						
							|  |  |  |  |                 spoiler_handle.write(f"{portal}\n") | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         spoiler = self.multiworld.spoiler | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         if self.options.shuffle_portals: | 
					
						
							|  |  |  |  |             # sort the portals as they appear left to right in-game | 
					
						
							|  |  |  |  |             portal_info = sorted( | 
					
						
							|  |  |  |  |                 self.spoiler_portal_mapping.items(), | 
					
						
							|  |  |  |  |                 key=lambda portal: | 
					
						
							|  |  |  |  |                 ["Autumn Hills", "Riviere Turquoise", | 
					
						
							|  |  |  |  |                  "Howling Grotto", "Sunken Shrine", | 
					
						
							|  |  |  |  |                  "Searing Crags", "Glacial Peak"].index(portal[0])) | 
					
						
							|  |  |  |  |             for portal, output in portal_info: | 
					
						
							|  |  |  |  |                 spoiler.set_entrance(f"{portal} Portal", output, "I can write anything I want here lmao", self.player) | 
					
						
							| 
									
										
										
										
											2023-03-12 09:05:50 -05:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |     def fill_slot_data(self) -> Dict[str, Any]: | 
					
						
							| 
									
										
										
										
											2024-03-11 17:23:41 -05:00
										 |  |  |  |         slot_data = { | 
					
						
							| 
									
										
										
										
											2023-11-23 17:38:57 -06:00
										 |  |  |  |             "shop": {SHOP_ITEMS[item].internal_name: price for item, price in self.shop_prices.items()}, | 
					
						
							|  |  |  |  |             "figures": {FIGURINES[item].internal_name: price for item, price in self.figurine_prices.items()}, | 
					
						
							| 
									
										
										
										
											2023-06-27 18:39:52 -05:00
										 |  |  |  |             "max_price": self.total_shards, | 
					
						
							| 
									
										
										
										
											2023-11-23 17:38:57 -06:00
										 |  |  |  |             "required_seals": self.required_seals, | 
					
						
							| 
									
										
										
										
											2024-03-11 17:23:41 -05:00
										 |  |  |  |             "starting_portals": self.starting_portals, | 
					
						
							|  |  |  |  |             "portal_exits": self.portal_mapping, | 
					
						
							|  |  |  |  |             "transitions": [[TRANSITIONS.index("Corrupted Future") if transition.name == "Artificer's Portal" | 
					
						
							|  |  |  |  |                              else TRANSITIONS.index(RANDOMIZED_CONNECTIONS[transition.parent_region.name]), | 
					
						
							|  |  |  |  |                              TRANSITIONS.index(transition.connected_region.name)] | 
					
						
							|  |  |  |  |                             for transition in self.transitions], | 
					
						
							| 
									
										
										
										
											2023-11-23 17:38:57 -06:00
										 |  |  |  |             **self.options.as_dict("music_box", "death_link", "logic_level"), | 
					
						
							| 
									
										
										
										
											2023-03-12 09:05:50 -05:00
										 |  |  |  |         } | 
					
						
							| 
									
										
										
										
											2024-03-11 17:23:41 -05:00
										 |  |  |  |         return slot_data | 
					
						
							| 
									
										
										
										
											2023-03-12 09:05:50 -05:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |     def get_filler_item_name(self) -> str: | 
					
						
							| 
									
										
										
										
											2023-08-01 12:43:10 -05:00
										 |  |  |  |         if not getattr(self, "_filler_items", None): | 
					
						
							|  |  |  |  |             self._filler_items = [name for name in self.random.choices( | 
					
						
							| 
									
										
										
										
											2024-03-31 10:47:11 -05:00
										 |  |  |  |                 list(self.filler), | 
					
						
							|  |  |  |  |                 weights=list(self.filler.values()), | 
					
						
							| 
									
										
										
										
											2023-08-01 12:43:10 -05:00
										 |  |  |  |                 k=20 | 
					
						
							|  |  |  |  |             )] | 
					
						
							|  |  |  |  |         return self._filler_items.pop(0) | 
					
						
							| 
									
										
										
										
											2023-03-12 09:05:50 -05:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |     def create_item(self, name: str) -> MessengerItem: | 
					
						
							|  |  |  |  |         item_id: Optional[int] = self.item_name_to_id.get(name, None) | 
					
						
							| 
									
										
										
										
											2024-03-11 17:23:41 -05:00
										 |  |  |  |         return MessengerItem( | 
					
						
							|  |  |  |  |             name, | 
					
						
							|  |  |  |  |             ItemClassification.progression if item_id is None else self.get_item_classification(name), | 
					
						
							|  |  |  |  |             item_id, | 
					
						
							|  |  |  |  |             self.player | 
					
						
							|  |  |  |  |         ) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     def get_item_classification(self, name: str) -> ItemClassification: | 
					
						
							| 
									
										
										
										
											2023-06-27 18:39:52 -05:00
										 |  |  |  |         if "Time Shard " in name: | 
					
						
							|  |  |  |  |             count = int(name.strip("Time Shard ()")) | 
					
						
							|  |  |  |  |             count = count if count >= 100 else 0 | 
					
						
							|  |  |  |  |             self.total_shards += count | 
					
						
							| 
									
										
										
										
											2024-03-11 17:23:41 -05:00
										 |  |  |  |             return ItemClassification.progression_skip_balancing if count else ItemClassification.filler | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         if name == "Windmill Shuriken" and getattr(self, "multiworld", None) is not None: | 
					
						
							|  |  |  |  |             return ItemClassification.progression if self.options.logic_level else ItemClassification.filler | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         if name == "Power Seal": | 
					
						
							|  |  |  |  |             self.created_seals += 1 | 
					
						
							|  |  |  |  |             return ItemClassification.progression_skip_balancing \ | 
					
						
							|  |  |  |  |                 if self.required_seals >= self.created_seals else ItemClassification.filler | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         if name in {*NOTES, *PROG_ITEMS, *PHOBEKINS, *PROG_SHOP_ITEMS}: | 
					
						
							|  |  |  |  |             return ItemClassification.progression | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         if name in {*USEFUL_ITEMS, *USEFUL_SHOP_ITEMS}: | 
					
						
							|  |  |  |  |             return ItemClassification.useful | 
					
						
							| 
									
										
										
										
											2024-03-31 10:47:11 -05:00
										 |  |  |  |          | 
					
						
							|  |  |  |  |         if name in TRAPS: | 
					
						
							|  |  |  |  |             return ItemClassification.trap | 
					
						
							| 
									
										
										
										
											2024-03-11 17:23:41 -05:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |         return ItemClassification.filler | 
					
						
							| 
									
										
										
										
											2023-06-27 18:39:52 -05:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-18 11:59:30 -05:00
										 |  |  |  |     @classmethod | 
					
						
							|  |  |  |  |     def create_group(cls, multiworld: "MultiWorld", new_player_id: int, players: Set[int]) -> World: | 
					
						
							|  |  |  |  |         group = super().create_group(multiworld, new_player_id, players) | 
					
						
							|  |  |  |  |         assert isinstance(group, MessengerWorld) | 
					
						
							|  |  |  |  |          | 
					
						
							|  |  |  |  |         group.filler = FILLER.copy() | 
					
						
							|  |  |  |  |         group.options.traps.value = all(multiworld.worlds[player].options.traps for player in players) | 
					
						
							|  |  |  |  |         if group.options.traps: | 
					
						
							|  |  |  |  |             group.filler.update(TRAPS) | 
					
						
							|  |  |  |  |         return group | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-11-25 15:07:02 -06:00
										 |  |  |  |     def collect(self, state: "CollectionState", item: "Item") -> bool: | 
					
						
							|  |  |  |  |         change = super().collect(state, item) | 
					
						
							|  |  |  |  |         if change and "Time Shard" in item.name: | 
					
						
							|  |  |  |  |             state.prog_items[self.player]["Shards"] += int(item.name.strip("Time Shard ()")) | 
					
						
							|  |  |  |  |         return change | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     def remove(self, state: "CollectionState", item: "Item") -> bool: | 
					
						
							|  |  |  |  |         change = super().remove(state, item) | 
					
						
							|  |  |  |  |         if change and "Time Shard" in item.name: | 
					
						
							|  |  |  |  |             state.prog_items[self.player]["Shards"] -= int(item.name.strip("Time Shard ()")) | 
					
						
							|  |  |  |  |         return change | 
					
						
							| 
									
										
										
										
											2024-03-11 17:23:41 -05:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |     @classmethod | 
					
						
							|  |  |  |  |     def stage_generate_output(cls, multiworld: MultiWorld, output_directory: str) -> None: | 
					
						
							|  |  |  |  |         # using stage_generate_output because it doesn't increase the logged player count for players without output | 
					
						
							|  |  |  |  |         # only generate output if there's a single player | 
					
						
							|  |  |  |  |         if multiworld.players > 1: | 
					
						
							|  |  |  |  |             return | 
					
						
							|  |  |  |  |         # the messenger client calls into AP with specific args, so check the out path matches what the client sends | 
					
						
							|  |  |  |  |         out_path = output_path(multiworld.get_out_file_name_base(1) + ".aptm") | 
					
						
							|  |  |  |  |         if "The Messenger\\Archipelago\\output" not in out_path: | 
					
						
							|  |  |  |  |             return | 
					
						
							|  |  |  |  |         import orjson | 
					
						
							|  |  |  |  |         data = { | 
					
						
							|  |  |  |  |             "name": multiworld.get_player_name(1), | 
					
						
							|  |  |  |  |             "slot_data": multiworld.worlds[1].fill_slot_data(), | 
					
						
							|  |  |  |  |             "loc_data": {loc.address: {loc.item.name: [loc.item.code, loc.item.flags]} | 
					
						
							|  |  |  |  |                          for loc in multiworld.get_filled_locations() if loc.address}, | 
					
						
							|  |  |  |  |         } | 
					
						
							|  |  |  |  |      | 
					
						
							|  |  |  |  |         output = orjson.dumps(data, option=orjson.OPT_NON_STR_KEYS) | 
					
						
							|  |  |  |  |         with open(out_path, "wb") as f: | 
					
						
							|  |  |  |  |             f.write(output) |