mirror of
https://github.com/LmeSzinc/StarRailCopilot.git
synced 2024-11-23 00:52:22 +00:00
commit
8c711d2d5f
@ -3,7 +3,6 @@ import logging
|
||||
import re
|
||||
import socket
|
||||
import subprocess
|
||||
import sys
|
||||
import time
|
||||
from functools import wraps
|
||||
|
||||
@ -12,10 +11,10 @@ from adbutils import AdbClient, AdbDevice, AdbTimeout, ForwardItem, ReverseItem
|
||||
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)
|
||||
@ -313,8 +312,16 @@ class Connection(ConnectionAttr):
|
||||
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):
|
||||
@ -337,7 +344,7 @@ class Connection(ConnectionAttr):
|
||||
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)
|
||||
@ -841,7 +848,7 @@ class Connection(ConnectionAttr):
|
||||
# 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:
|
||||
@ -903,7 +910,10 @@ class Connection(ConnectionAttr):
|
||||
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:
|
||||
@ -920,7 +930,8 @@ class Connection(ConnectionAttr):
|
||||
# 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')
|
||||
|
5
module/device/env.py
Normal file
5
module/device/env.py
Normal file
@ -0,0 +1,5 @@
|
||||
import sys
|
||||
|
||||
IS_WINDOWS = sys.platform == 'win32'
|
||||
IS_MACINTOSH = sys.platform == 'darwin'
|
||||
IS_LINUX = sys.platform == 'linux'
|
@ -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
|
||||
|
@ -330,15 +330,17 @@ class InventoryManager:
|
||||
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
|
||||
@ -346,6 +348,8 @@ class InventoryManager:
|
||||
self.main.device.screenshot()
|
||||
|
||||
self.update()
|
||||
|
||||
# End
|
||||
if timeout.reached():
|
||||
logger.warning('Wait inventory selected timeout')
|
||||
return False
|
||||
@ -353,3 +357,12 @@ class InventoryManager:
|
||||
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()
|
||||
|
@ -213,7 +213,8 @@ class Synthesize(CombatObtain, ItemUI):
|
||||
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()')
|
||||
|
@ -23,6 +23,7 @@ DETAIL_TITLE.load_search(RESULT_CHECK.search)
|
||||
|
||||
class OcrItemName(Ocr):
|
||||
def after_process(self, result):
|
||||
result = result.replace('方相果实', '万相果实')
|
||||
result = result.replace('念火之心', '忿火之心')
|
||||
result = re.sub('^火之心', '忿火之心', result)
|
||||
result = re.sub('工造机$', '工造机杼', result)
|
||||
|
@ -112,6 +112,9 @@ class RogueReward(RogueUI, CombatInteract, DungeonState):
|
||||
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')
|
||||
|
Loading…
Reference in New Issue
Block a user