Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
smallbomb committed Nov 27, 2021
2 parents fd8542e + 3ef6de2 commit 56a191d
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 12 deletions.
4 changes: 2 additions & 2 deletions bot_setting.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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"]},
Expand Down
8 changes: 5 additions & 3 deletions src/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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:
Expand Down
6 changes: 4 additions & 2 deletions src/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand All @@ -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)))
Expand Down
9 changes: 6 additions & 3 deletions src/orb.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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():
Expand All @@ -61,14 +63,15 @@ 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']:
adb.swipe(*self.objects['entrypoint'].coord, destX, destY, 1)
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()
Expand Down
13 changes: 11 additions & 2 deletions src/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand All @@ -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()
Expand All @@ -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')
Expand Down

0 comments on commit 56a191d

Please sign in to comment.