diff --git a/core/Baas_thread.py b/core/Baas_thread.py index 7692d41e..396ef46d 100644 --- a/core/Baas_thread.py +++ b/core/Baas_thread.py @@ -65,6 +65,8 @@ class Baas_thread: def __init__(self, config, logger_signal=None, button_signal=None, update_signal=None, exit_signal=None): + self.project_dir = os.path.abspath(os.path.dirname(__file__)) + self.project_dir = os.path.dirname(self.project_dir) self.u2_client = None self.u2 = None self.dailyGameActivity = None @@ -87,7 +89,7 @@ def __init__(self, config, logger_signal=None, button_signal=None, update_signal self.ratio = None self.next_time = None self.task_finish_to_main_page = False - self.static_config = None + self.static_config = self.config_set.static_config self.ocr = None self.logger = Logger(logger_signal) self.last_refresh_u2_time = 0 @@ -532,7 +534,7 @@ def init_image_resource(self): def init_rgb(self): try: - temp = 'src/rgb_feature/rgb_feature_' + self.server + '.json' + temp = self.project_dir + '/src/rgb_feature/rgb_feature_' + self.server + '.json' self.rgb_feature = json.load(open(temp, 'r', encoding='utf-8'))['rgb_feature'] return True except Exception as e: diff --git a/core/default_config.py b/core/default_config.py index da688a1d..07b2ebe0 100644 --- a/core/default_config.py +++ b/core/default_config.py @@ -339,14 +339,14 @@ "push_json":"", "push_serverchan":"", "cafe_reward_lowest_affection_first": true, - "cafe_reward_invite1_criterion" : "name", + "cafe_reward_invite1_criterion" : "starred", "favorStudent1": [ "爱丽丝" ], "cafe_reward_invite1_starred_student_position" : 1, "cafe_reward_has_no2_cafe": false, "cafe_reward_collect_hour_reward": true, - "cafe_reward_invite2_criterion" : "name", + "cafe_reward_invite2_criterion" : "starred", "favorStudent2": [ "爱丽丝(女仆)" ], @@ -533,6 +533,8 @@ ''' STATIC_DEFAULT_CONFIG = ''' { + "explore_normal_task_region_range": [4, 27], + "explore_hard_task_region_range": [1, 27], "screenshot_methods" : ["adb", "nemu", "uiautomator2"], "control_methods" : ["adb", "nemu", "uiautomator2"], "common_shop_price_list": { diff --git a/core/picture.py b/core/picture.py index 381ab725..8a0f5e52 100644 --- a/core/picture.py +++ b/core/picture.py @@ -1,7 +1,7 @@ import time from core import color, image from module.main_story import change_acc_auto - +from core.exception import RequestHumanTakeOver def co_detect(self, rgb_ends=None, rgb_possibles=None, img_ends=None, img_possibles=None, skip_first_screenshot=False, tentitive_click=False, tentitivex=1238, tentitivey=45, max_fail_cnt=10, rgb_pop_ups=None, @@ -103,6 +103,8 @@ def co_detect(self, rgb_ends=None, rgb_possibles=None, img_ends=None, img_possib self.click(tentitivex, tentitivey) time.sleep(self.screenshot_interval) fail_cnt = 0 + if not self.flag_run: + raise RequestHumanTakeOver def deal_with_pop_ups(self, rgb_pop_ups, img_pop_ups): diff --git a/core/scheduler.py b/core/scheduler.py index a6c5e3b7..a0be2b11 100644 --- a/core/scheduler.py +++ b/core/scheduler.py @@ -12,7 +12,7 @@ def __init__(self, update_signal, path): super().__init__() self.event_map = {} self.first_waiting = None - self.event_config_path = "./config/" + path + "/event.json" + self.event_config_path = path + "/event.json" self.update_signal = update_signal self._event_config = [] self._current_task = None diff --git a/develop_tools/config/gui.json b/develop_tools/config/gui.json new file mode 100644 index 00000000..b76fca15 --- /dev/null +++ b/develop_tools/config/gui.json @@ -0,0 +1,12 @@ +{ + "MainWindow": { + "configLoadType": "Card", + "DpiScale": 1, + "Language": "zh_CN", + "MicaEnabled": true + }, + "QFluentWidgets": { + "ThemeColor": "#ff0078d4", + "ThemeMode": "Light" + } +} \ No newline at end of file diff --git a/develop_tools/test_explore_task_data.py b/develop_tools/test_explore_task_data.py new file mode 100644 index 00000000..aa0d9602 --- /dev/null +++ b/develop_tools/test_explore_task_data.py @@ -0,0 +1,47 @@ +from module.explore_normal_task import get_explore_normal_task_missions +from module.explore_hard_task import get_explore_hard_task_data +from core.utils import Logger +from core.Baas_thread import Baas_thread +from gui.util.config_set import ConfigSet +from main import Main + +t = Main(ocr_needed=[]) +config = ConfigSet(config_dir="D:\\github\\bass\\blue_archive_auto_script\\config\\1708148000") +tt = Baas_thread(config, None, None, None) +tt.init_all_data() + +st = [ + 1, + 4, + 26, + 99, + "6,7", + "1,2,3", + "18,19,20", + "18,19,20", + [18, 19, 20], + "5,19,21", + [4, 23, -1], + "5,16,q9,", + [5, 16, "q9"] +] +expected_1 = [ + [], + [[4, 1], [4, 2], [4, 3], [4, 4], [4, 5]], + [[26, 1], [26, 2], [26, 3], [26, 4], [26, 5]], + [], + [[6, 1], [6, 2], [6, 3], [6, 4], [6, 5], [7, 1], [7, 2], [7, 3], [7, 4], [7, 5]], + [], + [[18, 1], [18, 2], [18, 3], [18, 4], [18, 5], [19, 1], [19, 2], [19, 3], [19, 4], [19, 5], [20, 1], [20, 2], [20, 3], [20, 4], [20, 5]], + [[18, 1], [18, 2], [18, 3], [18, 4], [18, 5], [19, 1], [19, 2], [19, 3], [19, 4], [19, 5], [20, 1], [20, 2], [20, 3], [20, 4], [20, 5]], + [[18, 1], [18, 2], [18, 3], [18, 4], [18, 5], [19, 1], [19, 2], [19, 3], [19, 4], [19, 5], [20, 1], [20, 2], [20, 3], [20, 4], [20, 5]], + [[5, 1], [5, 2], [5, 3], [5, 4], [5, 5], [19, 1], [19, 2], [19, 3], [19, 4], [19, 5], [21, 1], [21, 2], [21, 3], [21, 4], [21, 5]], + [[4, 1], [4, 2], [4, 3], [4, 4], [4, 5], [23, 1], [23, 2], [23, 3], [23, 4], [23, 5]], + [[5, 1], [5, 2], [5, 3], [5, 4], [5, 5], [16, 1], [16, 2], [16, 3], [16, 4], [16, 5]], + [[5, 1], [5, 2], [5, 3], [5, 4], [5, 5], [16, 1], [16, 2], [16, 3], [16, 4], [16, 5]] +] + +for i in range(len(st)): + ret = get_explore_normal_task_missions(tt, st[i], True) + print(ret) + assert ret == expected_1[i] diff --git a/gui/components/expand/featureSwitch.py b/gui/components/expand/featureSwitch.py index 95946b49..f539581a 100644 --- a/gui/components/expand/featureSwitch.py +++ b/gui/components/expand/featureSwitch.py @@ -173,14 +173,14 @@ def _init_components(self, config_list): self.config_buttons.append(cfbs_wrapper) def _read_config(self): - with open('./config/' + self.config.config_dir + '/event.json', 'r', encoding='utf-8') as f: + with open(self.config.config_dir + '/event.json', 'r', encoding='utf-8') as f: s = f.read() if s == '': return self._event_config = json.loads(s) def _save_config(self): - with open('./config/' + self.config.config_dir + '/event.json', 'w', encoding='utf-8') as f: + with open(self.config.config_dir + '/event.json', 'w', encoding='utf-8') as f: json.dump(self._event_config, f, ensure_ascii=False, indent=2) def _sort(self): diff --git a/gui/fragments/home.py b/gui/fragments/home.py index c94c0f04..71fa285c 100644 --- a/gui/fragments/home.py +++ b/gui/fragments/home.py @@ -126,7 +126,7 @@ def resizeEvent(self, event): def call_update(self, data=None, parent=None): try: if self.event_map == {}: - with open('./config/' + self.config.config_dir + '/event.json', 'r', encoding='utf-8') as f: + with open(self.config.config_dir + '/event.json', 'r', encoding='utf-8') as f: event_config = json.load(f) for item in event_config: self.event_map[item['func_name']] = item['event_name'] diff --git a/gui/fragments/switch.py b/gui/fragments/switch.py index 900d70c3..d98dd2ec 100644 --- a/gui/fragments/switch.py +++ b/gui/fragments/switch.py @@ -113,14 +113,14 @@ def _create_card(self, name: str, tip: str, setting_name: str) -> Union[ def _commit_change(self): with lock: - with open('./config/' + self.config.config_dir + '/event.json', 'w', encoding='utf-8') as f: + with open(self.config.config_dir + '/event.json', 'w', encoding='utf-8') as f: json.dump(self._event_config, f, ensure_ascii=False, indent=2) # 将_event_config列表写入配置文件 def _read_config(self): with lock: - with open('./config/' + self.config.config_dir + '/event.json', 'r', encoding='utf-8') as f: + with open(self.config.config_dir + '/event.json', 'r', encoding='utf-8') as f: self._event_config = json.load(f) # 从配置文件中读取数据并更新_event_config列表 - with open('./config/' + self.config.config_dir + '/switch.json', 'r', encoding='utf-8') as f: + with open(self.config.config_dir + '/switch.json', 'r', encoding='utf-8') as f: self._switch_config = json.load(f) # 从配置文件中读取数据并更新_switch_config列表 def update_settings(self): diff --git a/gui/util/config_set.py b/gui/util/config_set.py index 44f02122..79292a03 100644 --- a/gui/util/config_set.py +++ b/gui/util/config_set.py @@ -6,7 +6,7 @@ from qfluentwidgets import qconfig from gui.util.translator import baasTranslator as bt - +import os class BoundComponent(QObject): """ @@ -54,7 +54,6 @@ def config_updated(self, key): class ConfigSet: def __init__(self, config_dir): super().__init__() - print(config_dir) self.config = None self.gui_config = None self.server_mode = 'CN' @@ -63,14 +62,23 @@ def __init__(self, config_dir): self.window = None self.main_thread = None self.static_config = None - self.config_dir = config_dir + self.config_dir = None + self.static_config_path = None + if os.path.exists(f'config/{config_dir}/config.json'): # relative path + self.config_dir = os.path.abspath(f'config/{config_dir}') + self.static_config_path = os.path.dirname(self.config_dir) + '/static.json' + elif os.path.exists(f'{config_dir}/config.json'): # absolute path + self.config_dir = config_dir + self.static_config_path = os.path.abspath(os.path.dirname(config_dir) + '/static.json') + else: + raise FileNotFoundError(f'config/{config_dir}/config.json not found') self.signals = {} self._init_config() def _init_config(self): - with open(f'./config/{self.config_dir}/config.json', 'r', encoding='utf-8') as f: + with open(self.config_dir + "\\config.json", 'r', encoding='utf-8') as f: self.config = json.load(f) - with open("config/static.json", 'r', encoding='utf-8') as f: + with open(self.static_config_path, 'r', encoding='utf-8') as f: self.static_config = json.load(f) if self.config['server'] == '国服' or self.config['server'] == 'B服': self.server_mode = 'CN' @@ -92,7 +100,7 @@ def set(self, key, value): self._init_config() value = bt.undo(value) self.config[key] = value - with open(f'./config/{self.config_dir}/config.json', 'w', encoding='utf-8') as f: + with open(self.config_dir + "\\config.json", 'w', encoding='utf-8') as f: json.dump(self.config, f, indent=4, ensure_ascii=False) self.dynamic_update(key) @@ -108,7 +116,7 @@ def __getitem__(self, item: str): return self.config[item] def check(self, key, value): - with open(f'./config/{self.config_dir}/config.json', 'r', encoding='utf-8') as f: + with open(self.config_dir + "\\config.json", 'r', encoding='utf-8') as f: new_config = json.load(f) return new_config.get(key) == value diff --git a/main.py b/main.py index 2cb0166f..1acb7784 100644 --- a/main.py +++ b/main.py @@ -1,15 +1,19 @@ import json +import os from core.utils import Logger from core.ocr import ocr from gui.util.config_set import ConfigSet from core.Baas_thread import Baas_thread + class Main: def __init__(self, logger_signal=None, ocr_needed=None): self.ocr_needed = ocr_needed self.ocr = None self.static_config = None self.logger = Logger(logger_signal) + self.project_dir = os.path.abspath(os.path.dirname(__file__)) + self.logger.info(self.project_dir) self.init_all_data() self.threads = {} @@ -30,7 +34,6 @@ def init_ocr(self): def get_thread(self, config, name="1", logger_signal=None, button_signal=None, update_signal=None, exit_signal=None): t = Baas_thread(config, logger_signal, button_signal, update_signal, exit_signal) - t.static_config = self.static_config t.ocr = self.ocr self.threads.setdefault(name, t) return t @@ -45,7 +48,7 @@ def stop_script(self, name): def init_static_config(self): try: - self.static_config = self.operate_dict(json.load(open('config/static.json', 'r', encoding='utf-8'))) + self.static_config = self.operate_dict(json.load(open(self.project_dir + "/config/static.json", 'r', encoding='utf-8'))) return True except Exception as e: self.logger.error("Static Config initialization failed") @@ -95,7 +98,6 @@ def operate_item(self, item): if __name__ == '__main__': t = Main(ocr_needed=["NUM", "CN", "Global"]) - t.init_static_config() config = ConfigSet(config_dir="1708148000") tt = Baas_thread(config, None, None, None) tt.static_config = t.static_config @@ -112,7 +114,7 @@ def operate_item(self, item): # tt.solve("total_assault") # tt.solve("cafe_reward") # tt.solve("momo_talk") - # tt.solve("explore_normal_task") + tt.solve("explore_normal_task") # tt.solve("explore_hard_task") # tt.solve("normal_task") # tt.solve("hard_task") @@ -130,4 +132,4 @@ def operate_item(self, item): # tt.solve("create") # tt.solve("dailyGameActivity") # tt.solve("friend") - tt.solve("joint_firing_drill") + # tt.solve("joint_firing_drill") diff --git a/module/explore_normal_task.py b/module/explore_normal_task.py index b0471e44..53bad55f 100644 --- a/module/explore_normal_task.py +++ b/module/explore_normal_task.py @@ -5,14 +5,15 @@ def implement(self): + temp = get_explore_normal_task_missions(self, self.config['explore_normal_task_regions']) self.quick_method_to_main_page() if self.config['explore_normal_task_force_each_fight']: - tasks = get_explore_normal_task_missions(self, self.config['explore_normal_task_regions']) - self.logger.info("VALID TASKS : " + str(tasks)) + temp = get_explore_normal_task_missions(self, self.config['explore_normal_task_regions']) + self.logger.info("VALID TASKS : " + str(temp)) normal_task.to_normal_event(self) - for i in range(0, len(tasks)): - region = tasks[i][0] - mission = tasks[i][1] + for i in range(0, len(temp)): + region = temp[i][0] + mission = temp[i][1] self.logger.info("-- Start Pushing " + str(region) + "-" + str(mission) + " --") choose_region(self, region) self.swipe(917, 220, 917, 552, duration=0.1, post_sleep_time=1) @@ -29,13 +30,6 @@ def implement(self): normal_task.to_normal_event(self, True) else: need_change_acc = True - temp = [] - if type(self.config['explore_normal_task_regions']) is int: - temp.append(self.config['explore_normal_task_regions']) - elif type(self.config['explore_normal_task_regions']) is str: - t = self.config['explore_normal_task_regions'].split(',') - for i in range(0, len(t)): - temp.append(int(t[i])) self.logger.info("VALID REGIONS : " + str(temp)) self.quick_method_to_main_page() normal_task.to_normal_event(self, True) @@ -473,41 +467,81 @@ def to_normal_task_mission_operating_page(self, skip_first_screenshot=False): picture.co_detect(self, None, None, img_ends, img_possibles, skip_first_screenshot, img_pop_ups=img_pop_ups) -def get_explore_normal_task_missions(self, st): - try: - if type(st) is list: - for i in range(0, len(st)): - st[i] = str(st[i]) - elif type(st) is not str: +def get_explore_normal_task_missions(self, st, force_each_fight=False): + lg = "Tasks" + if not force_each_fight: + lg = "Regions" + self.logger.info("Get Explore Normal Task Valid " + lg) + region_range = self.static_config['explore_normal_task_region_range'] + ret = [] + if not force_each_fight: + if type(st) is int: st = str(st) if type(st) is str: + st = st.replace(' ', '') + st = st.replace(',', ',') st = st.split(',') - print(type(st)) - tasks = [] - min_area = 4 - max_area = 27 - for i in range(0, len(st)): - if '-' in st[i]: - temp = st[i].split('-') - region = int(temp[0]) - if region < min_area or region > max_area: - self.logger.error("region" + temp[0] + "not support") - continue - if len(temp) != 2: - continue - tasks.append([int(temp[0]), int(temp[1])]) - else: - region = int(st[i]) - if region < min_area or region > max_area: - self.logger.error("region" + st[i] + "not support") - continue - for j in range(1, 6): - tasks.append([int(st[i]), j]) - return tasks - except Exception as e: - self.logger.error(e.__str__()) - self.logger.error("explore_normal_task_missions config error") - return False + if type(st) is list: + for t in st: + if type(t) is str: + try: + t = int(t) + except ValueError: + self.logger.warning("[ " + t + " ] is not a number.Skip") + continue + if type(t) is int: + if t < region_range[0] or t > region_range[1]: + self.logger.warning("Region [ " + str(t) + " ] not support") + continue + ret.append(t) + + else: + try: + if type(st) is list: + for i in range(0, len(st)): + st[i] = str(st[i]) + elif type(st) is not str: + st = str(st) + if type(st) is str: + st = st.replace(' ', '') + st = st.replace(',', ',') + st = st.split(',') + for t in st: + if '-' in t: + temp = t.split('-') + if len(temp) != 2: + self.logger.error("[ " + t + " ] format error. Expected : 'region-mission'") + continue + try: + region = int(temp[0]) + except ValueError: + self.logger.warning("Region [ " + t + " ] is not a number.Skip") + continue + try: + mission = int(temp[1]) + except ValueError: + self.logger.warning("Mission [ " + t + " ] is not a number.Skip") + continue + if region < region_range[0] or region > region_range[1]: + self.logger.error("Region [ " + temp[0] + " ] not support") + continue + ret.append([region, mission]) + else: + try: + region = int(t) + except ValueError: + self.logger.warning("Region [ " + t + " ] is not a number.Skip") + continue + if region < region_range[0] or region > region_range[1]: + self.logger.error("Region [ " + t + " ] not support") + continue + for j in range(1, 6): + ret.append([int(t), j]) + except Exception as e: + self.logger.error(e.__str__()) + self.logger.error("explore_normal_task_missions config error") + return False + return ret def choose_team_according_to_stage_data_and_config(self, current_task_stage_data): diff --git a/service.example.py b/service.example.py index 13b4f913..bb1f59c6 100644 --- a/service.example.py +++ b/service.example.py @@ -5,10 +5,8 @@ def main(): main = Main(ocr_needed=["NUM", "Global", "JP"]) # 日服也必须要 Global,否则会崩溃 - main.init_static_config() config = ConfigSet(config_dir="jp_hoshino") # 修改为自己的配置目录名 baas = Baas_thread(config, None, None, None) - baas.static_config = main.static_config baas.init_all_data() baas.ocr = main.ocr # type: ignore