diff --git a/bot_setting.json b/bot_setting.json index 126a207..d179cb2 100644 --- a/bot_setting.json +++ b/bot_setting.json @@ -3,7 +3,7 @@ "img_dir": "img_1274x718", "game_region": [0, 41, 1274, 718], "aspect_ratio": "16:9", - "confidence": 0.94, + "confidence": 0.92, "crash_detection": false, "adb": { "use": false, @@ -123,7 +123,7 @@ "focus_ch_middle": {"x":0.77902, "y":0.26545, "color":"bronze", "owner": ["character"]}, "focus_ch_right": {"x":0.91242, "y":0.19032, "color":"bronze", "owner": ["character"]}, "auto_button": {"x":0.93279, "y":0.03636, "color":"blue", "owner": ["wave", "character"]}, - "normal_atk": {"x":0.75000, "y":0.78623, "color":"ivory", "owner": ["character"]}, + "normal_atk": {"x":0.73906, "y":0.89722, "color":"ivory", "owner": ["character"]}, "sk1": {"x":0.64634, "y":0.78623, "color":"ivory", "owner": ["character"]}, "sk1_cd": {"x":0.64634, "y":0.78623, "color":"flash_green", "owner": ["character"]}, "sk2": {"x":0.54065, "y":0.78623, "color":"ivory", "owner": ["character"]}, diff --git a/src/bot.py b/src/bot.py index 58b5aca..c043ba7 100644 --- a/src/bot.py +++ b/src/bot.py @@ -93,10 +93,12 @@ def __update_waveID(self, new_waveid: int): else: self.wave_change_flag = False - # crash count reset - self.__ck_crash_count = 0 + self.reset_crash_detection() self.wave_id = new_waveid + def reset_crash_detection(self): + self.__ck_crash_count = 0 + def wave_icon_found(self) -> bool: adb.set_update_cv2_IM_cache_flag() for new_wid in gen_circle_list(self.wave_id, self.wave_total): @@ -170,7 +172,7 @@ def time_in_range(start: datetime, end: datetime, now: datetime) -> bool: start_time = datetime.strptime(str(datetime.now().date()) + "T" + start_clock, "%Y-%m-%dT%H:%M:%S") end_time = datetime.strptime(str(datetime.now().date()) + "T" + end_clock, "%Y-%m-%dT%H:%M:%S") now_time = datetime.now() - if time_in_range(start_time, end_time, datetime.now()): + if time_in_range(start_time, end_time, now_time): if self.get_current_wave().is_myTurn(): wait_until(end_time if end_time >= now_time else end_time + timedelta(days=1)) else: diff --git a/src/data.py b/src/data.py index 1885e2b..9495050 100644 --- a/src/data.py +++ b/src/data.py @@ -22,8 +22,10 @@ def __init__(self): def __load(self) -> Dict: with open('bot_setting.json', encoding="utf-8") as f: data = json.load(f) + self.__adb_region = tuple(data['game_region'][:2] + data['adb']['emulator_resolution']) + self.__pyautogui_region = tuple(data['game_region']) data['ratio'] = data['ratio'][data['aspect_ratio']] - data['game_region'] = tuple(data['game_region'][:2] + data['adb']['emulator_resolution']) if data['adb']['use'] else tuple(data['game_region']) # noqa: E501 + data['game_region'] = self.__adb_region if data['adb']['use'] else self.__pyautogui_region data['quest_selector'] = data['questList']['quest_selector'] quest = data['questList'][data['quest_selector']] data['loop_count'] = quest['loop_count'] @@ -43,7 +45,7 @@ def reload(self): def adb_mode_switch(self): self.setting['adb']['use'] = not self.setting['adb']['use'] - self.setting['game_region'] = tuple(list(self.setting['game_region'][:2]) + self.setting['adb']['emulator_resolution']) if self.setting['adb']['use'] else tuple(self.setting['game_region']) # noqa: E501 + self.setting['game_region'] = self.__adb_region if self.setting['adb']['use'] else self.__pyautogui_region def region_is_init(self) -> bool: return all(x <= y for x, y in zip(self.setting['game_region'], (0, 0, 1, 1))) diff --git a/src/orb.py b/src/orb.py index 7d12f0c..9fd1d7b 100644 --- a/src/orb.py +++ b/src/orb.py @@ -35,7 +35,9 @@ def action(self) -> bool: if not self.use: return False - self.__slide_out_orb_list() + while not self.__slide_out_orb_list(): + logging.info('slide out orb list failed') + if self.__use_orb(): logging.info(f'orb action: use orb0{self.option} success') else: @@ -44,7 +46,7 @@ def action(self) -> bool: return True def __use_orb(self) -> bool: - if self.objects['option'].found(): + if self.objects['option'].found(False): self.objects['option'].click(2) self.__click_target() if self.objects['cancel'].found(): @@ -61,7 +63,7 @@ def __click_target(self): pass self.objects['target_cancel'].click(1, 1) - def __slide_out_orb_list(self): + def __slide_out_orb_list(self) -> bool: destX = uData.setting['game_region'][0] + uData.setting['game_region'][2] - 1 destY = self.objects['entrypoint'].coord[1] if uData.setting['adb']['use']: @@ -69,6 +71,7 @@ def __slide_out_orb_list(self): else: pyautogui.moveTo(*self.objects['entrypoint'].coord) pyautogui.dragTo(destX, destY, 1, button='left') + return self.objects['cancel'].found() def adb_mode_switch(self): self.objects = self.__object_init() diff --git a/src/run.py b/src/run.py index 6804b5d..0f509d3 100644 --- a/src/run.py +++ b/src/run.py @@ -115,7 +115,7 @@ def _skip_award_result(bot): logging.info(f'loop_count({kirafan.loop_count}) less than or equal to 0') bot.stop() - ct = 12 + ct, retry = 12, True while bot.is_running(): kirafan.objects['center_left'].click(ct) if kirafan.icons['again'].click(): @@ -126,6 +126,9 @@ def _skip_award_result(bot): elif kirafan.icons['tojiru'].click(adb_update_cache=False): logging.debug('icon: tojiru icon found. (Is character\'s crea mission?)') ct = 8 + elif retry: + logging.debug('try a again because again.png not found') + retry = False else: logging.error('icon: again.png not found...') bot.stop() @@ -146,9 +149,15 @@ def _ck_move_to_next_battle(bot) -> bool: def _battle_resume(bot): logging.warning('try to resume battle...') - kirafan.objects['center'].click_sec(75) + kirafan.objects['center'].click_sec(100) + while True: + if kirafan.icons['ok'].click(): + sleep(2) + continue + break if kirafan.icons['hai'].click(): logging.info('resume battle') + kirafan.reset_crash_detection() kirafan.wave_id -= 1 else: logging.error('resume battle failed')