Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pokemon Emerald: Send current map to trackers #3726

Merged
merged 1 commit into from
Aug 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions worlds/pokemon_emerald/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ class PokemonEmeraldClient(BizHawkClient):
previous_death_link: float
ignore_next_death_link: bool

current_map: Optional[int]

def __init__(self) -> None:
super().__init__()
self.local_checked_locations = set()
Expand All @@ -150,6 +152,7 @@ def __init__(self) -> None:
self.death_counter = None
self.previous_death_link = 0
self.ignore_next_death_link = False
self.current_map = None

async def validate_rom(self, ctx: "BizHawkClientContext") -> bool:
from CommonClient import logger
Expand Down Expand Up @@ -243,6 +246,7 @@ async def game_watcher(self, ctx: "BizHawkClientContext") -> None:
sb1_address = int.from_bytes(guards["SAVE BLOCK 1"][1], "little")
sb2_address = int.from_bytes(guards["SAVE BLOCK 2"][1], "little")

await self.handle_tracker_info(ctx, guards)
await self.handle_death_link(ctx, guards)
await self.handle_received_items(ctx, guards)
await self.handle_wonder_trade(ctx, guards)
Expand Down Expand Up @@ -403,6 +407,31 @@ async def game_watcher(self, ctx: "BizHawkClientContext") -> None:
# Exit handler and return to main loop to reconnect
pass

async def handle_tracker_info(self, ctx: "BizHawkClientContext", guards: Dict[str, Tuple[int, bytes, str]]) -> None:
# Current map
sb1_address = int.from_bytes(guards["SAVE BLOCK 1"][1], "little")

read_result = await bizhawk.guarded_read(
ctx.bizhawk_ctx,
[(sb1_address + 0x4, 2, "System Bus")],
[guards["SAVE BLOCK 1"]]
)
if read_result is None: # Save block moved
return

current_map = int.from_bytes(read_result[0], "big")
if current_map != self.current_map:
self.current_map = current_map
await ctx.send_msgs([{
"cmd": "Bounce",
"slots": [ctx.slot],
"tags": ["Tracker"],
"data": {
"type": "MapUpdate",
"mapId": current_map,
},
}])

async def handle_death_link(self, ctx: "BizHawkClientContext", guards: Dict[str, Tuple[int, bytes, str]]) -> None:
"""
Checks whether the player has died while connected and sends a death link if so. Queues a death link in the game
Expand Down
Loading