1
+ from copy import deepcopy
1
2
from typing import List , TYPE_CHECKING
2
3
3
4
from BaseClasses import CollectionState , PlandoOptions
18
19
]
19
20
20
21
21
- REGION_ORDER = [
22
- "Autumn Hills" ,
23
- "Forlorn Temple" ,
24
- "Catacombs" ,
25
- "Bamboo Creek" ,
26
- "Howling Grotto" ,
27
- "Quillshroom Marsh" ,
28
- "Searing Crags" ,
29
- "Glacial Peak" ,
30
- "Tower of Time" ,
31
- "Cloud Ruins" ,
32
- "Underworld" ,
33
- "Riviere Turquoise" ,
34
- "Elemental Skylands" ,
35
- "Sunken Shrine" ,
36
- ]
37
-
38
-
39
22
SHOP_POINTS = {
40
23
"Autumn Hills" : [
41
24
"Climbing Claws" ,
204
187
}
205
188
206
189
190
+ REGION_ORDER = [
191
+ "Autumn Hills" ,
192
+ "Forlorn Temple" ,
193
+ "Catacombs" ,
194
+ "Bamboo Creek" ,
195
+ "Howling Grotto" ,
196
+ "Quillshroom Marsh" ,
197
+ "Searing Crags" ,
198
+ "Glacial Peak" ,
199
+ "Tower of Time" ,
200
+ "Cloud Ruins" ,
201
+ "Underworld" ,
202
+ "Riviere Turquoise" ,
203
+ "Elemental Skylands" ,
204
+ "Sunken Shrine" ,
205
+ ]
206
+
207
+
207
208
def shuffle_portals (world : "MessengerWorld" ) -> None :
208
- def create_mapping (in_portal : str , warp : str ) -> None :
209
- nonlocal available_portals
209
+ """shuffles the output of the portals from the main hub"""
210
+ def create_mapping (in_portal : str , warp : str ) -> str :
211
+ """assigns the chosen output to the input"""
210
212
parent = out_to_parent [warp ]
211
213
exit_string = f"{ parent .strip (' ' )} - "
212
214
213
215
if "Portal" in warp :
214
216
exit_string += "Portal"
215
217
world .portal_mapping .append (int (f"{ REGION_ORDER .index (parent )} 00" ))
216
- elif warp_point in SHOP_POINTS [parent ]:
217
- exit_string += f"{ warp_point } Shop"
218
- world .portal_mapping .append (int (f"{ REGION_ORDER .index (parent )} 1{ SHOP_POINTS [parent ].index (warp_point )} " ))
218
+ elif warp in SHOP_POINTS [parent ]:
219
+ exit_string += f"{ warp } Shop"
220
+ world .portal_mapping .append (int (f"{ REGION_ORDER .index (parent )} 1{ SHOP_POINTS [parent ].index (warp )} " ))
219
221
else :
220
- exit_string += f"{ warp_point } Checkpoint"
221
- world .portal_mapping .append (int (f"{ REGION_ORDER .index (parent )} 2{ CHECKPOINTS [parent ].index (warp_point )} " ))
222
+ exit_string += f"{ warp } Checkpoint"
223
+ world .portal_mapping .append (int (f"{ REGION_ORDER .index (parent )} 2{ CHECKPOINTS [parent ].index (warp )} " ))
222
224
223
225
world .spoiler_portal_mapping [in_portal ] = exit_string
224
226
connect_portal (world , in_portal , exit_string )
225
227
226
- available_portals .remove (warp )
227
- if shuffle_type < ShufflePortals .option_anywhere :
228
- available_portals = [port for port in available_portals if port not in shop_points [parent ]]
228
+ return parent
229
229
230
230
def handle_planned_portals (plando_connections : List [PlandoConnection ]) -> None :
231
+ """checks the provided plando connections for portals and connects them"""
231
232
for connection in plando_connections :
232
233
if connection .entrance not in PORTALS :
233
234
continue
@@ -236,22 +237,28 @@ def handle_planned_portals(plando_connections: List[PlandoConnection]) -> None:
236
237
world .plando_portals .append (connection .entrance )
237
238
238
239
shuffle_type = world .options .shuffle_portals
239
- shop_points = SHOP_POINTS . copy ( )
240
+ shop_points = deepcopy ( SHOP_POINTS )
240
241
for portal in PORTALS :
241
242
shop_points [portal ].append (f"{ portal } Portal" )
242
243
if shuffle_type > ShufflePortals .option_shops :
243
- shop_points .update (CHECKPOINTS )
244
+ for area , points in CHECKPOINTS .items ():
245
+ shop_points [area ] += points
244
246
out_to_parent = {checkpoint : parent for parent , checkpoints in shop_points .items () for checkpoint in checkpoints }
245
247
available_portals = [val for zone in shop_points .values () for val in zone ]
248
+ world .random .shuffle (available_portals )
246
249
247
250
plando = world .multiworld .plando_connections [world .player ]
248
251
if plando and world .multiworld .plando_options & PlandoOptions .connections :
249
252
handle_planned_portals (plando )
250
- world .multiworld .plando_connections [world .player ] = [connection for connection in plando
251
- if connection .entrance not in PORTALS ]
253
+
252
254
for portal in PORTALS :
253
- warp_point = world .random .choice (available_portals )
254
- create_mapping (portal , warp_point )
255
+ if portal in world .plando_portals :
256
+ continue
257
+ warp_point = available_portals .pop ()
258
+ parent = create_mapping (portal , warp_point )
259
+ if shuffle_type < ShufflePortals .option_anywhere :
260
+ available_portals = [port for port in available_portals if port not in shop_points [parent ]]
261
+ world .random .shuffle (available_portals )
255
262
256
263
257
264
def connect_portal (world : "MessengerWorld" , portal : str , out_region : str ) -> None :
0 commit comments