1
1
import re
2
- import sys
3
- import time
4
2
5
- from ok import BaseTask
3
+ from ok import BaseTask , find_boxes_within_boundary , find_boxes_by_name
6
4
from ok import Logger
7
5
8
6
logger = Logger .get_logger (__name__ )
@@ -18,19 +16,48 @@ def __init__(self, *args, **kwargs):
18
16
# sys.exit(1)
19
17
20
18
def ensure_main (self , recheck_time = 1 , time_out = 30 , esc = True ):
19
+ self .info_set ('current_task' , 'go_to_main' )
21
20
if not self .wait_until (lambda : self .is_main (recheck_time = recheck_time , esc = esc ), time_out = time_out ):
22
21
raise Exception ("请从游戏主页进入" )
23
22
23
+ def auto_battle (self , end_match = None , end_box = None ):
24
+ self .info_set ('current_task' , 'auto battle' )
25
+ result = self .wait_ocr (match = ['作战开始' , '行动结束' ], box = 'bottom' , time_out = 60 ,
26
+ raise_if_not_found = True )
27
+ if result [0 ].name == '作战开始' :
28
+ self .click_box (result , after_sleep = 1 )
29
+ start_result = self .wait_ocr (match = ['行动结束' , re .compile ('还有可部署' )],
30
+ raise_if_not_found = True , time_out = 30 )
31
+ if '还有可部署' in start_result [0 ].name :
32
+ self .log_error ('阵容没上满, 请上阵后再点击继续任务, 不支持选择助战!' , notify = True )
33
+ self .pause ()
34
+ self .wait_click_ocr (match = ['作战开始' ], box = 'bottom' , time_out = 5 ,
35
+ raise_if_not_found = True )
36
+ self .wait_ocr (match = ['行动结束' ],
37
+ raise_if_not_found = True , time_out = 30 )
38
+ self .sleep (0.5 )
39
+ self .click_relative (0.85 , 0.05 , after_sleep = 1 )
40
+ result = self .wait_ocr (match = ['任务完成' , '任务失败' , '战斗失败' ], raise_if_not_found = True , time_out = 600 )
41
+ if result [0 ].name == '任务失败' :
42
+ raise Exception ('任务失败, 没打过!' )
43
+ else :
44
+ self .click (result [0 ])
45
+ if result [0 ].name != '战斗失败' :
46
+ self .wait_click_ocr (match = '确认' , box = 'bottom_right' , raise_if_not_found = True , time_out = 5 )
47
+ if end_match and end_box :
48
+ self .wait_ocr (match = end_match , box = end_box , raise_if_not_found = True , time_out = 30 )
49
+ self .sleep (0.5 )
50
+
24
51
def is_main (self , recheck_time = 0 , esc = True ):
25
- boxes = self .ocr (match = ['整备室' ,'公共区' ,'招募' ], box = 'right' )
52
+ boxes = self .ocr (match = ['整备室' , '公共区' , '招募' ], box = 'right' )
26
53
if len (boxes ) == 3 :
27
54
if recheck_time :
28
55
self .sleep (recheck_time )
29
56
return self .is_main (recheck_time = 0 , esc = False )
30
57
else :
31
58
return True
32
59
# if not self.do_handle_alert()[0]:
33
- if box := self .ocr (box = "bottom" , match = ["点击开始" , "点击空白处关闭" ],
60
+ if box := self .ocr (box = "bottom" , match = ["点击开始" , "点击空白处关闭" ],
34
61
log = True ):
35
62
self .click (box )
36
63
return False
@@ -40,3 +67,45 @@ def is_main(self, recheck_time=0, esc=True):
40
67
# self.do_handle_alert()
41
68
self .next_frame ()
42
69
70
+ def find_top_right_count (self ):
71
+ result = self .ocr (0.89 , 0.01 , 0.99 , 0.1 , match = re .compile (r"^\d+/\d+$" ), box = 'top_right' )
72
+ if not result :
73
+ raise Exception ('找不到当前体力或票' )
74
+ return int (result [0 ].name .split ('/' )[0 ])
75
+
76
+ def fast_combat (self ):
77
+ self .wait_click_ocr (match = ['自律' ], box = 'bottom_right' , after_sleep = 1 , raise_if_not_found = True )
78
+ boxes = self .ocr ()
79
+ current = find_boxes_within_boundary (boxes , self .box_of_screen (0.84 , 0 , 0.99 , 0.10 ))[0 ].name
80
+ current = int (current .split ('/' )[0 ])
81
+ if len (find_boxes_by_name (boxes , ["确认" , "取消" ])) != 2 :
82
+ self .log_info ("自律没有弹窗, 可能是调度权限不足" )
83
+ return current
84
+
85
+ cost = int (find_boxes_within_boundary (boxes , self .box_of_screen (0.48 , 0.56 , 0.57 , 0.67 ))[0 ].name )
86
+ battle_max = int (find_boxes_within_boundary (boxes , self .box_of_screen (0.61 , 0.50 , 0.66 , 0.57 ))[0 ].name )
87
+
88
+ self .info_set ('current_stamina' , current )
89
+ self .info_set ('battle_cost' , cost )
90
+ self .info_set ('battle_max' , battle_max )
91
+ can_fast_count = min (int (current / cost ), battle_max )
92
+ self .info_set ('can_fast_count' , can_fast_count )
93
+ self .info_set ('click_battle_plus' , 0 )
94
+ remaining = current - can_fast_count * cost
95
+ self .info_set ('remaining_stamina' , remaining )
96
+ for _ in range (can_fast_count - 1 ):
97
+ self .click (0.68 , 0.54 )
98
+ self .info_incr ('click_battle_plus' )
99
+ self .sleep (0.2 )
100
+ if can_fast_count > 0 :
101
+ self .click (find_boxes_by_name (boxes , "确认" ))
102
+ self .wait_pop_up ()
103
+ else :
104
+ self .click (find_boxes_by_name (boxes , "取消" ))
105
+ return remaining
106
+
107
+ def wait_pop_up (self , time_out = 15 ):
108
+ return self .wait_click_ocr (match = ['点击空白处关闭' , '点击屏幕任意位置继续' ], box = 'bottom' , time_out = time_out ,
109
+ after_sleep = 2 ,
110
+ recheck_time = 1 ,
111
+ raise_if_not_found = False )
0 commit comments