Skip to content

Commit

Permalink
v5.24 增加自动校准
Browse files Browse the repository at this point in the history
  • Loading branch information
CHNZYX committed Aug 28, 2023
1 parent 4775b37 commit 6dbc89d
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 40 deletions.
32 changes: 8 additions & 24 deletions align_angle.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

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


def get_angle(su, safe):
Expand All @@ -20,29 +19,24 @@ def get_angle(su, safe):
shape = (int(su.scx * 190), int(su.scx * 190))
local_screen = su.get_local(0.9333, 0.8657, shape)
local_screen[np.sum(np.abs(local_screen - blue), axis=-1) <= 150] = blue
if safe:
su.press("s")
return su.get_now_direc(local_screen)


# 不同电脑鼠标移动速度、放缩比、分辨率等不同,因此需要校准
# 基本逻辑:每次转60度,然后计算实际转了几度,计算出误差比
def main(cnt=10, safe=0):
if safe:
return
def main(cnt=10, safe=0, ang=[1,1,3], su=None):
log.info("开始校准")
su = UniverseUtils()
if su is None:
from utils.utils import UniverseUtils
su = UniverseUtils()
su.multi = 1
init_ang = get_angle(su, safe)
lst_ang = init_ang
win32api.mouse_event(win32con.MOUSEEVENTF_MOVE, 0, 3000)
if safe:
su.press("w", 0.2)
for i in [1,1,3]:
for i in ang:
ang_list = []
for j in range(i):
win32api.mouse_event(win32con.MOUSEEVENTF_MOVE, 0, 300)
su.mouse_move(60)
su.mouse_move(100,fine=3//i)
time.sleep(0.2)
now_ang = get_angle(su, safe)
sub = lst_ang - now_ang
while sub < 0:
Expand All @@ -56,7 +50,7 @@ def main(cnt=10, safe=0):
ay = 0
for j in ang_list:
if abs(j - np.median(ang_list)) <= 5:
ax += 60
ax += 100
ay += j
su.multi *= ax / ay
config.angle = str(su.multi)
Expand All @@ -66,16 +60,6 @@ def main(cnt=10, safe=0):
win32gui.SetForegroundWindow(su.my_nd)
except pywintypes.error:
pass
else:
key = "sasddwwwaw"
su.threshold = 0.97
for i in range(len(key)):
time.sleep(0.5)
su.get_screen()
if su.goodf() and not su.check("herta", 0.3656,0.4222):
break
else:
su.press(key[i], 0.2)
log.info("校准完成")
return 1

Expand Down
9 changes: 6 additions & 3 deletions states.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def route(self):
begin = 0
self.press("F4")
self.get_screen()
# self.click_target('imgs/tp.jpg',0.9,True) # 如果需要输出某张图片在游戏窗口中的坐标,可以用这个
# self.click_target('imgs/floor/ff1.jpg',0.9,True) # 如果需要输出某张图片在游戏窗口中的坐标,可以用这个
res = self.normal()
# 未匹配到图片,降低匹配阈值,若一直无法匹配则乱点
if res == 0:
Expand Down Expand Up @@ -287,8 +287,8 @@ def normal(self):
)
return 1
elif self.re_align == 1 and self.debug == 0:
align_angle(10, 1)
self.multi = config.multi
# align_angle(10, 1)
# self.multi = config.multi
self.re_align += 1
is_killed = text in ['沉浸','紧锁','复活','下载']
if is_killed == 0:
Expand Down Expand Up @@ -413,6 +413,7 @@ def normal(self):
self.re_align += 1
self.fail_count+=1
else:
self.multi = 1
if self.debug == 0:
notif("中途结算",f"地图{self.now_map},当前层数:{self.floor+1}")
self.floor = 0
Expand All @@ -428,6 +429,8 @@ def normal(self):
)
self.lst_changed = time.time()
return 1
if self.multi == 1:
align_angle(0,1,[1],self)
# 寻路
if self.mini_state:
self.get_direc_only_minimap()
Expand Down
26 changes: 13 additions & 13 deletions utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def __init__(self):
scale_x = dpi_x / 96
scale_y = dpi_y / 96
self.scale = ctypes.windll.user32.GetDpiForWindow(hwnd) / 96.0
log.info("DPI: "+str(self.scale))
log.info("DPI: "+str(self.scale)+" A:"+str(int(self.multi*100)/100))
# 计算出真实分辨率
self.real_width = int(self.xx * scale_x)
# x01y01:窗口左上右下坐标
Expand Down Expand Up @@ -266,7 +266,7 @@ def check(self, path, x, y, mask=None, threshold=None, large=True):
return local_screen
result = cv.matchTemplate(local_screen, target, cv.TM_CCORR_NORMED)
min_val, max_val, min_loc, max_loc = cv.minMaxLoc(result)
if path == "./imgs/bonus_c.jpg#":
if path == "./imgs/floor/ff1.jpg#":
cv.imwrite("tmp.jpg", local_screen)
print(max_val)
self.tx = x - (max_loc[0] - 0.5 * local_screen.shape[1]) / self.xx
Expand Down Expand Up @@ -533,8 +533,8 @@ def get_level(self):
self.press('m',0.2)
time.sleep(2.5)
self.get_screen()
for i in range(12,0,-1):
if self.check("floor/ff" + str(i + 1),0.0635,0.8917):
for i in range(12,-1,-1):
if self.check("floor/ff" + str(i + 1),0.0589,0.8796):
self.floor=i
log.info(f"当前层数:{i+1}")
self.floor_init=1
Expand Down Expand Up @@ -630,8 +630,8 @@ def move_to_interac(self, i=0, abyss=0):
sub*=1.2
else:
sub=0
if (abs(sub)>50 and target[1]==3 and not abyss) or self.floor in [3,7,12]:
sub=0
#if (abs(sub)>50 and target[1]==3 and not abyss) or self.floor in [3,7,12]:
# sub=0
self.mouse_move(sub)
return sub
else:
Expand Down Expand Up @@ -1021,19 +1021,19 @@ def get_direc(self):
pass

# 视角转动x度
def mouse_move(self, x, init=1):
if x > 30:
y = 30
elif x < -30:
y = -30
def mouse_move(self, x, fine=1):
if x > 30//fine:
y = 30//fine
elif x < -30//fine:
y = -30//fine
else:
y = x
dx = int(16.5 * y * self.multi * self.scale)
if self._stop == 0 and self.stop_move==0:
win32api.mouse_event(win32con.MOUSEEVENTF_MOVE, dx, 0) # 进行视角移动
time.sleep(0.05)
time.sleep(0.05*fine)
if x != y:
self.mouse_move(x - y,0)
self.mouse_move(x - y, fine)

# 在大地图中覆盖小地图
def write_map(self, bw_map):
Expand Down

0 comments on commit 6dbc89d

Please sign in to comment.