Skip to content

Commit 4263757

Browse files
committed
optimze auto combat
1 parent 019e041 commit 4263757

File tree

3 files changed

+51
-21
lines changed

3 files changed

+51
-21
lines changed

src/char/BaseChar.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,6 @@ def click_liberation(self, wait_end=True, con_less_than=-1, send_click=False):
258258
self.logger.debug(f'click_liberation liberation_available click')
259259
now = time.time()
260260
self.task.in_liberation = True
261-
clicked = True
262261
if now - last_click > 0.1:
263262
self.task.send_key(self.get_liberation_key())
264263
self.liberation_available_mark = False
@@ -267,6 +266,7 @@ def click_liberation(self, wait_end=True, con_less_than=-1, send_click=False):
267266
self.task.raise_not_in_combat('too long clicking a liberation')
268267
self.task.next_frame()
269268
while not self.task.in_team()[0]:
269+
clicked = True
270270
self.task.in_liberation = True
271271
if send_click:
272272
self.task.click(interval=0.1)
@@ -543,9 +543,9 @@ def is_full_ring(component_mask):
543543
}
544544

545545
dot_color = {
546-
'r': (245, 255), # Red range
547-
'g': (245, 255), # Green range
548-
'b': (245, 255) # Blue range
546+
'r': (235, 255), # Red range
547+
'g': (235, 255), # Green range
548+
'b': (235, 255) # Blue range
549549
}
550550

551551
con_colors = [

src/char/Jinhsi.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,13 @@ def handle_incarnation(self):
5757
self.logger.info(f'handle_incarnation click_resonance start')
5858
start = time.time()
5959
liberated = False
60-
while self.has_cd('resonance'):
60+
while True:
61+
current_res = self.current_resonance()
62+
if current_res > 0 and not self.has_cd('resonance'):
63+
self.logger.debug(f'handle_incarnation current_res: {current_res} breaking')
64+
if self.task.debug:
65+
self.task.screenshot(f'handle_incarnation e available')
66+
break
6167
self.task.click(interval=0.1)
6268
# if time.time() - start > 1.8 and not liberated:
6369
# liberated = True
@@ -71,7 +77,8 @@ def handle_incarnation(self):
7177
self.click_resonance(has_animation=True, send_click=True)
7278
if not self.click_echo():
7379
self.task.click()
74-
# self.task.screenshot(f'handle_incarnation click_resonance end {time.time() - start}')
80+
if self.task.debug:
81+
self.task.screenshot(f'handle_incarnation click_resonance end {time.time() - start}')
7582
self.logger.info(f'handle_incarnation click_resonance end {time.time() - start}')
7683

7784
def handle_intro(self):

src/combat/CombatCheck.py

Lines changed: 38 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,21 +33,30 @@ def reset_to_false(self):
3333
return False
3434

3535
def check_count_down(self):
36+
count_down_area = self.box_of_screen(1820 / 3840, 266 / 2160, 2100 / 3840,
37+
340 / 2160, name="check_count_down")
3638
count_down = self.calculate_color_percentage(text_white_color,
37-
self.box_of_screen(1820 / 3840, 266 / 2160, 2088 / 3840,
38-
330 / 2160, name="check_count_down"))
39+
count_down_area)
3940

4041
if self.has_count_down:
4142
if count_down < 0.03:
42-
# self.screenshot(f'out of combat because of count_down disappeared {count_down:.2f}%')
43-
logger.info(f'out of combat because of count_down disappeared {count_down:.2f}%')
44-
self.has_count_down = False
45-
return False
43+
numbers = self.ocr(box=count_down_area, match=count_down_re)
44+
if self.debug:
45+
self.screenshot(f'count_down disappeared {count_down:.2f}%')
46+
logger.info(f'count_down disappeared {numbers} {count_down:.2f}%')
47+
if not numbers:
48+
self.has_count_down = False
49+
return False
50+
else:
51+
return True
4652
else:
4753
return True
4854
else:
49-
self.has_count_down = count_down > 0.03
50-
logger.info(f'set count_down to {self.has_count_down} {count_down:.2f}%')
55+
if count_down > 0.03:
56+
numbers = self.ocr(box=count_down_area, match=count_down_re)
57+
if numbers:
58+
self.has_count_down = True
59+
logger.info(f'set count_down to {self.has_count_down} {numbers} {count_down:.2f}%')
5160
return self.has_count_down
5261

5362
def check_boss(self):
@@ -61,7 +70,8 @@ def check_boss(self):
6170
self.screenshot_boss_lv(current, f'boss lv not detected by edge {max_val}')
6271
logger.debug(f'boss lv not detected by edge')
6372
if not self.find_boss_lv_text(): # double check by text
64-
if not (self.in_team()[0] and self.check_health_bar()) and not self.check_count_down():
73+
if not self.in_team()[
74+
0] and not self.check_health_bar() and not self.check_count_down() and not self.find_target_enemy():
6575
if self.debug:
6676
self.screenshot_boss_lv(current, 'out_of combat boss_health disappeared')
6777
logger.info(f'out of combat because of boss_health disappeared, res:{max_val}')
@@ -114,6 +124,7 @@ def in_combat(self):
114124
if not self.target_enemy():
115125
logger.error('target_enemy failed, break out of combat')
116126
return self.reset_to_false()
127+
return True
117128
else:
118129
logger.debug(
119130
'check in combat pass')
@@ -122,18 +133,27 @@ def in_combat(self):
122133
else:
123134
return True
124135
else:
125-
in_combat = self.in_team()[0] and self.check_health_bar() and (
126-
(
127-
self.boss_health_box is not None or self.boss_lv_edge is not None or self.has_count_down) or self.target_enemy())
136+
in_combat = self.in_team()[0] and self.check_health_bar()
137+
if in_combat:
138+
in_combat = self.boss_health_box is not None or self.boss_lv_edge is not None or self.has_count_down
139+
if in_combat:
140+
self.target_enemy(wait=False)
141+
else:
142+
in_combat = self.target_enemy()
128143
if in_combat:
129144
logger.info(
130145
f'enter combat boss_lv_edge:{self.boss_lv_edge is not None} boss_health_box:{self.boss_health_box} has_count_down:{self.has_count_down}')
131146
self._in_combat = True
132147
return True
133148

134-
def target_enemy(self):
135-
self.middle_click()
136-
return self.wait_until(self.find_target_enemy, time_out=2)
149+
def target_enemy(self, wait=True):
150+
if not wait:
151+
self.middle_click()
152+
else:
153+
if self.find_target_enemy():
154+
return True
155+
self.middle_click()
156+
return self.wait_until(self.find_target_enemy, time_out=2)
137157

138158
def check_health_bar(self):
139159
if self._in_combat:
@@ -191,6 +211,9 @@ def keep_boss_text_white(self):
191211
return image, area
192212

193213

214+
count_down_re = re.compile(r'\d\d')
215+
216+
194217
def process_target_enemy_area(frame):
195218
frame[frame != 255] = 0
196219
return frame

0 commit comments

Comments
 (0)