Skip to content

Commit

Permalink
Merge pull request LmeSzinc#575 from LmeSzinc/dev
Browse files Browse the repository at this point in the history
Bug fix
  • Loading branch information
LmeSzinc authored Jul 12, 2024
2 parents ef892a1 + 287f513 commit 8c711d2
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 11 deletions.
25 changes: 18 additions & 7 deletions module/device/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import re
import socket
import subprocess
import sys
import time
from functools import wraps

Expand All @@ -12,10 +11,10 @@
from adbutils.errors import AdbError

import module.config.server as server_
import platform
from module.base.decorator import Config, cached_property, del_cached_property, run_once
from module.base.utils import SelectedGrids, ensure_time
from module.device.connection_attr import ConnectionAttr
from module.device.env import IS_LINUX, IS_MACINTOSH, IS_WINDOWS
from module.device.method.utils import (
PackageNotInstalled, RETRY_TRIES, get_serial_pair, handle_adb_error,
possible_reasons, random_port, recv_all, remove_shell_warning, retry_sleep)
Expand Down Expand Up @@ -313,8 +312,16 @@ def is_mumu_over_version_356(self) -> bool:
Returns:
bool: If MuMu12 version >= 3.5.6,
which has nemud.app_keep_alive and always be a vertical device
MuMu PRO on mac has the same feature
"""
return self.nemud_app_keep_alive != ''
if self.nemud_app_keep_alive != '':
return True
if IS_MACINTOSH:
res = self.adb_getprop('nemud.player_engine')
logger.attr('nemud.player_engine', res)
if 'MACPRO' in res:
return True
return False

@cached_property
def _nc_server_host_port(self):
Expand All @@ -337,7 +344,7 @@ def _nc_server_host_port(self):
logger.error(e)
logger.error(f'Unknown host name: {socket.gethostname()}')
host = '127.0.0.1'
if platform.system() == 'Linux' and host == '127.0.1.1':
if IS_LINUX and host == '127.0.1.1':
host = '127.0.0.1'
logger.info(f'Connecting to local emulator, using host {host}')
port = random_port(self.config.FORWARD_PORT_RANGE)
Expand Down Expand Up @@ -841,7 +848,7 @@ def brute_force_connect():
# brute_force_connect
if self.config.Emulator_Serial == 'auto' and available.count == 0:
logger.warning(f'No available device found')
if sys.platform == 'win32':
if IS_WINDOWS:
brute_force_connect()
continue
else:
Expand Down Expand Up @@ -903,7 +910,10 @@ def brute_force_connect():
self.serial = emu_serial

# Redirect MuMu12 from 127.0.0.1:7555 to 127.0.0.1:16xxx
if self.serial == '127.0.0.1:7555':
if (
(IS_WINDOWS and self.serial == '127.0.0.1:7555')
or (IS_MACINTOSH and self.serial == '127.0.0.1:5555')
):
for _ in range(2):
mumu12 = available.select(may_mumu12_family=True)
if mumu12.count == 1:
Expand All @@ -920,7 +930,8 @@ def brute_force_connect():
# is_mumu_over_version_356 and nemud_app_keep_alive was cached
# Acceptable since it's the same device
logger.warning(f'Device {self.serial} is MuMu12 but corresponding port not found')
brute_force_connect()
if IS_WINDOWS:
brute_force_connect()
devices = self.list_device()
# Show available devices
available = devices.select(status='device')
Expand Down
5 changes: 5 additions & 0 deletions module/device/env.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import sys

IS_WINDOWS = sys.platform == 'win32'
IS_MACINTOSH = sys.platform == 'darwin'
IS_LINUX = sys.platform == 'linux'
4 changes: 2 additions & 2 deletions module/device/platform/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import sys
from module.device.env import IS_WINDOWS

if sys.platform == 'win32':
if IS_WINDOWS:
from module.device.platform.platform_windows import PlatformWindows as Platform
else:
from module.device.platform.platform_base import PlatformBase as Platform
15 changes: 14 additions & 1 deletion tasks/item/inventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,26 +330,39 @@ def select(self, item, skip_first_screenshot=True):
clicked = True
continue

def wait_selected(self, skip_first_screenshot=True):
def wait_selected(self, select_first=False, skip_first_screenshot=True):
"""
Args:
select_first: True to click first item if no item was selected
skip_first_screenshot:
Returns:
bool: If success
"""
timeout = Timer(2, count=6).start()
interval = Timer(1, count=3)
while 1:
if skip_first_screenshot:
skip_first_screenshot = False
else:
self.main.device.screenshot()

self.update()

# End
if timeout.reached():
logger.warning('Wait inventory selected timeout')
return False
if len(self.items) > self.MAXIMUM_ITEMS:
continue
if self.selected is not None:
return True

# Click
if select_first:
first = self.get_first()
if first is None:
logger.warning(f'No items detected, cannot select inventory')
elif interval.reached():
self.main.device.click(first)
interval.reset()
3 changes: 2 additions & 1 deletion tasks/item/synthesize.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,8 @@ def synthesize_rarity_reset(self, inv, skip_first_screenshot=True):
if inv is not None:
if inv.wait_selected():
return True
else:
# Game bug that selection may have lost after setting rarity
elif inv.wait_selected(select_first=True):
continue
else:
logger.info('synthesize_rarity_reset ended without wait_selected()')
Expand Down
1 change: 1 addition & 0 deletions tasks/planner/scan.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

class OcrItemName(Ocr):
def after_process(self, result):
result = result.replace('方相果实', '万相果实')
result = result.replace('念火之心', '忿火之心')
result = re.sub('^火之心', '忿火之心', result)
result = re.sub('工造机$', '工造机杼', result)
Expand Down
3 changes: 3 additions & 0 deletions tasks/rogue/event/reward.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ def can_claim_domain_reward(
if not use_trailblaze_power and not use_immersifier:
logger.info('Cannot claim domain reward, as all disabled')
return False
if self.config.is_task_enabled('Ornament'):
logger.info(f'Cannot claim domain reward, saving immersifiers for ornament')
return False
if use_immersifier:
if self.config.stored.Immersifier.value > 0:
logger.info(f'Can claim domain reward, got immersifiers')
Expand Down

0 comments on commit 8c711d2

Please sign in to comment.