| 
									
										
										
										
											2019-12-16 02:05:33 +01:00
										 |  |  | import argparse | 
					
						
							|  |  |  | import logging | 
					
						
							|  |  |  | import random | 
					
						
							|  |  |  | import urllib.request | 
					
						
							|  |  |  | import urllib.parse | 
					
						
							| 
									
										
										
										
											2020-02-18 09:14:31 +01:00
										 |  |  | import typing | 
					
						
							| 
									
										
										
										
											2020-01-25 16:37:29 -08:00
										 |  |  | import os | 
					
						
							| 
									
										
										
										
											2021-03-12 17:43:50 -08:00
										 |  |  | from collections import Counter | 
					
						
							| 
									
										
										
										
											2020-01-19 23:30:22 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | import ModuleUpdate | 
					
						
							| 
									
										
										
										
											2021-01-03 14:32:32 +01:00
										 |  |  | from worlds.generic import PlandoItem, PlandoConnection | 
					
						
							| 
									
										
										
										
											2020-01-19 23:30:22 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | ModuleUpdate.update() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-09 05:28:48 +01:00
										 |  |  | from Utils import parse_yaml | 
					
						
							| 
									
										
										
										
											2020-10-24 05:38:56 +02:00
										 |  |  | from worlds.alttp.EntranceRandomizer import parse_arguments | 
					
						
							| 
									
										
										
										
											2021-02-21 20:17:24 +01:00
										 |  |  | from Main import main as ERmain | 
					
						
							|  |  |  | from Main import get_seed, seeddigits | 
					
						
							| 
									
										
										
										
											2021-03-14 08:38:02 +01:00
										 |  |  | import Options | 
					
						
							|  |  |  | from worlds import lookup_any_item_name_to_id | 
					
						
							| 
									
										
										
										
											2020-10-24 05:38:56 +02:00
										 |  |  | from worlds.alttp.Items import item_name_groups, item_table | 
					
						
							| 
									
										
										
										
											2021-01-03 14:32:32 +01:00
										 |  |  | from worlds.alttp import Bosses | 
					
						
							| 
									
										
										
										
											2021-01-17 06:54:38 +01:00
										 |  |  | from worlds.alttp.Text import TextTable | 
					
						
							| 
									
										
										
										
											2021-01-21 23:37:58 +01:00
										 |  |  | from worlds.alttp.Regions import location_table, key_drop_data | 
					
						
							| 
									
										
										
										
											2019-12-16 02:05:33 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-19 23:30:22 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-29 03:59:16 +02:00
										 |  |  | def mystery_argparse(): | 
					
						
							| 
									
										
										
										
											2019-12-30 20:43:43 +01:00
										 |  |  |     parser = argparse.ArgumentParser(add_help=False) | 
					
						
							| 
									
										
										
										
											2019-12-17 22:41:19 +01:00
										 |  |  |     parser.add_argument('--multi', default=1, type=lambda value: min(max(int(value), 1), 255)) | 
					
						
							|  |  |  |     multiargs, _ = parser.parse_known_args() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     parser = argparse.ArgumentParser() | 
					
						
							| 
									
										
										
										
											2020-01-19 23:30:22 +01:00
										 |  |  |     parser.add_argument('--weights', | 
					
						
							|  |  |  |                         help='Path to the weights file to use for rolling game settings, urls are also valid') | 
					
						
							|  |  |  |     parser.add_argument('--samesettings', help='Rolls settings per weights file rather than per player', | 
					
						
							|  |  |  |                         action='store_true') | 
					
						
							| 
									
										
										
										
											2019-12-16 02:05:33 +01:00
										 |  |  |     parser.add_argument('--seed', help='Define seed number to generate.', type=int) | 
					
						
							|  |  |  |     parser.add_argument('--multi', default=1, type=lambda value: min(max(int(value), 1), 255)) | 
					
						
							| 
									
										
										
										
											2020-01-14 10:42:27 +01:00
										 |  |  |     parser.add_argument('--teams', default=1, type=lambda value: max(int(value), 1)) | 
					
						
							| 
									
										
										
										
											2019-12-16 02:05:33 +01:00
										 |  |  |     parser.add_argument('--create_spoiler', action='store_true') | 
					
						
							| 
									
										
										
										
											2020-05-31 00:28:03 +02:00
										 |  |  |     parser.add_argument('--skip_playthrough', action='store_true') | 
					
						
							| 
									
										
										
										
											2021-03-03 02:20:37 -08:00
										 |  |  |     parser.add_argument('--pre_roll', action='store_true') | 
					
						
							| 
									
										
										
										
											2019-12-16 02:05:33 +01:00
										 |  |  |     parser.add_argument('--rom') | 
					
						
							|  |  |  |     parser.add_argument('--enemizercli') | 
					
						
							|  |  |  |     parser.add_argument('--outputpath') | 
					
						
							| 
									
										
										
										
											2020-01-13 19:47:30 +01:00
										 |  |  |     parser.add_argument('--race', action='store_true') | 
					
						
							| 
									
										
										
										
											2020-02-18 09:14:31 +01:00
										 |  |  |     parser.add_argument('--meta', default=None) | 
					
						
							| 
									
										
										
										
											2020-04-24 17:01:55 -07:00
										 |  |  |     parser.add_argument('--log_output_path', help='Path to store output log') | 
					
						
							|  |  |  |     parser.add_argument('--loglevel', default='info', help='Sets log level') | 
					
						
							| 
									
										
										
										
											2020-08-26 22:28:48 +02:00
										 |  |  |     parser.add_argument('--create_diff', action="store_true") | 
					
						
							| 
									
										
										
										
											2020-06-04 21:12:05 +02:00
										 |  |  |     parser.add_argument('--yaml_output', default=0, type=lambda value: min(max(int(value), 0), 255), | 
					
						
							| 
									
										
										
										
											2020-04-25 02:25:46 +02:00
										 |  |  |                         help='Output rolled mystery results to yaml up to specified number (made for async multiworld)') | 
					
						
							| 
									
										
										
										
											2021-01-02 12:49:43 +01:00
										 |  |  |     parser.add_argument('--plando', default="bosses", | 
					
						
							|  |  |  |                         help='List of options that can be set manually. Can be combined, for example "bosses, items"') | 
					
						
							| 
									
										
										
										
											2020-02-18 09:14:31 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-12-17 22:41:19 +01:00
										 |  |  |     for player in range(1, multiargs.multi + 1): | 
					
						
							|  |  |  |         parser.add_argument(f'--p{player}', help=argparse.SUPPRESS) | 
					
						
							| 
									
										
										
										
											2019-12-16 02:05:33 +01:00
										 |  |  |     args = parser.parse_args() | 
					
						
							| 
									
										
										
										
											2021-01-02 12:49:43 +01:00
										 |  |  |     args.plando: typing.Set[str] = {arg.strip().lower() for arg in args.plando.split(",")} | 
					
						
							| 
									
										
										
										
											2020-06-29 03:59:16 +02:00
										 |  |  |     return args | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-13 17:15:49 +02:00
										 |  |  | def main(args=None, callback=ERmain): | 
					
						
							| 
									
										
										
										
											2020-06-29 03:59:16 +02:00
										 |  |  |     if not args: | 
					
						
							|  |  |  |         args = mystery_argparse() | 
					
						
							| 
									
										
										
										
											2019-12-16 02:05:33 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-28 00:24:45 +02:00
										 |  |  |     seed = get_seed(args.seed) | 
					
						
							| 
									
										
										
										
											2019-12-17 22:41:19 +01:00
										 |  |  |     random.seed(seed) | 
					
						
							| 
									
										
										
										
											2019-12-16 02:05:33 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-29 03:59:16 +02:00
										 |  |  |     seedname = "M" + (f"{random.randint(0, pow(10, seeddigits) - 1)}".zfill(seeddigits)) | 
					
						
							| 
									
										
										
										
											2019-12-16 02:05:33 +01:00
										 |  |  |     print(f"Generating mystery for {args.multi} player{'s' if args.multi > 1 else ''}, {seedname} Seed {seed}") | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-21 02:02:13 -07:00
										 |  |  |     if args.race: | 
					
						
							|  |  |  |         random.seed()  # reset to time-based random source | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-12-17 22:41:19 +01:00
										 |  |  |     weights_cache = {} | 
					
						
							|  |  |  |     if args.weights: | 
					
						
							| 
									
										
										
										
											2020-02-18 09:14:31 +01:00
										 |  |  |         try: | 
					
						
							|  |  |  |             weights_cache[args.weights] = get_weights(args.weights) | 
					
						
							|  |  |  |         except Exception as e: | 
					
						
							|  |  |  |             raise ValueError(f"File {args.weights} is destroyed. Please fix your yaml.") from e | 
					
						
							| 
									
										
										
										
											2020-09-13 17:15:49 +02:00
										 |  |  |         print(f"Weights: {args.weights} >> " | 
					
						
							|  |  |  |               f"{get_choice('description', weights_cache[args.weights], 'No description specified')}") | 
					
						
							| 
									
										
										
										
											2020-02-18 09:14:31 +01:00
										 |  |  |     if args.meta: | 
					
						
							|  |  |  |         try: | 
					
						
							|  |  |  |             weights_cache[args.meta] = get_weights(args.meta) | 
					
						
							|  |  |  |         except Exception as e: | 
					
						
							| 
									
										
										
										
											2020-02-18 09:50:50 +01:00
										 |  |  |             raise ValueError(f"File {args.meta} is destroyed. Please fix your yaml.") from e | 
					
						
							| 
									
										
										
										
											2020-05-11 02:17:18 +02:00
										 |  |  |         meta_weights = weights_cache[args.meta] | 
					
						
							| 
									
										
										
										
											2020-06-18 08:52:31 -07:00
										 |  |  |         print(f"Meta: {args.meta} >> {get_choice('meta_description', meta_weights, 'No description specified')}") | 
					
						
							| 
									
										
										
										
											2020-02-18 09:14:31 +01:00
										 |  |  |         if args.samesettings: | 
					
						
							|  |  |  |             raise Exception("Cannot mix --samesettings with --meta") | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-12-17 22:41:19 +01:00
										 |  |  |     for player in range(1, args.multi + 1): | 
					
						
							|  |  |  |         path = getattr(args, f'p{player}') | 
					
						
							|  |  |  |         if path: | 
					
						
							| 
									
										
										
										
											2020-03-05 02:31:26 +01:00
										 |  |  |             try: | 
					
						
							|  |  |  |                 if path not in weights_cache: | 
					
						
							| 
									
										
										
										
											2020-01-12 17:03:30 +01:00
										 |  |  |                     weights_cache[path] = get_weights(path) | 
					
						
							| 
									
										
										
										
											2020-09-13 17:15:49 +02:00
										 |  |  |                 print(f"P{player} Weights: {path} >> " | 
					
						
							|  |  |  |                       f"{get_choice('description', weights_cache[path], 'No description specified')}") | 
					
						
							| 
									
										
										
										
											2020-03-05 02:31:26 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |             except Exception as e: | 
					
						
							|  |  |  |                 raise ValueError(f"File {path} is destroyed. Please fix your yaml.") from e | 
					
						
							| 
									
										
										
										
											2019-12-17 22:41:19 +01:00
										 |  |  |     erargs = parse_arguments(['--multi', str(args.multi)]) | 
					
						
							| 
									
										
										
										
											2019-12-16 02:05:33 +01:00
										 |  |  |     erargs.seed = seed | 
					
						
							| 
									
										
										
										
											2020-09-13 17:15:49 +02:00
										 |  |  |     erargs.name = {x: "" for x in range(1, args.multi + 1)}  # only so it can be overwrittin in mystery | 
					
						
							| 
									
										
										
										
											2019-12-16 02:05:33 +01:00
										 |  |  |     erargs.create_spoiler = args.create_spoiler | 
					
						
							| 
									
										
										
										
											2020-08-26 22:28:48 +02:00
										 |  |  |     erargs.create_diff = args.create_diff | 
					
						
							| 
									
										
										
										
											2020-01-13 19:47:30 +01:00
										 |  |  |     erargs.race = args.race | 
					
						
							| 
									
										
										
										
											2020-05-31 00:28:03 +02:00
										 |  |  |     erargs.skip_playthrough = args.skip_playthrough | 
					
						
							| 
									
										
										
										
											2019-12-16 02:05:33 +01:00
										 |  |  |     erargs.outputname = seedname | 
					
						
							|  |  |  |     erargs.outputpath = args.outputpath | 
					
						
							| 
									
										
										
										
											2020-02-23 07:21:05 +01:00
										 |  |  |     erargs.teams = args.teams | 
					
						
							| 
									
										
										
										
											2019-12-16 02:05:33 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-22 03:04:55 +01:00
										 |  |  |     # set up logger | 
					
						
							| 
									
										
										
										
											2020-04-24 17:01:55 -07:00
										 |  |  |     if args.loglevel: | 
					
						
							|  |  |  |         erargs.loglevel = args.loglevel | 
					
						
							| 
									
										
										
										
											2020-08-02 22:11:52 +02:00
										 |  |  |     loglevel = {'error': logging.ERROR, 'info': logging.INFO, 'warning': logging.WARNING, 'debug': logging.DEBUG}[ | 
					
						
							|  |  |  |         erargs.loglevel] | 
					
						
							| 
									
										
										
										
											2020-04-24 17:01:55 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if args.log_output_path: | 
					
						
							| 
									
										
										
										
											2020-08-02 22:11:52 +02:00
										 |  |  |         import sys | 
					
						
							|  |  |  |         class LoggerWriter(object): | 
					
						
							|  |  |  |             def __init__(self, writer): | 
					
						
							|  |  |  |                 self._writer = writer | 
					
						
							|  |  |  |                 self._msg = '' | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             def write(self, message): | 
					
						
							|  |  |  |                 self._msg = self._msg + message | 
					
						
							|  |  |  |                 while '\n' in self._msg: | 
					
						
							|  |  |  |                     pos = self._msg.find('\n') | 
					
						
							|  |  |  |                     self._writer(self._msg[:pos]) | 
					
						
							|  |  |  |                     self._msg = self._msg[pos + 1:] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             def flush(self): | 
					
						
							|  |  |  |                 if self._msg != '': | 
					
						
							|  |  |  |                     self._writer(self._msg) | 
					
						
							|  |  |  |                     self._msg = '' | 
					
						
							| 
									
										
										
										
											2020-09-13 17:15:49 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-24 17:01:55 -07:00
										 |  |  |         log = logging.getLogger("stderr") | 
					
						
							|  |  |  |         log.addHandler(logging.StreamHandler()) | 
					
						
							|  |  |  |         sys.stderr = LoggerWriter(log.error) | 
					
						
							|  |  |  |         os.makedirs(args.log_output_path, exist_ok=True) | 
					
						
							| 
									
										
										
										
											2020-09-13 17:15:49 +02:00
										 |  |  |         logging.basicConfig(format='%(message)s', level=loglevel, | 
					
						
							|  |  |  |                             filename=os.path.join(args.log_output_path, f"{seed}.log")) | 
					
						
							| 
									
										
										
										
											2020-04-24 17:01:55 -07:00
										 |  |  |     else: | 
					
						
							|  |  |  |         logging.basicConfig(format='%(message)s', level=loglevel) | 
					
						
							| 
									
										
										
										
											2019-12-16 02:05:33 +01:00
										 |  |  |     if args.rom: | 
					
						
							|  |  |  |         erargs.rom = args.rom | 
					
						
							| 
									
										
										
										
											2020-02-23 17:06:44 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-06 18:39:18 +01:00
										 |  |  |     if args.enemizercli: | 
					
						
							|  |  |  |         erargs.enemizercli = args.enemizercli | 
					
						
							| 
									
										
										
										
											2019-12-16 02:05:33 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-02 12:49:43 +01:00
										 |  |  |     settings_cache = {k: (roll_settings(v, args.plando) if args.samesettings else None) | 
					
						
							|  |  |  |                       for k, v in weights_cache.items()} | 
					
						
							| 
									
										
										
										
											2020-02-18 09:14:31 +01:00
										 |  |  |     player_path_cache = {} | 
					
						
							|  |  |  |     for player in range(1, args.multi + 1): | 
					
						
							|  |  |  |         player_path_cache[player] = getattr(args, f'p{player}') if getattr(args, f'p{player}') else args.weights | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if args.meta: | 
					
						
							|  |  |  |         for player, path in player_path_cache.items(): | 
					
						
							|  |  |  |             weights_cache[path].setdefault("meta_ignore", []) | 
					
						
							|  |  |  |         meta_weights = weights_cache[args.meta] | 
					
						
							|  |  |  |         for key in meta_weights: | 
					
						
							|  |  |  |             option = get_choice(key, meta_weights) | 
					
						
							|  |  |  |             if option is not None: | 
					
						
							|  |  |  |                 for player, path in player_path_cache.items(): | 
					
						
							| 
									
										
										
										
											2020-05-18 03:54:29 +02:00
										 |  |  |                     players_meta = weights_cache[path].get("meta_ignore", []) | 
					
						
							|  |  |  |                     if key not in players_meta: | 
					
						
							|  |  |  |                         weights_cache[path][key] = option | 
					
						
							|  |  |  |                     elif type(players_meta) == dict and players_meta[key] and option not in players_meta[key]: | 
					
						
							|  |  |  |                         weights_cache[path][key] = option | 
					
						
							| 
									
										
										
										
											2019-12-17 22:41:19 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-12 17:43:50 -08:00
										 |  |  |     name_counter = Counter() | 
					
						
							| 
									
										
										
										
											2021-03-14 08:38:02 +01:00
										 |  |  |     erargs.player_settings = {} | 
					
						
							| 
									
										
										
										
											2019-12-17 22:41:19 +01:00
										 |  |  |     for player in range(1, args.multi + 1): | 
					
						
							| 
									
										
										
										
											2020-02-18 09:14:31 +01:00
										 |  |  |         path = player_path_cache[player] | 
					
						
							| 
									
										
										
										
											2019-12-17 22:41:19 +01:00
										 |  |  |         if path: | 
					
						
							| 
									
										
										
										
											2020-01-12 17:03:30 +01:00
										 |  |  |             try: | 
					
						
							| 
									
										
										
										
											2021-01-02 12:49:43 +01:00
										 |  |  |                 settings = settings_cache[path] if settings_cache[path] else \ | 
					
						
							|  |  |  |                     roll_settings(weights_cache[path], args.plando) | 
					
						
							| 
									
										
										
										
											2021-03-03 02:20:37 -08:00
										 |  |  |                 if args.pre_roll: | 
					
						
							|  |  |  |                     import yaml | 
					
						
							|  |  |  |                     if path == args.weights: | 
					
						
							|  |  |  |                         settings.name = f"Player{player}" | 
					
						
							|  |  |  |                     elif not settings.name: | 
					
						
							| 
									
										
										
										
											2021-03-13 15:26:21 -08:00
										 |  |  |                         settings.name = os.path.splitext(os.path.split(path)[-1])[0] | 
					
						
							| 
									
										
										
										
											2021-03-03 02:20:37 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  |                     if "-" not in settings.shuffle and settings.shuffle != "vanilla": | 
					
						
							|  |  |  |                         settings.shuffle += f"-{random.randint(0, 2 ** 64)}" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                     pre_rolled = dict() | 
					
						
							| 
									
										
										
										
											2021-03-05 11:32:24 -08:00
										 |  |  |                     pre_rolled["original_seed_number"] = seed | 
					
						
							|  |  |  |                     pre_rolled["original_seed_name"] = seedname | 
					
						
							| 
									
										
										
										
											2021-03-05 02:50:40 -08:00
										 |  |  |                     pre_rolled["pre_rolled"] = vars(settings).copy() | 
					
						
							|  |  |  |                     if "plando_items" in pre_rolled["pre_rolled"]: | 
					
						
							|  |  |  |                         pre_rolled["pre_rolled"]["plando_items"] = [item.to_dict() for item in pre_rolled["pre_rolled"]["plando_items"]] | 
					
						
							|  |  |  |                     if "plando_connections" in pre_rolled["pre_rolled"]: | 
					
						
							|  |  |  |                         pre_rolled["pre_rolled"]["plando_connections"] = [connection.to_dict() for connection in pre_rolled["pre_rolled"]["plando_connections"]] | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-05 11:32:24 -08:00
										 |  |  |                     with open(os.path.join(args.outputpath if args.outputpath else ".", f"{os.path.split(path)[-1].split('.')[0]}_pre_rolled.yaml"), "wt") as f: | 
					
						
							| 
									
										
										
										
											2021-03-03 02:20:37 -08:00
										 |  |  |                         yaml.dump(pre_rolled, f) | 
					
						
							| 
									
										
										
										
											2020-01-12 17:03:30 +01:00
										 |  |  |                 for k, v in vars(settings).items(): | 
					
						
							|  |  |  |                     if v is not None: | 
					
						
							| 
									
										
										
										
											2021-03-14 08:38:02 +01:00
										 |  |  |                         try: | 
					
						
							|  |  |  |                             getattr(erargs, k)[player] = v | 
					
						
							|  |  |  |                         except AttributeError: | 
					
						
							|  |  |  |                             setattr(erargs, k, {player: v}) | 
					
						
							| 
									
										
										
										
											2020-02-18 09:14:31 +01:00
										 |  |  |             except Exception as e: | 
					
						
							|  |  |  |                 raise ValueError(f"File {path} is destroyed. Please fix your yaml.") from e | 
					
						
							| 
									
										
										
										
											2019-12-17 22:41:19 +01:00
										 |  |  |         else: | 
					
						
							|  |  |  |             raise RuntimeError(f'No weights specified for player {player}') | 
					
						
							| 
									
										
										
										
											2020-08-11 22:11:37 +02:00
										 |  |  |         if path == args.weights:  # if name came from the weights file, just use base player name | 
					
						
							|  |  |  |             erargs.name[player] = f"Player{player}" | 
					
						
							|  |  |  |         elif not erargs.name[player]:  # if name was not specified, generate it from filename | 
					
						
							| 
									
										
										
										
											2021-03-13 15:26:21 -08:00
										 |  |  |             erargs.name[player] = os.path.splitext(os.path.split(path)[-1])[0] | 
					
						
							| 
									
										
										
										
											2021-03-12 17:43:50 -08:00
										 |  |  |         name_counter[erargs.name[player]] += 1 | 
					
						
							| 
									
										
										
										
											2021-03-17 06:26:06 +01:00
										 |  |  |         erargs.name[player]= handle_name(erargs.name[player].format(number=name_counter[erargs.name[player]], | 
					
						
							|  |  |  |                                                                     player=player)) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-11 22:11:37 +02:00
										 |  |  |     erargs.names = ",".join(erargs.name[i] for i in range(1, args.multi + 1)) | 
					
						
							| 
									
										
										
										
											2020-04-22 13:52:03 +02:00
										 |  |  |     del (erargs.name) | 
					
						
							| 
									
										
										
										
											2020-04-25 02:24:37 +02:00
										 |  |  |     if args.yaml_output: | 
					
						
							|  |  |  |         import yaml | 
					
						
							|  |  |  |         important = {} | 
					
						
							|  |  |  |         for option, player_settings in vars(erargs).items(): | 
					
						
							|  |  |  |             if type(player_settings) == dict: | 
					
						
							| 
									
										
										
										
											2020-10-07 20:19:31 +02:00
										 |  |  |                 if all(type(value) != list for value in player_settings.values()): | 
					
						
							| 
									
										
										
										
											2021-02-05 08:07:12 +01:00
										 |  |  |                     if len(player_settings.values()) > 1: | 
					
						
							| 
									
										
										
										
											2020-10-07 20:19:31 +02:00
										 |  |  |                         important[option] = {player: value for player, value in player_settings.items() if | 
					
						
							|  |  |  |                                              player <= args.yaml_output} | 
					
						
							| 
									
										
										
										
											2021-02-05 08:07:12 +01:00
										 |  |  |                     elif len(player_settings.values()) > 0: | 
					
						
							| 
									
										
										
										
											2020-10-07 20:19:31 +02:00
										 |  |  |                         important[option] = player_settings[1] | 
					
						
							|  |  |  |                     else: | 
					
						
							|  |  |  |                         logging.debug(f"No player settings defined for option '{option}'") | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-25 02:24:37 +02:00
										 |  |  |             else: | 
					
						
							|  |  |  |                 if player_settings != "":  # is not empty name | 
					
						
							|  |  |  |                     important[option] = player_settings | 
					
						
							| 
									
										
										
										
											2020-04-25 17:57:20 -07:00
										 |  |  |                 else: | 
					
						
							|  |  |  |                     logging.debug(f"No player settings defined for option '{option}'") | 
					
						
							|  |  |  |         if args.outputpath: | 
					
						
							|  |  |  |             os.makedirs(args.outputpath, exist_ok=True) | 
					
						
							| 
									
										
										
										
											2020-04-25 02:24:37 +02:00
										 |  |  |         with open(os.path.join(args.outputpath if args.outputpath else ".", f"mystery_result_{seed}.yaml"), "wt") as f: | 
					
						
							|  |  |  |             yaml.dump(important, f) | 
					
						
							| 
									
										
										
										
											2020-02-23 17:06:44 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-25 22:40:24 +02:00
										 |  |  |     callback(erargs, seed) | 
					
						
							| 
									
										
										
										
											2019-12-17 22:41:19 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-23 17:06:44 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-12-17 22:41:19 +01:00
										 |  |  | def get_weights(path): | 
					
						
							|  |  |  |     try: | 
					
						
							| 
									
										
										
										
											2020-04-10 06:41:32 +02:00
										 |  |  |         if urllib.parse.urlparse(path).scheme: | 
					
						
							|  |  |  |             yaml = str(urllib.request.urlopen(path).read(), "utf-8") | 
					
						
							|  |  |  |         else: | 
					
						
							| 
									
										
										
										
											2019-12-17 22:41:19 +01:00
										 |  |  |             with open(path, 'rb') as f: | 
					
						
							|  |  |  |                 yaml = str(f.read(), "utf-8") | 
					
						
							|  |  |  |     except Exception as e: | 
					
						
							| 
									
										
										
										
											2020-09-18 06:03:04 +02:00
										 |  |  |         raise Exception(f"Failed to read weights ({path})") from e | 
					
						
							| 
									
										
										
										
											2019-12-17 22:41:19 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     return parse_yaml(yaml) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-19 23:30:22 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | def interpret_on_off(value): | 
					
						
							|  |  |  |     return {"on": True, "off": False}.get(value, value) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-23 17:06:44 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-20 03:29:13 +01:00
										 |  |  | def convert_to_on_off(value): | 
					
						
							|  |  |  |     return {True: "on", False: "off"}.get(value, value) | 
					
						
							| 
									
										
										
										
											2020-01-19 23:30:22 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-23 17:06:44 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-18 08:51:38 -07:00
										 |  |  | def get_choice(option, root, value=None) -> typing.Any: | 
					
						
							| 
									
										
										
										
											2020-02-18 09:14:31 +01:00
										 |  |  |     if option not in root: | 
					
						
							| 
									
										
										
										
											2020-06-18 08:51:38 -07:00
										 |  |  |         return value | 
					
						
							| 
									
										
										
										
											2020-11-05 17:03:10 -08:00
										 |  |  |     if type(root[option]) is list: | 
					
						
							|  |  |  |         return interpret_on_off(random.choices(root[option])[0]) | 
					
						
							| 
									
										
										
										
											2020-02-18 09:14:31 +01:00
										 |  |  |     if type(root[option]) is not dict: | 
					
						
							|  |  |  |         return interpret_on_off(root[option]) | 
					
						
							|  |  |  |     if not root[option]: | 
					
						
							| 
									
										
										
										
											2020-06-18 08:51:38 -07:00
										 |  |  |         return value | 
					
						
							| 
									
										
										
										
											2020-06-18 19:21:52 -07:00
										 |  |  |     if any(root[option].values()): | 
					
						
							| 
									
										
										
										
											2020-06-18 08:48:33 -07:00
										 |  |  |         return interpret_on_off( | 
					
						
							|  |  |  |             random.choices(list(root[option].keys()), weights=list(map(int, root[option].values())))[0]) | 
					
						
							| 
									
										
										
										
											2020-12-31 13:23:32 +01:00
										 |  |  |     raise RuntimeError(f"All options specified in \"{option}\" are weighted as zero.") | 
					
						
							| 
									
										
										
										
											2019-12-17 22:41:19 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-23 17:06:44 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | def handle_name(name: str): | 
					
						
							| 
									
										
										
										
											2020-08-25 19:45:33 +02:00
										 |  |  |     return name.strip().replace(' ', '_')[:16] | 
					
						
							| 
									
										
										
										
											2020-02-23 17:06:44 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-18 07:12:09 +02:00
										 |  |  | def prefer_int(input_data: str) -> typing.Union[str, int]: | 
					
						
							|  |  |  |     try: | 
					
						
							|  |  |  |         return int(input_data) | 
					
						
							|  |  |  |     except: | 
					
						
							|  |  |  |         return input_data | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-31 13:23:32 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | available_boss_names: typing.Set[str] = {boss.lower() for boss in Bosses.boss_table if boss not in | 
					
						
							|  |  |  |                                          {'Agahnim', 'Agahnim2', 'Ganon'}} | 
					
						
							| 
									
										
										
										
											2021-03-07 04:36:46 -08:00
										 |  |  | available_boss_locations: typing.Set[str] = {f"{loc.lower()}{f' {level}' if level else ''}" for loc, level in | 
					
						
							|  |  |  |                                              Bosses.boss_location_table} | 
					
						
							| 
									
										
										
										
											2020-12-31 13:23:32 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | boss_shuffle_options = {None: 'none', | 
					
						
							|  |  |  |                         'none': 'none', | 
					
						
							| 
									
										
										
										
											2021-01-06 11:12:23 -08:00
										 |  |  |                         'basic': 'basic', | 
					
						
							|  |  |  |                         'normal': 'normal', | 
					
						
							|  |  |  |                         'chaos': 'chaos', | 
					
						
							| 
									
										
										
										
											2021-03-14 08:38:02 +01:00
										 |  |  |                         'singularity': 'singularity' | 
					
						
							| 
									
										
										
										
											2020-12-31 13:23:32 +01:00
										 |  |  |                         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-02 12:49:43 +01:00
										 |  |  | def roll_percentage(percentage: typing.Union[int, float]) -> bool: | 
					
						
							|  |  |  |     """Roll a percentage chance.
 | 
					
						
							|  |  |  |     percentage is expected to be in range [0, 100]"""
 | 
					
						
							|  |  |  |     return random.random() < (float(percentage) / 100) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-13 10:26:02 -08:00
										 |  |  | def update_weights(weights: dict, new_weights: dict, type: str, name: str) -> dict: | 
					
						
							|  |  |  |     logging.debug(f'Applying {new_weights}') | 
					
						
							|  |  |  |     new_options = set(new_weights) - set(weights) | 
					
						
							|  |  |  |     weights.update(new_weights) | 
					
						
							|  |  |  |     if new_options: | 
					
						
							|  |  |  |         for new_option in new_options: | 
					
						
							|  |  |  |             logging.warning(f'{type} Suboption "{new_option}" of "{name}" did not ' | 
					
						
							|  |  |  |                             f'overwrite a root option. ' | 
					
						
							|  |  |  |                             f'This is probably in error.') | 
					
						
							|  |  |  |     return weights | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-13 14:03:23 +01:00
										 |  |  | def roll_linked_options(weights: dict) -> dict: | 
					
						
							|  |  |  |     weights = weights.copy()  # make sure we don't write back to other weights sets in same_settings | 
					
						
							|  |  |  |     for option_set in weights["linked_options"]: | 
					
						
							|  |  |  |         if "name" not in option_set: | 
					
						
							|  |  |  |             raise ValueError("One of your linked options does not have a name.") | 
					
						
							|  |  |  |         try: | 
					
						
							|  |  |  |             if roll_percentage(option_set["percentage"]): | 
					
						
							|  |  |  |                 logging.debug(f"Linked option {option_set['name']} triggered.") | 
					
						
							| 
									
										
										
										
											2021-02-13 10:26:02 -08:00
										 |  |  |                 if "options" in option_set: | 
					
						
							|  |  |  |                     weights = update_weights(weights, option_set["options"], "Linked", option_set["name"]) | 
					
						
							|  |  |  |                 if "rom_options" in option_set: | 
					
						
							|  |  |  |                     rom_weights = weights.get("rom", dict()) | 
					
						
							|  |  |  |                     rom_weights = update_weights(rom_weights, option_set["rom_options"], "Linked Rom", option_set["name"]) | 
					
						
							|  |  |  |                     weights["rom"] = rom_weights | 
					
						
							| 
									
										
										
										
											2021-02-13 14:03:23 +01:00
										 |  |  |             else: | 
					
						
							|  |  |  |                 logging.debug(f"linked option {option_set['name']} skipped.") | 
					
						
							|  |  |  |         except Exception as e: | 
					
						
							|  |  |  |             raise ValueError(f"Linked option {option_set['name']} is destroyed. " | 
					
						
							|  |  |  |                              f"Please fix your linked option.") from e | 
					
						
							|  |  |  |     return weights | 
					
						
							| 
									
										
										
										
											2021-01-02 12:49:43 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-13 14:03:23 +01:00
										 |  |  | def roll_triggers(weights: dict) -> dict: | 
					
						
							|  |  |  |     weights = weights.copy()  # make sure we don't write back to other weights sets in same_settings | 
					
						
							| 
									
										
										
										
											2021-02-19 23:21:18 -08:00
										 |  |  |     weights["_Generator_Version"] = "Main"  # Some means for triggers to know if the seed is on main or doors. | 
					
						
							| 
									
										
										
										
											2021-02-13 14:03:23 +01:00
										 |  |  |     for option_set in weights["triggers"]: | 
					
						
							|  |  |  |         try: | 
					
						
							|  |  |  |             key = get_choice("option_name", option_set) | 
					
						
							| 
									
										
										
										
											2021-02-13 13:57:52 -08:00
										 |  |  |             if key not in weights: | 
					
						
							|  |  |  |                 logging.warning(f'Specified option name {option_set["option_name"]} did not ' | 
					
						
							|  |  |  |                                 f'match with a root option. ' | 
					
						
							|  |  |  |                                 f'This is probably in error.') | 
					
						
							| 
									
										
										
										
											2021-02-13 14:03:23 +01:00
										 |  |  |             trigger_result = get_choice("option_result", option_set) | 
					
						
							|  |  |  |             result = get_choice(key, weights) | 
					
						
							|  |  |  |             if result == trigger_result and roll_percentage(get_choice("percentage", option_set, 100)): | 
					
						
							| 
									
										
										
										
											2021-02-13 10:26:02 -08:00
										 |  |  |                 if "options" in option_set: | 
					
						
							|  |  |  |                     weights = update_weights(weights, option_set["options"], "Triggered", option_set["option_name"]) | 
					
						
							|  |  |  |                 if "rom_options" in option_set: | 
					
						
							|  |  |  |                     rom_weights = weights.get("rom", dict()) | 
					
						
							|  |  |  |                     rom_weights = update_weights(rom_weights, option_set["rom_options"], "Triggered Rom", option_set["option_name"]) | 
					
						
							|  |  |  |                     weights["rom"] = rom_weights | 
					
						
							| 
									
										
										
										
											2021-02-13 14:03:23 +01:00
										 |  |  |             weights[key] = result | 
					
						
							|  |  |  |         except Exception as e: | 
					
						
							|  |  |  |             raise ValueError(f"A trigger is destroyed. " | 
					
						
							|  |  |  |                              f"Please fix your triggers.") from e | 
					
						
							|  |  |  |     return weights | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-07 03:38:49 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | def get_plando_bosses(boss_shuffle: str, plando_options: typing.Set[str]) -> str: | 
					
						
							|  |  |  |     if boss_shuffle in boss_shuffle_options: | 
					
						
							|  |  |  |         return boss_shuffle_options[boss_shuffle] | 
					
						
							|  |  |  |     elif "bosses" in plando_options: | 
					
						
							|  |  |  |         options = boss_shuffle.lower().split(";") | 
					
						
							|  |  |  |         remainder_shuffle = "none"  # vanilla | 
					
						
							|  |  |  |         bosses = [] | 
					
						
							|  |  |  |         for boss in options: | 
					
						
							|  |  |  |             if boss in boss_shuffle_options: | 
					
						
							|  |  |  |                 remainder_shuffle = boss_shuffle_options[boss] | 
					
						
							| 
									
										
										
										
											2021-03-07 04:36:46 -08:00
										 |  |  |             elif "-" in boss: | 
					
						
							|  |  |  |                 loc, boss_name = boss.split("-") | 
					
						
							|  |  |  |                 if boss_name not in available_boss_names: | 
					
						
							|  |  |  |                     raise ValueError(f"Unknown Boss name {boss_name}") | 
					
						
							|  |  |  |                 if loc not in available_boss_locations: | 
					
						
							|  |  |  |                     raise ValueError(f"Unknown Boss Location {loc}") | 
					
						
							|  |  |  |                 level = '' | 
					
						
							|  |  |  |                 if loc.split(" ")[-1] in {"top", "middle", "bottom"}: | 
					
						
							|  |  |  |                     # split off level | 
					
						
							|  |  |  |                     loc = loc.split(" ") | 
					
						
							|  |  |  |                     level = f" {loc[-1]}" | 
					
						
							|  |  |  |                     loc = " ".join(loc[:-1]) | 
					
						
							|  |  |  |                 loc = loc.title().replace("Of", "of") | 
					
						
							|  |  |  |                 if not Bosses.can_place_boss(boss_name.title(), loc, level): | 
					
						
							|  |  |  |                     raise ValueError(f"Cannot place {boss_name} at {loc}{level}") | 
					
						
							|  |  |  |                 bosses.append(boss) | 
					
						
							|  |  |  |             elif boss not in available_boss_names: | 
					
						
							| 
									
										
										
										
											2021-03-07 03:38:49 -08:00
										 |  |  |                 raise ValueError(f"Unknown Boss name or Boss shuffle option {boss}.") | 
					
						
							|  |  |  |             else: | 
					
						
							|  |  |  |                 bosses.append(boss) | 
					
						
							|  |  |  |         return ";".join(bosses + [remainder_shuffle]) | 
					
						
							|  |  |  |     else: | 
					
						
							|  |  |  |         raise Exception(f"Boss Shuffle {boss_shuffle} is unknown and boss plando is turned off.") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-14 08:38:02 +01:00
										 |  |  | def roll_settings(weights: dict, plando_options: typing.Set[str] = frozenset(("bosses", ))): | 
					
						
							| 
									
										
										
										
											2021-03-03 02:20:37 -08:00
										 |  |  |     if "pre_rolled" in weights: | 
					
						
							| 
									
										
										
										
											2021-03-05 02:50:40 -08:00
										 |  |  |         pre_rolled = weights["pre_rolled"] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if "plando_items" in pre_rolled: | 
					
						
							|  |  |  |             pre_rolled["plando_items"] = [PlandoItem(item["item"], | 
					
						
							|  |  |  |                                                      item["location"], | 
					
						
							|  |  |  |                                                      item["world"], | 
					
						
							|  |  |  |                                                      item["from_pool"], | 
					
						
							|  |  |  |                                                      item["force"]) for item in pre_rolled["plando_items"]] | 
					
						
							| 
									
										
										
										
											2021-03-07 03:38:49 -08:00
										 |  |  |             if "items" not in plando_options and pre_rolled["plando_items"]: | 
					
						
							|  |  |  |                 raise Exception("Item Plando is turned off. Reusing this pre-rolled setting not permitted.") | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-05 02:50:40 -08:00
										 |  |  |         if "plando_connections" in pre_rolled: | 
					
						
							|  |  |  |             pre_rolled["plando_connections"] = [PlandoConnection(connection["entrance"], | 
					
						
							|  |  |  |                                                                  connection["exit"], | 
					
						
							|  |  |  |                                                                  connection["direction"]) for connection in pre_rolled["plando_connections"]] | 
					
						
							| 
									
										
										
										
											2021-03-07 03:38:49 -08:00
										 |  |  |             if "connections" not in plando_options and pre_rolled["plando_connections"]: | 
					
						
							|  |  |  |                 raise Exception("Connection Plando is turned off. Reusing this pre-rolled setting not permitted.") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if "bosses" not in plando_options: | 
					
						
							|  |  |  |             try: | 
					
						
							|  |  |  |                 pre_rolled["shufflebosses"] = get_plando_bosses(pre_rolled["shufflebosses"], plando_options) | 
					
						
							|  |  |  |             except Exception as ex: | 
					
						
							|  |  |  |                 raise Exception("Boss Plando is turned off. Reusing this pre-rolled setting not permitted.") from ex | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if pre_rolled.get("plando_texts") and "texts" not in plando_options: | 
					
						
							|  |  |  |             raise Exception("Text Plando is turned off. Reusing this pre-rolled setting not permitted.") | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-05 02:50:40 -08:00
										 |  |  |         return argparse.Namespace(**pre_rolled) | 
					
						
							| 
									
										
										
										
											2021-03-03 02:20:37 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-25 02:24:37 +02:00
										 |  |  |     if "linked_options" in weights: | 
					
						
							| 
									
										
										
										
											2021-02-13 14:03:23 +01:00
										 |  |  |         weights = roll_linked_options(weights) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if "triggers" in weights: | 
					
						
							|  |  |  |         weights = roll_triggers(weights) | 
					
						
							| 
									
										
										
										
											2020-04-25 02:24:37 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-13 14:03:23 +01:00
										 |  |  |     ret = argparse.Namespace() | 
					
						
							| 
									
										
										
										
											2020-04-24 20:49:59 -07:00
										 |  |  |     ret.name = get_choice('name', weights) | 
					
						
							| 
									
										
										
										
											2021-03-14 08:38:02 +01:00
										 |  |  |     ret.accessibility = get_choice('accessibility', weights) | 
					
						
							| 
									
										
										
										
											2021-02-21 20:17:24 +01:00
										 |  |  |     ret.game = get_choice("game", weights, "A Link to the Past") | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-14 08:38:02 +01:00
										 |  |  |     ret.local_items = set() | 
					
						
							|  |  |  |     for item_name in weights.get('local_items', []): | 
					
						
							|  |  |  |         items = item_name_groups.get(item_name, {item_name}) | 
					
						
							|  |  |  |         for item in items: | 
					
						
							|  |  |  |             if item in lookup_any_item_name_to_id: | 
					
						
							|  |  |  |                 ret.local_items.add(item) | 
					
						
							|  |  |  |             else: | 
					
						
							|  |  |  |                 raise Exception(f"Could not force item {item} to be world-local, as it was not recognized.") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ret.non_local_items = set() | 
					
						
							|  |  |  |     for item_name in weights.get('non_local_items', []): | 
					
						
							|  |  |  |         items = item_name_groups.get(item_name, {item_name}) | 
					
						
							|  |  |  |         for item in items: | 
					
						
							|  |  |  |             if item in lookup_any_item_name_to_id: | 
					
						
							|  |  |  |                 ret.non_local_items.add(item) | 
					
						
							|  |  |  |             else: | 
					
						
							|  |  |  |                 raise Exception(f"Could not force item {item} to be world-non-local, as it was not recognized.") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if ret.game == "A Link to the Past": | 
					
						
							|  |  |  |         roll_alttp_settings(ret, weights, plando_options) | 
					
						
							|  |  |  |     elif ret.game == "Hollow Knight": | 
					
						
							|  |  |  |         for option_name, option in Options.hollow_knight_options.items(): | 
					
						
							|  |  |  |             setattr(ret, option_name, option.from_any(get_choice(option_name, weights, True))) | 
					
						
							|  |  |  |     else: | 
					
						
							|  |  |  |         raise Exception(f"Unsupported game {ret.game}") | 
					
						
							|  |  |  |     return ret | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def roll_alttp_settings(ret: argparse.Namespace, weights, plando_options): | 
					
						
							| 
									
										
										
										
											2020-02-18 09:14:31 +01:00
										 |  |  |     glitches_required = get_choice('glitches_required', weights) | 
					
						
							| 
									
										
										
										
											2020-09-19 22:25:58 -07:00
										 |  |  |     if glitches_required not in [None, 'none', 'no_logic', 'overworld_glitches', 'minor_glitches']: | 
					
						
							| 
									
										
										
										
											2020-04-08 15:07:19 +02:00
										 |  |  |         logging.warning("Only NMG, OWG and No Logic supported") | 
					
						
							| 
									
										
										
										
											2019-12-17 22:41:19 +01:00
										 |  |  |         glitches_required = 'none' | 
					
						
							| 
									
										
										
										
											2020-06-10 19:02:11 +02:00
										 |  |  |     ret.logic = {None: 'noglitches', 'none': 'noglitches', 'no_logic': 'nologic', 'overworld_glitches': 'owglitches', | 
					
						
							| 
									
										
										
										
											2020-09-13 17:15:49 +02:00
										 |  |  |                  'minor_glitches': 'minorglitches'}[ | 
					
						
							| 
									
										
										
										
											2020-04-25 02:24:37 +02:00
										 |  |  |         glitches_required] | 
					
						
							| 
									
										
										
										
											2020-10-07 19:51:46 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     ret.dark_room_logic = get_choice("dark_room_logic", weights, "lamp") | 
					
						
							| 
									
										
										
										
											2020-10-07 23:19:16 +02:00
										 |  |  |     if not ret.dark_room_logic:  # None/False | 
					
						
							| 
									
										
										
										
											2020-10-07 19:51:46 +02:00
										 |  |  |         ret.dark_room_logic = "none" | 
					
						
							|  |  |  |     if ret.dark_room_logic == "sconces": | 
					
						
							|  |  |  |         ret.dark_room_logic = "torches" | 
					
						
							|  |  |  |     if ret.dark_room_logic not in {"lamp", "torches", "none"}: | 
					
						
							|  |  |  |         raise ValueError(f"Unknown Dark Room Logic: \"{ret.dark_room_logic}\"") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ret.restrict_dungeon_item_on_boss = get_choice('restrict_dungeon_item_on_boss', weights, False) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-18 08:55:15 -07:00
										 |  |  |     ret.progression_balancing = get_choice('progression_balancing', weights, True) | 
					
						
							| 
									
										
										
										
											2020-01-19 23:30:22 +01:00
										 |  |  |     # item_placement = get_choice('item_placement') | 
					
						
							| 
									
										
										
										
											2019-12-16 02:05:33 +01:00
										 |  |  |     # not supported in ER | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-18 09:14:31 +01:00
										 |  |  |     dungeon_items = get_choice('dungeon_items', weights) | 
					
						
							| 
									
										
										
										
											2020-01-23 08:35:52 +01:00
										 |  |  |     if dungeon_items == 'full' or dungeon_items == True: | 
					
						
							| 
									
										
										
										
											2020-01-19 23:30:22 +01:00
										 |  |  |         dungeon_items = 'mcsb' | 
					
						
							| 
									
										
										
										
											2020-02-17 13:29:25 -05:00
										 |  |  |     elif dungeon_items == 'standard': | 
					
						
							|  |  |  |         dungeon_items = "" | 
					
						
							| 
									
										
										
										
											2020-01-23 08:35:52 +01:00
										 |  |  |     elif not dungeon_items: | 
					
						
							|  |  |  |         dungeon_items = "" | 
					
						
							| 
									
										
										
										
											2020-08-30 03:19:02 +02:00
										 |  |  |     if "u" in dungeon_items: | 
					
						
							|  |  |  |         dungeon_items.replace("s", "") | 
					
						
							| 
									
										
										
										
											2020-01-23 08:35:52 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-18 08:55:15 -07:00
										 |  |  |     ret.mapshuffle = get_choice('map_shuffle', weights, 'm' in dungeon_items) | 
					
						
							|  |  |  |     ret.compassshuffle = get_choice('compass_shuffle', weights, 'c' in dungeon_items) | 
					
						
							| 
									
										
										
										
											2020-08-20 20:13:00 +02:00
										 |  |  |     ret.keyshuffle = get_choice('smallkey_shuffle', weights, | 
					
						
							|  |  |  |                                 'universal' if 'u' in dungeon_items else 's' in dungeon_items) | 
					
						
							| 
									
										
										
										
											2020-06-18 08:55:15 -07:00
										 |  |  |     ret.bigkeyshuffle = get_choice('bigkey_shuffle', weights, 'b' in dungeon_items) | 
					
						
							| 
									
										
										
										
											2019-12-16 02:05:33 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-24 17:10:41 -08:00
										 |  |  |     entrance_shuffle = get_choice('entrance_shuffle', weights, 'vanilla') | 
					
						
							| 
									
										
										
										
											2021-02-24 13:23:42 -08:00
										 |  |  |     if entrance_shuffle.startswith('none-'): | 
					
						
							|  |  |  |         ret.shuffle = 'vanilla' | 
					
						
							|  |  |  |     else: | 
					
						
							|  |  |  |         ret.shuffle = entrance_shuffle if entrance_shuffle != 'none' else 'vanilla' | 
					
						
							| 
									
										
										
										
											2019-12-16 02:05:33 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-19 22:25:58 -07:00
										 |  |  |     goal = get_choice('goals', weights, 'ganon') | 
					
						
							| 
									
										
										
										
											2019-12-17 22:41:19 +01:00
										 |  |  |     ret.goal = {'ganon': 'ganon', | 
					
						
							| 
									
										
										
										
											2021-03-14 08:38:02 +01:00
										 |  |  |                 'crystals': 'crystals', | 
					
						
							|  |  |  |                 'bosses': 'bosses', | 
					
						
							| 
									
										
										
										
											2019-12-17 22:41:19 +01:00
										 |  |  |                 'pedestal': 'pedestal', | 
					
						
							| 
									
										
										
										
											2020-10-15 15:24:52 -07:00
										 |  |  |                 'ganon_pedestal': 'ganonpedestal', | 
					
						
							| 
									
										
										
										
											2020-06-03 02:19:16 +02:00
										 |  |  |                 'triforce_hunt': 'triforcehunt', | 
					
						
							| 
									
										
										
										
											2020-06-26 07:18:53 -07:00
										 |  |  |                 'local_triforce_hunt': 'localtriforcehunt', | 
					
						
							|  |  |  |                 'ganon_triforce_hunt': 'ganontriforcehunt', | 
					
						
							| 
									
										
										
										
											2021-01-07 12:36:39 -08:00
										 |  |  |                 'local_ganon_triforce_hunt': 'localganontriforcehunt', | 
					
						
							|  |  |  |                 'ice_rod_hunt': 'icerodhunt' | 
					
						
							| 
									
										
										
										
											2020-01-18 10:06:50 +01:00
										 |  |  |                 }[goal] | 
					
						
							| 
									
										
										
										
											2020-09-11 03:23:00 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-13 17:15:49 +02:00
										 |  |  |     # TODO consider moving open_pyramid to an automatic variable in the core roller, set to True when | 
					
						
							| 
									
										
										
										
											2020-09-13 17:13:47 +02:00
										 |  |  |     # fast ganon + ganon at hole | 
					
						
							| 
									
										
										
										
											2021-01-29 13:27:42 -08:00
										 |  |  |     ret.open_pyramid = get_choice('open_pyramid', weights, 'goal') | 
					
						
							| 
									
										
										
										
											2019-12-16 02:05:33 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-18 07:12:09 +02:00
										 |  |  |     ret.crystals_gt = prefer_int(get_choice('tower_open', weights)) | 
					
						
							| 
									
										
										
										
											2019-12-16 02:05:33 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-18 07:12:09 +02:00
										 |  |  |     ret.crystals_ganon = prefer_int(get_choice('ganon_open', weights)) | 
					
						
							| 
									
										
										
										
											2019-12-16 02:05:33 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-18 00:51:50 -04:00
										 |  |  |     extra_pieces = get_choice('triforce_pieces_mode', weights, 'available') | 
					
						
							| 
									
										
										
										
											2020-06-17 01:02:54 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-18 07:12:09 +02:00
										 |  |  |     ret.triforce_pieces_required = int(get_choice('triforce_pieces_required', weights, 20)) | 
					
						
							| 
									
										
										
										
											2020-06-18 08:48:33 -07:00
										 |  |  |     ret.triforce_pieces_required = min(max(1, int(ret.triforce_pieces_required)), 90) | 
					
						
							| 
									
										
										
										
											2020-06-07 15:22:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-23 19:43:18 +02:00
										 |  |  |     # sum a percentage to required | 
					
						
							|  |  |  |     if extra_pieces == 'percentage': | 
					
						
							| 
									
										
										
										
											2020-10-18 07:12:09 +02:00
										 |  |  |         percentage = max(100, float(get_choice('triforce_pieces_percentage', weights, 150))) / 100 | 
					
						
							|  |  |  |         ret.triforce_pieces_available = int(round(ret.triforce_pieces_required * percentage, 0)) | 
					
						
							| 
									
										
										
										
											2020-09-23 19:43:18 +02:00
										 |  |  |     # vanilla mode (specify how many pieces are) | 
					
						
							|  |  |  |     elif extra_pieces == 'available': | 
					
						
							| 
									
										
										
										
											2020-10-18 07:12:09 +02:00
										 |  |  |         ret.triforce_pieces_available = int(get_choice('triforce_pieces_available', weights, 30)) | 
					
						
							| 
									
										
										
										
											2020-09-23 19:43:18 +02:00
										 |  |  |     # required pieces + fixed extra | 
					
						
							|  |  |  |     elif extra_pieces == 'extra': | 
					
						
							| 
									
										
										
										
											2020-10-18 07:12:09 +02:00
										 |  |  |         extra_pieces = max(0, int(get_choice('triforce_pieces_extra', weights, 10))) | 
					
						
							| 
									
										
										
										
											2020-09-23 19:43:18 +02:00
										 |  |  |         ret.triforce_pieces_available = ret.triforce_pieces_required + extra_pieces | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # change minimum to required pieces to avoid problems | 
					
						
							| 
									
										
										
										
											2020-10-07 23:19:16 +02:00
										 |  |  |     ret.triforce_pieces_available = min(max(ret.triforce_pieces_required, int(ret.triforce_pieces_available)), 90) | 
					
						
							| 
									
										
										
										
											2021-03-13 05:19:53 +01:00
										 |  |  |     shuffle_slots = get_choice('shop_shuffle_slots', weights, '0') | 
					
						
							| 
									
										
										
										
											2021-03-12 23:13:30 -08:00
										 |  |  |     if str(shuffle_slots).lower() == "random": | 
					
						
							| 
									
										
										
										
											2021-03-13 05:19:53 +01:00
										 |  |  |         ret.shop_shuffle_slots = random.randint(0, 30) | 
					
						
							|  |  |  |     else: | 
					
						
							|  |  |  |         ret.shop_shuffle_slots = int(shuffle_slots) | 
					
						
							| 
									
										
										
										
											2020-11-23 20:05:04 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-25 19:45:33 +02:00
										 |  |  |     ret.shop_shuffle = get_choice('shop_shuffle', weights, '') | 
					
						
							| 
									
										
										
										
											2020-08-23 15:03:06 +02:00
										 |  |  |     if not ret.shop_shuffle: | 
					
						
							| 
									
										
										
										
											2020-08-23 21:38:21 +02:00
										 |  |  |         ret.shop_shuffle = '' | 
					
						
							| 
									
										
										
										
											2020-08-23 15:03:06 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-20 20:13:00 +02:00
										 |  |  |     ret.mode = get_choice('world_state', weights, None)  # legacy support | 
					
						
							| 
									
										
										
										
											2020-01-09 17:46:07 +01:00
										 |  |  |     if ret.mode == 'retro': | 
					
						
							| 
									
										
										
										
											2019-12-17 22:41:19 +01:00
										 |  |  |         ret.mode = 'open' | 
					
						
							|  |  |  |         ret.retro = True | 
					
						
							| 
									
										
										
										
											2020-08-20 20:13:00 +02:00
										 |  |  |     elif ret.mode is None: | 
					
						
							|  |  |  |         ret.mode = get_choice("mode", weights) | 
					
						
							|  |  |  |         ret.retro = get_choice("retro", weights) | 
					
						
							| 
									
										
										
										
											2019-12-16 02:05:33 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-18 09:14:31 +01:00
										 |  |  |     ret.hints = get_choice('hints', weights) | 
					
						
							| 
									
										
										
										
											2019-12-16 02:05:33 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-12-17 22:41:19 +01:00
										 |  |  |     ret.swords = {'randomized': 'random', | 
					
						
							|  |  |  |                   'assured': 'assured', | 
					
						
							|  |  |  |                   'vanilla': 'vanilla', | 
					
						
							|  |  |  |                   'swordless': 'swordless' | 
					
						
							| 
									
										
										
										
											2020-09-19 22:25:58 -07:00
										 |  |  |                   }[get_choice('weapons', weights, 'assured')] | 
					
						
							| 
									
										
										
										
											2019-12-16 02:05:33 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-18 09:14:31 +01:00
										 |  |  |     ret.difficulty = get_choice('item_pool', weights) | 
					
						
							| 
									
										
										
										
											2019-12-16 02:05:33 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-18 09:14:31 +01:00
										 |  |  |     ret.item_functionality = get_choice('item_functionality', weights) | 
					
						
							| 
									
										
										
										
											2019-12-16 02:05:33 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-31 13:23:32 +01:00
										 |  |  |     boss_shuffle = get_choice('boss_shuffle', weights) | 
					
						
							| 
									
										
										
										
											2021-03-07 03:38:49 -08:00
										 |  |  |     ret.shufflebosses = get_plando_bosses(boss_shuffle, plando_options) | 
					
						
							| 
									
										
										
										
											2019-12-16 02:05:33 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-03-14 08:38:02 +01:00
										 |  |  |     ret.enemy_shuffle = bool(get_choice('enemy_shuffle', weights, False)) | 
					
						
							| 
									
										
										
										
											2020-08-19 23:24:17 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     ret.killable_thieves = get_choice('killable_thieves', weights, False) | 
					
						
							|  |  |  |     ret.tile_shuffle = get_choice('tile_shuffle', weights, False) | 
					
						
							|  |  |  |     ret.bush_shuffle = get_choice('bush_shuffle', weights, False) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-19 22:25:58 -07:00
										 |  |  |     ret.enemy_damage = {None: 'default', | 
					
						
							|  |  |  |                         'default': 'default', | 
					
						
							| 
									
										
										
										
											2019-12-17 22:41:19 +01:00
										 |  |  |                         'shuffled': 'shuffled', | 
					
						
							|  |  |  |                         'random': 'chaos' | 
					
						
							| 
									
										
										
										
											2020-02-18 09:14:31 +01:00
										 |  |  |                         }[get_choice('enemy_damage', weights)] | 
					
						
							| 
									
										
										
										
											2019-12-16 02:05:33 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-18 09:14:31 +01:00
										 |  |  |     ret.enemy_health = get_choice('enemy_health', weights) | 
					
						
							| 
									
										
										
										
											2019-12-16 02:05:33 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-18 09:14:31 +01:00
										 |  |  |     ret.shufflepots = get_choice('pot_shuffle', weights) | 
					
						
							| 
									
										
										
										
											2020-01-09 09:13:50 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-18 08:55:15 -07:00
										 |  |  |     ret.beemizer = int(get_choice('beemizer', weights, 0)) | 
					
						
							| 
									
										
										
										
											2019-12-30 03:03:53 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-04 13:55:03 +01:00
										 |  |  |     ret.timer = {'none': False, | 
					
						
							|  |  |  |                  None: False, | 
					
						
							|  |  |  |                  False: False, | 
					
						
							| 
									
										
										
										
											2020-02-02 20:10:56 -05:00
										 |  |  |                  'timed': 'timed', | 
					
						
							|  |  |  |                  'timed_ohko': 'timed-ohko', | 
					
						
							|  |  |  |                  'ohko': 'ohko', | 
					
						
							|  |  |  |                  'timed_countdown': 'timed-countdown', | 
					
						
							| 
									
										
										
										
											2020-06-18 08:55:15 -07:00
										 |  |  |                  'display': 'display'}[get_choice('timer', weights, False)] | 
					
						
							| 
									
										
										
										
											2020-02-02 20:10:56 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-28 16:20:59 -07:00
										 |  |  |     ret.countdown_start_time = int(get_choice('countdown_start_time', weights, 10)) | 
					
						
							|  |  |  |     ret.red_clock_time = int(get_choice('red_clock_time', weights, -2)) | 
					
						
							|  |  |  |     ret.blue_clock_time = int(get_choice('blue_clock_time', weights, 2)) | 
					
						
							|  |  |  |     ret.green_clock_time = int(get_choice('green_clock_time', weights, 4)) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-18 08:55:15 -07:00
										 |  |  |     ret.dungeon_counters = get_choice('dungeon_counters', weights, 'default') | 
					
						
							| 
									
										
										
										
											2020-04-12 15:46:32 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-18 08:55:15 -07:00
										 |  |  |     ret.progressive = convert_to_on_off(get_choice('progressive', weights, 'on')) | 
					
						
							| 
									
										
										
										
											2020-09-20 04:35:45 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     ret.shuffle_prizes = get_choice('shuffle_prizes', weights, "g") | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-24 21:14:58 -05:00
										 |  |  |     ret.required_medallions = [get_choice("misery_mire_medallion", weights, "random"), | 
					
						
							|  |  |  |                                get_choice("turtle_rock_medallion", weights, "random")] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     for index, medallion in enumerate(ret.required_medallions): | 
					
						
							| 
									
										
										
										
											2021-03-14 08:38:02 +01:00
										 |  |  |         ret.required_medallions[index] = {"ether": "Ether", "quake": "Quake", "bombos": "Bombos", "random": "random"} \ | 
					
						
							| 
									
										
										
										
											2021-01-24 21:14:58 -05:00
										 |  |  |             .get(medallion.lower(), None) | 
					
						
							|  |  |  |         if not ret.required_medallions[index]: | 
					
						
							| 
									
										
										
										
											2021-03-07 03:31:36 -08:00
										 |  |  |             raise Exception(f"unknown Medallion {medallion} for {'misery mire' if index == 0 else 'turtle rock'}") | 
					
						
							| 
									
										
										
										
											2021-01-24 21:14:58 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-06 19:09:46 +01:00
										 |  |  |     inventoryweights = weights.get('startinventory', {}) | 
					
						
							|  |  |  |     startitems = [] | 
					
						
							|  |  |  |     for item in inventoryweights.keys(): | 
					
						
							| 
									
										
										
										
											2020-01-20 09:21:55 -08:00
										 |  |  |         itemvalue = get_choice(item, inventoryweights) | 
					
						
							| 
									
										
										
										
											2020-03-30 08:47:53 +02:00
										 |  |  |         if item.startswith(('Progressive ', 'Small Key ', 'Rupee', 'Piece of Heart', 'Boss Heart Container', | 
					
						
							|  |  |  |                             'Sanctuary Heart Container', 'Arrow', 'Bombs ', 'Bomb ', 'Bottle')) and isinstance( | 
					
						
							| 
									
										
										
										
											2020-04-10 20:58:52 +02:00
										 |  |  |             itemvalue, int): | 
					
						
							| 
									
										
										
										
											2020-01-22 08:29:43 -08:00
										 |  |  |             for i in range(int(itemvalue)): | 
					
						
							| 
									
										
										
										
											2020-01-20 09:21:55 -08:00
										 |  |  |                 startitems.append(item) | 
					
						
							| 
									
										
										
										
											2020-01-22 08:29:43 -08:00
										 |  |  |         elif itemvalue: | 
					
						
							| 
									
										
										
										
											2020-01-06 19:09:46 +01:00
										 |  |  |             startitems.append(item) | 
					
						
							|  |  |  |     ret.startinventory = ','.join(startitems) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-18 08:55:15 -07:00
										 |  |  |     ret.glitch_boots = get_choice('glitch_boots', weights, True) | 
					
						
							| 
									
										
										
										
											2020-06-03 22:13:58 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-18 08:55:15 -07:00
										 |  |  |     ret.remote_items = get_choice('remote_items', weights, False) | 
					
						
							| 
									
										
										
										
											2020-03-30 08:47:53 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-19 16:10:22 -07:00
										 |  |  |     if get_choice("local_keys", weights, "l" in dungeon_items): | 
					
						
							| 
									
										
										
										
											2020-09-06 17:19:34 +02:00
										 |  |  |         # () important for ordering of commands, without them the Big Keys section is part of the Small Key else | 
					
						
							| 
									
										
										
										
											2021-03-14 08:38:02 +01:00
										 |  |  |         ret.local_items |= item_name_groups["Small Keys"] if ret.keyshuffle else set() | 
					
						
							|  |  |  |         ret.local_items |= item_name_groups["Big Keys"] if ret.bigkeyshuffle else set() | 
					
						
							| 
									
										
										
										
											2020-11-22 22:53:31 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-02 12:49:43 +01:00
										 |  |  |     ret.plando_items = [] | 
					
						
							|  |  |  |     if "items" in plando_options: | 
					
						
							| 
									
										
										
										
											2021-01-17 17:58:58 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-06 09:55:16 -08:00
										 |  |  |         def add_plando_item(item: str, location: str): | 
					
						
							|  |  |  |             if item not in item_table: | 
					
						
							|  |  |  |                 raise Exception(f"Could not plando item {item} as the item was not recognized") | 
					
						
							| 
									
										
										
										
											2021-01-08 06:37:23 -08:00
										 |  |  |             if location not in location_table and location not in key_drop_data: | 
					
						
							| 
									
										
										
										
											2021-03-14 08:38:02 +01:00
										 |  |  |                 raise Exception( | 
					
						
							|  |  |  |                     f"Could not plando item {item} at location {location} as the location was not recognized") | 
					
						
							| 
									
										
										
										
											2021-01-06 09:55:16 -08:00
										 |  |  |             ret.plando_items.append(PlandoItem(item, location, location_world, from_pool, force)) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-02 12:49:43 +01:00
										 |  |  |         options = weights.get("plando_items", []) | 
					
						
							|  |  |  |         for placement in options: | 
					
						
							|  |  |  |             if roll_percentage(get_choice("percentage", placement, 100)): | 
					
						
							| 
									
										
										
										
											2021-01-19 01:02:03 +01:00
										 |  |  |                 from_pool = get_choice("from_pool", placement, PlandoItem._field_defaults["from_pool"]) | 
					
						
							|  |  |  |                 location_world = get_choice("world", placement, PlandoItem._field_defaults["world"]) | 
					
						
							|  |  |  |                 force = str(get_choice("force", placement, PlandoItem._field_defaults["force"])).lower() | 
					
						
							| 
									
										
										
										
											2021-01-06 09:55:16 -08:00
										 |  |  |                 if "items" in placement and "locations" in placement: | 
					
						
							|  |  |  |                     items = placement["items"] | 
					
						
							|  |  |  |                     locations = placement["locations"] | 
					
						
							|  |  |  |                     if isinstance(items, dict): | 
					
						
							|  |  |  |                         item_list = [] | 
					
						
							|  |  |  |                         for key, value in items.items(): | 
					
						
							|  |  |  |                             item_list += [key] * value | 
					
						
							|  |  |  |                         items = item_list | 
					
						
							|  |  |  |                     if not items or not locations: | 
					
						
							|  |  |  |                         raise Exception("You must specify at least one item and one location to place items.") | 
					
						
							|  |  |  |                     random.shuffle(items) | 
					
						
							|  |  |  |                     random.shuffle(locations) | 
					
						
							| 
									
										
										
										
											2021-01-17 02:15:46 +01:00
										 |  |  |                     for item, location in zip(items, locations): | 
					
						
							| 
									
										
										
										
											2021-01-06 09:55:16 -08:00
										 |  |  |                         add_plando_item(item, location) | 
					
						
							|  |  |  |                 else: | 
					
						
							|  |  |  |                     item = get_choice("item", placement, get_choice("items", placement)) | 
					
						
							|  |  |  |                     location = get_choice("location", placement) | 
					
						
							|  |  |  |                     add_plando_item(item, location) | 
					
						
							| 
									
										
										
										
											2021-01-02 12:49:43 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-02 16:44:58 +01:00
										 |  |  |     ret.plando_texts = {} | 
					
						
							|  |  |  |     if "texts" in plando_options: | 
					
						
							| 
									
										
										
										
											2021-01-03 07:14:31 -08:00
										 |  |  |         tt = TextTable() | 
					
						
							|  |  |  |         tt.removeUnwantedText() | 
					
						
							| 
									
										
										
										
											2021-01-02 16:44:58 +01:00
										 |  |  |         options = weights.get("plando_texts", []) | 
					
						
							|  |  |  |         for placement in options: | 
					
						
							|  |  |  |             if roll_percentage(get_choice("percentage", placement, 100)): | 
					
						
							| 
									
										
										
										
											2021-01-03 07:14:31 -08:00
										 |  |  |                 at = str(get_choice("at", placement)) | 
					
						
							|  |  |  |                 if at not in tt: | 
					
						
							|  |  |  |                     raise Exception(f"No text target \"{at}\" found.") | 
					
						
							|  |  |  |                 ret.plando_texts[at] = str(get_choice("text", placement)) | 
					
						
							| 
									
										
										
										
											2021-01-02 16:44:58 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-02 22:41:03 +01:00
										 |  |  |     ret.plando_connections = [] | 
					
						
							|  |  |  |     if "connections" in plando_options: | 
					
						
							|  |  |  |         options = weights.get("plando_connections", []) | 
					
						
							|  |  |  |         for placement in options: | 
					
						
							|  |  |  |             if roll_percentage(get_choice("percentage", placement, 100)): | 
					
						
							|  |  |  |                 ret.plando_connections.append(PlandoConnection( | 
					
						
							|  |  |  |                     get_choice("entrance", placement), | 
					
						
							|  |  |  |                     get_choice("exit", placement), | 
					
						
							|  |  |  |                     get_choice("direction", placement, "both") | 
					
						
							|  |  |  |                 )) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-09 17:46:07 +01:00
										 |  |  |     if 'rom' in weights: | 
					
						
							|  |  |  |         romweights = weights['rom'] | 
					
						
							| 
									
										
										
										
											2020-10-14 12:46:05 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-06 13:22:03 -07:00
										 |  |  |         ret.sprite_pool = romweights['sprite_pool'] if 'sprite_pool' in romweights else [] | 
					
						
							| 
									
										
										
										
											2020-09-05 05:20:34 +02:00
										 |  |  |         ret.sprite = get_choice('sprite', romweights, "Link") | 
					
						
							| 
									
										
										
										
											2020-10-14 12:46:05 -07:00
										 |  |  |         if 'random_sprite_on_event' in romweights: | 
					
						
							|  |  |  |             randomoneventweights = romweights['random_sprite_on_event'] | 
					
						
							|  |  |  |             if get_choice('enabled', randomoneventweights, False): | 
					
						
							|  |  |  |                 ret.sprite = 'randomon' | 
					
						
							|  |  |  |                 ret.sprite += '-hit' if get_choice('on_hit', randomoneventweights, True) else '' | 
					
						
							|  |  |  |                 ret.sprite += '-enter' if get_choice('on_enter', randomoneventweights, False) else '' | 
					
						
							|  |  |  |                 ret.sprite += '-exit' if get_choice('on_exit', randomoneventweights, False) else '' | 
					
						
							|  |  |  |                 ret.sprite += '-slash' if get_choice('on_slash', randomoneventweights, False) else '' | 
					
						
							|  |  |  |                 ret.sprite += '-item' if get_choice('on_item', randomoneventweights, False) else '' | 
					
						
							|  |  |  |                 ret.sprite += '-bonk' if get_choice('on_bonk', randomoneventweights, False) else '' | 
					
						
							|  |  |  |                 ret.sprite = 'randomonall' if get_choice('on_everything', randomoneventweights, False) else ret.sprite | 
					
						
							|  |  |  |                 ret.sprite = 'randomonnone' if ret.sprite == 'randomon' else ret.sprite | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 if (not ret.sprite_pool or get_choice('use_weighted_sprite_pool', randomoneventweights, False)) \ | 
					
						
							|  |  |  |                         and 'sprite' in romweights:  # Use sprite as a weighted sprite pool, if a sprite pool is not already defined. | 
					
						
							| 
									
										
										
										
											2020-10-14 20:33:12 -07:00
										 |  |  |                     for key, value in romweights['sprite'].items(): | 
					
						
							| 
									
										
										
										
											2020-10-14 12:46:05 -07:00
										 |  |  |                         if key.startswith('random'): | 
					
						
							|  |  |  |                             ret.sprite_pool += ['random'] * int(value) | 
					
						
							|  |  |  |                         else: | 
					
						
							|  |  |  |                             ret.sprite_pool += [key] * int(value) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-05 05:20:34 +02:00
										 |  |  |         ret.disablemusic = get_choice('disablemusic', romweights, False) | 
					
						
							| 
									
										
										
										
											2021-02-05 20:37:27 -06:00
										 |  |  |         ret.triforcehud = get_choice('triforcehud', romweights, 'hide_goal') | 
					
						
							| 
									
										
										
										
											2020-09-05 05:20:34 +02:00
										 |  |  |         ret.quickswap = get_choice('quickswap', romweights, True) | 
					
						
							|  |  |  |         ret.fastmenu = get_choice('menuspeed', romweights, "normal") | 
					
						
							| 
									
										
										
										
											2021-02-19 10:45:54 -06:00
										 |  |  |         ret.reduceflashing = get_choice('reduceflashing', romweights, False) | 
					
						
							| 
									
										
										
										
											2020-09-05 05:20:34 +02:00
										 |  |  |         ret.heartcolor = get_choice('heartcolor', romweights, "red") | 
					
						
							|  |  |  |         ret.heartbeep = convert_to_on_off(get_choice('heartbeep', romweights, "normal")) | 
					
						
							|  |  |  |         ret.ow_palettes = get_choice('ow_palettes', romweights, "default") | 
					
						
							|  |  |  |         ret.uw_palettes = get_choice('uw_palettes', romweights, "default") | 
					
						
							| 
									
										
										
										
											2020-10-24 02:44:27 +02:00
										 |  |  |         ret.hud_palettes = get_choice('hud_palettes', romweights, "default") | 
					
						
							|  |  |  |         ret.sword_palettes = get_choice('sword_palettes', romweights, "default") | 
					
						
							|  |  |  |         ret.shield_palettes = get_choice('shield_palettes', romweights, "default") | 
					
						
							|  |  |  |         ret.link_palettes = get_choice('link_palettes', romweights, "default") | 
					
						
							| 
									
										
										
										
											2021-01-02 12:49:43 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-05 05:20:34 +02:00
										 |  |  |     else: | 
					
						
							|  |  |  |         ret.quickswap = True | 
					
						
							| 
									
										
										
										
											2020-09-19 22:25:58 -07:00
										 |  |  |         ret.sprite = "Link" | 
					
						
							| 
									
										
										
										
											2020-09-13 17:15:49 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-12-16 02:05:33 +01:00
										 |  |  | if __name__ == '__main__': | 
					
						
							|  |  |  |     main() |