This repository has been archived by the owner on Aug 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
start.py
216 lines (198 loc) · 8.1 KB
/
start.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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
import os
import time
from core.worker import worker, box
from ppadb.client import Client
from cv2 import cv2
import json
import sys
from tqdm import tqdm
import argparse
__author__ = "Paver(Zhen_Bo)"
os.system('cls')
def app_path():
"""Returns the base application path."""
if hasattr(sys, 'frozen'):
# Handles PyInstaller
return os.path.dirname(sys.executable) # 使用pyinstaller打包后的exe目录
return os.path.dirname(__file__) # 没打包前的py目录
root_path = app_path()
def setup():
adb_path = "{}/adb/adb.exe".format(root_path)
os.system("{0} start-server".format(adb_path))
os.system("cls")
client = Client(host="127.0.0.1", port=5037)
devices = client.devices()
return select_devices(client, devices)
def get_template(version, folder=None):
templates = dict()
templates_path = os.path.join(root_path, "templates")
templates_path = os.path.join(templates_path, version)
if folder is not None:
templates_path = os.path.join(templates_path, folder)
for name in os.listdir(templates_path):
img = cv2.imread(os.path.join(templates_path, name))
templates[name.replace('.png', '')] = img
return templates
def select_devices(client, devices, error=0):
for i in range(len(devices)):
print("\033[1;32m{}: {}\033[0m".format(i, devices[i].serial))
if error == 1:
print("\033[1;31m{}\033[0m".format("!!!輸入設備編號過大!!!"))
elif error == 2:
print("\033[1;31m{}\033[0m".format("!!!編號輸入錯誤,請在試一次!!!"))
print("輸入a以新增設備")
try:
inputIndex = input("請輸入編號 [1 ~ {0}]:".format(len(devices)))
value = int(inputIndex)
if value < 0:
exit()
elif value > len(devices):
os.system('cls')
return select_devices(client, devices, 1)
else:
return devices[value]
except (KeyboardInterrupt, SystemExit):
raise Exception("KeyboardInterrupt")
except:
if inputIndex.lower() == "a":
port = input("port號為?")
if len(port) == 4 and port.isdigit():
client.remote_connect("127.0.0.1", int(port))
devices = client.devices()
os.system('cls')
return select_devices(client, devices)
else:
os.system('cls')
return select_devices(client, devices, 2)
else:
os.system('cls')
return select_devices(client, devices, 2)
def recovery_plane():
apple_dict = {"": "", "0": "quartz",
"1": "goldden", "2": "silver", "3": "copper"}
apple_name = {"": "自然回體", "0": "聖晶石", "1": "金蘋果", "2": "銀蘋果", "3": "銅蘋果"}
while True:
os.system('cls')
print("回體方案:")
for i in range(1, 4):
print("{} = {}".format(i, apple_name["{}".format(i)]))
print("不輸入為自然回體")
apple = input("請選擇方案: ")
if apple not in apple_dict:
continue
else:
apple = apple_dict[apple]
if apple == "":
return {"apple": "", "count": ""}
else:
break
while True:
count = input("請輸入使用上限: ")
if count.isdigit():
return {"apple": apple, "count": count}
def get_script():
with open('{}/UserData/script.json'.format(root_path), newline='', encoding='utf8') as jsonfile:
data = json.load(jsonfile)
print("請選擇要使用的腳本")
for i in range(len(data['script'])):
print("{}: {}".format(i, data['script'][i]['name']))
number = input("請輸入編號:")
while not number.isdigit() or int(number) > len(data['script']) or int(number) < 0:
print("輸入編號錯誤,請重新輸入")
number = input("請輸入編號:")
return data['script'][int(number)]
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument("--debug", type=bool, default=False)
parser.add_argument("--boxmode", type=bool, default=False)
parser.add_argument("--version", type=str, default="JP")
args = parser.parse_args()
debug = args.debug
boxmode = args.boxmode
version = args.version
os.system('cls')
dev = setup()
os.system('cls')
if boxmode == False:
script_data = get_script()
templates = get_template(script_data["version"])
while True:
times = input("請問要執行幾次:")
if times == "":
times = 999
break
elif times.isdigit():
break
apple = recovery_plane()
width = len(script_data['battle'])+2
bar_format = "{{desc:}}{{percentage:3.0f}}%|{{bar:{}}}|".format(
width)
progress = tqdm(range(width), desc="腳本進度",
bar_format=bar_format, file=sys.stdout)
bot = worker(root=root_path, device=dev, templates=templates, name=script_data["name"], times=times,
apple=apple['apple'], count=apple['count'], team=script_data['team'],
support=script_data['support'], recover=script_data['recover'], progress_bar=progress)
print("\r\x1b[2K", end='')
total_runtime = 0
singel_runtime = 0
if debug:
while debug:
shell = input("\r\x1b[2K指令: ")
exec("bot.{}".format(shell))
else:
while True:
tstart = time.time()
bot.pbar.reset()
for instruct in script_data["battle"]:
if instruct == "start_battle()":
instruct = "start_battle({},{})".format(
round(total_runtime, 1), round(singel_runtime, 1))
exec("bot.{}".format(instruct))
time.sleep(1)
# for instruct in progress:
# if instruct == "start_battle()":
# instruct = "start_battle({},{})".format(
# round(total_runtime, 1), round(singel_runtime, 1))
# print("\r", end='')
# exec("bot.{}".format(instruct))
# time.sleep(1)
tend = time.time()
singel_runtime = int(tend)-int(tstart)
total_runtime += singel_runtime
else:
game = {"0": "JP", "1": "TW"}
print("\033[31m Scrpit made by\033[0m\033[41;37mPaver\033[0m,github:\033[37;34mhttps://github.com/Zhen-Bo\033[0m")
print(
"\033[31m此腳本作者為\033[0m\033[41;37mPaver\033[0m,github頁面:\033[37;34mhttps://github.com/Zhen-Bo\033[0m")
print("\033[31m請勿使用於商業用途,此程式包含MIT授權\033[0m")
while True:
print("請問遊戲版本?")
print("輸入0 = 日版")
print("輸入1 = 台版")
version = input("請輸入版本(0/1): ")
if version in ["0", "1"]:
break
bot = box(device=dev, templates=get_template(
"{}".format(game[version]), folder="box"))
while True:
os.system('cls')
print(
"\033[31m Scrpit made by\033[0m\033[41;37mPaver\033[0m,github:\033[37;34mhttps://github.com/Zhen-Bo\033[0m")
print(
"\033[31m此腳本作者為\033[0m\033[41;37mPaver\033[0m,github頁面:\033[37;34mhttps://github.com/Zhen-Bo\033[0m")
print("\033[31m請勿使用於商業用途,此程式包含MIT授權\033[0m")
i = 0
times = int(input("請問要抽幾箱: "))
while i <= times:
i += 1
if i > times:
break
elif i > 1:
bot.tap(bot.result[1])
bot.standby("execute")
bot.standby("close")
print("目前在抽第 {} 箱".format(i))
status = bot.box_gacha()
if status == True:
break
os.system('PAUSE')