def jie_chu_tu_po_block_liao(self, handle): tu = self.window.jie_tu(handle) tu.save('temp/temp.bmp') x = 100 - 2 * 10 + 15 + 188 y = 100 - 2 * 10 + 12 + 10 w = 300 - 82 h = 120 - 35 point0 = [x, y] for i in range(8): if i == 0: point = point0 else: point = [ int(point0[0] + int(i % 2) * 226), int(point0[1] + int(i / 4) * 91) ] point2 = [point[0] + w, point[1] + h] print(str(i) + str(point)) src_img = Img.cut_img_path('temp/temp.bmp', point, point2) Img.save('temp/temp' + str(i) + '.bmp', src_img) re, x, y = Img.find_img_in_img('temp/temp' + str(i) + '.bmp', self.mei_da_guo_path) if re == 0: return 0, x + handle.left + point[0], y + handle.top + point[1] return -1, 0, 0
def test_main(self): # 测试函数:截取游戏窗口temp.bmp # 再截出N卡的小块,确定准确后的百分比 handle = Handle() game = Game() arr12 = [[2, 0], [2, 1], [2, 2], [2, 3], [2, 4], [2, 5], [2, 6], [2, 7], [0, 1], [0, 4], [0, 7], [1, 1], [1, 4], [1, 7]] if self.set_yys("1", game, handle) == 0: # while 1: game.get_scene(handle) # 产生temp.bmp # metrics_x = GetSystemMetrics(0) # 获取分辨率 # metrics_y = GetSystemMetrics(1) # 获取分辨率 # gou = Gouliang(metrics_x, metrics_y, handle) # gou.find_and_huang(False, False) # n 卡分块 print("kais") top = 0.25 left = 0.15 bottom = codedef.n_bottom right = codedef.n_right kuang = int(0.1 * (handle.right - handle.left)) img = Img() name = 0 j = 0 while j < 4: i = 0 while i < 8: # p = arr12[name] # i = p[1] # j = p[0] point = [ int(left * (handle.right - handle.left)) + kuang * (i + 0), int(top * (handle.bottom - handle.top)) + kuang * (j + 0) ] point2 = [ int(left * (handle.right - handle.left)) + kuang * (i + 1), int(top * (handle.bottom - handle.top)) + kuang * (j + 1) ] tag_img = img.cut_img_path('temp/temp.bmp', point, point2) img.save("temp/t" + str(name) + ".bmp", tag_img) i += 1 name += 1 time.sleep(0.2) j += 1
def jie_jie_number(self, handle): # 获得游戏界面截图 tu = self.window.jie_tu(handle) tu.save('temp/temp.bmp') re1 = Img.find_all_img_in_img('temp/temp.bmp', self.da_guo_le_path, 0.8) re2 = Img.find_all_img_in_img('temp/temp.bmp', self.da_bu_guo_path, 0.96) # 匹配精度0.96 re3 = Img.find_all_img_in_img('temp/temp.bmp', self.mei_da_guo_path, 0.90) # print("打过了" + str(re1) + ";打不过:" + str(re2) + ";没打过:" + str(re3)) return re1, re2, re3
def find_img(handle, img_path, accuracy=0.90): window_img = ImageGrab.grab( (handle.left, handle.top, handle.right, handle.bottom)) window_img.save('temp/temp.bmp') re, x, y = Img.find_img_in_img('temp/temp.bmp', img_path, accuracy) if re == -1: return codedef.ERROR_END, -1, -1 return codedef.NORMAL_END, x + handle.left, y + handle.top
def is_max(self, point, point2, accuracy): # 返回找到的图的位置 在指定路径的图《裁剪后》找另一路径的图 re, x, y = Img.find_img_in_cut_img(src_img_path='temp/temp.bmp', target_img_path='yys/满级标记.bmp', point=point, point2=point2, accuracy=accuracy) if re == 0: return True else: re, x, y = Img.find_img_in_cut_img(src_img_path='temp/temp.bmp', target_img_path='yys/观战标记.bmp', point=point, point2=point2, accuracy=accuracy) if re == 0: return True return False
def get_ji_bai_times(self): target_img_path = "yys/击败次数.bmp" re, x, y = Img.find_img_in_img('temp/temp.bmp', target_img_path, 0.90) if re != 0: return -1 x1 = 60 # 左右偏移量 y1 = 0 # 上下偏移量 width = 34 # 目标宽度 height = 20 # 目标高度 # 最后一个参数,如果是黑底白字 赋True 白底黑字 赋False power_number_str = Img.find_str_in_img(self.src_img_path, target_img_path, x1, y1, width, height, False) if power_number_str != "-1": power_number_str = power_number_str.split('/') power_number = power_number_str[0] if power_number == '': return -1 return int(power_number) return -1
def lianjie(): t = 0 re = -1 while t < 5: window_img = ImageGrab.grab( (1920 / 2 + 300, 1080 - 50, 1920 / 2 + 800, 1080)) window_img.save('temp/temp.bmp') re, x, y = Img.find_img_in_img('temp/temp.bmp', '异星工厂/警报.bmp', 0.8) if re == 0: break t += 1 return re
def jie_chu_tu_po_block(self, handle): tu = self.window.jie_tu(handle) tu.save('temp/temp.bmp') if self.metrics_x == 1920: x = 100 - 2 * 10 + 15 y = 100 - 2 * 10 + 12 w = 300 - 80 h = 120 - 35 w_silde = 230 h_silde = 91 jindu = 0.5 else: x = 68 y = 74 w = 151 h = 58 w_silde = 158 h_silde = 61 jindu = 0.7 point0 = [x, y] for i in range(9): if i == 0: point = point0 else: point = [ int(point0[0] + int(i % 3) * w_silde), int(point0[1] + int(i / 3) * h_silde) ] point2 = [point[0] + w, point[1] + h] # print(str(i) + str(point)) src_img = Img.cut_img_path('temp/temp.bmp', point, point2) Img.save('temp/temp' + str(i) + '.bmp', src_img) re, x, y = Img.find_img_in_img('temp/temp' + str(i) + '.bmp', self.mei_da_guo_path, jindu) if re == 0: return 0, x + handle.left + point[0], y + handle.top + point[1] return -1, 0, 0
def witch_up(self, handle, UP, src_img_path, target_img_path): pos_list = Img.find_all_pos_img_in_img(src_img_path, target_img_path, 0.9) if pos_list is None: return codedef.ERROR_END for i in range(len(pos_list)): x = int(pos_list[i]['result'][0]) y = int(pos_list[i]['result'][1]) if self.find_UP(x, y, UP, src_img_path) == codedef.NORMAL_END: mouse = Mouse() # mouse.mouse_to(handle.left + x, handle.top + y) mouse.click(handle.left + x, handle.top + y) return codedef.NORMAL_END return codedef.ERROR_END
def __init__(self, buyyan=0, buyyu=0, mod=0): super(rilunzhicheng, self).__init__() # 获取分辨率 self.m = Mouse(GetSystemMetrics(0), GetSystemMetrics(1)) self.HadOpenEye = False self.mod = mod # 0刷玉,1刷层 self.top = 0.25 self.left = 0.15 self.img = Img() self.mouse = Mouse() self.arr1 = [[1, 0], [1, 1], [1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [2, 1], [2, 4], [2, 6], [3, 1], [3, 4], [3, 6]] self.arr2 = [[1, 7], [1, 6], [1, 5], [1, 4], [1, 3], [1, 2], [1, 1], [1, 0], [2, 1], [2, 4], [2, 6], [3, 1], [3, 4], [3, 6]] self.arr3 = [[2, 0], [2, 1], [2, 2], [2, 3], [2, 4] , [2, 5], [2, 6], [2, 7], [1, 1], [1, 4], [1, 6], [0, 1], [0, 4], [0, 6]] self.arr4 = [[2, 7], [2, 6], [2, 5], [2, 4], [2, 3], [2, 2], [2, 1], [2, 0], [1, 1], [1, 4], [1, 6], [0, 1], [0, 4], [0, 6]] self.da_wang = False self.buyyan = buyyan # 花勾玉买眼的最大次数 self.buyyu = buyyu # 花勾玉买溯玉的最大次数 self.jiao_pos = 0
def fight_win(self, argument, handle): # 查找已满级的数量 num_max_l = Img.find_all_img_in_img('temp/temp.bmp', "yys/已满级.bmp", 0.8) print("队员找已满级的数量:" + str(num_max_l)) huan_num = 0 # 超过就换狗粮 if self.Beater is False and self.BeatMax is True: huan_num += 1 if num_max_l != -1: if num_max_l > huan_num: # 换狗粮标记 self.huang_flag = True self.fight_end(argument, handle) return num_max_l
def find_UP(self, x, y, UP, src_img_path): if UP == codedef.UP_C_COIN: target_BGR = codedef.UP_COIN elif UP == codedef.UP_C_EXP: target_BGR = codedef.UP_EXP elif UP == codedef.UP_C_REWARD: target_BGR = codedef.UP_REWARD else: return codedef.ERROR_END point_from = [x - 80, y + 50] point_to = [x + 80, y + 160] src_img = Img.cut_img_path(src_img_path, point_from, point_to) # Img.save("temp/tt.bmp", src_img) # src_img = Img.read_img("temp/tt.bmp") img_info = src_img.shape # BGR image_height = img_info[0] image_weight = img_info[1] dxx = [3, 3, 3] max = 10 if self.metrics_x == 1920: pass else: dxx = [5, 5, 5] max = 5 index = 0 for w in range(image_height): for j in range(image_weight): yxx = list(abs(src_img[w][j] - target_BGR)) if yxx[0] < dxx[0] and yxx[1] < dxx[1] and yxx[2] < dxx[2]: index += 1 if index > max: return codedef.NORMAL_END return codedef.ERROR_END
class rilunzhicheng(Game): def __init__(self, buyyan=0, buyyu=0, mod=0): super(rilunzhicheng, self).__init__() # 获取分辨率 self.m = Mouse(GetSystemMetrics(0), GetSystemMetrics(1)) self.HadOpenEye = False self.mod = mod # 0刷玉,1刷层 self.top = 0.25 self.left = 0.15 self.img = Img() self.mouse = Mouse() self.arr1 = [[1, 0], [1, 1], [1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [2, 1], [2, 4], [2, 6], [3, 1], [3, 4], [3, 6]] self.arr2 = [[1, 7], [1, 6], [1, 5], [1, 4], [1, 3], [1, 2], [1, 1], [1, 0], [2, 1], [2, 4], [2, 6], [3, 1], [3, 4], [3, 6]] self.arr3 = [[2, 0], [2, 1], [2, 2], [2, 3], [2, 4] , [2, 5], [2, 6], [2, 7], [1, 1], [1, 4], [1, 6], [0, 1], [0, 4], [0, 6]] self.arr4 = [[2, 7], [2, 6], [2, 5], [2, 4], [2, 3], [2, 2], [2, 1], [2, 0], [1, 1], [1, 4], [1, 6], [0, 1], [0, 4], [0, 6]] self.da_wang = False self.buyyan = buyyan # 花勾玉买眼的最大次数 self.buyyu = buyyu # 花勾玉买溯玉的最大次数 self.jiao_pos = 0 def do_work(self, argument, handle): switcher = { SceneKey.NUKOWN: self.error_scene, SceneKey.ZHANG_DOU_JIANG_LI: self.fight_end, SceneKey.ZHANG_DOU_SHENG_LI: self.fight_end, SceneKey.ZHANG_DOU_SHI_BAI: self.fight_end, SceneKey.XUAN_SHANG_FENG_YING_YAO_QING: self.fight_end, SceneKey.LUN_HUI_MI_JING: self.this_main, SceneKey.DA_GUAI_KAI_SHI: self.kai_shi_da_guai, SceneKey.XUAN_ZI_YUAN: self.xuan_zi_yuan, } # Get the function from switcher dictionary func = switcher.get(argument, self.father)(argument, handle) # Execute the function return func def father(self, argument, handle): Game.do_work(self, argument, handle) return codedef.NORMAL_END def get_scene(self, handle): window_img = self.window.jie_tu(handle) window_img.save('temp/temp.bmp') path = "yys/scene/" if Game.if_exist(path + "悬赏封印邀请界面.bmp") == 0: return SceneKey.XUAN_SHANG_FENG_YING_YAO_QING if Game.if_exist(path + "战斗奖励界面.bmp") == 0: return SceneKey.ZHANG_DOU_JIANG_LI if Game.if_exist(path + "战斗胜利界面.bmp") == 0: return SceneKey.ZHANG_DOU_SHENG_LI if Game.if_exist(path + "战斗失败界面.bmp") == 0: return SceneKey.ZHANG_DOU_SHI_BAI if Game.if_exist("yys/日轮之城/轮回秘境界面.bmp") == 0: return SceneKey.LUN_HUI_MI_JING if Game.if_exist("yys/日轮之城/打怪开始界面.bmp") == 0: return SceneKey.DA_GUAI_KAI_SHI if Game.if_exist("yys/日轮之城/选资源界面.bmp") == 0: return SceneKey.XUAN_ZI_YUAN return SceneKey.NUKOWN def xuan_zi_yuan(self, argument, handle): if self.click_img("yys/日轮之城/选金币按钮.bmp", handle) == 0: time.sleep(1) if self.click_img("yys/日轮之城/确认按钮.bmp", handle) == 0: time.sleep(1) return codedef.NORMAL_END def re_set(self): self.jiao_pos = 0 self.HadOpenEye = False self.da_wang = False return codedef.NORMAL_END def this_main(self, argument, handle): self.HadOpenEye = False self.da_wang = False # 如果是刷层,先看看有没有下一关 if self.if_exist("yys/日轮之城/已开眼.bmp", 0.8) == 0: self.HadOpenEye = True elif self.if_exist("yys/日轮之城/已开眼2.bmp", 0.8) == 0: self.HadOpenEye = True if self.click_img("yys/日轮之城/获取时玉.bmp", handle, 0.8) == 0: time.sleep(1) if self.click_img("yys/日轮之城/获取奖励.bmp", handle, 0.8) == 0: time.sleep(1) if self.click_img("yys/日轮之城/获取轮回眼.bmp", handle, 0.8) == 0: time.sleep(1) if self.mod == 1: if self.click_img("yys/日轮之城/时玉.bmp", handle, 0.8) == 0: time.sleep(1.5) return codedef.NORMAL_END elif self.click_img("yys/日轮之城/轮回眼.bmp", handle, 0.8) == 0: time.sleep(1.5) return codedef.NORMAL_END elif self.click_img("yys/日轮之城/下一关.bmp", handle, 0.8) == 0: time.sleep(1) if self.click_img("yys/日轮之城/确定按钮.bmp", handle, 0.8) == 0: time.sleep(1) self.re_set() return codedef.NORMAL_END # 没开眼 if self.HadOpenEye is False: # 分格子,看看缺口在哪个角 # if self.jiao_pos == 0: self.jiao_pos = self.checkJiao(handle) re = codedef.NORMAL_END if self.jiao_pos == 1: re = self.xunhuan_da(handle, self.arr1) elif self.jiao_pos == 2: re = self.xunhuan_da(handle, self.arr2) elif self.jiao_pos == 3 : re = self.xunhuan_da(handle, self.arr3) elif self.jiao_pos == 4: re = self.xunhuan_da(handle, self.arr4) if re == codedef.ERROR_END: self.da_wang = True else: time.sleep(1) # 如果还在轮回秘境界面,重新判断 # if self.if_exist("yys/日轮之城/轮回秘境界面.bmp", 0.98) == 0: # self.jiao_pos = self.checkJiao(handle) if self.da_wang: if self.if_exist("yys/日轮之城/已开眼.bmp", 0.98) == 0: self.HadOpenEye = True elif self.if_exist("yys/日轮之城/已开眼2.bmp", 0.98) == 0: self.HadOpenEye = True else: if self.if_exist("yys/日轮之城/买眼按钮.bmp") == 0: if self.buyyan > 0: self.buyyan -= 1 if self.click_img("yys/日轮之城/买眼按钮.bmp", handle, 0.98) == 0: time.sleep(2) else: # 直接当做打完,这样副本次数就会累加,最后结束脚本 return codedef.FIGHT_END elif self.click_img("yys/日轮之城/开眼按钮.bmp", handle, 0.98) == 0: time.sleep(2) else: if self.click_img("yys/日轮之城/时玉.bmp", handle, 0.8) == 0: time.sleep(1.5) elif self.click_img("yys/日轮之城/轮回眼.bmp", handle, 0.8) == 0: time.sleep(1.5) elif self.click_img("yys/日轮之城/下一关.bmp", handle, 0.8) == 0: time.sleep(1) if self.click_img("yys/日轮之城/确定按钮.bmp", handle, 0.8) == 0: time.sleep(1) self.re_set() elif self.click_img("yys/日轮之城/奖励.bmp", handle, 0.8) == 0: time.sleep(1) return codedef.NORMAL_END def kai_shi_da_guai(self, argument, handle): if self.click_img("yys/未固定阵容.bmp", handle) == 0: time.sleep(0.5) if self.click_img("yys/日轮之城/单人.bmp", handle) == 0: time.sleep(1) return codedef.NORMAL_END # 返回缺口位置 1左上角,2右上角,3左下角,4右下角 def checkJiao(self, handle): jiao1 = self.Jiao(handle, 0, 0) jiao2 = self.Jiao(handle, 7, 0) jiao3 = self.Jiao(handle, 0, 3) jiao4 = self.Jiao(handle, 7, 3) if jiao1 != 0 and jiao2 == 0 and jiao3 == 0 and jiao4 == 0: return 1 pass elif jiao1 == 0 and jiao2 != 0 and jiao3 == 0 and jiao4 == 0: return 2 pass elif jiao1 == 0 and jiao2 == 0 and jiao3 != 0 and jiao4 == 0: return 3 pass elif jiao1 == 0 and jiao2 == 0 and jiao3 == 0 and jiao4 != 0: return 4 pass jiao1 = self.Jiao(handle, 0, 0) jiao2 = self.Jiao(handle, 7, 0) jiao3 = self.Jiao(handle, 0, 3) jiao4 = self.Jiao(handle, 7, 3) if jiao1 != 0 and jiao2 == 0 and jiao3 == 0 and jiao4 == 0: return 1 pass elif jiao1 == 0 and jiao2 != 0 and jiao3 == 0 and jiao4 == 0: return 2 pass elif jiao1 == 0 and jiao2 == 0 and jiao3 != 0 and jiao4 == 0: return 3 pass elif jiao1 == 0 and jiao2 == 0 and jiao3 == 0 and jiao4 != 0: return 4 pass if jiao1 != 0: return 1 pass elif jiao2 != 0: return 2 pass elif jiao3 != 0: return 3 pass elif jiao4 != 0: return 4 pass return 1 # 判断某个位置是否是没打过,是未打过的话,返回0,否则返回非0 def Jiao(self, handle, i, j): name = "temp/checkJiao.bmp" self.savekuai(handle, i, j, name) re, x, y = self.img.find_img_in_img(name, "yys/日轮之城/未打过.bmp") return re def savekuai(self, handle, i, j, name): kuang = int(0.1 * (handle.right - handle.left)) point = [int(self.left * (handle.right - handle.left)) + kuang * (i + 0), int(self.top * (handle.bottom - handle.top)) + kuang * (j + 0)] point2 = [int(self.left * (handle.right - handle.left)) + kuang * (i + 1), int(self.top * (handle.bottom - handle.top)) + kuang * (j + 1)] tag_img = self.img.cut_img_path('temp/temp.bmp', point, point2) self.img.save(name, tag_img) return codedef.NORMAL_END def da(self, handle, i, j): name = "temp/da.bmp" self.savekuai(handle, i, j, name) re, x, y = self.img.find_img_in_img(name, "yys/日轮之城/未打过.bmp") if re != 0: re, x, y = self.img.find_img_in_img(name, "yys/日轮之城/未打过2.bmp") if re == 0: kuang = int(0.1 * (handle.right - handle.left)) point = [int(self.left * (handle.right - handle.left)) + kuang * (i + 0), int(self.top * (handle.bottom - handle.top)) + kuang * (j + 0)] x += handle.left + point[0] y += handle.top + point[1] self.mouse.click(x, y) return codedef.NORMAL_END return codedef.ERROR_END def xunhuan_da(self, handle, arr): name = 0 # 0是刷玉,1是刷层,直接打一排就开眼 if self.mod == 0: ilen = len(arr) else: ilen = 8 while name < ilen: p = arr[name] i = p[1] j = p[0] if self.da(handle, i, j) == codedef.NORMAL_END: time.sleep(1) return codedef.NORMAL_END name += 1 return codedef.ERROR_END