Last active
October 19, 2020 18:50
-
-
Save Kraballa/33f1fa78b9698c8664084f844296b3f0 to your computer and use it in GitHub Desktop.
pokecrystal encounter checker. check for pokemon without encounters and more
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# made for people modifying pret/pokecrystal who want to | |
# check what pokemon need changes in their wild encounter | |
# rates. prints 2 tables, one containing a list of all | |
# pokemon without encounters, one containing all | |
# encounters sorted by their total overall probability | |
# | |
# 1. place this file in your ./tools folder | |
# 2. make sure the paths and encounter rates below are accurate (only if you changed them) | |
# 3. if you don't want to incorporate water encounters comment out the last 2 'parse_encounters' lines | |
# 4. finally run 'python encounter_checker.py' | |
# | |
# made with python 3 | |
# licensed under gpl3 | |
from dataclasses import dataclass | |
POKE_CONST = "../constants/pokemon_constants.asm" | |
JOHTO_GRASS = "../data/wild/johto_grass.asm" | |
KANTO_GRASS = "../data/wild/kanto_grass.asm" | |
JOHTO_WATER = "../data/wild/johto_water.asm" | |
KANTO_WATER = "../data/wild/kanto_water.asm" | |
PROB = [30,30,20,10,5,4,1] | |
WATER_PROB = [60,30,10] | |
@dataclass | |
class EncounterData: | |
name: str | |
areas: int | |
prob: int | |
def __repr__(self): | |
return f"{self.name: <14} areas:{self.areas: >2}, prob:{self.prob: >4}" | |
def parse_poke_contants(): | |
table = {} | |
with open(POKE_CONST, "r") as consts: | |
lines = consts.readlines() | |
for line in lines: | |
line = line.strip() | |
if line.startswith("const "): | |
name = line.split(" ")[1] | |
table[name] = EncounterData(name,0,0) | |
return table | |
def parse_encounters(table, file, prob, num_lines): | |
with open(file) as data: | |
line = data.readline() | |
while line: | |
if line.strip().startswith("map_id"): | |
data.readline() # skip encounter rates | |
remaining = num_lines | |
lines = [] | |
while remaining > 0: | |
line = data.readline().strip() | |
while not line.startswith("db"): | |
line = data.readline().strip() | |
lines.append(line) | |
remaining -= 1 | |
parse_area_data(lines, table, prob) | |
line = data.readline() | |
def parse_area_data(lines, table, prob): | |
index = 0 | |
encountered = [] | |
for line in lines: | |
name = line.split(",")[1].strip() | |
table[name].prob += prob[index] | |
if(not name in encountered): | |
table[name].areas += 1 | |
encountered.append(name) | |
index += 1 | |
if index > len(prob)-1: | |
index = 0 | |
def visualize(table): | |
no_enc = [] | |
enc = [] | |
for (k,value) in table.items(): | |
if(value.areas > 0): | |
enc.append(value) | |
else: | |
no_enc.append(value) | |
no_enc.sort(key=lambda item:item.name) | |
enc.sort(key=lambda item:item.prob, reverse=True) | |
print("+-------------------------------------+-----------------------------------+") | |
print("| mons without encounters | mons sorted by encounters |") | |
print("+-------------------------------------+-----------------------------------+") | |
pad = " " | |
if(len(no_enc) < len(enc)): | |
for _ in range(len(enc) - len(no_enc)): | |
no_enc.append(f"{pad: <34}") | |
elif(len(no_enc) > len(enc)): | |
for _ in range(len(no_enc) - len(enc)): | |
enc.append(f"{pad: <34}") | |
for (a,b) in zip(no_enc, enc): | |
print(a, "\t", b) | |
if __name__ == "__main__": | |
table = parse_poke_contants() | |
# 3 different sets of encounters and 7 encounters each | |
parse_encounters(table, JOHTO_GRASS, PROB, 3 * 7) | |
parse_encounters(table, KANTO_GRASS, PROB, 3 * 7) | |
# 3 encounters each | |
parse_encounters(table, JOHTO_WATER, WATER_PROB, 3) | |
parse_encounters(table, KANTO_WATER, WATER_PROB, 3) | |
visualize(table) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment