Skip to content

Commit

Permalink
Merge pull request #149 from 40Cakes/soft-resets
Browse files Browse the repository at this point in the history
Universal static soft-reset + Tower Duo methods
  • Loading branch information
40Cakes authored Dec 15, 2023
2 parents f9a8b90 + 6f582f2 commit 307fd9c
Show file tree
Hide file tree
Showing 14 changed files with 455 additions and 322 deletions.
2 changes: 1 addition & 1 deletion modules/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def print_stats(total_stats: dict, pokemon: Pokemon, session_pokemon: set, encou
case "basic":
console.print(
f"{rich_name}: PID: {str(hex(pokemon.personality_value)[2:]).upper()} | "
f"Lv.: {pokemon.level:,} | "
f"Lv: {pokemon.level:,} | "
f"Item: {pokemon.held_item.name if pokemon.held_item else '-'} | "
f"Nature: {pokemon.nature.name} | "
f"Ability: {pokemon.ability.name} | "
Expand Down
2 changes: 1 addition & 1 deletion modules/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def reload_config(self) -> str:
raise error
message = (
"[bold red]The configuration could not be loaded, no changes have been made.[/]\n"
"[bold yellow]This is Probably due to a malformed file."
"[bold yellow]This is probably due to a malformed file."
"For more information run the bot with the --debug flag.[/]"
)
return message
Expand Down
20 changes: 10 additions & 10 deletions modules/data/map.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,9 +368,9 @@ class MapRSE(Enum):
ARTISAN_CAVE_A = (24, 100)
UNDERWATER_L = (24, 101)
MARINE_CAVE = (24, 102) # Outside Kyogre Cave
MARINE_CAVE_A = (24, 103) # Kyogre Cave
MARINE_CAVE_A = (24, 103) # Main Kyogre Cave
TERRA_CAVE = (24, 104) # Outside Groudon Cave
TERRA_CAVE_A = (24, 105) # Groudon Cave
TERRA_CAVE_A = (24, 105) # Main Groudon Cave
ALTERING_CAVE = (24, 106)
METEOR_FALLS_D = (24, 107)

Expand Down Expand Up @@ -510,8 +510,8 @@ class MapRSE(Enum):
NAVEL_ROCK_E = (26, 71)
NAVEL_ROCK_F = (26, 72)
NAVEL_ROCK_G = (26, 73)
NAVEL_ROCK_H = (26, 74) # Ho-Oh
NAVEL_ROCK_I = (26, 75) # Ho-Oh
NAVEL_ROCK_H = (26, 74) # Below Ho-Oh Room
NAVEL_ROCK_I = (26, 75) # Main Ho-Oh Room
NAVEL_ROCK_J = (26, 76)
NAVEL_ROCK_K = (26, 77)
NAVEL_ROCK_L = (26, 78)
Expand All @@ -522,8 +522,8 @@ class MapRSE(Enum):
NAVEL_ROCK_Q = (26, 83)
NAVEL_ROCK_R = (26, 84)
NAVEL_ROCK_S = (26, 85)
NAVEL_ROCK_T = (26, 86) # Lugia
NAVEL_ROCK_U = (26, 87) # Lugia
NAVEL_ROCK_T = (26, 86) # Above Lugia Room
NAVEL_ROCK_U = (26, 87) # Main Lugia Room
TRAINER_HILL_F = (26, 88)

ROUTE_104_C = (27, 0)
Expand Down Expand Up @@ -723,12 +723,12 @@ class MapFRLG(Enum):
THREE_ISLE_PATH = (2, 34)
TANOBY_KEY = (2, 35)
NAVEL_ROCK = (2, 36)
NAVEL_ROCK_A = (2, 37)
NAVEL_ROCK_B = (2, 38)
NAVEL_ROCK_A = (2, 37) # Main Ho-Oh Room
NAVEL_ROCK_B = (2, 38) # Main Lugia Room
NAVEL_ROCK_C = (2, 39)
NAVEL_ROCK_D = (2, 40)
NAVEL_ROCK_E = (2, 41)
NAVEL_ROCK_F = (2, 42)
NAVEL_ROCK_F = (2, 42) # Below Ho-Oh Room
NAVEL_ROCK_G = (2, 43)
NAVEL_ROCK_H = (2, 44)
NAVEL_ROCK_I = (2, 45)
Expand All @@ -739,7 +739,7 @@ class MapFRLG(Enum):
NAVEL_ROCK_N = (2, 50)
NAVEL_ROCK_O = (2, 51)
NAVEL_ROCK_P = (2, 52)
NAVEL_ROCK_Q = (2, 53)
NAVEL_ROCK_Q = (2, 53) # Above Lugia Room
NAVEL_ROCK_R = (2, 54)
NAVEL_ROCK_S = (2, 55)
BIRTH_ISLAND = (2, 56)
Expand Down
27 changes: 22 additions & 5 deletions modules/encounter.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,22 @@ def encounter_pokemon(pokemon: Pokemon) -> None:

total_stats.log_encounter(pokemon, config.catch_block.block_list, custom_filter_result)

context.message = f"Encountered a {pokemon.species.name} with a shiny value of {pokemon.shiny_value:,}!"
encounter_summary = (
f"Encountered a {pokemon.species.name} with a shiny value of {pokemon.shiny_value:,}!\n\n"
f"PID: {str(hex(pokemon.personality_value)[2:]).upper()} | "
f"Lv: {pokemon.level:,} | "
f"Item: {pokemon.held_item.name if pokemon.held_item else '-'} | "
f"Nature: {pokemon.nature.name} | "
f"Ability: {pokemon.ability.name} \n"
f"IVs: HP: {pokemon.ivs.hp} | "
f"ATK: {pokemon.ivs.attack} | "
f"DEF: {pokemon.ivs.defence} | "
f"SPATK: {pokemon.ivs.special_attack} | "
f"SPDEF: {pokemon.ivs.special_defence} | "
f"SPD: {pokemon.ivs.speed} | "
f"Sum: {pokemon.ivs.sum()}"
)
context.message = encounter_summary

battle_type_flags = get_battle_type_flags()

Expand All @@ -38,25 +53,27 @@ def encounter_pokemon(pokemon: Pokemon) -> None:
save_pk3(pokemon)
state_tag = "shiny"
console.print("[bold yellow]Shiny found!")
context.message = "Shiny found! Bot has been switched to manual mode so you can catch it."
context.message = (
f"Shiny found! The bot has been switched to manual mode so you can catch it.\n{encounter_summary}"
)

alert_title = "Shiny found!"
alert_message = f"Found a shiny {pokemon.species.name}. 🥳"
alert_message = f"Found a shiny {pokemon.species.name}✨! 🥳"

elif custom_found:
if not config.logging.save_pk3.all and config.logging.save_pk3.custom:
save_pk3(pokemon)
state_tag = "customfilter"
console.print("[bold green]Custom filter Pokemon found!")
context.message = f"Custom filter triggered ({custom_filter_result})! Bot has been switched to manual mode so you can catch it."
context.message = f"Custom filter triggered ({custom_filter_result})! The bot has been switched to manual mode so you can catch it.\n{encounter_summary}"

alert_title = "Custom filter triggered!"
alert_message = f"Found a {pokemon.species.name} that matched one of your filters. ({custom_filter_result})"

elif BattleTypeFlag.ROAMER in battle_type_flags:
state_tag = "roamer"
console.print("[bold pink]Roaming Pokemon found!")
context.message = f"Roaming Pokemon found! Bot has been switched to manual mode so you can catch it."
context.message = f"Roaming Pokemon found! The bot has been switched to manual mode so you can catch it.\n{encounter_summary}"

alert_title = "Roaming Pokemon found!"
alert_message = f"Encountered a roaming {pokemon.species.name}."
Expand Down
8 changes: 4 additions & 4 deletions modules/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ def save_pk3(pokemon: Pokemon) -> None:
binary_file.write(pokemon.data)


def get_rng_state_history(name: str) -> list:
def get_rng_state_history() -> list:
default = []
try:
file = read_file(context.profile.path / "rng" / f"{name}.json")
file = read_file(context.profile.path / "soft_reset_frames.json")
data = json.loads(file) if file else default
return data
except SystemExit:
Expand All @@ -84,8 +84,8 @@ def get_rng_state_history(name: str) -> list:
return default


def save_rng_state_history(name: str, data: list) -> bool:
if write_file(context.profile.path / "rng" / f"{name}.json", json.dumps(data)):
def save_rng_state_history(data: list) -> bool:
if write_file(context.profile.path / "soft_reset_frames.json", json.dumps(data)):
return True
else:
return False
2 changes: 1 addition & 1 deletion modules/libmgba.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ def press_button(self, button: str = None, inputs: int = 0):
:param button: A GBA button to be pressed, if pressed on previous frame it will be released
:param inputs: Alternate raw input bitfield
"""
self._pressed_inputs |= (input_map[button] ^ self._prev_pressed_inputs) if not inputs else inputs
self._pressed_inputs |= (self._prev_pressed_inputs & input_map[button]) ^ input_map[button]

def hold_button(self, button: str = None, inputs: int = 0):
"""
Expand Down
13 changes: 9 additions & 4 deletions modules/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def main_loop() -> None:
if (
not mode
and get_game_state() == GameState.BATTLE
and context.bot_mode not in ["Starters", "Legendary Birds"]
and context.bot_mode not in ["Starters", "Static Soft Resets"]
):
if opponent_changed():
encounter_pokemon(get_opponent())
Expand Down Expand Up @@ -78,10 +78,15 @@ def main_loop() -> None:

mode = ModeBunnyHop()

case "Legendary Birds":
from modules.modes.legendary_birds import ModeLegendaryBirds
case "Static Soft Resets":
from modules.modes.soft_resets import ModeStaticSoftResets

mode = ModeLegendaryBirds()
mode = ModeStaticSoftResets()

case "Tower Duo":
from modules.modes.tower_duo import ModeTowerDuo

mode = ModeTowerDuo()

case "Ancient Legendaries":
from modules.modes.ancient_legendaries import ModeAncientLegendaries
Expand Down
11 changes: 10 additions & 1 deletion modules/modes/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
"""Contains modes of operation for the bot."""

available_bot_modes = ["Manual", "Spin", "Starters", "Fishing", "Bunny Hop", "Legendary Birds", "Ancient Legendaries"]
available_bot_modes = [
"Manual",
"Spin",
"Starters",
"Fishing",
"Bunny Hop",
"Static Soft Resets",
"Tower Duo",
"Ancient Legendaries",
]
Loading

0 comments on commit 307fd9c

Please sign in to comment.