Пример #1
0
def homepage():
    """
    Render the homepage template on the / route
    """
    a = Logic()
    print(a.run())
    return render_template('home/index.html', title="Welcome")
Пример #2
0
  def __init__(self, options: Options, progress_callback=dummy_progress_callback):
    self.options = options
    self.progress_callback = progress_callback
    self.dry_run = bool(self.options['dry-run'])
    # TODO: maybe make paths configurable?
    # exe root path is where the executable is
    self.exe_root_path = Path('.').resolve()
    # this is where all assets/read only files are
    self.rando_root_path = RANDO_ROOT_PATH
    if not self.dry_run:
      self.actual_extract_path = self.exe_root_path / 'actual-extract'
      self.modified_extract_path = self.exe_root_path / 'modified-extract'
      self.oarc_cache_path = self.exe_root_path / 'oarc'
    self.no_logs = False
    self.seed = self.options['seed']
    if self.seed == -1:
        self.seed = random.randint(0,1000000)
    self.rng = random.Random()
    self.rng.seed(self.seed)
    self.entrance_connections = OrderedDict([
      ("Dungeon Entrance In Deep Woods", "Skyview"),
      ("Dungeon Entrance In Eldin Volcano", "Earth Temple"),
      ("Dungeon Entrance In Lanayru Desert", "Lanayru Mining Facility"),
      ("Dungeon Entrance In Lake Floria", "Ancient Cistern"),
      ("Dungeon Entrance In Sand Sea", "Sandship"),
      ("Dungeon Entrance In Volcano Summit", "Fire Sanctuary"),
      ("Dungeon Entrance On Skyloft", "Skykeep"),
    ])
    # self.starting_items = (x.strip() for x in self.options['starting_items']
    # self.starting_items: List[str] = list(filter(lambda x: x != '', self.starting_items))
    self.starting_items = []

    self.required_dungeons = self.rng.sample(constants.POTENTIALLY_REQUIRED_DUNGEONS, k=self.options['required-dungeon-count'])
    # make the order always consistent
    self.required_dungeons = [dungeon for dungeon in constants.POTENTIALLY_REQUIRED_DUNGEONS
      if dungeon in self.required_dungeons]

    if not self.options['randomize-tablets']:
      self.starting_items.append('Emerald Tablet')
      self.starting_items.append('Ruby Tablet')
      self.starting_items.append('Amber Tablet')
    if not self.options['swordless']:
      self.starting_items.append('Progressive Sword')
      self.starting_items.append('Progressive Sword')
    # if not self.options.get('randomize-sailcloth',False):
    #   self.starting_items.append('Sailcloth')
    self.banned_types = self.options['banned-types']
    self.race_mode_banned_locations = []
    self.non_required_dungeons = [dungeon for dungeon in
      constants.POTENTIALLY_REQUIRED_DUNGEONS if not dungeon in self.required_dungeons]
    self.logic = Logic(self)
def create_logic(db, user_id):
    logging.debug(
        "creating logic for user id {user_id}".format(user_id=user_id))
    user = db.get_user_by_user_id(user_id=user_id)
    logging.debug("user is {user}".format(user=user))

    doist = TodoistAPIWrapper(token=user.token)
    duration_setter = DurationSetter(doist)

    logging.debug("user mode is {user_mode}".format(user_mode=user.mode))
    logic = Logic(ds=duration_setter,
                  doist=doist,
                  mode=modes[user.mode](doist=doist))
    return logic
Пример #4
0
    def __init__(self, logic=Logic()):
        # initiate screen
        self.root = Tk()
        self.root.title('SPACEGame')
        self.root.geometry(constants.SCREEN)
        self.root.configure(background='black')
        # create frames
        self.f_menu = Frame(master=self.root,
                            width=100,
                            height=400,
                            bg='black')
        self.f_resources = Frame(master=self.root,
                                 width=300,
                                 height=100,
                                 bg='black')
        self.f_screen = Frame(master=self.root,
                              width=300,
                              height=300,
                              bg='black')
        self.f_menu.pack(side=LEFT)
        self.f_resources.pack()
        self.f_screen.pack()

        # initiate game
        self.logic = logic
        # create_player
        self.logic.world.create_player('gon')
        self.player = self.logic.world.players[0]
        self.village = self.player.villages[0]

        # Available Resources
        self.resources = Resources(self.f_resources, self.village, 0, 1)

        # create MENU
        self.menu = Menu(root=self.root,
                         menu=self.f_menu,
                         screen=self.f_screen,
                         world=self.logic.world,
                         village=self.village,
                         resources=self.resources,
                         row_i=0,
                         column_i=0)

        self.root.mainloop()
Пример #5
0
    def __init__(self,
                 seed,
                 clean_iso_path,
                 randomized_output_folder,
                 options,
                 permalink=None,
                 cmd_line_args=OrderedDict()):
        self.randomized_output_folder = randomized_output_folder
        self.options = options
        self.seed = seed
        self.permalink = permalink

        self.dry_run = ("-dry" in cmd_line_args)
        self.disassemble = ("-disassemble" in cmd_line_args)
        self.export_disc_to_folder = ("-exportfolder" in cmd_line_args)
        self.no_logs = ("-nologs" in cmd_line_args)
        self.bulk_test = ("-bulk" in cmd_line_args)
        if self.bulk_test:
            self.dry_run = True
            self.no_logs = True
        self.print_used_flags = ("-printflags" in cmd_line_args)

        self.test_room_args = None
        if "-test" in cmd_line_args:
            args = cmd_line_args["-test"]
            if args is not None:
                stage, room, spawn = args.split(",")
                self.test_room_args = {
                    "stage": stage,
                    "room": int(room),
                    "spawn": int(spawn)
                }

        seed_string = self.seed
        if not self.options.get("generate_spoiler_log"):
            seed_string += SEED_KEY

        self.integer_seed = self.convert_string_to_integer_md5(seed_string)
        self.rng = self.get_new_rng()

        self.arcs_by_path = {}
        self.jpcs_by_path = {}
        self.raw_files_by_path = {}

        self.read_text_file_lists()

        if not self.dry_run:
            if not os.path.isfile(clean_iso_path):
                raise InvalidCleanISOError("Clean WW ISO does not exist: %s" %
                                           clean_iso_path)

            self.verify_supported_version(clean_iso_path)

            self.gcm = GCM(clean_iso_path)
            self.gcm.read_entire_disc()

            try:
                self.chart_list = self.get_arc(
                    "files/res/Msg/fmapres.arc").get_file("cmapdat.bin")
            except InvalidOffsetError:
                # An invalid offset error when reading fmapres.arc seems to happen when the user has a corrupted clean ISO.
                # The reason for this is unknown, but when this happens check the ISO's MD5 and if it's wrong say so in an error message.
                self.verify_correct_clean_iso_md5(clean_iso_path)

                # But if the ISO's MD5 is correct just raise the normal offset error.
                raise

            self.bmg = self.get_arc("files/res/Msg/bmgres.arc").get_file(
                "zel_00.bmg")

            if self.disassemble:
                self.disassemble_all_code()
            if self.print_used_flags:
                stage_searcher.print_all_used_item_pickup_flags(self)
                stage_searcher.print_all_used_chest_open_flags(self)
                stage_searcher.print_all_event_flags_used_by_stb_cutscenes(
                    self)

        # Starting items. This list is read by the Logic when initializing your currently owned items list.
        self.starting_items = [
            "Wind Waker",
            "Wind's Requiem",
            "Ballad of Gales",
            "Song of Passing",
            "Hero's Shield",
            "Boat's Sail",
        ]
        self.starting_items += self.options.get("starting_gear", [])

        if self.options.get("sword_mode") == "Start with Sword":
            self.starting_items.append("Progressive Sword")
        # Add starting Triforce Shards.
        num_starting_triforce_shards = int(
            self.options.get("num_starting_triforce_shards", 0))
        for i in range(num_starting_triforce_shards):
            self.starting_items.append("Triforce Shard %d" % (i + 1))

        # Default entrances connections to be used if the entrance randomizer is not on.
        self.entrance_connections = OrderedDict([
            ("Dungeon Entrance On Dragon Roost Island", "Dragon Roost Cavern"),
            ("Dungeon Entrance In Forest Haven Sector", "Forbidden Woods"),
            ("Dungeon Entrance In Tower of the Gods Sector",
             "Tower of the Gods"),
            ("Dungeon Entrance On Headstone Island", "Earth Temple"),
            ("Dungeon Entrance On Gale Isle", "Wind Temple"),
            ("Secret Cave Entrance on Outset Island", "Savage Labyrinth"),
            ("Secret Cave Entrance on Dragon Roost Island",
             "Dragon Roost Island Secret Cave"),
            ("Secret Cave Entrance on Fire Mountain",
             "Fire Mountain Secret Cave"),
            ("Secret Cave Entrance on Ice Ring Isle",
             "Ice Ring Isle Secret Cave"),
            ("Secret Cave Entrance on Private Oasis", "Cabana Labyrinth"),
            ("Secret Cave Entrance on Needle Rock Isle",
             "Needle Rock Isle Secret Cave"),
            ("Secret Cave Entrance on Angular Isles",
             "Angular Isles Secret Cave"),
            ("Secret Cave Entrance on Boating Course",
             "Boating Course Secret Cave"),
            ("Secret Cave Entrance on Stone Watcher Island",
             "Stone Watcher Island Secret Cave"),
            ("Secret Cave Entrance on Overlook Island",
             "Overlook Island Secret Cave"),
            ("Secret Cave Entrance on Bird's Peak Rock",
             "Bird's Peak Rock Secret Cave"),
            ("Secret Cave Entrance on Pawprint Isle",
             "Pawprint Isle Chuchu Cave"),
            ("Secret Cave Entrance on Pawprint Isle Side Isle",
             "Pawprint Isle Wizzrobe Cave"),
            ("Secret Cave Entrance on Diamond Steppe Island",
             "Diamond Steppe Island Warp Maze Cave"),
            ("Secret Cave Entrance on Bomb Island", "Bomb Island Secret Cave"),
            ("Secret Cave Entrance on Rock Spire Isle",
             "Rock Spire Isle Secret Cave"),
            ("Secret Cave Entrance on Shark Island",
             "Shark Island Secret Cave"),
            ("Secret Cave Entrance on Cliff Plateau Isles",
             "Cliff Plateau Isles Secret Cave"),
            ("Secret Cave Entrance on Horseshoe Island",
             "Horseshoe Island Secret Cave"),
            ("Secret Cave Entrance on Star Island", "Star Island Secret Cave"),
        ])
        self.dungeon_and_cave_island_locations = OrderedDict([
            ("Dragon Roost Cavern", "Dragon Roost Island"),
            ("Forbidden Woods", "Forest Haven"),
            ("Tower of the Gods", "Tower of the Gods"),
            ("Earth Temple", "Headstone Island"),
            ("Wind Temple", "Gale Isle"),
            ("Secret Cave Entrance on Outset Island", "Outset Island"),
            ("Secret Cave Entrance on Dragon Roost Island",
             "Dragon Roost Island"),
            ("Secret Cave Entrance on Fire Mountain", "Fire Mountain"),
            ("Secret Cave Entrance on Ice Ring Isle", "Ice Ring Isle"),
            ("Secret Cave Entrance on Private Oasis", "Private Oasis"),
            ("Secret Cave Entrance on Needle Rock Isle", "Needle Rock Isle"),
            ("Secret Cave Entrance on Angular Isles", "Angular Isles"),
            ("Secret Cave Entrance on Boating Course", "Boating Course"),
            ("Secret Cave Entrance on Stone Watcher Island",
             "Stone Watcher Island"),
            ("Secret Cave Entrance on Overlook Island", "Overlook Island"),
            ("Secret Cave Entrance on Bird's Peak Rock", "Bird's Peak Rock"),
            ("Secret Cave Entrance on Pawprint Isle", "Pawprint Isle"),
            ("Secret Cave Entrance on Pawprint Isle Side Isle",
             "Pawprint Isle"),
            ("Secret Cave Entrance on Diamond Steppe Island",
             "Diamond Steppe Island"),
            ("Secret Cave Entrance on Bomb Island", "Bomb Island"),
            ("Secret Cave Entrance on Rock Spire Isle", "Rock Spire Isle"),
            ("Secret Cave Entrance on Shark Island", "Shark Island"),
            ("Secret Cave Entrance on Cliff Plateau Isles",
             "Cliff Plateau Isles"),
            ("Secret Cave Entrance on Horseshoe Island", "Horseshoe Island"),
            ("Secret Cave Entrance on Star Island", "Star Island"),
        ])

        # Default starting island (Outset) if the starting island randomizer is not on.
        self.starting_island_index = 44

        # Default charts for each island.
        self.island_number_to_chart_name = OrderedDict([
            (1, "Treasure Chart 25"),
            (2, "Treasure Chart 7"),
            (3, "Treasure Chart 24"),
            (4, "Triforce Chart 2"),
            (5, "Treasure Chart 11"),
            (6, "Triforce Chart 7"),
            (7, "Treasure Chart 13"),
            (8, "Treasure Chart 41"),
            (9, "Treasure Chart 29"),
            (10, "Treasure Chart 22"),
            (11, "Treasure Chart 18"),
            (12, "Treasure Chart 30"),
            (13, "Treasure Chart 39"),
            (14, "Treasure Chart 19"),
            (15, "Treasure Chart 8"),
            (16, "Treasure Chart 2"),
            (17, "Treasure Chart 10"),
            (18, "Treasure Chart 26"),
            (19, "Treasure Chart 3"),
            (20, "Treasure Chart 37"),
            (21, "Treasure Chart 27"),
            (22, "Treasure Chart 38"),
            (23, "Triforce Chart 1"),
            (24, "Treasure Chart 21"),
            (25, "Treasure Chart 6"),
            (26, "Treasure Chart 14"),
            (27, "Treasure Chart 34"),
            (28, "Treasure Chart 5"),
            (29, "Treasure Chart 28"),
            (30, "Treasure Chart 35"),
            (31, "Triforce Chart 3"),
            (32, "Triforce Chart 6"),
            (33, "Treasure Chart 1"),
            (34, "Treasure Chart 20"),
            (35, "Treasure Chart 36"),
            (36, "Treasure Chart 23"),
            (37, "Treasure Chart 12"),
            (38, "Treasure Chart 16"),
            (39, "Treasure Chart 4"),
            (40, "Treasure Chart 17"),
            (41, "Treasure Chart 31"),
            (42, "Triforce Chart 5"),
            (43, "Treasure Chart 9"),
            (44, "Triforce Chart 4"),
            (45, "Treasure Chart 40"),
            (46, "Triforce Chart 8"),
            (47, "Treasure Chart 15"),
            (48, "Treasure Chart 32"),
            (49, "Treasure Chart 33"),
        ])

        # This list will hold the randomly selected dungeon boss locations that are required in race mode.
        # If race mode is not on, this list will remain empty.
        self.race_mode_required_locations = []
        # This list will hold the dungeon names of the race mode required locations.
        # If race mode is not on, this list will remain empty.
        self.race_mode_required_dungeons = []
        # This list will hold all item location names that should not have any items in them in race mode.
        # If race mode is not on, this list will remain empty.
        self.race_mode_banned_locations = []

        self.custom_model_name = "Link"

        self.logic = Logic(self)

        num_progress_locations = self.logic.get_num_progression_locations()
        num_progress_items = self.logic.get_num_progression_items()
        if num_progress_locations < num_progress_items:
            error_message = "Not enough progress locations to place all progress items.\n\n"
            error_message += "Total progress items: %d\n" % num_progress_items
            error_message += "Progress locations with current options: %d\n\n" % num_progress_locations
            error_message += "You need to check more of the progress location options in order to give the randomizer enough space to place all the items."
            raise TooFewProgressionLocationsError(error_message)

        # We need to determine if the user's selected options result in a dungeons-only-start.
        # Dungeons-only-start meaning that the only locations accessible at the start of the run are dungeon locations.
        # e.g. If the user selects Dungeons, Expensive Purchases, and Sunken Treasures, the dungeon locations are the only ones the player can check first.
        # We need to distinguish this situation because it can cause issues for the randomizer's item placement logic (specifically when placing keys in DRC).
        self.logic.temporarily_make_dungeon_entrance_macros_impossible()
        accessible_undone_locations = self.logic.get_accessible_remaining_locations(
            for_progression=True)
        if len(accessible_undone_locations) == 0:
            self.dungeons_only_start = True
        else:
            self.dungeons_only_start = False
        self.logic.update_entrance_connection_macros(
        )  # Reset the dungeon entrance macros.

        # Also determine if these options result in a dungeons-and-caves-only-start.
        # Dungeons-and-caves-only-start means the only locations accessible at the start of the run are dungeon or secret cave locations.
        # This situation can also cause issues for the item placement logic (specifically when placing the first item of the run).
        self.logic.temporarily_make_entrance_macros_impossible()
        accessible_undone_locations = self.logic.get_accessible_remaining_locations(
            for_progression=True)
        if len(accessible_undone_locations) == 0:
            self.dungeons_and_caves_only_start = True
        else:
            self.dungeons_and_caves_only_start = False
        self.logic.update_entrance_connection_macros(
        )  # Reset the entrance macros.
Пример #6
0
    def calculate_playthrough_progression_spheres(self):
        progression_spheres = []

        logic = Logic(self)
        previously_accessible_locations = []
        game_beatable = False
        while logic.unplaced_progress_items:
            progress_items_in_this_sphere = OrderedDict()

            accessible_locations = logic.get_accessible_remaining_locations()
            locations_in_this_sphere = [
                loc for loc in accessible_locations
                if loc not in previously_accessible_locations
            ]
            if not locations_in_this_sphere:
                raise Exception("Failed to calculate progression spheres")

            if not self.options.get("keylunacy"):
                # If the player gained access to any small keys, we need to give them the keys without counting that as a new sphere.
                newly_accessible_predetermined_item_locations = [
                    loc for loc in locations_in_this_sphere
                    if loc in self.logic.prerandomization_item_locations
                ]
                newly_accessible_small_key_locations = [
                    loc
                    for loc in newly_accessible_predetermined_item_locations
                    if self.logic.prerandomization_item_locations[loc].
                    endswith(" Small Key")
                ]
                if newly_accessible_small_key_locations:
                    for small_key_location_name in newly_accessible_small_key_locations:
                        item_name = self.logic.prerandomization_item_locations[
                            small_key_location_name]
                        assert item_name.endswith(" Small Key")

                        logic.add_owned_item(item_name)

                    previously_accessible_locations += newly_accessible_small_key_locations
                    continue  # Redo this loop iteration with the small key locations no longer being considered 'remaining'.

            for location_name in locations_in_this_sphere:
                item_name = self.logic.done_item_locations[location_name]
                if item_name in logic.all_progress_items:
                    progress_items_in_this_sphere[location_name] = item_name

            if not game_beatable:
                game_beatable = logic.check_requirement_met(
                    "Can Reach and Defeat Ganondorf")
                if game_beatable:
                    progress_items_in_this_sphere[
                        "Ganon's Tower - Rooftop"] = "Defeat Ganondorf"

            progression_spheres.append(progress_items_in_this_sphere)

            for location_name, item_name in progress_items_in_this_sphere.items(
            ):
                if item_name == "Defeat Ganondorf":
                    continue
                logic.add_owned_item(item_name)
            for group_name, item_names in logic.progress_item_groups.items():
                entire_group_is_owned = all(
                    item_name in logic.currently_owned_items
                    for item_name in item_names)
                if entire_group_is_owned and group_name in logic.unplaced_progress_items:
                    logic.unplaced_progress_items.remove(group_name)

            previously_accessible_locations = accessible_locations

        if not game_beatable:
            # If the game wasn't already beatable on a previous progression sphere but it is now we add one final one just for this.
            game_beatable = logic.check_requirement_met(
                "Can Reach and Defeat Ganondorf")
            if game_beatable:
                final_progression_sphere = OrderedDict([
                    ("Ganon's Tower - Rooftop", "Defeat Ganondorf"),
                ])
                progression_spheres.append(final_progression_sphere)

        return progression_spheres
Пример #7
0
    def __init__(self,
                 options: Options,
                 progress_callback=dummy_progress_callback):
        self.options = options
        self.progress_callback = progress_callback
        self.dry_run = bool(self.options['dry-run'])
        # TODO: maybe make paths configurable?
        # exe root path is where the executable is
        self.exe_root_path = Path('.').resolve()
        # this is where all assets/read only files are
        self.rando_root_path = RANDO_ROOT_PATH
        if not self.dry_run:
            self.actual_extract_path = self.exe_root_path / 'actual-extract'
            self.modified_extract_path = self.exe_root_path / 'modified-extract'
            self.oarc_cache_path = self.exe_root_path / 'oarc'
        self.no_logs = self.options['no-spoiler-log']
        self.seed = self.options['seed']
        if self.seed == -1:
            self.seed = random.randint(0, 1000000)

        self.randomizer_hash = self._get_rando_hash()
        self.rng = random.Random()
        self.rng.seed(self.seed)
        if self.no_logs:
            self.rng.randint(0, 100)
        dungeons = [
            "Skyview", "Earth Temple", "Lanayru Mining Facility",
            "Ancient Cistern", "Sandship", "Fire Sanctuary"
        ]
        if self.options['randomize-entrances'] == 'None':
            dungeons.append('Skykeep')
            dungeons.reverse()
        else:
            if self.options['randomize-entrances'] == 'Dungeons':
                self.rng.shuffle(dungeons)
                dungeons.append('Skykeep')
                dungeons.reverse()
            else:
                dungeons.append('Skykeep')
                self.rng.shuffle(dungeons)
        self.entrance_connections = OrderedDict([
            ("Dungeon Entrance In Deep Woods", dungeons.pop()),
            ("Dungeon Entrance In Eldin Volcano", dungeons.pop()),
            ("Dungeon Entrance In Lanayru Desert", dungeons.pop()),
            ("Dungeon Entrance In Lake Floria", dungeons.pop()),
            ("Dungeon Entrance In Sand Sea", dungeons.pop()),
            ("Dungeon Entrance In Volcano Summit", dungeons.pop()),
            ("Dungeon Entrance On Skyloft", dungeons.pop()),
        ])
        assert len(dungeons) == 0, 'Not all dungeons linked to an entrance'
        # self.starting_items = (x.strip() for x in self.options['starting_items']
        # self.starting_items: List[str] = list(filter(lambda x: x != '', self.starting_items))
        self.starting_items = []

        self.required_dungeons = self.rng.sample(
            constants.POTENTIALLY_REQUIRED_DUNGEONS,
            k=self.options['required-dungeon-count'])
        # make the order always consistent
        self.required_dungeons = [
            dungeon for dungeon in constants.POTENTIALLY_REQUIRED_DUNGEONS
            if dungeon in self.required_dungeons
        ]

        tablets = ['Emerald Tablet', 'Ruby Tablet', 'Amber Tablet']
        self.starting_items.extend(
            self.rng.sample(tablets, k=self.options['starting-tablet-count']))

        if not self.options['swordless']:
            self.starting_items.append('Progressive Sword')
            self.starting_items.append('Progressive Sword')
        # if not self.options.get('randomize-sailcloth',False):
        #   self.starting_items.append('Sailcloth')
        if self.options['start-with-pouch']:
            self.starting_items.append('Progressive Pouch')
        self.banned_types = self.options['banned-types']
        self.race_mode_banned_locations = []
        self.non_required_dungeons = [
            dungeon for dungeon in constants.POTENTIALLY_REQUIRED_DUNGEONS
            if not dungeon in self.required_dungeons
        ]
        rupoor_mode = self.options['rupoor-mode']
        if rupoor_mode != 'Off':
            if rupoor_mode == 'Added':
                logic.item_types.CONSUMABLE_ITEMS += ['Rupoor'] * 15
            else:
                self.rng.shuffle(logic.item_types.CONSUMABLE_ITEMS)
                replace_end_index = len(logic.item_types.CONSUMABLE_ITEMS)
                if rupoor_mode == 'Rupoor Mayhem':
                    replace_end_index /= 2
                for i in range(int(replace_end_index)):
                    logic.item_types.CONSUMABLE_ITEMS[i] = 'Rupoor'

        self.logic = Logic(self)
Пример #8
0
 def __init__(self, seed, clean_iso_path, randomized_output_folder, options, permalink=None, cmd_line_args=[]):
   self.randomized_output_folder = randomized_output_folder
   self.options = options
   self.seed = seed
   self.permalink = permalink
   
   self.dry_run = ("-dry" in cmd_line_args)
   self.disassemble = ("-disassemble" in cmd_line_args)
   self.export_disc_to_folder = ("-exportfolder" in cmd_line_args)
   self.no_logs = ("-nologs" in cmd_line_args)
   self.bulk_test = ("-bulk" in cmd_line_args)
   if self.bulk_test:
     self.dry_run = True
     self.no_logs = True
   
   self.integer_seed = self.convert_string_to_integer_md5(self.seed)
   self.rng = self.get_new_rng()
   
   self.arcs_by_path = {}
   self.jpcs_by_path = {}
   self.raw_files_by_path = {}
   
   if not self.dry_run:
     self.verify_supported_version(clean_iso_path)
     
     self.gcm = GCM(clean_iso_path)
     self.gcm.read_entire_disc()
     
     self.chart_list = self.get_arc("files/res/Msg/fmapres.arc").get_file("cmapdat.bin")
     self.bmg = self.get_arc("files/res/Msg/bmgres.arc").get_file("zel_00.bmg")
     
     if self.disassemble:
       self.disassemble_all_code()
   
   self.read_text_file_lists()
   
   # Starting items. This list is read by the Logic when initializing your currently owned items list.
   self.starting_items = [
     "Wind Waker",
     "Wind's Requiem",
     "Ballad of Gales",
     "Song of Passing",
     "Hero's Shield",
     "Boat's Sail",
   ]
   if self.options.get("sword_mode") == "Start with Sword":
     self.starting_items.append("Progressive Sword")
   # Add starting Triforce Shards.
   num_starting_triforce_shards = int(self.options.get("num_starting_triforce_shards", 0))
   for i in range(num_starting_triforce_shards):
     self.starting_items.append("Triforce Shard %d" % (i+1))
   
   # Default dungeon entrances to be used if dungeon entrance randomizer is not on.
   self.dungeon_entrances = OrderedDict([
     ("Dungeon Entrance On Dragon Roost Island", "Dragon Roost Cavern"),
     ("Dungeon Entrance In Forest Haven Sector", "Forbidden Woods"),
     ("Dungeon Entrance In Tower of the Gods Sector", "Tower of the Gods"),
     ("Dungeon Entrance On Headstone Island", "Earth Temple"),
     ("Dungeon Entrance On Gale Isle", "Wind Temple"),
   ])
   self.dungeon_island_locations = OrderedDict([
     ("Dragon Roost Cavern", "Dragon Roost Island"),
     ("Forbidden Woods", "Forest Haven"),
     ("Tower of the Gods", "Tower of the Gods"),
     ("Earth Temple", "Headstone Island"),
     ("Wind Temple", "Gale Isle"),
   ])
   
   # Default starting island (Outset) if the starting island randomizer is not on.
   self.starting_island_index = 44
   
   # Default charts for each island.
   self.island_number_to_chart_name = OrderedDict([
     (1, "Treasure Chart 25"),
     (2, "Treasure Chart 7"),
     (3, "Treasure Chart 24"),
     (4, "Triforce Chart 2"),
     (5, "Treasure Chart 11"),
     (6, "Triforce Chart 7"),
     (7, "Treasure Chart 13"),
     (8, "Treasure Chart 41"),
     (9, "Treasure Chart 29"),
     (10, "Treasure Chart 22"),
     (11, "Treasure Chart 18"),
     (12, "Treasure Chart 30"),
     (13, "Treasure Chart 39"),
     (14, "Treasure Chart 19"),
     (15, "Treasure Chart 8"),
     (16, "Treasure Chart 2"),
     (17, "Treasure Chart 10"),
     (18, "Treasure Chart 26"),
     (19, "Treasure Chart 3"),
     (20, "Treasure Chart 37"),
     (21, "Treasure Chart 27"),
     (22, "Treasure Chart 38"),
     (23, "Triforce Chart 1"),
     (24, "Treasure Chart 21"),
     (25, "Treasure Chart 6"),
     (26, "Treasure Chart 14"),
     (27, "Treasure Chart 34"),
     (28, "Treasure Chart 5"),
     (29, "Treasure Chart 28"),
     (30, "Treasure Chart 35"),
     (31, "Triforce Chart 3"),
     (32, "Triforce Chart 6"),
     (33, "Treasure Chart 1"),
     (34, "Treasure Chart 20"),
     (35, "Treasure Chart 36"),
     (36, "Treasure Chart 23"),
     (37, "Treasure Chart 12"),
     (38, "Treasure Chart 16"),
     (39, "Treasure Chart 4"),
     (40, "Treasure Chart 17"),
     (41, "Treasure Chart 31"),
     (42, "Triforce Chart 5"),
     (43, "Treasure Chart 9"),
     (44, "Triforce Chart 4"),
     (45, "Treasure Chart 40"),
     (46, "Triforce Chart 8"),
     (47, "Treasure Chart 15"),
     (48, "Treasure Chart 32"),
     (49, "Treasure Chart 33"),
   ])
   
   self.custom_model_name = "Link"
   
   self.logic = Logic(self)
   
   num_progress_locations = self.logic.get_num_progression_locations()
   num_progress_items = self.logic.get_num_progression_items()
   if num_progress_locations < num_progress_items: 
     error_message = "Not enough progress locations to place all progress items.\n\n"
     error_message += "Total progress items: %d\n" % num_progress_items
     error_message += "Progress locations with current options: %d\n\n" % num_progress_locations
     error_message += "You need to check more of the progress location options in order to give the randomizer enough space to place all the items."
     raise TooFewProgressionLocationsError(error_message)
   
   # We need to determine if the user's selected options result in a dungeons-only-start.
   # Dungeons-only-start meaning that the only locations accessible at the start of the run are dungeon locations.
   # e.g. If the user selects Dungeons, Expensive Purchases, and Sunken Treasures, the dungeon locations are the only ones the player can check first.
   # We need to distinguish this situation because it can cause issues for the randomizer's item placement logic.
   self.logic.temporarily_make_dungeon_entrance_macros_impossible()
   accessible_undone_locations = self.logic.get_accessible_remaining_locations(for_progression=True)
   if len(accessible_undone_locations) == 0:
     self.dungeons_only_start = True
   else:
     self.dungeons_only_start = False
   self.logic.update_dungeon_entrance_macros() # Reset the dungeon entrance macros.
Пример #9
0
    def __init__(self,
                 seed,
                 clean_iso_path,
                 randomized_output_folder,
                 options,
                 permalink=None,
                 dry_run=False):
        self.randomized_output_folder = randomized_output_folder
        self.options = options
        self.seed = seed
        self.permalink = permalink
        self.dry_run = dry_run

        self.integer_seed = int(
            hashlib.md5(self.seed.encode('utf-8')).hexdigest(), 16)
        self.rng = Random()
        self.rng.seed(self.integer_seed)

        self.arcs_by_path = {}
        self.jpcs_by_path = {}
        self.raw_files_by_path = {}

        if not self.dry_run:
            self.verify_supported_version(clean_iso_path)

            self.gcm = GCM(clean_iso_path)
            self.gcm.read_entire_disc()

            self.chart_list = self.get_arc(
                "files/res/Msg/fmapres.arc").get_file("cmapdat.bin")
            self.bmg = self.get_arc("files/res/Msg/bmgres.arc").get_file(
                "zel_00.bmg")

        self.read_text_file_lists()

        # Starting items. This list is read by the Logic when initializing your currently owned items list.
        self.starting_items = [
            "Wind Waker",
            "Wind's Requiem",
            "Ballad of Gales",
            "Progressive Sword",
            "Hero's Shield",
            "Boat's Sail",
        ]
        # Add starting Triforce Shards.
        num_starting_triforce_shards = int(
            self.options.get("num_starting_triforce_shards", 0))
        for i in range(num_starting_triforce_shards):
            self.starting_items.append("Triforce Shard %d" % (i + 1))

        # Default dungeon entrances to be used if dungeon entrance randomizer is not on.
        self.dungeon_entrances = OrderedDict([
            ("Dungeon Entrance On Dragon Roost Island", "Dragon Roost Cavern"),
            ("Dungeon Entrance In Forest Haven Sector", "Forbidden Woods"),
            ("Dungeon Entrance In Tower of the Gods Sector",
             "Tower of the Gods"),
            ("Dungeon Entrance On Headstone Island", "Earth Temple"),
            ("Dungeon Entrance On Gale Isle", "Wind Temple"),
        ])
        self.dungeon_island_locations = OrderedDict([
            ("Dragon Roost Cavern", "Dragon Roost Island"),
            ("Forbidden Woods", "Forest Haven"),
            ("Tower of the Gods", "Tower of the Gods"),
            ("Earth Temple", "Headstone Island"),
            ("Wind Temple", "Gale Isle"),
        ])

        # Default starting island (Outset) if the starting island randomizer is not on.
        self.starting_island_index = 44

        # Default charts for each island.
        self.island_number_to_chart_name = OrderedDict([
            (1, "Treasure Chart 25"),
            (2, "Treasure Chart 7"),
            (3, "Treasure Chart 24"),
            (4, "Triforce Chart 2"),
            (5, "Treasure Chart 11"),
            (6, "Triforce Chart 7"),
            (7, "Treasure Chart 13"),
            (8, "Treasure Chart 41"),
            (9, "Treasure Chart 29"),
            (10, "Treasure Chart 22"),
            (11, "Treasure Chart 18"),
            (12, "Treasure Chart 30"),
            (13, "Treasure Chart 39"),
            (14, "Treasure Chart 19"),
            (15, "Treasure Chart 8"),
            (16, "Treasure Chart 2"),
            (17, "Treasure Chart 10"),
            (18, "Treasure Chart 26"),
            (19, "Treasure Chart 3"),
            (20, "Treasure Chart 37"),
            (21, "Treasure Chart 27"),
            (22, "Treasure Chart 38"),
            (23, "Triforce Chart 1"),
            (24, "Treasure Chart 21"),
            (25, "Treasure Chart 6"),
            (26, "Treasure Chart 14"),
            (27, "Treasure Chart 34"),
            (28, "Treasure Chart 5"),
            (29, "Treasure Chart 28"),
            (30, "Treasure Chart 35"),
            (31, "Triforce Chart 3"),
            (32, "Triforce Chart 6"),
            (33, "Treasure Chart 1"),
            (34, "Treasure Chart 20"),
            (35, "Treasure Chart 36"),
            (36, "Treasure Chart 23"),
            (37, "Treasure Chart 12"),
            (38, "Treasure Chart 16"),
            (39, "Treasure Chart 4"),
            (40, "Treasure Chart 17"),
            (41, "Treasure Chart 31"),
            (42, "Triforce Chart 5"),
            (43, "Treasure Chart 9"),
            (44, "Triforce Chart 4"),
            (45, "Treasure Chart 40"),
            (46, "Triforce Chart 8"),
            (47, "Treasure Chart 15"),
            (48, "Treasure Chart 32"),
            (49, "Treasure Chart 33"),
        ])

        self.logic = Logic(self)

        num_progress_locations = self.logic.get_num_progression_locations()
        num_progress_items = self.logic.get_num_progression_items()
        if num_progress_locations < num_progress_items:
            error_message = "Not enough progress locations to place all progress items.\n\n"
            error_message += "Total progress items: %d\n" % num_progress_items
            error_message += "Progress locations with current options: %d\n\n" % num_progress_locations
            error_message += "You need to check more of the progress location options in order to give the randomizer enough space to place all the items."
            raise TooFewProgressionLocationsError(error_message)
Пример #10
0
    def __init__(self,
                 options: Options,
                 progress_callback=dummy_progress_callback):
        self.options = options
        # hack: if shops are vanilla, disable them as banned types because of bug net and progressive pouches
        if self.options['shop-mode'] == 'Vanilla':
            banned_types = self.options['banned-types']
            for unban_shop_item in ['beedle', 'cheap', 'medium', 'expensive']:
                if unban_shop_item in banned_types:
                    banned_types.remove(unban_shop_item)
            self.options.set_option('banned-types', banned_types)

        self.progress_callback = progress_callback
        self.dry_run = bool(self.options['dry-run'])
        # TODO: maybe make paths configurable?
        # exe root path is where the executable is
        self.exe_root_path = Path('.').resolve()
        # this is where all assets/read only files are
        self.rando_root_path = RANDO_ROOT_PATH
        if not self.dry_run:
            self.actual_extract_path = self.exe_root_path / 'actual-extract'
            self.modified_extract_path = self.exe_root_path / 'modified-extract'
            self.oarc_cache_path = self.exe_root_path / 'oarc'
        self.no_logs = self.options['no-spoiler-log']
        self.seed = self.options['seed']
        if self.seed == -1:
            self.seed = random.randint(0, 1000000)
        self.options.set_option('seed', self.seed)

        self.randomizer_hash = self._get_rando_hash()
        self.rng = random.Random()
        self.rng.seed(self.seed)
        if self.no_logs:
            self.rng.randint(0, 100)
        dungeons = [
            "Skyview", "Earth Temple", "Lanayru Mining Facility",
            "Ancient Cistern", "Sandship", "Fire Sanctuary"
        ]
        if self.options['randomize-entrances'] == 'None':
            dungeons.append('Sky Keep')
            dungeons.reverse()
        else:
            if self.options['randomize-entrances'] == 'Dungeons':
                self.rng.shuffle(dungeons)
                dungeons.append('Sky Keep')
                dungeons.reverse()
            else:
                dungeons.append('Sky Keep')
                self.rng.shuffle(dungeons)
        self.entrance_connections = OrderedDict([
            ("Dungeon Entrance in Deep Woods", dungeons.pop()),
            ("Dungeon Entrance in Eldin Volcano", dungeons.pop()),
            ("Dungeon Entrance in Lanayru Desert", dungeons.pop()),
            ("Dungeon Entrance in Lake Floria", dungeons.pop()),
            ("Dungeon Entrance in Sand Sea", dungeons.pop()),
            ("Dungeon Entrance in Volcano Summit", dungeons.pop()),
            ("Dungeon Entrance on Skyloft", dungeons.pop()),
        ])
        assert len(dungeons) == 0, 'Not all dungeons linked to an entrance'
        # self.starting_items = (x.strip() for x in self.options['starting_items']
        # self.starting_items: List[str] = list(filter(lambda x: x != '', self.starting_items))
        self.starting_items = []

        self.required_dungeons = self.rng.sample(
            constants.POTENTIALLY_REQUIRED_DUNGEONS,
            k=self.options['required-dungeon-count'])
        # make the order always consistent
        self.required_dungeons = [
            dungeon for dungeon in constants.POTENTIALLY_REQUIRED_DUNGEONS
            if dungeon in self.required_dungeons
        ]

        tablets = ['Emerald Tablet', 'Ruby Tablet', 'Amber Tablet']
        self.starting_items.extend(
            self.rng.sample(tablets, k=self.options['starting-tablet-count']))

        if not self.options['swordless']:
            self.starting_items.append('Progressive Sword')
            self.starting_items.append('Progressive Sword')
        # if not self.options.get('randomize-sailcloth',False):
        #   self.starting_items.append('Sailcloth')
        if self.options['start-with-pouch']:
            self.starting_items.append('Progressive Pouch')
        self.banned_types = self.options['banned-types']
        self.race_mode_banned_locations = []
        self.non_required_dungeons = [
            dungeon for dungeon in constants.POTENTIALLY_REQUIRED_DUNGEONS
            if not dungeon in self.required_dungeons
        ]

        self.logic = Logic(self)
        # self.logic.set_prerandomization_item_location("Beedle - Second 100 Rupee Item", "Rare Treasure")
        # self.logic.set_prerandomization_item_location("Beedle - Third 100 Rupee Item", "Rare Treasure")
        # self.logic.set_prerandomization_item_location("Beedle - 1000 Rupee Item", "Rare Treasure")
        self.hints = Hints(self.logic)
Пример #11
0
import sys
from PyQt5.QtWidgets import QApplication
from utils import json_hook
import json
from ui.login import LoginWindow
from ui.room import RoomWindow
from ui.game import GameWindow
from logic.logic import Logic

if __name__ == '__main__':

    app = QApplication([])

    logic = Logic()

    login_window = LoginWindow()
    login_window.username_signal.connect(logic.check_username)
    # valid username signal:
    logic.username_valid_signal.connect(login_window.close)
    # invalid username signal:
    logic.username_invalid_signal.connect(login_window.invalid_username)

    room_window = RoomWindow()
    # signal emitted when username is valid in login_window
    logic.username_valid_signal.connect(room_window.show)
    # signal emitted when new player joins the room:
    logic.new_player_signal.connect(room_window.new_player)
    # signal emitted when game starts:
    logic.start_game_signal.connect(room_window.close)

    game_window = GameWindow()
Пример #12
0
    def __init__(self, options):
        self.options = options
        self.dry_run = bool(options.get('dry-run', False))
        # TODO: maybe make paths configurable?
        if not self.dry_run:
            self.actual_extract_path = Path(__file__).parent / 'actual-extract'
            self.modified_extract_path = Path(
                __file__).parent / 'modified-extract'
            self.oarc_cache_path = Path(__file__).parent / 'oarc'
            # catch common errors with directory setup
            if not self.actual_extract_path.is_dir():
                raise StartupException(
                    "ERROR: directory actual-extract doesn't exist! Make sure you have the ISO extracted into that directory"
                )
            if not self.modified_extract_path.is_dir():
                raise StartupException(
                    "ERROR: directory modified-extract doesn't exist! Make sure you have the contents of actual-extract copied over to modified-extract"
                )
            if not (self.actual_extract_path / 'DATA').is_dir():
                raise StartupException(
                    "ERROR: directory actual-extract doesn't contain a DATA directory! Make sure you have the ISO properly extracted into actual-extract"
                )
            if not (self.modified_extract_path / 'DATA').is_dir():
                raise StartupException(
                    "ERROR: directory 'DATA' in modified-extract doesn't exist! Make sure you have the contents of actual-extract copied over to modified-extract"
                )
            if not (self.modified_extract_path / 'DATA' / 'files' /
                    'COPYDATE_CODE_2011-09-28_153155').exists():
                raise StartupException(
                    "ERROR: the randomizer only supports E1.00")
        self.options = options
        self.no_logs = False
        self.seed = options.get('seed', -1)
        if self.seed == -1:
            self.seed = random.randint(0, 1000000)
        self.rng = random.Random()
        self.rng.seed(self.seed)
        self.entrance_connections = OrderedDict([
            ("Dungeon Entrance In Deep Woods", "Skyview"),
            ("Dungeon Entrance In Eldin Volcano", "Earth Temple"),
            ("Dungeon Entrance In Lanayru Desert", "Lanayru Mining Facility"),
            ("Dungeon Entrance In Lake Floria", "Ancient Cistern"),
            ("Dungeon Entrance In Sand Sea", "Sandship"),
            ("Dungeon Entrance In Volcano Summit", "Fire Sanctuary"),
            ("Dungeon Entrance On Skyloft", "Skykeep"),
        ])
        self.starting_items = (
            x.strip()
            for x in self.options.get('starting_items', '').split(','))
        self.starting_items: List[str] = list(
            filter(lambda x: x != '', self.starting_items))

        self.required_dungeons = self.rng.sample(
            constants.POTENTIALLY_REQUIRED_DUNGEONS, k=2)

        if not self.options.get('randomize-tablets', False):
            self.starting_items.append('Emerald Tablet')
            self.starting_items.append('Ruby Tablet')
            self.starting_items.append('Amber Tablet')
        if not self.options.get('swordless', False):
            self.starting_items.append('Progressive Sword')
            self.starting_items.append('Progressive Sword')
        # if not self.options.get('randomize-sailcloth',False):
        #   self.starting_items.append('Sailcloth')
        self.banned_types = self.options.get('banned-types', '').split(',')
        self.banned_types = [
            x.strip() for x in self.banned_types if x.strip() != ''
        ]
        unknown_types = [
            x for x in self.banned_types if not x in constants.ALL_TYPES
        ]
        if len(unknown_types) > 0:
            print(f"ERROR: unknown banned type(s): {unknown_types}")
        self.race_mode_banned_locations = []
        self.logic = Logic(self)
        self.non_required_dungeons = [
            dungeon for dungeon in constants.POTENTIALLY_REQUIRED_DUNGEONS
            if not dungeon in self.required_dungeons
        ]
        if self.options.get('empty-unrequired-dungeons', False):
            for location_name in self.logic.item_locations:
                zone, _ = Logic.split_location_name_by_zone(location_name)
                if zone in self.non_required_dungeons:
                    self.race_mode_banned_locations.append(location_name)

            # checks outside dungeons that require dungeons:
            if 'Lanayru Mining Facility' in self.non_required_dungeons:
                self.race_mode_banned_locations.append(
                    'Skyloft - Fledge Crystals')
            elif 'Skyview' in self.non_required_dungeons:
                # TODO: check again with entrance rando
                self.race_mode_banned_locations.append(
                    'Sky - Lumpy Pumpkin Roof Goddess Chest')
                self.race_mode_banned_locations.append(
                    'Sealed Grounds - Gorko Goddess Wall Reward')