Skip to content

Commit

Permalink
Merge branch 'release/2.0.0a8' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
Konano committed Feb 24, 2022
2 parents be4c07a + fc8722b commit 117846d
Show file tree
Hide file tree
Showing 17 changed files with 396 additions and 72 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,18 @@ screenshot/*
screenshot_right/*
test/*
test_*
test.py
release.sh

# Windows
venv64
release_test.bat
publish/*

# Myself
test.py
cron.py
cron.json

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
Expand Down
2 changes: 1 addition & 1 deletion arknights_mower/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@
__cli__ = not (__pyinstall__ and not sys.argv[1:])

__system__ = platform.system().lower()
__version__ = '2.0.0a7'
__version__ = '2.0.0a8'
91 changes: 41 additions & 50 deletions arknights_mower/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from .utils import config
from .utils.log import logger
from .utils.device import Device
from .utils.operation import parse_operation_params


class ParamError(ValueError):
Expand Down Expand Up @@ -110,35 +111,7 @@ def operation(args: list[str] = [], device: Device = None):
config.update_ope_plan(remain_plan)
return

level = None
times = -1
potion = 0
originite = 0
eliminate = False

try:
for p in args:
if p[0] == '-':
val = -1
if len(p) > 2:
val = int(p[2:])
if p[1] == 'r':
assert potion == 0
potion = val
elif p[1] == 'R':
assert originite == 0
originite = val
elif p[1] == 'e':
assert not eliminate
eliminate = True
elif p.find('-') == -1:
assert times == -1
times = int(p)
else:
assert level is None
level = p
except Exception:
raise ParamError
level, times, potion, originite, eliminate = parse_operation_params(args)

OpeSolver(device).run(level, times, potion, originite, eliminate)

Expand Down Expand Up @@ -169,27 +142,17 @@ def help(args: list[str] = [], device: Device = None):
print(f' --config filepath\n 指定配置文件,默认使用 {config.PATH}')


def schedule(args: list[str] = [], device: Device = None):
"""
schedule
执行配置文件中的计划任务
"""
if config.SCHEDULE_PLAN is not None:
sd.every().hour.do(task, tag='per_hour', device=device)
for tag in config.SCHEDULE_PLAN.keys():
if tag[:4] == 'day_':
sd.every().day.at(tag.replace('_', ':')[4:]).do(
task, tag=tag, device=device)
task(device=device)
while True:
sd.run_pending()
time.sleep(60)
else:
logger.warning('empty plan')
"""
commands for schedule
operation will be replaced by operation_one in ScheduleSolver
"""
schedule_cmds = [base, credit, mail, mission, shop, recruit, operation]


def task(tag: str = 'start_up', device: Device = None):
""" run single task """
def add_tasks(solver: ScheduleSolver = None, tag: str = ''):
"""
为 schedule 模块添加任务
"""
plan = config.SCHEDULE_PLAN.get(tag)
if plan is not None:
for args in plan:
Expand All @@ -199,13 +162,41 @@ def task(tag: str = 'start_up', device: Device = None):
'Found `schedule` in `schedule`. Are you kidding me?')
raise NotImplementedError
try:
target_cmd = match_cmd(args[0])
target_cmd = match_cmd(args[0], schedule_cmds)
if target_cmd is not None:
target_cmd(args[1:], device)
solver.add_task(tag, target_cmd, args[1:])
except Exception as e:
logger.error(e)


def schedule(args: list[str] = [], device: Device = None):
"""
schedule
执行配置文件中的计划任务
计划执行时会自动存档至本地磁盘,启动时若检测到有存档,则会使用存档内容继续完成计划
-n 忽略之前中断的计划任务,按照配置文件重新开始新的计划
"""
new_schedule = False

try:
for p in args:
if p[0] == '-':
if p[1] == 'n':
new_schedule = True
except Exception:
raise ParamError

solver = ScheduleSolver(device)
if new_schedule or solver.load_from_disk(schedule_cmds, match_cmd) is False:
if config.SCHEDULE_PLAN is not None:
for tag in config.SCHEDULE_PLAN.keys():
add_tasks(solver, tag)
else:
logger.warning('empty plan')
solver.per_run()
solver.run()


# all available commands
global_cmds = [base, credit, mail, mission, shop,
recruit, operation, version, help, schedule]
Expand Down
1 change: 1 addition & 0 deletions arknights_mower/solvers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
from .operation import OpeSolver
from .recruit import RecruitSolver
from .shop import ShopSolver
from .schedule import ScheduleSolver
6 changes: 3 additions & 3 deletions arknights_mower/solvers/base_construct.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def clue(self) -> None:
self.find('clue_summary') and self.back()

# 识别右侧按钮
(x0, y0), (x1, y1) = self.find('clue_func')
(x0, y0), (x1, y1) = self.find('clue_func', strict=True)

logger.info('接收赠送线索')
self.tap(((x0+x1)//2, (y0*3+y1)//4), interval=3, rebuild=False)
Expand Down Expand Up @@ -203,7 +203,7 @@ def recog_bar(self) -> None:
""" 识别阵营选择栏 """
global x1, x2, y0, y1

(x1, y0), (x2, y1) = self.find('clue_nav')
(x1, y0), (x2, y1) = self.find('clue_nav', strict=True)
while int(self.recog.img[y0, x1-1].max()) - int(self.recog.img[y0, x1].max()) <= 1:
x1 -= 1
while int(self.recog.img[y0, x2].max()) - int(self.recog.img[y0, x2-1].max()) <= 1:
Expand Down Expand Up @@ -328,7 +328,7 @@ def enter_room(self, room: str) -> tp.Rectangle:
""" 获取房间的位置并进入 """

# 获取基建各个房间的位置
base_room = segment.base(self.recog.img, self.find('control_central'))
base_room = segment.base(self.recog.img, self.find('control_central', strict=True))

# 将画面外的部分删去
room = base_room[room]
Expand Down
2 changes: 1 addition & 1 deletion arknights_mower/solvers/credit.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def transition(self) -> bool:
elif self.scene() == Scene.FRIEND_LIST_OFF:
self.tap_element('friend_list')
elif self.scene() == Scene.FRIEND_LIST_ON:
down = self.find('friend_list_on')[1][1]
down = self.find('friend_list_on', strict=True)[1][1]
scope = [(0, 0), (100000, down)]
if not self.tap_element('friend_visit', scope=scope, detected=True):
self.sleep(1)
Expand Down
6 changes: 3 additions & 3 deletions arknights_mower/solvers/operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,15 +406,15 @@ def choose_zone_supple(self, zone: list, scope: tp.Scope) -> None:
def choose_zone_resource(self, zone: list) -> None:
""" 识别资源收集区域 """
ocr = ocrhandle.predict(self.recog.img)
unable = list(filter(lambda x: x[1] == '不可进入', ocr))
unable = list(filter(lambda x: x[1] in ['不可进入', '关卡尚未开放'], ocr))
ocr = list(filter(lambda x: x[1] in weekly_zones, ocr))
weekly = sorted([x[1] for x in ocr])
while zone[0] not in weekly:
_weekly = weekly
self.swipe((self.recog.w // 4, self.recog.h // 4),
(self.recog.w // 16, 0))
ocr = ocrhandle.predict(self.recog.img)
unable = list(filter(lambda x: x[1] == '不可进入', ocr))
unable = list(filter(lambda x: x[1] in ['不可进入', '关卡尚未开放'], ocr))
ocr = list(filter(lambda x: x[1] in weekly_zones, ocr))
weekly = sorted([x[1] for x in ocr])
if _weekly == weekly:
Expand All @@ -424,7 +424,7 @@ def choose_zone_resource(self, zone: list) -> None:
self.swipe((self.recog.w // 4, self.recog.h // 4),
(-self.recog.w // 16, 0))
ocr = ocrhandle.predict(self.recog.img)
unable = list(filter(lambda x: x[1] == '不可进入', ocr))
unable = list(filter(lambda x: x[1] in ['不可进入', '关卡尚未开放'], ocr))
ocr = list(filter(lambda x: x[1] in weekly_zones, ocr))
weekly = sorted([x[1] for x in ocr])
if _weekly == weekly:
Expand Down
Loading

0 comments on commit 117846d

Please sign in to comment.