def after_order(self): objs = [] if 'p' in get_flags(): objs.append(ShopObject) if 'm' in get_flags(): objs.append(MonsterObject) return objs
def mutate(self): if "f" not in get_flags(): return if (self.index < 20 and random.randint(1, 4) == 4) or ( self.index == 19 and BattleFormationObject.num_special < 5): self.become_boss() BattleFormationObject.num_special += 1 return if self.is_boss: return if self.index >= 20: leaders = [f.leader for f in self.formations] maxrank = max([f.maxrank for f in self.formations]) assert len(set(leaders)) == 1 leader = leaders[0] candidates = [f for f in FormationObject.every if f.leader == leader and f.maxrank <= maxrank] else: candidates = list(FormationObject.every) new_ids = [f.get_similar(candidates).index for f in self.formations] if len(set(new_ids)) < len(set(self.formation_ids)): return self.formation_ids = new_ids
def rewrite_title_screen(): title_len_1, title_len_2 = 17, 20 s1 = 'v{0} SN {1}'.format(VERSION, get_seed()) if any(hasattr(o, 'custom_random_degree') for o in ALL_OBJECTS): random_degree = 'CUSTOM' else: random_degree = round(get_random_degree() ** 0.5, 2) s2 = '{0} {1}'.format(random_degree, get_flags()) s1 = s1.strip() s2 = s2.strip() assert len(s1) <= title_len_1 assert len(s2) <= title_len_2 while len(s1) < title_len_1: s1 = ' {0} '.format(s1) s1 = s1[:title_len_1] while len(s2) < title_len_2: s2 = ' {0} '.format(s2) s2 = s2[:title_len_2] assert len(s1) == title_len_1 assert len(s2) == title_len_2 f = open(get_outfile(), 'r+b') f.seek(addresses.title_text_1) f.write(NameMixin.encode(s1)) f.seek(addresses.title_text_2) f.write(NameMixin.encode(s2)) f.close()
def rank(self): if self.index in self.BANNED_INDEXES or self.index not in ITEM_NAMES: return -1 elif 'o' not in get_flags() and self.index in self.CONSUMABLES: return -1 elif self.is_event_only_item: rank = max([p.price for p in PriceObject.every]) + 2 elif self.price <= 2: rank = max([p.price for p in PriceObject.every]) + 1 else: rank = self.price return rank
def full_randomize(cls): super(ShopObject, cls).full_randomize() ShopObject.class_reseed("shops") types = ["Magic", "Weapons", "Armor", "Items"] if 'o' not in get_flags(): types.remove('Items') for pretty_shop_type in types: shops = [ s for s in ShopObject.ranked if s.rank > 0 and s.pretty_shop_type == pretty_shop_type ] itemranks = defaultdict(set) all_items = set([]) avg = 0 for n, s in enumerate(shops): items = [i for i in s.items if i] itemranks[n] |= set(items) all_items |= set(items) avg += len(items) magic_shop = pretty_shop_type == "Magic" if magic_shop: all_items = [SpellPriceObject.get(i) for i in all_items] else: all_items = [PriceObject.get(i) for i in all_items] all_items = sorted(all_items, key=lambda i: (i.rank, i.signature)) done_items = set([]) random.shuffle(shops) for s in shops: s.reseed("wares") shop_items = [i for i in s.items if i > 0] chosen_items = [] while len(chosen_items) < len(shop_items): base_index = random.choice(shop_items) candidates = [i for i in all_items if i not in done_items] if not candidates: candidates = list(all_items) candidates = [ c for c in candidates if c not in chosen_items ] price = SpellPriceObject.get( base_index) if magic_shop else PriceObject.get( base_index) chosen = price.get_similar(candidates, override_outsider=True) chosen_items.append(chosen) assert len(chosen_items) == len(set(chosen_items)) chosen_items = sorted(chosen_items, reverse=True, key=lambda i: i.price) s.items = [c.index for c in chosen_items]
def full_cleanup(cls): if 'e' in get_flags(): rope_candidates = [ i for i in ItemObject.every if 0x12d7a <= i.pointer <= 0x12da6 ] if not any([i.item_type == 0xd for i in rope_candidates]): chosen = random.choice(rope_candidates) chosen.item_type = 0xd else: chosen = random.choice( [i for i in rope_candidates if i.item_type == 0xd]) rope_candidates.remove(chosen) if not any([i.item_type == 0xc for i in rope_candidates]): chosen = random.choice(rope_candidates) chosen.item_type = 0xc super(ItemObject, cls).full_cleanup()
def become_boss(self): flamerus_rank = MonsterObject.get(0x4a).rank battlefields = [bf for bf in BattleFormationObject.ranked if bf.index < 20] my_index = battlefields.index(self) candidates = [m for m in MonsterObject.ranked if m.rank >= flamerus_rank] new_index = int(round(my_index * (len(candidates) / 20.0))) new_index = mutate_normal(new_index, minimum=0, maximum=len(candidates)-1) leader = candidates[new_index] candidates = [m for m in MonsterObject.ranked if m.rank < leader.rank] max_index = len(candidates)-1 follow_index = random.randint(random.randint(0, max_index), max_index) follower = candidates[follow_index].index if random.randint(0, max_index) >= follow_index: follow2_index = random.randint( random.randint(max_index-follow_index, max_index), max_index) follower2 = candidates[follow2_index].index new_ids = [follower, leader.index, follower2] else: new_ids = [leader.index, follower, 0xFF] f = FormationObject.get_unused() f.special_boss = True f.enemy_ids = new_ids self.formation_ids = [f.index] * 3 f.mutated = True br = BattleRoundsObject.get(self.index) br.num_rounds = 1 br.mutated = True if "t" not in get_flags(): return br2 = BattleRewardObject.get(self.index) br2.reward = 0x4000 done_items = [t.reward & 0xFF for t in BattleRewardObject.every if hasattr(t, "mutated") and t.mutated and t.reward & 0x4000] if TreasureIndexObject.well_hidden: value = random.choice(sorted(TreasureIndexObject.well_hidden)) TreasureIndexObject.well_hidden.remove(value) else: value = random.choice([i for i in DESIRABLE_ITEMS if i != 0x14 and i not in done_items]) br2.reward |= value br2.mutated = True
def intershuffle(cls): candidates = sorted( [jco for jco in JobCrystalObject.every if jco.intershuffle_valid], key=lambda jco: (jco.ability_ap_rank, jco.signature)) shuffled = [] while candidates: max_index = len(candidates) - 1 index = random.randint(0, max_index) degree = JobCrystalObject.random_degree**0.25 if degree <= 0.5: degree = degree * 2 a, b = 0, index else: degree = (degree - 0.5) * 2 a, b = index, max_index index = int(round((a * (1 - degree)) + (b * degree))) index = random.randint(0, index) chosen = candidates[index] shuffled.append(chosen) candidates.remove(chosen) candidates = sorted(shuffled, key=lambda jco: (jco.rank, jco.signature)) if 'GBA' not in get_global_label(): assert len(candidates) == len(shuffled) == 21 else: assert len(candidates) == len(shuffled) == 25 for c, s in zip(candidates, shuffled): c.crystal_index = s.old_data["crystal_index"] freelancer = [jco for jco in candidates if jco.is_freelancer][0] fight_crystals = [jco for jco in shuffled if jco.has_fight_command] if freelancer not in fight_crystals: assert not freelancer.has_fight_command chosen = fight_crystals[0] freelancer.crystal_index, chosen.crystal_index = ( chosen.crystal_index, freelancer.crystal_index) assert freelancer.has_fight_command if 'r' in get_flags(): chance = int(RemoveJobs.random_degree * 100) print('Removing jobs ({}% chance)...'.format(chance)) for c in candidates: if random.random() < RemoveJobs.random_degree: c.crystal_index = freelancer.crystal_index
def intershuffle_valid(self): ''' 01 - whole pizza 02 - half pizza 03 - quarter pizza 05 - shuriken 06 - 3x shuriken 07 - boomerang 08 - ninja scroll 0b - invincibility 0c - missile 0d - ropes ''' if 'e' in get_flags(): return 0x1 <= self.item_type <= 0xf else: # omit missiles and ropes return 0x1 <= self.item_type <= 0xb
def after_order(self): if "t" not in get_flags(): return [] return [TreasureIndexObject]
def after_order(self): if "t" in get_flags(): return [BattleFormationObject] return []
def after_order(self): if 'f' in get_flags(): return [FormationObject] return []
'randomizer version %s.' % VERSION) ALL_OBJECTS = [g for g in globals().values() if isinstance(g, type) and issubclass(g, TableObject) and g not in [TableObject]] run_interface(ALL_OBJECTS, snes=True) if get_global_label() == "FFMQ_NA_1.1": DemoPlay = CharacterObject.get(0) DemoPlay.name_text = [texttable[c] for c in "Abyssnym"] while len(DemoPlay.name_text) < 16: DemoPlay.name_text += [0x03] hexify = lambda x: "{0:0>2}".format("%x" % x) numify = lambda x: "{0: >3}".format(x) minmax = lambda x: (min(x), max(x)) clean_and_write(ALL_OBJECTS) if get_global_label() == "FFMQ_NA_1.1": write_title_screen(get_outfile(), get_seed(), get_flags()) enemy_jump = 0xef8e elif get_global_label() == "FFMQ_JP": enemy_jump = 0xef92 x = raw_input("Do you want to give Benjamin the power " "to jump over enemies? (y/n) ") if x and x[0].lower() == 'y': f = open(get_outfile(), "r+b") f.seek(enemy_jump) f.write(chr(0x80)) f.close() rewrite_snes_meta("FFMQ-R", VERSION, megabits=24, lorom=True) finish_interface() except Exception, e: print "ERROR: %s" % e raw_input("Press Enter to close this program.")
f.write(chr(value)) f.close() if __name__ == "__main__": print ("You are using the Chrono Trigger: Eternal Nightmare randomizer " "version %s." % VERSION) ALL_OBJECTS = [g for g in globals().values() if isinstance(g, type) and issubclass(g, TableObject) and g not in [TableObject]] run_interface(ALL_OBJECTS, snes=True, custom_degree=True) minmax = lambda x: (min(x), max(x)) add_singing_mountain() #randomize_battle_animations() if "l" in get_flags(): answer = raw_input("WARNING: I've noticed that you decided to " "randomize the color palettes. It's not too " "late to turn back. Disabling this feature " "has no effect on gameplay. Will you randomize " "the palettes? (y/n) ") if answer and answer[0].lower() == 'n': allow_palette_swap = False else: allow_palette_swap = True clean_and_write(ALL_OBJECTS) randomize_rng(0xFE00) randomize_rng(0x3DBA61) rewrite_snes_meta("CT-R", VERSION, lorom=False) finish_interface()
def after_order(self): if 'q' in get_flags(): return [ItemObject] return []
f.close() if __name__ == "__main__": print("You are using the Chrono Trigger: Eternal Nightmare randomizer " "version %s." % VERSION) ALL_OBJECTS = [ g for g in globals().values() if isinstance(g, type) and issubclass(g, TableObject) and g not in [TableObject] ] run_interface(ALL_OBJECTS, snes=True, custom_degree=True) minmax = lambda x: (min(x), max(x)) add_singing_mountain() #randomize_battle_animations() if "l" in get_flags(): answer = raw_input("WARNING: I've noticed that you decided to " "randomize the color palettes. It's not too " "late to turn back. Disabling this feature " "has no effect on gameplay. Will you randomize " "the palettes? (y/n) ") if answer and answer[0].lower() == 'n': allow_palette_swap = False else: allow_palette_swap = True clean_and_write(ALL_OBJECTS) randomize_rng(0xFE00) randomize_rng(0x3DBA61) rewrite_snes_meta("CT-R", VERSION, lorom=False) finish_interface()