From 89fad04c006e05dc3b61f6323ec80956a0ba4843 Mon Sep 17 00:00:00 2001 From: Zhao Zuohong Date: Mon, 6 Nov 2023 11:41:16 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=86=E5=9F=BA=E5=BB=BA=E9=87=8D=E5=A4=8D?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=E6=8F=90=E5=8F=96=E5=88=B0Mixin=E4=B8=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- arknights_mower/solvers/base_construct.py | 84 +--------------- arknights_mower/solvers/base_mixin.py | 113 ++++++++++++++++++++++ arknights_mower/solvers/base_schedule.py | 79 +-------------- 3 files changed, 118 insertions(+), 158 deletions(-) create mode 100644 arknights_mower/solvers/base_mixin.py diff --git a/arknights_mower/solvers/base_construct.py b/arknights_mower/solvers/base_construct.py index 6dbd1ebc3..31cd9bb94 100644 --- a/arknights_mower/solvers/base_construct.py +++ b/arknights_mower/solvers/base_construct.py @@ -1,7 +1,5 @@ from __future__ import annotations -from enum import Enum - import numpy as np from ..data import base_room_list @@ -15,22 +13,10 @@ import copy +from arknights_mower.solvers.base_mixin import ArrangeOrder, arrange_order_res, BaseMixin -class ArrangeOrder(Enum): - STATUS = 1 - SKILL = 2 - FEELING = 3 - TRUST = 4 - -arrange_order_res = { - ArrangeOrder.STATUS: (1560 / 2496, 96 / 1404), - ArrangeOrder.SKILL: (1720 / 2496, 96 / 1404), - ArrangeOrder.FEELING: (1880 / 2496, 96 / 1404), - ArrangeOrder.TRUST: (2050 / 2496, 96 / 1404), -} - -class BaseConstructSolver(BaseSolver): +class BaseConstructSolver(BaseSolver, BaseMixin): """ 收集基建的产物:物资、赤金、信赖 """ @@ -45,6 +31,7 @@ def run(self, arrange: dict[str, tp.BasePlan] = None, clue_collect: bool = False :param drone_room: str, 是否使用无人机加速 :param fia_room: str, 是否使用菲亚梅塔恢复心情 """ + self.last_room = "" self.arrange = arrange self.clue_collect = clue_collect self.drone_room = drone_room @@ -408,75 +395,10 @@ def drone(self, room: str): self.back(interval=2) - def switch_arrange_order(self, index: int, asc="false") -> None: - self.tap((self.recog.w * arrange_order_res[ArrangeOrder(index)][0], - self.recog.h * arrange_order_res[ArrangeOrder(index)][1]), interval=0, rebuild=False) - # 点个不需要的 - if index < 4: - self.tap((self.recog.w * arrange_order_res[ArrangeOrder(index + 1)][0], - self.recog.h * arrange_order_res[ArrangeOrder(index)][1]), interval=0, rebuild=False) - else: - self.tap((self.recog.w * arrange_order_res[ArrangeOrder(index - 1)][0], - self.recog.h * arrange_order_res[ArrangeOrder(index)][1]), interval=0, rebuild=False) - # 切回来 - self.tap((self.recog.w * arrange_order_res[ArrangeOrder(index)][0], - self.recog.h * arrange_order_res[ArrangeOrder(index)][1]), interval=0.2, rebuild=True) - # 倒序 - if asc != "false": - self.tap((self.recog.w * arrange_order_res[ArrangeOrder(index)][0], - self.recog.h * arrange_order_res[ArrangeOrder(index)][1]), interval=0.2, rebuild=True) - - - def scan_agent(self, agent: list[str], error_count=0, max_agent_count=-1): - try: - # 识别干员 - self.recog.update() - ret = character_recognize.agent(self.recog.img) # 返回的顺序是从左往右从上往下 - # 提取识别出来的干员的名字 - select_name = [] - for y in ret: - name = y[0] - if name in agent: - select_name.append(name) - # self.get_agent_detail((y[1][0])) - self.tap((y[1][0]), interval=0) - agent.remove(name) - # 如果是按照个数选择 Free - if max_agent_count != -1: - if len(select_name) >= max_agent_count: - return select_name, ret - return select_name, ret - except Exception as e: - error_count += 1 - if error_count < 3: - logger.exception(e) - self.sleep(3) - return self.scan_agent(agent, error_count, max_agent_count) - else: - raise e - - - def swipe_left(self, right_swipe, w, h): - for _ in range(right_swipe): - self.swipe_only((w // 2, h // 2), (w // 2, 0), interval=0.5) - return 0 - - def get_order(self, name): return False, [2, "false"] - def detail_filter(self, turn_on, type="not_in_dorm"): - logger.info(f'开始 {("打开" if turn_on else "关闭")} {type} 筛选') - self.tap((self.recog.w * 0.95, self.recog.h * 0.05), interval=1) - if type == "not_in_dorm": - not_in_dorm = self.find('arrange_non_check_in', score=0.9) - if turn_on ^ (not_in_dorm is None): - self.tap((self.recog.w * 0.3, self.recog.h * 0.5), interval=0.5) - # 确认 - self.tap((self.recog.w * 0.8, self.recog.h * 0.8), interval=0.5) - - def choose_agent(self, agents: list[str], room: str) -> None: """ :param order: ArrangeOrder, 选择干员时右上角的排序功能 diff --git a/arknights_mower/solvers/base_mixin.py b/arknights_mower/solvers/base_mixin.py new file mode 100644 index 000000000..47a401bbf --- /dev/null +++ b/arknights_mower/solvers/base_mixin.py @@ -0,0 +1,113 @@ +from __future__ import annotations + +from enum import Enum +from arknights_mower.utils import character_recognize +from arknights_mower.utils.log import logger + + +class ArrangeOrder(Enum): + STATUS = 1 + SKILL = 2 + FEELING = 3 + TRUST = 4 + + +arrange_order_res = { + ArrangeOrder.STATUS: (1560 / 2496, 96 / 1404), + ArrangeOrder.SKILL: (1720 / 2496, 96 / 1404), + ArrangeOrder.FEELING: (1880 / 2496, 96 / 1404), + ArrangeOrder.TRUST: (2050 / 2496, 96 / 1404), +} + + +class BaseMixin: + def switch_arrange_order(self, index: int, asc="false") -> None: + self.tap( + ( + self.recog.w * arrange_order_res[ArrangeOrder(index)][0], + self.recog.h * arrange_order_res[ArrangeOrder(index)][1], + ), + interval=0, + rebuild=False, + ) + # 点个不需要的 + if index < 4: + self.tap( + ( + self.recog.w * arrange_order_res[ArrangeOrder(index + 1)][0], + self.recog.h * arrange_order_res[ArrangeOrder(index)][1], + ), + interval=0, + rebuild=False, + ) + else: + self.tap( + ( + self.recog.w * arrange_order_res[ArrangeOrder(index - 1)][0], + self.recog.h * arrange_order_res[ArrangeOrder(index)][1], + ), + interval=0, + rebuild=False, + ) + # 切回来 + self.tap( + ( + self.recog.w * arrange_order_res[ArrangeOrder(index)][0], + self.recog.h * arrange_order_res[ArrangeOrder(index)][1], + ), + interval=0.2, + rebuild=True, + ) + # 倒序 + if asc != "false": + self.tap( + ( + self.recog.w * arrange_order_res[ArrangeOrder(index)][0], + self.recog.h * arrange_order_res[ArrangeOrder(index)][1], + ), + interval=0.2, + rebuild=True, + ) + + def scan_agent(self, agent: list[str], error_count=0, max_agent_count=-1): + try: + # 识别干员 + self.recog.update() + ret = character_recognize.agent(self.recog.img) # 返回的顺序是从左往右从上往下 + # 提取识别出来的干员的名字 + select_name = [] + for y in ret: + name = y[0] + if name in agent: + select_name.append(name) + # self.get_agent_detail((y[1][0])) + self.tap((y[1][0]), interval=0) + agent.remove(name) + # 如果是按照个数选择 Free + if max_agent_count != -1: + if len(select_name) >= max_agent_count: + return select_name, ret + return select_name, ret + except Exception as e: + error_count += 1 + if error_count < 3: + logger.exception(e) + self.sleep(3) + return self.scan_agent(agent, error_count, max_agent_count) + else: + raise e + + def swipe_left(self, right_swipe, w, h): + for _ in range(right_swipe): + self.swipe_only((w // 2, h // 2), (w // 2, 0), interval=0.5) + return 0 + + def detail_filter(self, turn_on, type="not_in_dorm"): + logger.info(f'开始 {("打开" if turn_on else "关闭")} {type} 筛选') + self.tap((self.recog.w * 0.95, self.recog.h * 0.05), interval=1) + if type == "not_in_dorm": + not_in_dorm = self.find("arrange_non_check_in", score=0.9) + if turn_on ^ (not_in_dorm is None): + self.tap((self.recog.w * 0.3, self.recog.h * 0.5), interval=0.5) + # 确认 + self.tap((self.recog.w * 0.8, self.recog.h * 0.8), interval=0.5) diff --git a/arknights_mower/solvers/base_schedule.py b/arknights_mower/solvers/base_schedule.py index 92f908ab2..81cef14df 100644 --- a/arknights_mower/solvers/base_schedule.py +++ b/arknights_mower/solvers/base_schedule.py @@ -6,7 +6,6 @@ import sys import pathlib import urllib.request -from enum import Enum from datetime import datetime, timedelta import numpy as np import smtplib @@ -43,26 +42,13 @@ from arknights_mower.utils.email import maa_template - -class ArrangeOrder(Enum): - STATUS = 1 - SKILL = 2 - FEELING = 3 - TRUST = 4 - - -arrange_order_res = { - ArrangeOrder.STATUS: (1560 / 2496, 96 / 1404), - ArrangeOrder.SKILL: (1720 / 2496, 96 / 1404), - ArrangeOrder.FEELING: (1880 / 2496, 96 / 1404), - ArrangeOrder.TRUST: (2050 / 2496, 96 / 1404), -} +from arknights_mower.solvers.base_mixin import ArrangeOrder, arrange_order_res, BaseMixin stage_drop = {} -class BaseSchedulerSolver(BaseSolver): +class BaseSchedulerSolver(BaseSolver, BaseMixin): """ 收集基建的产物:物资、赤金、信赖 """ @@ -1565,68 +1551,12 @@ def get_arrange_order(self) -> ArrangeOrder: logger.debug((best_score, best_order)) return best_order - def switch_arrange_order(self, index: int, asc="false") -> None: - self.tap((self.recog.w * arrange_order_res[ArrangeOrder(index)][0], - self.recog.h * arrange_order_res[ArrangeOrder(index)][1]), interval=0, rebuild=False) - # 点个不需要的 - if index < 4: - self.tap((self.recog.w * arrange_order_res[ArrangeOrder(index + 1)][0], - self.recog.h * arrange_order_res[ArrangeOrder(index)][1]), interval=0, rebuild=False) - else: - self.tap((self.recog.w * arrange_order_res[ArrangeOrder(index - 1)][0], - self.recog.h * arrange_order_res[ArrangeOrder(index)][1]), interval=0, rebuild=False) - # 切回来 - self.tap((self.recog.w * arrange_order_res[ArrangeOrder(index)][0], - self.recog.h * arrange_order_res[ArrangeOrder(index)][1]), interval=0.2, rebuild=True) - # 倒序 - if asc != "false": - self.tap((self.recog.w * arrange_order_res[ArrangeOrder(index)][0], - self.recog.h * arrange_order_res[ArrangeOrder(index)][1]), interval=0.2, rebuild=True) - - def scan_agent(self, agent: list[str], error_count=0, max_agent_count=-1): - try: - # 识别干员 - self.recog.update() - ret = character_recognize.agent(self.recog.img) # 返回的顺序是从左往右从上往下 - # 提取识别出来的干员的名字 - select_name = [] - for y in ret: - name = y[0] - if name in agent: - select_name.append(name) - # self.get_agent_detail((y[1][0])) - self.tap((y[1][0]), interval=0) - agent.remove(name) - # 如果是按照个数选择 Free - if max_agent_count != -1: - if len(select_name) >= max_agent_count: - return select_name, ret - return select_name, ret - except Exception as e: - error_count += 1 - if error_count < 3: - logger.exception(e) - self.sleep(3) - return self.scan_agent(agent, error_count, max_agent_count) - else: - raise e - def get_order(self, name): if name in self.op_data.operators: return True, self.op_data.operators[name].arrange_order else: return False, [2, "false"] - def detail_filter(self, turn_on, type="not_in_dorm"): - logger.info(f'开始 {("打开" if turn_on else "关闭")} {type} 筛选') - self.tap((self.recog.w * 0.95, self.recog.h * 0.05), interval=1) - if type == "not_in_dorm": - not_in_dorm = self.find('arrange_non_check_in', score=0.9) - if turn_on ^ (not_in_dorm is None): - self.tap((self.recog.w * 0.3, self.recog.h * 0.5), interval=0.5) - # 确认 - self.tap((self.recog.w * 0.8, self.recog.h * 0.8), interval=0.5) - def choose_agent(self, agents: list[str], room: str, fast_mode=True) -> None: """ :param order: ArrangeOrder, 选择干员时右上角的排序功能 @@ -1787,11 +1717,6 @@ def choose_agent(self, agents: list[str], room: str, fast_mode=True) -> None: self.last_room = room logger.info(f"设置上次房间为{self.last_room}") - def swipe_left(self, right_swipe, w, h): - for _ in range(right_swipe): - self.swipe_only((w // 2, h // 2), (w // 2, 0), interval=0.5) - return 0 - def read_accurate_mood(self, img, cord): try: img = img[cord[1]:cord[3], cord[0]:cord[2]]