| 
									
										
										
										
											2021-08-29 14:02:02 -04:00
										 |  |  |  | import string | 
					
						
							| 
									
										
										
										
											2022-08-20 18:09:35 -05:00
										 |  |  |  | from typing import Dict, List | 
					
						
							| 
									
										
										
										
											2021-09-07 17:14:20 -05:00
										 |  |  |  | from .Items import RiskOfRainItem, item_table, item_pool_weights | 
					
						
							| 
									
										
										
										
											2022-08-20 18:09:35 -05:00
										 |  |  |  | from .Locations import RiskOfRainLocation, item_pickups | 
					
						
							| 
									
										
										
										
											2021-08-29 14:02:02 -04:00
										 |  |  |  | from .Rules import set_rules | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-06-17 03:23:27 +02:00
										 |  |  |  | from BaseClasses import Region, RegionType, Entrance, Item, ItemClassification, MultiWorld, Tutorial | 
					
						
							| 
									
										
										
										
											2022-08-20 18:09:35 -05:00
										 |  |  |  | from .Options import ror2_options, ItemWeights | 
					
						
							| 
									
										
										
										
											2022-08-15 23:52:03 +02:00
										 |  |  |  | from worlds.AutoWorld import World, WebWorld | 
					
						
							| 
									
										
										
										
											2021-08-29 14:02:02 -04:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | client_version = 1 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-05-11 13:05:53 -05:00
										 |  |  |  | class RiskOfWeb(WebWorld): | 
					
						
							|  |  |  |  |     tutorials = [Tutorial( | 
					
						
							|  |  |  |  |         "Multiworld Setup Guide", | 
					
						
							|  |  |  |  |         "A guide to setting up the Risk of Rain 2 integration for Archipelago multiworld games.", | 
					
						
							|  |  |  |  |         "English", | 
					
						
							|  |  |  |  |         "setup_en.md", | 
					
						
							|  |  |  |  |         "setup/en", | 
					
						
							|  |  |  |  |         ["Ijwu"] | 
					
						
							|  |  |  |  |     )] | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-29 14:02:02 -04:00
										 |  |  |  | class RiskOfRainWorld(World): | 
					
						
							| 
									
										
										
										
											2021-08-31 20:45:09 -04:00
										 |  |  |  |     """
 | 
					
						
							|  |  |  |  |      Escape a chaotic alien planet by fighting through hordes of frenzied monsters – with your friends, or on your own. | 
					
						
							|  |  |  |  |      Combine loot in surprising ways and master each character until you become the havoc you feared upon your | 
					
						
							|  |  |  |  |      first crash landing. | 
					
						
							|  |  |  |  |     """
 | 
					
						
							| 
									
										
										
										
											2021-08-29 14:02:02 -04:00
										 |  |  |  |     game: str = "Risk of Rain 2" | 
					
						
							| 
									
										
										
										
											2022-08-15 16:46:59 -05:00
										 |  |  |  |     option_definitions = ror2_options | 
					
						
							| 
									
										
										
										
											2021-08-29 14:02:02 -04:00
										 |  |  |  |     topology_present = False | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-01 16:46:44 +02:00
										 |  |  |  |     item_name_to_id = item_table | 
					
						
							| 
									
										
										
										
											2022-08-20 18:09:35 -05:00
										 |  |  |  |     location_name_to_id = item_pickups | 
					
						
							| 
									
										
										
										
											2021-08-29 14:02:02 -04:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-20 18:09:35 -05:00
										 |  |  |  |     data_version = 4 | 
					
						
							| 
									
										
										
										
											2021-08-31 10:08:19 -04:00
										 |  |  |  |     forced_auto_forfeit = True | 
					
						
							| 
									
										
										
										
											2022-05-11 13:05:53 -05:00
										 |  |  |  |     web = RiskOfWeb() | 
					
						
							| 
									
										
										
										
											2022-08-20 18:09:35 -05:00
										 |  |  |  |     total_revivals: int | 
					
						
							| 
									
										
										
										
											2021-08-29 14:02:02 -04:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-20 18:09:35 -05:00
										 |  |  |  |     def generate_early(self) -> None: | 
					
						
							|  |  |  |  |         # figure out how many revivals should exist in the pool | 
					
						
							| 
									
										
										
										
											2022-10-31 21:41:21 -05:00
										 |  |  |  |         self.total_revivals = int(self.multiworld.total_revivals[self.player].value / 100 * | 
					
						
							|  |  |  |  |                                   self.multiworld.total_locations[self.player].value) | 
					
						
							| 
									
										
										
										
											2022-08-20 18:09:35 -05:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |     def generate_basic(self) -> None: | 
					
						
							| 
									
										
										
										
											2021-08-29 14:02:02 -04:00
										 |  |  |  |         # shortcut for starting_inventory... The start_with_revive option lets you start with a Dio's Best Friend | 
					
						
							| 
									
										
										
										
											2022-10-31 21:41:21 -05:00
										 |  |  |  |         if self.multiworld.start_with_revive[self.player].value: | 
					
						
							|  |  |  |  |             self.multiworld.push_precollected(self.multiworld.create_item("Dio's Best Friend", self.player)) | 
					
						
							| 
									
										
										
										
											2021-08-29 14:02:02 -04:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-08 13:53:06 -05:00
										 |  |  |  |         # if presets are enabled generate junk_pool from the selected preset | 
					
						
							| 
									
										
										
										
											2022-10-31 21:41:21 -05:00
										 |  |  |  |         pool_option = self.multiworld.item_weights[self.player].value | 
					
						
							| 
									
										
										
										
											2022-08-20 18:09:35 -05:00
										 |  |  |  |         junk_pool: Dict[str, int] = {} | 
					
						
							| 
									
										
										
										
											2022-10-31 21:41:21 -05:00
										 |  |  |  |         if self.multiworld.item_pool_presets[self.player]: | 
					
						
							| 
									
										
										
										
											2021-09-08 13:53:06 -05:00
										 |  |  |  |             # generate chaos weights if the preset is chosen | 
					
						
							| 
									
										
										
										
											2022-08-20 18:09:35 -05:00
										 |  |  |  |             if pool_option == ItemWeights.option_chaos: | 
					
						
							|  |  |  |  |                 for name, max_value in item_pool_weights[pool_option].items(): | 
					
						
							| 
									
										
										
										
											2022-10-31 21:41:21 -05:00
										 |  |  |  |                     junk_pool[name] = self.multiworld.random.randint(0, max_value) | 
					
						
							| 
									
										
										
										
											2021-09-08 13:53:06 -05:00
										 |  |  |  |             else: | 
					
						
							| 
									
										
										
										
											2021-09-10 04:11:01 +02:00
										 |  |  |  |                 junk_pool = item_pool_weights[pool_option].copy() | 
					
						
							| 
									
										
										
										
											2021-09-11 22:14:39 +02:00
										 |  |  |  |         else:  # generate junk pool from user created presets | 
					
						
							| 
									
										
										
										
											2021-09-08 13:53:06 -05:00
										 |  |  |  |             junk_pool = { | 
					
						
							| 
									
										
										
										
											2022-10-31 21:41:21 -05:00
										 |  |  |  |                 "Item Scrap, Green": self.multiworld.green_scrap[self.player].value, | 
					
						
							|  |  |  |  |                 "Item Scrap, Red": self.multiworld.red_scrap[self.player].value, | 
					
						
							|  |  |  |  |                 "Item Scrap, Yellow": self.multiworld.yellow_scrap[self.player].value, | 
					
						
							|  |  |  |  |                 "Item Scrap, White": self.multiworld.white_scrap[self.player].value, | 
					
						
							|  |  |  |  |                 "Common Item": self.multiworld.common_item[self.player].value, | 
					
						
							|  |  |  |  |                 "Uncommon Item": self.multiworld.uncommon_item[self.player].value, | 
					
						
							|  |  |  |  |                 "Legendary Item": self.multiworld.legendary_item[self.player].value, | 
					
						
							|  |  |  |  |                 "Boss Item": self.multiworld.boss_item[self.player].value, | 
					
						
							|  |  |  |  |                 "Lunar Item": self.multiworld.lunar_item[self.player].value, | 
					
						
							|  |  |  |  |                 "Equipment": self.multiworld.equipment[self.player].value | 
					
						
							| 
									
										
										
										
											2021-09-06 23:40:39 -05:00
										 |  |  |  |             } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-09 22:11:05 -05:00
										 |  |  |  |         # remove lunar items from the pool if they're disabled in the yaml unless lunartic is rolled | 
					
						
							| 
									
										
										
										
											2022-10-31 21:41:21 -05:00
										 |  |  |  |         if not (self.multiworld.enable_lunar[self.player] or pool_option == ItemWeights.option_lunartic): | 
					
						
							| 
									
										
										
										
											2022-08-20 18:09:35 -05:00
										 |  |  |  |             junk_pool.pop("Lunar Item") | 
					
						
							| 
									
										
										
										
											2021-09-26 20:56:04 -05:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-29 14:02:02 -04:00
										 |  |  |  |         # Generate item pool | 
					
						
							| 
									
										
										
										
											2022-08-20 18:09:35 -05:00
										 |  |  |  |         itempool: List = [] | 
					
						
							| 
									
										
										
										
											2021-08-29 14:02:02 -04:00
										 |  |  |  |         # Add revive items for the player | 
					
						
							| 
									
										
										
										
											2022-08-20 18:09:35 -05:00
										 |  |  |  |         itempool += ["Dio's Best Friend"] * self.total_revivals | 
					
						
							| 
									
										
										
										
											2021-08-29 14:02:02 -04:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |         # Fill remaining items with randomly generated junk | 
					
						
							| 
									
										
										
										
											2022-10-31 21:41:21 -05:00
										 |  |  |  |         itempool += self.multiworld.random.choices(list(junk_pool.keys()), weights=list(junk_pool.values()), | 
					
						
							|  |  |  |  |                                               k=self.multiworld.total_locations[self.player].value - self.total_revivals) | 
					
						
							| 
									
										
										
										
											2021-08-29 14:02:02 -04:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |         # Convert itempool into real items | 
					
						
							| 
									
										
										
										
											2021-09-11 22:14:39 +02:00
										 |  |  |  |         itempool = list(map(lambda name: self.create_item(name), itempool)) | 
					
						
							| 
									
										
										
										
											2021-08-29 14:02:02 -04:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-31 21:41:21 -05:00
										 |  |  |  |         self.multiworld.itempool += itempool | 
					
						
							| 
									
										
										
										
											2021-08-29 14:02:02 -04:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-20 18:09:35 -05:00
										 |  |  |  |     def set_rules(self) -> None: | 
					
						
							| 
									
										
										
										
											2022-10-31 21:41:21 -05:00
										 |  |  |  |         set_rules(self.multiworld, self.player) | 
					
						
							| 
									
										
										
										
											2021-08-29 14:02:02 -04:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-20 18:09:35 -05:00
										 |  |  |  |     def create_regions(self) -> None: | 
					
						
							| 
									
										
										
										
											2022-10-31 21:41:21 -05:00
										 |  |  |  |         menu = create_region(self.multiworld, self.player, "Menu") | 
					
						
							|  |  |  |  |         petrichor = create_region(self.multiworld, self.player, "Petrichor V", | 
					
						
							|  |  |  |  |                                   [f"ItemPickup{i + 1}" for i in range(self.multiworld.total_locations[self.player].value)]) | 
					
						
							| 
									
										
										
										
											2022-08-20 18:09:35 -05:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |         connection = Entrance(self.player, "Lobby", menu) | 
					
						
							|  |  |  |  |         menu.exits.append(connection) | 
					
						
							|  |  |  |  |         connection.connect(petrichor) | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-31 21:41:21 -05:00
										 |  |  |  |         self.multiworld.regions += [menu, petrichor] | 
					
						
							| 
									
										
										
										
											2022-08-20 18:09:35 -05:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-31 21:41:21 -05:00
										 |  |  |  |         create_events(self.multiworld, self.player) | 
					
						
							| 
									
										
										
										
											2021-08-29 14:02:02 -04:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |     def fill_slot_data(self): | 
					
						
							|  |  |  |  |         return { | 
					
						
							| 
									
										
										
										
											2022-10-31 21:41:21 -05:00
										 |  |  |  |             "itemPickupStep": self.multiworld.item_pickup_step[self.player].value, | 
					
						
							|  |  |  |  |             "seed": "".join(self.multiworld.slot_seeds[self.player].choice(string.digits) for _ in range(16)), | 
					
						
							|  |  |  |  |             "totalLocations": self.multiworld.total_locations[self.player].value, | 
					
						
							|  |  |  |  |             "totalRevivals": self.multiworld.total_revivals[self.player].value, | 
					
						
							|  |  |  |  |             "startWithDio": self.multiworld.start_with_revive[self.player].value, | 
					
						
							|  |  |  |  |             "FinalStageDeath": self.multiworld.final_stage_death[self.player].value | 
					
						
							| 
									
										
										
										
											2021-08-29 14:02:02 -04:00
										 |  |  |  |         } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     def create_item(self, name: str) -> Item: | 
					
						
							|  |  |  |  |         item_id = item_table[name] | 
					
						
							| 
									
										
										
										
											2022-07-15 16:19:36 -05:00
										 |  |  |  |         if name == "Dio's Best Friend": | 
					
						
							| 
									
										
										
										
											2022-08-20 18:09:35 -05:00
										 |  |  |  |             classification = ItemClassification.progression | 
					
						
							| 
									
										
										
										
											2022-07-15 16:19:36 -05:00
										 |  |  |  |         elif name in {"Equipment", "Legendary Item"}: | 
					
						
							| 
									
										
										
										
											2022-08-20 18:09:35 -05:00
										 |  |  |  |             classification = ItemClassification.useful | 
					
						
							|  |  |  |  |         else: | 
					
						
							|  |  |  |  |             classification = ItemClassification.filler | 
					
						
							|  |  |  |  |         item = RiskOfRainItem(name, classification, item_id, self.player) | 
					
						
							| 
									
										
										
										
											2021-08-29 14:02:02 -04:00
										 |  |  |  |         return item | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-23 16:22:31 -05:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-20 18:09:35 -05:00
										 |  |  |  | def create_events(world: MultiWorld, player: int) -> None: | 
					
						
							|  |  |  |  |     total_locations = world.total_locations[player].value | 
					
						
							| 
									
										
										
										
											2022-03-23 16:22:31 -05:00
										 |  |  |  |     num_of_events = total_locations // 25 | 
					
						
							|  |  |  |  |     if total_locations / 25 == num_of_events: | 
					
						
							|  |  |  |  |         num_of_events -= 1 | 
					
						
							| 
									
										
										
										
											2022-08-20 18:09:35 -05:00
										 |  |  |  |     world_region = world.get_region("Petrichor V", player) | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-23 16:22:31 -05:00
										 |  |  |  |     for i in range(num_of_events): | 
					
						
							| 
									
										
										
										
											2022-08-20 18:09:35 -05:00
										 |  |  |  |         event_loc = RiskOfRainLocation(player, f"Pickup{(i + 1) * 25}", None, world_region) | 
					
						
							| 
									
										
										
										
											2022-06-17 03:23:27 +02:00
										 |  |  |  |         event_loc.place_locked_item(RiskOfRainItem(f"Pickup{(i + 1) * 25}", ItemClassification.progression, None, player)) | 
					
						
							| 
									
										
										
										
											2022-03-23 16:22:31 -05:00
										 |  |  |  |         event_loc.access_rule(lambda state, i=i: state.can_reach(f"ItemPickup{((i + 1) * 25) - 1}", player)) | 
					
						
							| 
									
										
										
										
											2022-08-20 18:09:35 -05:00
										 |  |  |  |         world_region.locations.append(event_loc) | 
					
						
							| 
									
										
										
										
											2022-03-23 16:22:31 -05:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-20 18:09:35 -05:00
										 |  |  |  |     victory_event = RiskOfRainLocation(player, "Victory", None, world_region) | 
					
						
							|  |  |  |  |     victory_event.place_locked_item(RiskOfRainItem("Victory", ItemClassification.progression, None, player)) | 
					
						
							|  |  |  |  |     world_region.locations.append(victory_event) | 
					
						
							| 
									
										
										
										
											2021-08-29 14:02:02 -04:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-20 18:09:35 -05:00
										 |  |  |  | def create_region(world: MultiWorld, player: int, name: str, locations: List[str] = None) -> Region: | 
					
						
							|  |  |  |  |     ret = Region(name, RegionType.Generic, name, player, world) | 
					
						
							| 
									
										
										
										
											2021-08-29 14:02:02 -04:00
										 |  |  |  |     if locations: | 
					
						
							|  |  |  |  |         for location in locations: | 
					
						
							| 
									
										
										
										
											2022-08-20 18:09:35 -05:00
										 |  |  |  |             loc_id = item_pickups[location] | 
					
						
							| 
									
										
										
										
											2021-08-29 14:02:02 -04:00
										 |  |  |  |             location = RiskOfRainLocation(player, location, loc_id, ret) | 
					
						
							|  |  |  |  |             ret.locations.append(location) | 
					
						
							|  |  |  |  |     return ret |