Skip to content

Commit

Permalink
Pokemon Emerald: Send current map to trackers (ArchipelagoMW#3726)
Browse files Browse the repository at this point in the history
  • Loading branch information
Zunawe authored and agilbert1412 committed Aug 24, 2024
1 parent 16ddbde commit 0f0986a
Showing 1 changed file with 29 additions and 0 deletions.
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

0 comments on commit 0f0986a

Please sign in to comment.