Skip to content

Commit

Permalink
Merge branch 'main' into soft-resets
Browse files Browse the repository at this point in the history
  • Loading branch information
40Cakes authored Dec 14, 2023
2 parents da41fa3 + f9a8b90 commit d4166fb
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 14 deletions.
15 changes: 13 additions & 2 deletions modules/encounter.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from modules.files import save_pk3
from modules.gui.desktop_notification import desktop_notification
from modules.pokemon_storage import get_pokemon_storage
from modules.pokemon import Pokemon
from modules.pokemon import Pokemon, get_battle_type_flags, BattleTypeFlag
from modules.stats import total_stats


Expand All @@ -29,8 +29,10 @@ def encounter_pokemon(pokemon: Pokemon) -> None:

context.message = f"Encountered a {pokemon.species.name} with a shiny value of {pokemon.shiny_value:,}!"

battle_type_flags = get_battle_type_flags()

# TODO temporary until auto-catch is ready
if pokemon.is_shiny or custom_found:
if pokemon.is_shiny or custom_found or BattleTypeFlag.ROAMER in battle_type_flags:
if pokemon.is_shiny:
if not config.logging.save_pk3.all and config.logging.save_pk3.shiny:
save_pk3(pokemon)
Expand All @@ -50,6 +52,15 @@ def encounter_pokemon(pokemon: Pokemon) -> None:

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."

alert_title = "Roaming Pokemon found!"
alert_message = f"Encountered a roaming {pokemon.species.name}."

else:
state_tag = ""
alert_title = None
Expand Down
1 change: 1 addition & 0 deletions modules/gui/create_profile_screen.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ def handle_selected_file(selection: list[str]) -> None:
"*.ss7",
"*.ss8",
"*.ss9",
"*.sav",
]
],
title="Load Existing Save",
Expand Down
10 changes: 8 additions & 2 deletions modules/items.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,14 @@ def has_space_for(self, item: Item) -> bool:
if len(pocket) < pocket_size:
return True

# In FireRed/LeafGreen, you can always put 999 items in a stack. In RSE, this only works for berries.
if context.rom.game_title in ["POKEMON FIRE", "POKEMON LEAF"] or item.pocket == ItemPocket.Berries:
stack_size = 999
else:
stack_size = 99

for slot in pocket:
if slot.item == item and slot.quantity < 99:
if slot.item == item and slot.quantity < stack_size:
return True

return False
Expand Down Expand Up @@ -243,7 +249,7 @@ def has_space_for(self, item: Item) -> bool:
return True

for slot in self.items:
if slot.item == item and slot.quantity < 99:
if slot.item == item and slot.quantity < 999:
return True

return False
Expand Down
40 changes: 37 additions & 3 deletions modules/pokemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -1511,7 +1511,42 @@ def get_opponent() -> Pokemon:


class BattleTypeFlag(Flag, boundary=KEEP):
BATTLE_TYPE_TRAINER = 1 << 3
DOUBLE = 1 << 0
LINK = 1 << 1
IS_MASTER = 1 << 2
TRAINER = 1 << 3
FIRST_BATTLE = 1 << 4
LINK_IN_BATTLE = 1 << 5
MULTI = 1 << 6
SAFARI = 1 << 7
BATTLE_TOWER = 1 << 8
WALLY_TUTORIAL = 1 << 9
ROAMER = 1 << 10
EREADER_TRAINER = 1 << 11
KYOGRE_GROUDON = 1 << 12
LEGENDARY = 1 << 13
REGI = 1 << 14
TWO_OPPONENTS = 1 << 15
DOME = 1 << 16
PALACE = 1 << 17
ARENA = 1 << 18
FACTORY = 1 << 19
PIKE = 1 << 20
PYRAMID = 1 << 21
INGAME_PARTNER = 1 << 22
TOWER_LINK_MULTI = 1 << 23
RECORDED = 1 << 24
RECORDED_LINK = 1 << 25
TRAINER_HILL = 1 << 26
SECRET_BASE = 1 << 27
GROUDON = 1 << 28
KYOGRE = 1 << 29
RAYQUAZA = 1 << 30
RECORDED_IS_MASTER = 1 << 31


def get_battle_type_flags() -> BattleTypeFlag:
return BattleTypeFlag(unpack_uint32(read_symbol("gBattleTypeFlags")))


def opponent_changed() -> bool:
Expand All @@ -1524,11 +1559,10 @@ def opponent_changed() -> bool:
try:
global last_opid
opponent_pid = read_symbol("gEnemyParty", size=4)
g_battle_type_flags = read_symbol("gBattleTypeFlags", size=4)
if (
opponent_pid != last_opid
and opponent_pid != b"\x00\x00\x00\x00"
and (BattleTypeFlag.BATTLE_TYPE_TRAINER not in BattleTypeFlag(unpack_uint32(g_battle_type_flags)))
and (BattleTypeFlag.TRAINER not in get_battle_type_flags())
):
last_opid = opponent_pid
return True
Expand Down
2 changes: 1 addition & 1 deletion modules/profiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def load_profile(path: Path) -> Profile:
[
rom.game_code == metadata.rom.game_code,
rom.revision == metadata.rom.revision,
rom.language == metadata.rom.language,
rom.language.value == metadata.rom.language,
]
):
return Profile(rom, path, last_played)
Expand Down
28 changes: 23 additions & 5 deletions modules/web/http_example.html
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ <h2>Event Log</h2>
*/
function handlePartyChange(data)
{
for (let index = 0; index < 6; index++) {
for (let index = 0; index < data.length; index++) {
const listEntry = document.getElementById("party" + index);

const nameParts = [];
Expand Down Expand Up @@ -305,7 +305,14 @@ <h2>Event Log</h2>
hpBarColoured.style.backgroundColor = "#080";
}
hpBar.append(hpBarColoured);
listEntry.append(hpBar);

const expBar = document.createElement("div");
expBar.className = "exp-bar";
const expBarColoured = document.createElement("div");
expBarColoured.style.width = `${data[index].exp_fraction_to_next_level * 100}%`;
expBar.append(expBarColoured);

listEntry.append(hpBar, expBar);
}
}

Expand Down Expand Up @@ -646,14 +653,25 @@ <h2>Current Encounter</h2>
margin-bottom: .5rem;
}

.party-entry .hp-bar {
height: 3px;
.party-entry .hp-bar, .party-entry .exp-bar {
width: 200px;
background-color: #ddd;
border: 1px #888 solid;
}

.party-entry .hp-bar {
height: 5px;
margin-top: 2px;
}

.party-entry .exp-bar {
height: 3px;
margin-top: 1px;
}

.party-entry .hp-bar div {
.party-entry .hp-bar div, .party-entry .exp-bar div {
height: 100%;
background-color: #5ae;
}

.encounter-container {
Expand Down
2 changes: 1 addition & 1 deletion modules/web/pokemon.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export type Type = {
index: number;

// English name of this type.
name: string;
name: TypeName;

kind: "???" | "Physical" | "Special";
}
Expand Down

0 comments on commit d4166fb

Please sign in to comment.