| 
									
										
										
										
											2021-02-21 20:17:24 +01:00
										 |  |  | import logging | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | logger = logging.getLogger("Hollow Knight") | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-24 06:02:51 +01:00
										 |  |  | from .Locations import lookup_name_to_id | 
					
						
							|  |  |  | from .Items import item_table | 
					
						
							|  |  |  | from .Regions import create_regions | 
					
						
							|  |  |  | from .Rules import set_rules | 
					
						
							| 
									
										
										
										
											2021-02-21 20:17:24 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | from BaseClasses import Region, Entrance, Location, MultiWorld, Item | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-24 06:02:51 +01:00
										 |  |  | def create_region(world: MultiWorld, player: int, name: str, locations=None, exits=None): | 
					
						
							|  |  |  |     ret = Region(name, None, name, player) | 
					
						
							|  |  |  |     ret.world = world | 
					
						
							|  |  |  |     if locations: | 
					
						
							|  |  |  |         for location in locations: | 
					
						
							|  |  |  |             loc_id = lookup_name_to_id.get(location, 0) | 
					
						
							|  |  |  |             location = HKLocation(player, location, loc_id, ret) | 
					
						
							|  |  |  |             ret.locations.append(location) | 
					
						
							|  |  |  |     if exits: | 
					
						
							|  |  |  |         for exit in exits: | 
					
						
							|  |  |  |             ret.exits.append(Entrance(player, exit, ret)) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return ret | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-01 11:40:58 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-21 20:17:24 +01:00
										 |  |  | class HKLocation(Location): | 
					
						
							|  |  |  |     game: str = "Hollow Knight" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def __init__(self, player: int, name: str, address=None, parent=None): | 
					
						
							|  |  |  |         super(HKLocation, self).__init__(player, name, address, parent) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-01 11:40:58 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-21 20:17:24 +01:00
										 |  |  | class HKItem(Item): | 
					
						
							| 
									
										
										
										
											2021-02-22 11:18:53 +01:00
										 |  |  |     game = "Hollow Knight" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-21 00:47:17 +01:00
										 |  |  |     def __init__(self, name, advancement, code, type, player: int = None): | 
					
						
							| 
									
										
										
										
											2021-02-21 20:17:24 +01:00
										 |  |  |         super(HKItem, self).__init__(name, advancement, code, player) | 
					
						
							| 
									
										
										
										
											2021-03-21 00:47:17 +01:00
										 |  |  |         self.type = type | 
					
						
							| 
									
										
										
										
											2021-02-21 20:17:24 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-24 06:02:51 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-21 20:17:24 +01:00
										 |  |  | def gen_hollow(world: MultiWorld, player: int): | 
					
						
							|  |  |  |     link_regions(world, player) | 
					
						
							|  |  |  |     gen_items(world, player) | 
					
						
							| 
									
										
										
										
											2021-02-22 11:18:53 +01:00
										 |  |  |     set_rules(world, player) | 
					
						
							| 
									
										
										
										
											2021-02-21 20:17:24 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def link_regions(world: MultiWorld, player: int): | 
					
						
							|  |  |  |     world.get_entrance('Hollow Nest S&Q', player).connect(world.get_region('Hollow Nest', player)) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-01 11:40:58 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-21 00:47:17 +01:00
										 |  |  | not_shufflable_types = {"Essence_Boss"} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | option_to_type_lookup = { | 
					
						
							|  |  |  |     "Root": "RandomizeWhisperingRoots", | 
					
						
							|  |  |  |     "Dreamer": "RandomizeDreamers", | 
					
						
							|  |  |  |     "Geo": "RandomizeGeoChests", | 
					
						
							|  |  |  |     "Skill": "RandomizeSkills", | 
					
						
							|  |  |  |     "Map": "RandomizeMaps", | 
					
						
							|  |  |  |     "Relic": "RandomizeRelics", | 
					
						
							|  |  |  |     "Charm": "RandomizeCharms", | 
					
						
							|  |  |  |     "Notch": "RandomizeCharmNotches", | 
					
						
							|  |  |  |     "Key": "RandomizeKeys", | 
					
						
							|  |  |  |     "Stag": "RandomizeStags", | 
					
						
							|  |  |  |     "Flame": "RandomizeFlames", | 
					
						
							|  |  |  |     "Grub": "RandomizeGrubs", | 
					
						
							|  |  |  |     "Cocoon": "RandomizeLifebloodCocoons", | 
					
						
							|  |  |  |     "Mask": "RandomizeMaskShards", | 
					
						
							|  |  |  |     "Ore": "RandomizePaleOre", | 
					
						
							|  |  |  |     "Egg": "RandomizeRancidEggs", | 
					
						
							|  |  |  |     "Vessel": "RandomizeVesselFragments", | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2021-02-21 20:17:24 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | def gen_items(world: MultiWorld, player: int): | 
					
						
							|  |  |  |     pool = [] | 
					
						
							| 
									
										
										
										
											2021-02-24 06:02:51 +01:00
										 |  |  |     for item_name, item_data in item_table.items(): | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-21 00:47:17 +01:00
										 |  |  |         item = HKItem(item_name, item_data.advancement, item_data.id, item_data.type, player=player) | 
					
						
							| 
									
										
										
										
											2021-02-24 06:02:51 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         if item_data.type == "Event": | 
					
						
							|  |  |  |             event_location = world.get_location(item_name, player) | 
					
						
							|  |  |  |             world.push_item(event_location, item) | 
					
						
							|  |  |  |             event_location.event = True | 
					
						
							|  |  |  |             event_location.locked = True | 
					
						
							|  |  |  |             if item.name == "King's_Pass": | 
					
						
							|  |  |  |                 world.push_precollected(item) | 
					
						
							| 
									
										
										
										
											2021-03-21 00:47:17 +01:00
										 |  |  |         elif item_data.type == "Cursed": | 
					
						
							|  |  |  |             if world.CURSED[player]: | 
					
						
							| 
									
										
										
										
											2021-03-23 08:57:04 +01:00
										 |  |  |                 pool.append(item) | 
					
						
							| 
									
										
										
										
											2021-03-21 00:47:17 +01:00
										 |  |  |             else: | 
					
						
							| 
									
										
										
										
											2021-03-23 08:57:04 +01:00
										 |  |  |                 # fill Focus Location with Focus and add it to start inventory as well. | 
					
						
							| 
									
										
										
										
											2021-03-21 00:47:17 +01:00
										 |  |  |                 event_location = world.get_location(item_name, player) | 
					
						
							|  |  |  |                 world.push_item(event_location, item) | 
					
						
							|  |  |  |                 event_location.event = True | 
					
						
							|  |  |  |                 event_location.locked = True | 
					
						
							|  |  |  |                 world.push_precollected(item) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-26 21:03:16 +01:00
										 |  |  |         elif item_data.type == "Fake": | 
					
						
							|  |  |  |             pass | 
					
						
							| 
									
										
										
										
											2021-03-21 00:47:17 +01:00
										 |  |  |         elif item_data.type in not_shufflable_types: | 
					
						
							|  |  |  |             location = world.get_location(item_name, player) | 
					
						
							|  |  |  |             world.push_item(location, item) | 
					
						
							|  |  |  |             location.event = item.advancement | 
					
						
							|  |  |  |             location.locked = True | 
					
						
							| 
									
										
										
										
											2021-02-24 06:02:51 +01:00
										 |  |  |         else: | 
					
						
							| 
									
										
										
										
											2021-03-21 00:47:17 +01:00
										 |  |  |             target = option_to_type_lookup[item.type] | 
					
						
							|  |  |  |             shuffle_it = getattr(world, target) | 
					
						
							|  |  |  |             if shuffle_it[player]: | 
					
						
							|  |  |  |                 pool.append(item) | 
					
						
							|  |  |  |             else: | 
					
						
							|  |  |  |                 location = world.get_location(item_name, player) | 
					
						
							|  |  |  |                 world.push_item(location, item) | 
					
						
							|  |  |  |                 location.event = item.advancement | 
					
						
							|  |  |  |                 location.locked = True | 
					
						
							|  |  |  |                 logger.debug(f"Placed {item_name} to vanilla for player {player}") | 
					
						
							| 
									
										
										
										
											2021-02-24 06:02:51 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-21 20:17:24 +01:00
										 |  |  |     world.itempool += pool | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 |