Skip to content

Commit 711469a

Browse files
committed
fix: Open map briefing to detect map before entering round
fixes #34
1 parent 672c0ca commit 711469a

3 files changed

Lines changed: 40 additions & 0 deletions

File tree

BF2AutoSpectator/common/constants.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
'disconnect-prompt-yes-button': (706, 394),
2727
'disconnect-button': (1210, 725),
2828
'game-message-close-button': (806, 412),
29+
'map-briefing-eor-item': (750, 85),
2930
'join-game-button': (1210, 725),
3031
'spawnpoint-deselect': (250, 50),
3132
'suicide-button': (469, 459)
@@ -82,6 +83,7 @@
8283
'disconnect-prompt-yes-button': (885, 487),
8384
'disconnect-button': (1468, 906),
8485
'game-message-close-button': (1002, 501),
86+
'map-briefing-eor-item': (938, 97),
8587
'join-game-button': (1468, 906),
8688
'spawnpoint-deselect': (250, 50),
8789
'suicide-button': (497, 455)

BF2AutoSpectator/game/instance_manager.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,29 @@ def is_map_briefing_visible(self) -> bool:
345345
image_ops=[(ImageOperation.invert, None)]
346346
)
347347

348+
def open_map_briefing(self) -> bool:
349+
# Don't block any OCR regions
350+
mouse_reset(self.game_window)
351+
352+
if self.is_map_briefing_visible():
353+
return True
354+
355+
# Cannot open map briefing unless join game button is visible
356+
if not self.is_join_game_button_visible():
357+
return False
358+
359+
# Move cursor onto map briefing header and click
360+
mouse_move_to_game_window_coord(self.game_window, self.resolution, 'map-briefing-eor-item')
361+
time.sleep(.2)
362+
mouse_click_in_game_window(self.game_window, legacy=True)
363+
364+
time.sleep(.5)
365+
366+
# Move cursor back to default position
367+
mouse_reset(self.game_window)
368+
369+
return self.is_map_briefing_visible()
370+
348371
def is_spawn_menu_visible(self) -> bool:
349372
histogram = histogram_screenshot_region(
350373
self.game_window,

BF2AutoSpectator/spectate.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -584,6 +584,21 @@ def run():
584584
cc.update_game_phase(GamePhase.betweenRounds)
585585
gis.round_end_reset()
586586
continue
587+
588+
"""
589+
When server "rotates" on the same map, we enter the loading state and reset the map details.
590+
However, the map briefing is not opened automatically. So unless we open it manually, we never see the
591+
map briefing and thus cannot detect the map.
592+
"""
593+
if gim.is_join_game_button_visible():
594+
logger.info('Join game button is visible but map briefing is not, opening map briefing')
595+
if not gim.open_map_briefing():
596+
logger.error('Failed to open map briefing, attempting to join game and queuing reconnect')
597+
# We need to join the game, else the ESC press to open the menu will join the game instead of
598+
# opening the menu
599+
gim.join_game()
600+
gis.set_spectator_on_server(False)
601+
continue
587602
time.sleep(3)
588603
elif default_camera_view_visible and gis.round_spawned() and \
589604
iterations_on_default_camera_view == 0:

0 commit comments

Comments
 (0)