-
Notifications
You must be signed in to change notification settings - Fork 74
/
Copy pathmhxy_bangpai2.py
179 lines (151 loc) · 6.18 KB
/
mhxy_bangpai2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
import argparse
import os
from configparser import ConfigParser
from mhxy import *
nxtNode = PicNode(r'resources/bangpai/small/next.png')
class BangpaiPicNode(PicNode):
def setNext(self, nxt):
super().setNext(nxt)
# 防止卡了的情况,自己下一个包含自己
self.next.append(self)
self.next.append(nxtNode)
# 小窗口
class Bangpai(MhxyScript):
chaseWin = [-0.5, 3.8 + 0]
# 结束状态
_rootList = []
_allList = []
def __init__(self, idx=0, changWinPos=True) -> None:
super().__init__(idx=idx, changWinPos=changWinPos)
file_path = os.path.join(os.path.abspath('.'), 'resources/bangpai/small/bangpai.ini')
if not os.path.exists(file_path):
raise FileNotFoundError("文件不存在")
conn = ConfigParser()
conn.read(file_path)
chasepos = float(conn.get('main', 'chasepos'))
self.chaseWin[1] = 3.8 + chasepos * 2
# 结束状态 下一步是root(除了finish标志)
leafNode = []
def clickFunc(locate, chaseWin):
pyautogui.leftClick(locate.x, locate.y)
cooldown(0.2)
def shangchen(locate, chaseWin):
cooldown(1)
shangchen = Util.locateCenterOnScreen(r'resources/bangpai/small/shangchen.png') is not None
# 选择第二个商品(防止商品被买)
if shangchen:
Util.leftClick(17, 7)
cooldown(0.3)
pyautogui.leftClick(locate.x, locate.y)
else:
clickFunc(locate, chaseWin)
def battleFunc(locate, chaseWin):
while Util.locateCenterOnScreen(r'resources/small/enter_battle_flag.png') is not None:
cooldown(1)
pyautogui.leftClick(locate.x, locate.y)
cooldown(0.5)
# 访问任务
battle = BangpaiPicNode(r'resources/small/enter_battle_flag.png', completeFunc=battleFunc)
qiecuo = BangpaiPicNode(r'resources/bangpai/small/qiecuo.png', completeFunc=clickFunc)
fanwen = BangpaiPicNode(r'resources/bangpai/small/fanwen.png')
qiecuo.setNext([battle])
fanwen.next = [battle, nxtNode]
# 访问、已有二级药的任务结束
leafNode.append(fanwen)
# 巡逻、挂机场景结束
leafNode.append(battle)
# 三级药烹饪wupin任务 *购买->总管->上交 二级药wupin2任务 *购买->总管
shangjiao = BangpaiPicNode(r'resources/bangpai/small/shangjiao.png')
fanwen.next.append(shangjiao)
wupin = BangpaiPicNode(r'resources/bangpai/small/wupin.png', completeFunc=shangchen)
# 可能购买失败,所以还是
wupin.setNext([fanwen])
wupin2 = BangpaiPicNode(r'resources/bangpai/small/wupin2.png', completeFunc=clickFunc)
wupin2.next = [fanwen, nxtNode]
# 二级药结束点
# leafNode.append(fanwen)
# 烹饪药结束点
leafNode.append(shangjiao)
def fanwenFunc(locate, chaseWin):
pyautogui.leftClick(locate.x, locate.y)
cooldown(3)
pyautogui.leftClick(locate.x, locate.y)
cooldown(0.3)
def hanhuaFunc(locate, chaseWin):
Util.leftClick(-3.5, -3)
cooldown(3)
Util.leftClick(-3.5, -3)
cooldown(0.3)
# 喊话任务
hanhua = BangpaiPicNode(r'resources/bangpai/small/hanhua.png', completeFunc=hanhuaFunc)
leafNode.append(hanhua)
# 结束
def finishFunc(locate, chaseWin):
sys.exit(0)
finish = BangpaiPicNode(r'resources/bangpai/small/finish.png', completeFunc=finishFunc)
self._rootList = [qiecuo, fanwen, wupin, wupin2, hanhua] # finish
for item in leafNode:
if item.next is not None:
for each in self._rootList:
item.next.append(each)
else:
item.next = self._rootList
item.next.append(nxtNode)
nxtNode.next = self._rootList
def do(self):
nodePointer = self._rootList
findPicNode = None
while findPicNode is None or findPicNode.next is not None:
Util.leftClick(self.chaseWin[0], self.chaseWin[1])
idx, locate = self._findPic(nodePointer)
time = 0
while locate is None:
if not self._stopCheck():
sys.exit(0)
cooldown(0.2)
time += 1
cooldown(0.5)
idx, locate = self._findPic(nodePointer)
if time >= 5 and locate is None and time % 4 == 0:
# 没法判断特征图片的任务都能通过不断点击追踪完成(因为挂机刷怪会停止没发判断,先这么搞)
Util.leftClick(self.chaseWin[0], self.chaseWin[1])
findPicNode = nodePointer[idx]
log("选中:" + findPicNode.elem)
findPicNode.completeFunc(locate, self.chaseWin)
nodePointer = findPicNode.next
log("后续可能出现:")
for each in nodePointer:
log(each.elem)
cooldown(0.3)
# 有特征图片的任务
def _findPic(self, nodeList):
for idx, each in enumerate(nodeList):
if each.elem is None:
continue
locate = None
if isinstance(each.elem, list):
for iid, item in enumerate(each.elem):
locate = Util.locateCenterOnScreen(item)
if locate is not None:
break
else:
locate = Util.locateCenterOnScreen(each.elem)
if locate is not None:
return idx, locate
return None, None
# 大窗口
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='OF Generate')
parser.add_argument('-i', '--idx', required=False, default=0, type=int)
args = parser.parse_args()
pyautogui.PAUSE = 0.5
log("start task....")
def func(idx):
Bangpai(idx=idx).do()
if args.idx == -1:
i = 0
while args.idx == -1 and len(getWindowList()) > i:
func(i)
i = i + 1
else:
func(args.idx)