def open_cw_bank():
"""Finds the visiblest square of the chest in castle wars bank, wors better when viewing from above at shortest distance."""
# gets RS window's position
rsx,rsy = position()
# Takes screenshot, as Hue-saturated-value image
play_window,psx,psy = getPlayingScreen()
psx += rsx
psy += rsy
lower_gray = np.array([0,15,55])
upper_gray = np.array([10,25,125])
# Makes a black/white mask
mask = cv2.inRange(play_window, lower_gray, upper_gray)
# inverts selection
#res = cv2.bitwise_and(play_window, play_window, mask=mask)
kernel = np.ones((5,5), np.uint8)
dilation = cv2.dilate(mask, kernel, iterations = 1)
#cv2.imshow('img', dilation)
#cv2.waitKey(0)
# Finds contours
_,contours,_ = cv2.findContours(dilation.copy(), cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
try:
# looks for center of grey color with biggest area, > 3000
for con in contours:
if cv2.contourArea(con) > 3000:
M = cv2.moments(con)
# finds centroid
cx,cy = (int(M["m10"] / M["m00"]), int(M["m01"] / M["m00"]))
psx += cx
psy += cy
# adds randomness to coords
psx += random.randint(-17,17)
psy += random.randint(-17,17)
#move click chest
Mouse.moveClick(psx,psy,1)
RandTime.randTime(0,0,0,0,9,9)
break
except Exception as e:
print("Bank NOT found!\nMove camera around!")
评论列表
文章目录