def load_from_export_state(self): new_floor_list = [] new_item_list = [] data = self.get_export_state() try: if self.game_version == "Repentance" or self.game_version == "Afterbirth+": data = data[self.game_version][str(self.save)] else: data = data[self.game_version] self.seed = data['seed'] self.player = data['player'] self.greedmode = data['greedmode'] for floor in data['floor_list']: new_floor = Floor(floor["floor_id"], floor["curse"]) new_floor_list.append(new_floor) self.floor_list = new_floor_list for item in data['item_list']: new_item = Item(flagstr=item["flags"], item_id=item['item_id'], floor=Floor(floor_id=item['floor_id'])) new_item_list.append(new_item) self.item_list = new_item_list self.player_transforms = data['player_transforms'] if self.player == "19": self.player2_transforms = data['player2_transforms'] self.modified = True except: return True
def last_floor(self): """ Get current floor If no floor is in the floor list, create a default one """ if len(self.floor_list) == 0: self.add_floor(Floor("f1")) return self.floor_list[-1]
def __parse_floor(self, line, line_number): """ Parse the floor in line and push it to the state """ # Create a floor tuple with the floor id and the alternate id if self.opt.game_version == "Afterbirth" or self.opt.game_version == "Afterbirth+": regexp_str = r"Level::Init m_Stage (\d+), m_StageType (\d+)" elif self.opt.game_version == "Rebirth" or self.opt.game_version == "Antibirth": regexp_str = r"Level::Init m_Stage (\d+), m_AltStage (\d+)" else: return search_result = re.search(regexp_str, line) if search_result is None: self.log.debug("log.txt line doesn't match expected regex\nline: \"" + line+ "\"\nregex:\"" + regexp_str + "\"") return floor = int(search_result.group(1)) alt = search_result.group(2) self.getting_start_items = True # we use generation of the first floor as our trigger that a new run started. # in racing+, it doesn't count if the game is currently in the process of "reseeding" that floor. # in antibirth, this doesn't work at all; instead we have to use the seed being printed as our trigger. # that means if you s+q in antibirth, it resets the tracker. if self.reseeding_floor: self.reseeding_floor = False elif floor == 1 and self.opt.game_version != "Antibirth": self.__trigger_new_run(line_number) # Special handling for the Cathedral and The Chest and Afterbirth if self.opt.game_version == "Afterbirth" or self.opt.game_version == "Afterbirth+": # In Afterbirth, Cath is an alternate of Sheol (which is 10) # and Chest is an alternate of Dark Room (which is 11) if floor == 10 and alt == '0': floor -= 1 elif floor == 11 and alt == '1': floor += 1 else: # In Rebirth, floors have different numbers if alt == '1' and (floor == 9 or floor == 11): floor += 1 floor_id = 'f' + str(floor) # Greed mode if alt == '3': floor_id += 'g' self.state.add_floor(Floor(floor_id)) return True
def __parse_floor(self, line): """ Parse the floor in line and push it to the state """ # Create a floor tuple with the floor id and the alternate id if self.opt.game_version == "Afterbirth" or self.opt.game_version == "Afterbirth+": regexp_str = r"Level::Init m_Stage (\d+), m_StageType (\d+)" elif self.opt.game_version == "Rebirth" or self.opt.game_version == "Antibirth": regexp_str = r"Level::Init m_Stage (\d+), m_AltStage (\d+)" else: return floor_tuple = tuple( [re.search(regexp_str, line).group(x) for x in [1, 2]]) self.getting_start_items = True # Assume floors aren't cursed until we see they are floor = int(floor_tuple[0]) alt = floor_tuple[1] # Special handling for cath and chest and Afterbirth if self.opt.game_version == "Afterbirth" or self.opt.game_version == "Afterbirth+": # In Afterbirth Cath is an alternate of Sheol (which is 10) # and Chest is an alternate of Dark room (which is 11) if floor == 10 and alt == '0': floor -= 1 elif floor == 11 and alt == '1': floor += 1 else: # In Rebirth floors have different numbers if alt == '1' and (floor == 9 or floor == 11): floor += 1 floor_id = 'f' + str(floor) # Greed mode if alt == '3': floor_id += 'g' self.state.add_floor(Floor(floor_id)) return True
def __parse_floor(self, line, line_number): """ Parse the floor in line and push it to the state """ # Create a floor tuple with the floor id and the alternate id if self.opt.game_version == "Afterbirth" or self.opt.game_version == "Afterbirth+" or self.opt.game_version == "Repentance": regexp_str = r"Level::Init m_Stage (\d+), m_StageType (\d+)" elif self.opt.game_version == "Rebirth" or self.opt.game_version == "Antibirth": regexp_str = r"Level::Init m_Stage (\d+), m_AltStage (\d+)" else: return search_result = re.search(regexp_str, line) if search_result is None: self.log.debug( "log.txt line doesn't match expected regex\nline: \"" + line + "\"\nregex:\"" + regexp_str + "\"") return floor = int(search_result.group(1)) alt = search_result.group(2) self.getting_start_items = True # we use generation of the first floor as our trigger that a new run started. # in racing+, it doesn't count if the game is currently in the process of "reseeding" that floor. # in antibirth, this doesn't work at all; instead we have to use the seed being printed as our trigger. # that means if you s+q in antibirth, it resets the tracker. # In Repentance, Downpour 1 and Dross 1 are considered Stage 1. # So we need to add a condition to avoid tracker resetting when entering those floors. # In Repentance, don't trigger a new run on floor 1 because of the R Key item if self.reseeding_floor: self.reseeding_floor = False elif floor == 1 and self.opt.game_version != "Antibirth" and self.opt.game_version != "Repentance": self.__trigger_new_run(line_number) # Special handling for the Cathedral and The Chest and Afterbirth if self.opt.game_version == "Afterbirth" or self.opt.game_version == "Afterbirth+" or self.opt.game_version == "Repentance": self.log.debug("floor") # In Afterbirth, Cath is an alternate of Sheol (which is 10) # and Chest is an alternate of Dark Room (which is 11) # In Repentance, alt paths are same stage as their counterparts (ex: Basement 1 = Downpour 1) if alt == '4' or alt == '5': floor += 15 elif floor == 10 and alt == '0': floor -= 1 elif floor == 11 and alt == '1': floor += 1 elif floor == 9: floor = 13 elif floor == 12: floor = 14 elif floor == 13: floor = 15 else: # In Rebirth, floors have different numbers if alt == '1' and (floor == 9 or floor == 11): floor += 1 floor_id = 'f' + str(floor) # Greed mode if (alt == '3' and self.opt.game_version != "Repentance") or ( self.opt.game_version == "Repentance" and self.state.greedmode): floor_id += 'g' self.state.add_floor(Floor(floor_id)) self.state.export_state() return True