Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Kuwernv committed May 28, 2023
2 parents ca8ca94 + f070936 commit c5e4610
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 29 deletions.
2 changes: 1 addition & 1 deletion info.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
0.7086614173228346
2
巡猎
4e7323fce15194516fb6cbb432e5d65dbd314928
c1feb69b4d6b166def00a597e272cabaca770c2f
13 changes: 8 additions & 5 deletions states.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ def normal(self):
ok = 1
flag = False
break
if self._stop:return 1
if flag:
# 是否有巡猎buf
self.check('bless/'+str(self.my_fate), 0.5062, 0.3157, mask='mask')
Expand All @@ -137,6 +138,7 @@ def normal(self):
if ok == 0:
self.click((0.2990, 0.1046))
time.sleep(2.5)
if self._stop:return 1
self.get_screen()
# cv.imwrite('imgs/collect/'+time.strftime("%Y-%m-%d-%H-%M-%S", time.localtime())+'.jpg',self.screen)
# 特殊优先级buf
Expand Down Expand Up @@ -190,7 +192,10 @@ def normal(self):
if self.big_map_c == 0:
while 1:
if np.mean(self.get_screen()) >30: break
time.sleep(0.1)
if self._stop:return 1
time.sleep(2.2)
if self._stop:return 1
self.get_screen()
self.exist_minimap()
self.big_map_c = 1
Expand All @@ -216,13 +221,12 @@ def normal(self):
if time.time() - self.lst_tm > 5:
if self.find == 0:
self.press('s', 0.5)
pyautogui.keyDown('w')
if self._stop==0:
pyautogui.keyDown('w')
time.sleep(0.5)
self.get_screen()
else:
pyautogui.keyDown('w')
time.sleep(0.2)
pyautogui.keyUp('w')
self.press('w',0.2)
self.get_screen()
self.lst_tm = time.time()
if time.time() - self.lst_changed >= 35 and self.find == 1 and self.debug == 0:
Expand Down Expand Up @@ -353,7 +357,6 @@ def get_center(self, img, i, j):
def stop(self, *_, **__):
log.info("尝试停止运行")
self._stop = True
exit()

def check_f8(self):
"""检测F8键是否被按下,如果按下则停止运行"""
Expand Down
9 changes: 6 additions & 3 deletions utils/update_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def download_and_extract_zip(url, root_path):
total_size = int(response.headers.get('Content-Length', 0))
if total_size == 0:
print("下载失败!")
return
return 0
block_size = 1024 # 每次下载的块大小
progress = 0
with open(zip_file_path, 'wb') as file:
Expand All @@ -36,6 +36,7 @@ def download_and_extract_zip(url, root_path):
zip_ref.extractall(root_path)

os.remove(zip_file_path) # 删除ZIP文件
return 1


def sync_github_repo(repo_url, root_path):
Expand All @@ -46,7 +47,7 @@ def sync_github_repo(repo_url, root_path):
os.makedirs(root_path, exist_ok=True)

# 下载并解压ZIP文件
download_and_extract_zip(api_url, root_path)
return download_and_extract_zip(api_url, root_path)


def get_latest_branch_sha(repo_url):
Expand Down Expand Up @@ -87,7 +88,9 @@ def update_map():
map_path = os.path.join(root_path, 'imgs\\maps')
print("Map path: " + map_path)
# 下载map仓库并解压
sync_github_repo(repo_url, root_path)
status = sync_github_repo(repo_url, root_path)
if status==0:
return
print("下载完成")
# 找出下载的map文件夹
t = os.listdir(root_path)
Expand Down
64 changes: 44 additions & 20 deletions utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,33 @@
from copy import deepcopy
import math
import random
import win32gui,win32com.client,pythoncom

from utils.config import config
from utils.log import log


def set_forground():
config.read()
try:
pythoncom.CoInitialize()
shell = win32com.client.Dispatch("WScript.Shell")
shell.SendKeys(' ') #Undocks my focus from Python IDLE
game_nd = win32gui.FindWindow('UnityWndClass', "崩坏:星穹铁道")
win32gui.SetForegroundWindow(game_nd)
except:
pass
class UniverseUtils:
def __init__(self):
self.my_nd = win32gui.GetForegroundWindow()
set_forground()
self.multi = config.multi
self.diffi = config.diffi
self.fate = config.fate
self.my_fate = 4
for i in range(len(config.fates)):
if config.fates[i]==self.fate:
self.my_fate=i
self.my_nd = win32gui.GetForegroundWindow()
self.game_nd = win32gui.FindWindow('UnityWndClass', "崩坏:星穹铁道")
try:
win32gui.SetForegroundWindow(self.game_nd)
except pywintypes.error:
pass
self.debug, self.find = 0, 1
self.bx, self.by = 1920, 1080
log.warning("等待游戏窗口")
Expand Down Expand Up @@ -59,6 +66,7 @@ def __init__(self):
# xx yy:窗口大小
# scx scy:当前窗口和基准窗口(1920*1080)缩放大小比例
if Text == '崩坏:星穹铁道':
time.sleep(1)
break
else:
time.sleep(0.3)
Expand All @@ -70,9 +78,11 @@ def __init__(self):

def press(self, c, t=0):
log.debug(f"按下按钮 {c},等待 {t} 秒后释放")
pyautogui.keyDown(c)
if self._stop==0:
pyautogui.keyDown(c)
time.sleep(t)
pyautogui.keyUp(c)
if self._stop==0:
pyautogui.keyUp(c)

def get_point(self, x, y):
# 得到一个点的浮点表示
Expand Down Expand Up @@ -111,10 +121,12 @@ def click(self, points):
if self.full:
x += 11
y += 11
win32api.SetCursorPos((x, y))
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, x, y, 0, 0)
if self._stop==0:
win32api.SetCursorPos((x, y))
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, x, y, 0, 0)
time.sleep(0.3)
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, x, y, 0, 0)
if self._stop==0:
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, x, y, 0, 0)
time.sleep(0.5)

def click_target(self, target_path, threshold, flag=True):
Expand Down Expand Up @@ -361,7 +373,8 @@ def get_direc(self):
ps = 6
else:
ps = 6
pyautogui.keyDown('w')
if self._stop==0:
pyautogui.keyDown('w')
time.sleep(0.5)
ltm = time.time()
bw_map = self.get_bw_map(sbl=bl)
Expand All @@ -374,6 +387,8 @@ def get_direc(self):
td = 0
t = 2
for i in range(1000):
if self._stop==1:
return
ctm = time.time()
bw_map = self.get_bw_map(sbl=(i <= 4 and bl))
self.get_loc(bw_map, fbw=1)
Expand Down Expand Up @@ -402,32 +417,39 @@ def get_direc(self):
if dls[-4] == nds:
ts = ' da'
if t > 0:
pyautogui.keyUp('w')
if self._stop==0:
pyautogui.keyUp('w')
self.press('s', 0.35)
self.press(ts[t], 0.5)
pyautogui.keyDown('w')
if self._stop==0:
pyautogui.keyDown('w')
t -= 1
else:
pyautogui.keyUp('w')
if self._stop==0:
pyautogui.keyUp('w')
break
if nds <= ps or self.check('f', 0.3901, 0.5093) or self.check('run', 0.9844, 0.7889,
threshold=0.93) == 0:
pyautogui.keyUp('w')
if self._stop==0:
pyautogui.keyUp('w')
break
ds = nds
dls.append(ds)
log.info("进入新地图或者进入战斗")
if type == 0:
self.lst_tm = time.time()
if type == 1:
pyautogui.click()
if self._stop==0:
pyautogui.click()
time.sleep(1)
pyautogui.click()
if self._stop==0:
pyautogui.click()
time.sleep(1)
if type == 2 or type == 3:
key_list = ['sasddww', 'sdsaaww', 'sssw']
key = key_list[random.randint(0, 2)]
for i in range(-1,len(key)):
if self._stop:return
time.sleep(0.4)
self.get_screen()
if self.check('f', 0.3901, 0.5093):
Expand All @@ -438,7 +460,8 @@ def get_direc(self):
break
else:
if i == -1:
pyautogui.click()
if self._stop==0:
pyautogui.click()
time.sleep(1.6)
else:
self.press(key[i], 0.25)
Expand All @@ -463,7 +486,8 @@ def mouse_move(self, x):
else:
y = x
dx = int(9800 * y * 1295 / self.real_width / 180 * self.multi)
win32api.mouse_event(win32con.MOUSEEVENTF_MOVE, dx, 0) # 进行视角移动
if self._stop==0:
win32api.mouse_event(win32con.MOUSEEVENTF_MOVE, dx, 0) # 进行视角移动
time.sleep(0.05)
if x != y:
self.mouse_move(x - y)
Expand Down

0 comments on commit c5e4610

Please sign in to comment.