def intershuffle(cls): for m in MonsterObject.every: m.name monsters = [m for m in MonsterObject.ranked if m.intershuffle_valid] max_index = len(monsters) - 1 hard_mode = "chaos" in get_activated_codes() if hard_mode: def shuffle_func(m): index = monsters.index(m) rand_index = random.random() * max_index ratio = (random.random() + random.random() + random.random()) / 3 new_index = (index * ratio) + (rand_index * (1 - ratio)) return (new_index, m.index) else: shuffle_func = lambda m: (random.random(), m.index) for attrs in ["common_drop", "rare_drop", ("soul_type", "soul")]: if "bal" in get_activated_codes() and attrs in [ "common_drop", "rare_drop" ]: continue if isinstance(attrs, basestring): attrs = [attrs] shuffled = sorted(monsters, key=shuffle_func) for attr in attrs: values = [getattr(m, attr) for m in shuffled] assert len(values) == len(monsters) for m, value in zip(monsters, values): setattr(m, attr, value)
def route_items(): print "Now routing items. Please wait." hard_mode = "chaos" in get_activated_codes() custom_mode = "custom" in get_activated_codes() nosoul = "nosoul" in get_activated_codes() or 'd' not in get_flags() if hard_mode: print "CHAOS MODE ACTIVATED" ir = ItemRouter(path.join(tblpath, "hard_requirements.txt")) elif custom_mode: ir = ItemRouter(path.join(tblpath, "hard_requirements.txt")) else: ir = ItemRouter(path.join(tblpath, "requirements.txt")) if custom_mode: hard_mode = True ir.set_custom_assignments(custom_items) if hard_mode: aggression = 4 else: aggression = 3 try: ir.assign_everything(aggression=aggression) except ItemRouterException, e: if not custom_mode: raise e
def cleanup(self): if 'vegan' in get_activated_codes() and self.status < 3: self.boost = 0 if 'foodie' in get_activated_codes(): self.bites = 1 if self.sync == self.old_data['sync']: return self.sync = int(round(self.sync * 2 / 10.0)) * 5
def cleanup(self): if 'lowlevel' in get_activated_codes(): self.exp = 0 if 'easymodo' in get_activated_codes(): self.hp = 1 self.attack = 1 if 'extra' in get_activated_codes(): self.drop_rates = [10000] * 4
def cleanup(self): if 'fierce' in get_activated_codes(): self.bravery = 1 for attr in self.mutate_attributes: if self.old_data[attr] == 0: setattr(self, attr, 0)
def rank(self): hard_mode = "chaos" in get_activated_codes() if hard_mode: if self.xp == 0: return 20000 + random.random() else: return self.xp + random.random() else: return 0
def intershuffle_valid(self): if self.soul_type == 0 and self.soul == 0: return False codes = get_activated_codes() item_rando = ("i" in get_flags() or "chaos" in codes or "custom" in codes or "oops" in codes) if (self.index in [0x5F, 0x68] and not item_rando and "vangram" in codes): return False return True
def mutate(self): for attr in ["common_drop", "rare_drop"]: value = getattr(self, attr) if value == 0: continue while True: i = ItemObject.superget(value - 1) i = i.get_similar() if ("fam" in get_activated_codes() and i.item_type == 2 and i.index in HP_HEALING_ITEMS): continue if ("gun" in get_activated_codes() and i.item_type == 3): i = WeaponObject.get(random.choice(GUNS)) if ("fist" in get_activated_codes() and i.item_type == 3): i = WeaponObject.get(random.choice(FISTS)) if ("ass" in get_activated_codes() and i.item_type == 3): i = WeaponObject.get(random.choice(KNIVES)) value = (value & 0xFF00) | (i.superindex + 1) setattr(self, attr, value) break
def randomize(self): if self.index == 6: # berserker passive candidates = [ jao.ability for jao in JobAbilityObject.groups[self.index] if jao.ability > 0x4D ] if candidates: self.commands[1] = random.choice(candidates) return if self.index > 20: return old_commands = list(self.commands) candidates = [ jao.ability for jao in JobAbilityObject.groups[self.index] if jao.ability <= 0x4D ] if self.index == 20: candidates += [5, 2] redundant_groups = [ range(0x2C, 0x32), range(0x32, 0x38), range(0x38, 0x3E), range(0x3E, 0x44), ] for i, ability in enumerate(self.commands): if not candidates: break if "fight" in get_activated_codes() and ability == 5: pass elif ability > 0 and random.random() <= (self.random_degree**0.75): new_command = random.choice(candidates) if new_command in self.commands: continue self.commands[i] = new_command for rg in redundant_groups: if len(set(self.commands) & set(rg)) >= 2: self.commands[i] = ability break else: candidates.remove(new_command) if ability in candidates: candidates.remove(ability) while not set(self.commands) & set([5, 0x2b, 2]): i, c = random.choice(sorted(enumerate(old_commands))) if c in [5, 0x2b, 2]: self.commands[i] = c for rg in redundant_groups: if len(set(self.commands) & set(rg)) >= 2: assert False
def write_seed_display(): f = open(get_outfile(), "r+b") f.seek(addresses.start_game_text) s = "%s" % get_seed() while len(s) < 11: s += " " s = s[:11] f.write(s) f.seek(addresses.soul_set_text) s = ("%s-%s" % (VERSION, get_seed())) + chr(0x06) s += get_flags() + " " + " ".join(get_activated_codes()) while len(s) < 26: s += " " s = s[:26].upper() f.write(s) f.close()
def price_cleanup(self): if 'phantomthief' in get_activated_codes(): self.price = 0 if self.price == self.old_data['price']: return price = self.price * 2 counter = 0 while price >= 100: price = int(round(price / 10.0)) counter += 1 if random.randint(1, 10) == 10: break price = price * (10**counter) self.price = price // 2 if self.price % 10: self.price += 10 - (self.price % 10)
def randomize_all(cls): f = open(get_outfile(), "r+b") f.seek(addresses.hammer3) num_items = ord(f.read(1)) indexes = map(ord, f.read(num_items)) f.close() sios = [ShopIndexObject.get(i) for i in indexes] hard_mode = "chaos" in get_activated_codes() total_new_items = [] for item_type in [2, 3, 4]: subsios = [sio for sio in sios if sio.item_type == item_type] new_items = [] candidates = [ i for i in ItemObject.every if i.item_type == item_type and i.price > 0 ] candidates = sorted(candidates, key=lambda c: (c.price, random.random())) max_index = len(candidates) - 1 while len(new_items) < len(subsios): if hard_mode: index = random.randint(0, random.randint(0, max_index)) else: index = random.randint(0, max_index) chosen = candidates[index] if ("fam" in get_activated_codes() and item_type == 2 and chosen.index in HP_HEALING_ITEMS): continue restricted_items = None if "gun" in get_activated_codes() and item_type == 3: restricted_items = [WeaponObject.get(i) for i in GUNS] if "fist" in get_activated_codes() and item_type == 3: restricted_items = [WeaponObject.get(i) for i in FISTS] if "ass" in get_activated_codes() and item_type == 3: restricted_items = [WeaponObject.get(i) for i in KNIVES] if restricted_items is not None: temp = [i for i in restricted_items if i not in new_items] if temp: restricted_items = temp chosen = random.choice(restricted_items) if chosen in new_items and restricted_items is None: continue new_items.append(chosen) new_items = sorted(new_items, key=lambda ni: ni.index) total_new_items.extend(new_items) sios = [ShopIndexObject.get(i) for i in xrange(len(total_new_items))] for sio, ni in zip(sios, total_new_items): sio.item_type = ni.item_type sio.item_index = ni.index f = open(get_outfile(), "r+b") previous = list(sios) for address in ["hammer3", "hammer2", "hammer1"]: f.seek(getattr(addresses, address)) num_items = ord(f.read(1)) f.seek(getattr(addresses, address) + 1) chosen_sios = random.sample(previous, num_items) chosen_sios = sorted(chosen_sios, key=lambda sio: sio.index) for sio in chosen_sios: f.write(chr(sio.index)) sio.shop_rank = int(address[-1]) sio.inserted_item = False previous = chosen_sios f.close()
if replaceable: replacement = replaceable.pop(0) replacement.soul_type = boss.soul_type replacement.soul = boss.soul else: erased_souls.add((boss.soul_type + 5, boss.soul)) boss.soul_type = soul_type boss.soul = soul assert 0 <= boss.soul_type <= 3 remaining_treasures = [ t for t in TreasureObject.every if t not in done_treasures ] random.shuffle(remaining_treasures) max_rank = max(ir.location_ranks) oops_all_souls = 'oops' in get_activated_codes() if oops_all_souls: print "OOPS ALL SOULS MODE ACTIVATED" for t in remaining_treasures: rank = ir.get_location_rank("item_{0:0>2}".format("%x" % t.index)) if rank is None: rank = ((random.random() + random.random() + random.random()) * max_rank / 3.0) ratio = float(rank) / max_rank old_item_type, old_index = t.item_type, t.item_index old_ratio = None if old_item_type == 1: old_ratio = old_index / 6.0 elif 2 <= old_item_type <= 4: old_item = ItemObject.superget(old_item_type, old_index) index = ItemObject.ranked.index(old_item)
def intershuffle_valid(self): if self.is_monster: return "miab" in get_activated_codes() return True
def cleanup(self): if "GBA" not in get_global_label(): self.innates |= 0x8 if "zerker" in get_activated_codes(): self.innates |= 0x800
def intershuffle_valid(self): return "equipshuffle" in get_activated_codes()
ALL_OBJECTS = [ g for g in globals().values() if isinstance(g, type) and issubclass(g, TableObject) and g not in [TableObject] ] codes = { "zerker": ["zerker"], "miab": ["miab"], "fight": ["fight"], "fiesta": ["fiesta"], } run_interface(ALL_OBJECTS, snes=True, codes=codes, custom_degree=True) for code in codes: if code in get_activated_codes(): print "%s CODE ACTIVATED." % code.upper() if "fiesta" in get_activated_codes(): do_fiesta() hexify = lambda x: "{0:0>2}".format("%x" % x) numify = lambda x: "{0: >3}".format(x) minmax = lambda x: (min(x), max(x)) randomize_rng() clean_and_write(ALL_OBJECTS) if "GBA" not in get_global_label(): rewrite_snes_meta("FF5-GC", VERSION, lorom=False) finish_interface() except Exception, e: