| 
									
										
										
										
											2021-11-06 01:12:11 +01:00
										 |  |  | from typing import Dict, List, Set, TextIO | 
					
						
							| 
									
										
										
										
											2021-09-30 19:51:07 +02:00
										 |  |  | from BaseClasses import Item, MultiWorld, Location | 
					
						
							| 
									
										
										
										
											2021-09-24 04:07:32 +02:00
										 |  |  | from ..AutoWorld import World | 
					
						
							|  |  |  | from .LogicMixin import TimespinnerLogic | 
					
						
							| 
									
										
										
										
											2021-09-30 19:51:07 +02:00
										 |  |  | from .Items import get_item_names_per_category, item_table, starter_melee_weapons, starter_spells, starter_progression_items, filler_items | 
					
						
							| 
									
										
										
										
											2021-09-24 04:07:32 +02:00
										 |  |  | from .Locations import get_locations, starter_progression_locations, EventId | 
					
						
							|  |  |  | from .Regions import create_regions | 
					
						
							|  |  |  | from .Options import is_option_enabled, timespinner_options | 
					
						
							|  |  |  | from .PyramidKeys import get_pyramid_keys_unlock | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class TimespinnerWorld(World): | 
					
						
							| 
									
										
										
										
											2021-09-30 19:51:07 +02:00
										 |  |  |     """
 | 
					
						
							|  |  |  |     Timespinner is a beautiful metroidvania inspired by classic 90s action-platformers. | 
					
						
							|  |  |  |     Travel back in time to change fate itself. Join timekeeper Lunais on her quest for revenge against the empire that killed her family. | 
					
						
							|  |  |  |     """
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-24 04:07:32 +02:00
										 |  |  |     options = timespinner_options | 
					
						
							|  |  |  |     game = "Timespinner" | 
					
						
							|  |  |  |     topology_present = True | 
					
						
							| 
									
										
										
										
											2021-09-30 19:51:07 +02:00
										 |  |  |     remote_items = False | 
					
						
							| 
									
										
										
										
											2021-10-15 17:51:18 -05:00
										 |  |  |     data_version = 3 | 
					
						
							| 
									
										
										
										
											2021-09-24 04:07:32 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     item_name_to_id = {name: data.code for name, data in item_table.items()} | 
					
						
							| 
									
										
										
										
											2021-09-25 02:31:32 +02:00
										 |  |  |     location_name_to_id = {location.name: location.code for location in get_locations(None, None)} | 
					
						
							| 
									
										
										
										
											2021-09-30 19:51:07 +02:00
										 |  |  |     item_name_groups = get_item_names_per_category() | 
					
						
							| 
									
										
										
										
											2021-09-24 04:07:32 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     locked_locations: Dict[int, List[str]] = {} | 
					
						
							|  |  |  |     pyramid_keys_unlock: Dict[int, str] = {} | 
					
						
							| 
									
										
										
										
											2021-09-30 19:51:07 +02:00
										 |  |  |     location_cache: Dict[int, List[Location]] = {} | 
					
						
							| 
									
										
										
										
											2021-09-24 04:07:32 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     def generate_early(self): | 
					
						
							|  |  |  |         self.locked_locations[self.player] = [] | 
					
						
							| 
									
										
										
										
											2021-09-30 19:51:07 +02:00
										 |  |  |         self.location_cache[self.player] = [] | 
					
						
							| 
									
										
										
										
											2021-09-24 04:07:32 +02:00
										 |  |  |         self.pyramid_keys_unlock[self.player] = get_pyramid_keys_unlock(self.world, self.player) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def create_regions(self): | 
					
						
							| 
									
										
										
										
											2021-09-30 19:51:07 +02:00
										 |  |  |         create_regions(self.world, self.player, get_locations(self.world, self.player),  | 
					
						
							|  |  |  |                         self.location_cache[self.player], self.pyramid_keys_unlock[self.player]) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-24 04:07:32 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     def create_item(self, name: str) -> Item: | 
					
						
							| 
									
										
										
										
											2021-10-10 13:05:41 +02:00
										 |  |  |         return create_item_with_correct_settings(self.world, self.player, name) | 
					
						
							| 
									
										
										
										
											2021-09-24 04:07:32 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-30 19:51:07 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-24 04:07:32 +02:00
										 |  |  |     def set_rules(self): | 
					
						
							| 
									
										
										
										
											2021-10-10 13:05:41 +02:00
										 |  |  |         setup_events(self.world, self.player, self.locked_locations[self.player], self.location_cache[self.player]) | 
					
						
							| 
									
										
										
										
											2021-09-24 04:07:32 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         self.world.completion_condition[self.player] = lambda state: state.has('Killed Nightmare', self.player) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-30 19:51:07 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-24 04:07:32 +02:00
										 |  |  |     def generate_basic(self): | 
					
						
							|  |  |  |         excluded_items = get_excluded_items_based_on_options(self.world, self.player) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         assign_starter_items(self.world, self.player, excluded_items, self.locked_locations[self.player]) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-30 19:51:07 +02:00
										 |  |  |         if not is_option_enabled(self.world, self.player, "QuickSeed") and not is_option_enabled(self.world, self.player, "Inverted"): | 
					
						
							| 
									
										
										
										
											2021-09-24 04:07:32 +02:00
										 |  |  |             place_first_progression_item(self.world, self.player, excluded_items, self.locked_locations[self.player]) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         pool = get_item_pool(self.world, self.player, excluded_items) | 
					
						
							| 
									
										
										
										
											2021-09-25 02:31:32 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-10 13:05:41 +02:00
										 |  |  |         fill_item_pool_with_dummy_items(self.world, self.player, self.locked_locations[self.player], self.location_cache[self.player], pool) | 
					
						
							| 
									
										
										
										
											2021-09-24 04:07:32 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         self.world.itempool += pool | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-30 19:51:07 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-03 12:37:06 +02:00
										 |  |  |     def fill_slot_data(self) -> Dict[str, object]: | 
					
						
							|  |  |  |         slot_data: Dict[str, object] = {} | 
					
						
							| 
									
										
										
										
											2021-09-24 04:07:32 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         for option_name in timespinner_options: | 
					
						
							| 
									
										
										
										
											2021-09-30 19:51:07 +02:00
										 |  |  |             slot_data[option_name] = is_option_enabled(self.world, self.player, option_name) | 
					
						
							| 
									
										
										
										
											2021-09-24 04:07:32 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-30 19:51:07 +02:00
										 |  |  |         slot_data["StinkyMaw"] = True | 
					
						
							|  |  |  |         slot_data["ProgressiveVerticalMovement"] = False | 
					
						
							|  |  |  |         slot_data["ProgressiveKeycards"] = False | 
					
						
							| 
									
										
										
										
											2021-09-25 02:31:32 +02:00
										 |  |  |         slot_data["PyramidKeysGate"] = self.pyramid_keys_unlock[self.player] | 
					
						
							| 
									
										
										
										
											2021-09-30 19:51:07 +02:00
										 |  |  |         slot_data["PersonalItems"] = get_personal_items(self.player, self.location_cache[self.player]) | 
					
						
							| 
									
										
										
										
											2021-09-24 04:07:32 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         return slot_data | 
					
						
							| 
									
										
										
										
											2021-11-06 01:12:11 +01:00
										 |  |  |          | 
					
						
							| 
									
										
										
										
											2021-09-24 04:07:32 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-06 01:12:11 +01:00
										 |  |  |     def write_spoiler_header(self, spoiler_handle: TextIO): | 
					
						
							|  |  |  |         spoiler_handle.write('Twin Pyramid Keys unlock:        %s\n' % (self.pyramid_keys_unlock[self.player])) | 
					
						
							|  |  |  |          | 
					
						
							| 
									
										
										
										
											2021-09-25 02:31:32 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-09 11:58:38 +02:00
										 |  |  | def get_excluded_items_based_on_options(world: MultiWorld, player: int) -> Set[str]: | 
					
						
							| 
									
										
										
										
											2021-10-09 15:53:18 +02:00
										 |  |  |     excluded_items: Set[str] = set() | 
					
						
							| 
									
										
										
										
											2021-09-24 04:07:32 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if is_option_enabled(world, player, "StartWithJewelryBox"): | 
					
						
							| 
									
										
										
										
											2021-10-09 11:58:38 +02:00
										 |  |  |         excluded_items.add('Jewelry Box') | 
					
						
							| 
									
										
										
										
											2021-09-24 04:07:32 +02:00
										 |  |  |     if is_option_enabled(world, player, "StartWithMeyef"): | 
					
						
							| 
									
										
										
										
											2021-10-09 11:58:38 +02:00
										 |  |  |         excluded_items.add('Meyef') | 
					
						
							| 
									
										
										
										
											2021-09-24 04:07:32 +02:00
										 |  |  |     if is_option_enabled(world, player, "QuickSeed"): | 
					
						
							| 
									
										
										
										
											2021-10-09 11:58:38 +02:00
										 |  |  |         excluded_items.add('Talaria Attachment') | 
					
						
							| 
									
										
										
										
											2021-09-25 02:31:32 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-24 04:07:32 +02:00
										 |  |  |     return excluded_items | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-25 02:31:32 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-09 11:58:38 +02:00
										 |  |  | def assign_starter_items(world: MultiWorld, player: int, excluded_items: Set[str], locked_locations: List[str]): | 
					
						
							| 
									
										
										
										
											2021-09-24 04:07:32 +02:00
										 |  |  |     melee_weapon = world.random.choice(starter_melee_weapons) | 
					
						
							|  |  |  |     spell = world.random.choice(starter_spells) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-09 11:58:38 +02:00
										 |  |  |     excluded_items.add(melee_weapon) | 
					
						
							|  |  |  |     excluded_items.add(spell) | 
					
						
							| 
									
										
										
										
											2021-09-24 04:07:32 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-10 13:05:41 +02:00
										 |  |  |     melee_weapon_item = create_item_with_correct_settings(world, player, melee_weapon) | 
					
						
							|  |  |  |     spell_item = create_item_with_correct_settings(world, player, spell) | 
					
						
							| 
									
										
										
										
											2021-09-25 02:31:32 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-24 04:07:32 +02:00
										 |  |  |     world.get_location('Yo Momma 1', player).place_locked_item(melee_weapon_item) | 
					
						
							|  |  |  |     world.get_location('Yo Momma 2', player).place_locked_item(spell_item) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     locked_locations.append('Yo Momma 1') | 
					
						
							|  |  |  |     locked_locations.append('Yo Momma 2') | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-25 02:31:32 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-09 11:58:38 +02:00
										 |  |  | def get_item_pool(world: MultiWorld, player: int, excluded_items: Set[str]) -> List[Item]: | 
					
						
							| 
									
										
										
										
											2021-09-30 19:51:07 +02:00
										 |  |  |     pool: List[Item] = [] | 
					
						
							| 
									
										
										
										
											2021-09-24 04:07:32 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     for name, data in item_table.items(): | 
					
						
							|  |  |  |         if not name in excluded_items: | 
					
						
							|  |  |  |             for _ in range(data.count): | 
					
						
							| 
									
										
										
										
											2021-10-10 13:05:41 +02:00
										 |  |  |                 item = create_item_with_correct_settings(world, player, name) | 
					
						
							| 
									
										
										
										
											2021-09-24 04:07:32 +02:00
										 |  |  |                 pool.append(item) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return pool | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-25 02:31:32 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-10 13:05:41 +02:00
										 |  |  | def fill_item_pool_with_dummy_items(world: MultiWorld, player: int, locked_locations: List[str], | 
					
						
							|  |  |  |                                     location_cache: List[Location], pool: List[Item]): | 
					
						
							|  |  |  |     for _ in range(len(location_cache) - len(locked_locations) - len(pool)): | 
					
						
							|  |  |  |         item = create_item_with_correct_settings(world, player, world.random.choice(filler_items)) | 
					
						
							| 
									
										
										
										
											2021-09-24 04:07:32 +02:00
										 |  |  |         pool.append(item) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-25 02:31:32 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-09 11:58:38 +02:00
										 |  |  | def place_first_progression_item(world: MultiWorld, player: int, excluded_items: Set[str], locked_locations: List[str]): | 
					
						
							| 
									
										
										
										
											2021-09-24 04:07:32 +02:00
										 |  |  |     progression_item = world.random.choice(starter_progression_items) | 
					
						
							| 
									
										
										
										
											2021-09-25 02:31:32 +02:00
										 |  |  |     location = world.random.choice(starter_progression_locations) | 
					
						
							| 
									
										
										
										
											2021-09-24 04:07:32 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-09 11:58:38 +02:00
										 |  |  |     excluded_items.add(progression_item) | 
					
						
							| 
									
										
										
										
											2021-09-24 04:07:32 +02:00
										 |  |  |     locked_locations.append(location) | 
					
						
							| 
									
										
										
										
											2021-09-25 02:31:32 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-10 13:05:41 +02:00
										 |  |  |     item = create_item_with_correct_settings(world, player, progression_item) | 
					
						
							| 
									
										
										
										
											2021-09-24 04:07:32 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     world.get_location(location, player).place_locked_item(item) | 
					
						
							| 
									
										
										
										
											2021-09-25 02:31:32 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-10 13:05:41 +02:00
										 |  |  | def create_item_with_correct_settings(world: MultiWorld, player: int, name: str) -> Item: | 
					
						
							|  |  |  |     data = item_table[name] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     item = Item(name, data.progression, data.code, player) | 
					
						
							| 
									
										
										
										
											2021-10-11 11:41:45 +02:00
										 |  |  |     item.never_exclude = data.never_exclude | 
					
						
							| 
									
										
										
										
											2021-10-10 13:05:41 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if not item.advancement: | 
					
						
							|  |  |  |         return item | 
					
						
							| 
									
										
										
										
											2021-09-24 04:07:32 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if (name == 'Tablet' or name == 'Library Keycard V') and not is_option_enabled(world, player, "DownloadableItems"): | 
					
						
							| 
									
										
										
										
											2021-10-10 13:05:41 +02:00
										 |  |  |         item.advancement = False | 
					
						
							| 
									
										
										
										
											2021-09-24 04:07:32 +02:00
										 |  |  |     if name == 'Oculus Ring' and not is_option_enabled(world, player, "FacebookMode"): | 
					
						
							| 
									
										
										
										
											2021-10-10 13:05:41 +02:00
										 |  |  |         item.advancement = False | 
					
						
							| 
									
										
										
										
											2021-09-24 04:07:32 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-10 13:05:41 +02:00
										 |  |  |     return item | 
					
						
							| 
									
										
										
										
											2021-09-24 04:07:32 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-25 02:31:32 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-10 13:05:41 +02:00
										 |  |  | def setup_events(world: MultiWorld, player: int, locked_locations: List[str], location_cache: List[Location]): | 
					
						
							|  |  |  |     for location in location_cache: | 
					
						
							|  |  |  |         if location.address == EventId: | 
					
						
							| 
									
										
										
										
											2021-09-24 04:07:32 +02:00
										 |  |  |             item = Item(location.name, True, EventId, player) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             locked_locations.append(location.name) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             location.place_locked_item(item) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-25 02:31:32 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-30 19:51:07 +02:00
										 |  |  | def get_personal_items(player: int, locations: List[Location]) -> Dict[int, int]: | 
					
						
							|  |  |  |     personal_items: Dict[int, int] = {} | 
					
						
							| 
									
										
										
										
											2021-09-24 04:07:32 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-30 19:51:07 +02:00
										 |  |  |     for location in locations: | 
					
						
							|  |  |  |         if location.address and location.item and location.item.code and location.item.player == player: | 
					
						
							|  |  |  |             personal_items[location.address] = location.item.code | 
					
						
							|  |  |  |      | 
					
						
							|  |  |  |     return personal_items |