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_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 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