@@ -33,21 +33,30 @@ def reset_to_false(self):
33
33
return False
34
34
35
35
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" )
36
38
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 )
39
40
40
41
if self .has_count_down :
41
42
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
46
52
else :
47
53
return True
48
54
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} %' )
51
60
return self .has_count_down
52
61
53
62
def check_boss (self ):
@@ -61,7 +70,8 @@ def check_boss(self):
61
70
self .screenshot_boss_lv (current , f'boss lv not detected by edge { max_val } ' )
62
71
logger .debug (f'boss lv not detected by edge' )
63
72
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 ():
65
75
if self .debug :
66
76
self .screenshot_boss_lv (current , 'out_of combat boss_health disappeared' )
67
77
logger .info (f'out of combat because of boss_health disappeared, res:{ max_val } ' )
@@ -114,6 +124,7 @@ def in_combat(self):
114
124
if not self .target_enemy ():
115
125
logger .error ('target_enemy failed, break out of combat' )
116
126
return self .reset_to_false ()
127
+ return True
117
128
else :
118
129
logger .debug (
119
130
'check in combat pass' )
@@ -122,18 +133,27 @@ def in_combat(self):
122
133
else :
123
134
return True
124
135
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 ()
128
143
if in_combat :
129
144
logger .info (
130
145
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 } ' )
131
146
self ._in_combat = True
132
147
return True
133
148
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 )
137
157
138
158
def check_health_bar (self ):
139
159
if self ._in_combat :
@@ -191,6 +211,9 @@ def keep_boss_text_white(self):
191
211
return image , area
192
212
193
213
214
+ count_down_re = re .compile (r'\d\d' )
215
+
216
+
194
217
def process_target_enemy_area (frame ):
195
218
frame [frame != 255 ] = 0
196
219
return frame
0 commit comments