def choose_10_floor_of_yuhun_private_team(): # 为了效率,默认跳过 # # 副本类型选择魂十 # mouse_move(Coordinate.create_team_choose_type_of_battle_x_left, Coordinate.create_team_choose_type_of_battle_y_top) # time.sleep(0.5) # mouseevent_wheel.scroll_down_to_the_bottom() # time.sleep(0.5) # 选择十层 if not identifyImg.look_for_template_for_a_moment_return_boolean("check_floor_10.png", 2, 0.85): print("未选择十层,开始选择十层") mouse_move(Coordinate.create_team_choose_floor_of_battle_x_left, Coordinate.create_team_choose_floor_of_battle_y_top) mouseevent_wheel.scroll_down_to_the_bottom() # 滚轮滚到底之后,开始向上滚动寻找魂十 while not identifyImg.look_for_template_for_a_moment_return_boolean("check_floor_10.png", 2, 0.85): time.sleep(0.3) win32api.mouse_event(win32con.MOUSEEVENTF_WHEEL, 0, 0, 32) time.sleep(0.5) # 限制60级进入 if not identifyImg.look_for_template_for_a_moment_return_boolean("check_allowed_maxlevel.png", 2, 0.85): print("最大等级不是60级,开始调整等级限制") mouse_move(Coordinate.create_team_minimum_lv_x_left, Coordinate.create_team_minimum_lv_y_top) mouseevent_wheel.scroll_down_to_the_bottom() time.sleep(0.5) mouse_move(Coordinate.create_team_max_lv_x_left, Coordinate.create_team_max_lv_y_top) mouseevent_wheel.scroll_down_to_the_bottom() time.sleep(0.5) # 点击创建 create_button_filename = "create_button.png" identifyImg.identify_template_click(create_button_filename, template_cv2_entity[create_button_filename], 0.75) time.sleep(1)
def explore_main(omyuji_hwnd_info): print("start explore_main()") while True: # 切换队长号 win32gui.SetForegroundWindow(list(omyuji_hwnd_info.keys())[1]) print("进入点怪界面,先观察有没有BOSS") boss_appear_flag = identifyImg.look_for_template_for_a_moment_return_boolean("boss_appear.png", 1, 0.85) boss_flag = identifyImg.look_for_template_for_a_moment_return_boolean("boss.png", 1, 0.85) if boss_appear_flag or boss_flag: print("出BOSS了,开始打BOSS") identifyImg.wait_for_a_moment_and_click_template("boss.png", 5, 0.85) fight.fight_for_experience(omyuji_hwnd_info) identifyImg.look_for_template_to_click("monster.png",0.85) fight.fight_for_experience(omyuji_hwnd_info)
def accept_invite_from_captain(omyuji_hwnd_info): # 切换大号接受 windowTools.switch_window(list(omyuji_hwnd_info.keys())[0]) # 添加意外处理,防止大号被6000御魂、掉线以及其他异常情况卡在战斗收益画面没有出来 if identifyImg.identify_find_template_or_not("money_ico.png",0.85): mouse_click(Coordinate.explore_getoutofbattle_x_left, Coordinate.explore_getoutofbattle_y_top) # 开始接受队长邀请 accept_xiaohao_invite = "accept_xiaohao_invite.png" for i in range(10): # 检测小号邀请信息,点击对号 xiaohao_invite_coordinate = identifyImg. \ identify_find_template_or_not(accept_xiaohao_invite, 0.8) if xiaohao_invite_coordinate: # 如果找到默认邀请了,仅点击对号接受邀请 if identifyImg.look_for_template_for_a_moment_return_boolean("continuous_invited_flag.png", 3, 0.8): mouse_click(xiaohao_invite_coordinate['x'] - 170, xiaohao_invite_coordinate['y'] + 10) print("invitationTask.py:检测到小号发来的默认邀请,仅点击对号接受本次邀请") time.sleep(0.2) break # 如果没找到默认邀请的标志,那么就是普通邀请 mouse_click(xiaohao_invite_coordinate['x'] - 95, xiaohao_invite_coordinate['y'] + 10) time.sleep(0.2) print("检测到小号发来的普通邀请,点击对号接受本次邀请") break # 切换队长号继续流程 windowTools.switch_window(list(omyuji_hwnd_info.keys())[1])
def choose_the_latest_chapter(chapter): # 鼠标选择指定章节,鼠标滚轮一直滚到看到指定章节的模板为止,并点击 print("开始找最新章节,当前试图寻找 %d" % chapter + " 章") chapter_coordinate = identifyImg.identify_find_template_or_not("explore_choose_chapter.png", 0.85) if chapter_coordinate: mouse_move(chapter_coordinate['x'], chapter_coordinate['y']) time.sleep(1) while True: # 先找章节模板,找不到就滚动滚轮寻找 aim_of_chapter_coordinate = identifyImg.identify_find_template_or_not("explore_chapter_%d.png" % chapter, 0.9) if aim_of_chapter_coordinate: # 点击指定章节 mouse_click(aim_of_chapter_coordinate['x'], aim_of_chapter_coordinate['y']) # 等待屏幕移动出现选择难度及组队信息 wait_for_explore_button = identifyImg.look_for_template_for_a_moment_return_boolean("common_button_explore.png", 3.5, 0.85) # 看到屏幕出现等待信息后,判断是否点击了困难标志,否则无法组队 if wait_for_explore_button: hard_status_coordinate = identifyImg.identify_find_template_or_not("experience_hard.png", 0.85) # 如果看到了困难标志没有点上,点击 if hard_status_coordinate: mouse_click(hard_status_coordinate['x'],hard_status_coordinate['y']) # 点击组队,结束本方法 identifyImg.identify_template_click("common_button_creatteam.png", template_cv2_entity["common_button_creatteam.png"], 0.85) break # win32con.MOUSEEVENTF_WHEEL代表鼠标中轮,第四个参数正数代表往上轮滚,负数代表往下 win32api.mouse_event(win32con.MOUSEEVENTF_WHEEL, 0, 0, -128) time.sleep(0.3) print("choose_the_latest_chapter()结束") return
def foster_execute(): # 点击进入结界 identifyImg.look_for_template_to_click("boundary_entry_other_boundary.png", 0.8) # 寻找【友】字的坑位 if identifyImg.look_for_template_for_a_moment_return_boolean( "boundary_foster_available_flag.png", 8, 0.8): # 寻找目标式神,并返回等级的坐标位置 shikigami_level_coordinate = shikigamiTools.select_shikigami() # 如果没找到滑块,直接return if shikigami_level_coordinate.__len__() == 0: return # N卡被吃光,直接切回全部,随便选第一个寄养 elif shikigami_level_coordinate.__len__( ) > 0 and shikigami_level_coordinate['x'] == 0: identifyImg.wait_for_a_moment_and_click_template( "common_rare_N.png", 3, 0.8) identifyImg.wait_for_a_moment_and_click_template( "common_rare_button.png", 3, 0.8) temp_coordinate = identifyImg.identify_find_template_or_not( "common_rare_button.png", 0.8) mouse_click(temp_coordinate['x'], temp_coordinate['y']) identifyImg.wait_for_a_moment_and_click_template( "common_confirm_button.png", 3, 0.8) return else: # 如果正常返回坐标,开始寄养 mouse_click(shikigami_level_coordinate['x'], shikigami_level_coordinate['y']) identifyImg.wait_for_a_moment_and_click_template( "common_confirm_button.png", 3, 0.8) return datetime.datetime.now()
def fight_for_experience(omyuji_hwnd_info, template_filename=None): battle_result = False whether_battle_start = identifyImg.look_for_template_for_a_moment_return_boolean("common_exit_battle.png", 15, 0.85) # 如果没找到返回按钮,则判断没有进入战斗 if not whether_battle_start: print("fight_for_experience()判断未进入战斗,返回战斗失败退出方法") return battle_result # 开始更换两个号的狗粮 check_level_of_hellspawn(omyuji_hwnd_info)
def check_time_and_foster(task_type): # 进入方法时间,目前方法不够精确,所以是否寄养成功,都返回寄养时间,防止寄养失败后,每一次循环都启用一次寄养。 foster_time = datetime.datetime.now() # 首先检查人物所处位置,如果在探索菜单就先返回主界面 # 先找下有没有后退的蓝色按钮,不断地按直到没有找到 if identifyImg.look_for_template_for_a_moment_return_boolean( "back_button_blue.png", 2, 0.8): while identifyImg.look_for_template_for_a_moment_return_boolean( "back_button_blue.png", 5, 0.8): identifyImg.look_for_template_to_click("back_button_blue.png", 0.8) if identifyImg.look_for_template_for_a_moment_return_boolean( "main_menu_yinyangliao.png", 0.5, 0.8): print("检测到退回主界面了,开始点击阴阳寮") break # 点击主界面阴阳寮按钮 identifyImg.look_for_template_to_click("main_menu_yinyangliao.png", 0.8) # 点击结界,进入结界界面 identifyImg.wait_for_a_moment_and_click_template("boundary_button.png", 5, 0.8) # 点击式神育成 identifyImg.wait_for_a_moment_and_click_template("boundary_index.png", 8, 0.7) time.sleep(1) # 观察一下寄养按钮是否可用 foster_coordinate = identifyImg.identify_find_template_or_not( "boundary_foster_button.png", 0.8) # 如果寄养还没结束,则终止寄养流程,开始准备返回上一级调用 if not foster_coordinate: # 返回正在进行的任务,比如御魂 back_to_mission(task_type) return foster_time mouse_click(foster_coordinate['x'], foster_coordinate['y']) # 最多等待5秒寄养主界面弹出,方法是检测模板中的【结界卡】字样 identifyImg.look_for_template_for_a_moment_return_boolean( "boundary_foster_main_menu_flag.png", 5, 0.8) # 开始挑卡寄养,尽量选择收益高的 foster_time = check_friend_to_foster() # 挂完卡之后,开始返回进行中任务 back_to_mission(task_type) return foster_time
def invite_main_account_experience(omyuji_hwnd_info, chapter): # 首先等待看见大号名字 main_account_appeare_flag = identifyImg.wait_for_a_moment_and_click_template("headportrait_of_main_account.png", 3, 0.85) if not main_account_appeare_flag: # 如果出现异常,直接点击X退出到探索主界面,重新选择章节再邀请一次。 catch_invite_main_account_error(chapter) # invite_click_is_done_flag = identifyImg.wait_for_a_moment_and_click_template("invite_click_is_done.png", 2, 0.85) # if not invite_click_is_done_flag: # # 如果出现异常,直接点击X退出到探索主界面,重新选择章节再邀请一次。 # catch_invite_main_account_error(chapter) # 疯狂邀请至大号进来为止 while True: # 点击邀请 identifyImg.wait_for_a_moment_and_click_template("invite_button.png", 1, 0.85) # 接受队长邀请 accept_invite_from_captain(omyuji_hwnd_info) # 判断大号是否进入 success_flag = identifyImg.look_for_template_for_a_moment_return_boolean("experience_move_left.png", 9, 0.85) if success_flag: print("end invite_main_account_experience()") return
def battle_statistics_and_command(omyuji_hwnd_info, mission): residue_number = mission battle_count = 0 win_count = 0 # 寮突破是否可以继续打的Flag,True:可以打,False:不可以继续打了 whether_breakthrough_is_available = True # 切换大号开始判断首先要处理的事情,比如寄养、突破 windowTools.switch_window(list(omyuji_hwnd_info.keys())[0]) # 首先去寄养,然后再记下寄养的时间 the_last_foster_time = fosterCare.check_time_and_foster("yuhun") # 然后判断收益号是否开始执行个人突破,突破票28张以上就开打 breakthrough.AOP_for_breakthrough(omyuji_hwnd_info) # 切回队长小号开始流程 windowTools.switch_window(list(omyuji_hwnd_info.keys())[1]) # 开始进入刷御魂主流程 start_yuhun_to_attack_for_multi_player(omyuji_hwnd_info, mission) # 邀请大号,返回开始战斗图标坐标 start_battle_button_is_availeable_coordinate = invitationTask.invite_main_account_for_yuhun( omyuji_hwnd_info) # 点击开始战斗 mouse_click(start_battle_button_is_availeable_coordinate['x'], start_battle_button_is_availeable_coordinate['y']) # 获取当前时间点,用时间差计算何时进入寮突: the_last_breakthrough_union_time = datetime.now() while win_count < residue_number: # 进入大小号无限刷的循环 print("当前已打:" + str(battle_count) + "次,胜利:" + str(win_count) + "次,还需再打" + str(residue_number - win_count) + "次") # 进入战斗,注意当前是小号视角,退出战斗可以找开始战斗按钮是否出现 battle_result = fight.fight("common_team_start_battle_button.png") battle_count += 1 if battle_result: win_count += 1 # 设置默认邀请队友界面是否会弹出的Flag default_invite = False # 第一次组队,一定会弹出默认邀请 first_default_invite = True # 检测弹出【是否默认邀请队友界面】 if not default_invite and first_default_invite: # 开始执行点击默认邀请流程,首先要把首次进入战斗Flag设为False first_default_invite = False checkbox_need_to_click_filename = "checkbox_need_to_click.png" checkbox_need_to_click_coordinate = identifyImg.\ identify_find_template_or_not( checkbox_need_to_click_filename,0.85) if checkbox_need_to_click_coordinate.__len__() > 0: print("点击默认邀请队友") mouse_click(checkbox_need_to_click_coordinate['x'], checkbox_need_to_click_coordinate['y']) # 点击确定 common_confirm_button_filename = "common_confirm_button.png" identifyImg.identify_template_click( common_confirm_button_filename, template_cv2_entity[common_confirm_button_filename], 0.8) # 点了默认邀请之后,默认邀请Flag设置为True default_invite = False windowTools.switch_window(list(omyuji_hwnd_info.keys())[0]) check_explore_filename = "check_explore.png" # 切出去等待大号点出战斗,判断方式为左下角出现御魂图标 while True: time.sleep(0.6) print("点击屏幕退出战斗画面") # 为了防止弹出御魂6000超量警告,这里加一个判断点击 # 判断御魂数量大于6000 yuhun_number_exceeded_filename = "yuhun_number_exceeded.png" yuhun_number_exceeded_coordinate = identifyImg.identify_find_template_or_not( yuhun_number_exceeded_filename, 0.85) if yuhun_number_exceeded_coordinate.__len__() > 0: mouse_click(yuhun_number_exceeded_coordinate['x'], yuhun_number_exceeded_coordinate['y']) print("大号御魂超数了,赶紧去清了") # 如果没见到超量,就正常点击小号邀请 check_explore = identifyImg.identify_find_template_or_not( check_explore_filename, 0.75) if check_explore.__len__() > 0: break # 如果意外地弹出去直接进了队,那么离开点击 leave_the_team_button_filename = "leave_the_team_button.png" leave_the_team_button_coordinate = identifyImg.identify_find_template_or_not( leave_the_team_button_filename, 0.85) if leave_the_team_button_coordinate.__len__() > 0: break mouse_click(Coordinate.explore_getoutofbattle_x_left, Coordinate.explore_getoutofbattle_y_top) # 在接受前,上次寄养是否超过了6小时,如是,则先去寄养 if (datetime.now() - the_last_foster_time).seconds > 21600: # Sensitive operation!!! # 关buffer bufferTools.switch_off_all_of_buffer() # 寄养 the_last_foster_time = fosterCare.check_time_and_foster("yuhun") # Sensitive operation!!! # 开buffer bufferTools.switch_on_buffer("yuhun") # 在接受前,判断大号突破票是否大于28张,如是,则先进行突破 personal_breakthrough_ticket = observerTools.remaining_of_personal_breakthrough_ticket( ) print("当前突破票剩余:" + personal_breakthrough_ticket) if int(personal_breakthrough_ticket) > 28: # Sensitive operation!!! # 关buffer bufferTools.switch_off_all_of_buffer() # 开始突破 breakthrough.breakthrough_personal("yuhun") # Sensitive operation!!! # 开buffer bufferTools.switch_on_buffer("yuhun") # 接下来判断经过时间,用于进入寮突破 breakthrough_loop_time = datetime.now() time_lapse = (breakthrough_loop_time - the_last_breakthrough_union_time).seconds print("与上次突破时间相比,当前经过了:" + str(time_lapse) + "秒") if time_lapse > 300 or time_lapse < 5: # 加入定时寮突破 print("又该打寮突了,当前时间 :" + str(datetime.now())) if whether_breakthrough_is_available: # Sensitive operation!!! # 关buffer bufferTools.switch_off_all_of_buffer() # 开始寮突破 whether_breakthrough_is_available = breakthrough.start_to_breakthrough( "union", "yuhun") # Sensitive operation!!! # 开buffer bufferTools.switch_on_buffer("yuhun") # 记录打完突破的时间点,用于下一次计算时长 the_last_breakthrough_union_time = datetime.now() else: print("记得上一次看到100%被攻破了,那今天先不打寮突了") # 判断完个突(如果票够)和寮突(如果时间点对)后,点击对号接受组队 # mouse_click(Coordinate.accept_invite_x_left, Coordinate.accept_invite_y_top) accept_xiaohao_invite = "accept_xiaohao_invite.png" for i in range(10): # 检测小号邀请信息,点击对号 xiaohao_invite_coordinate = identifyImg. \ identify_find_template_or_not(accept_xiaohao_invite, 0.85) if xiaohao_invite_coordinate: # 如果找到默认邀请了,仅点击对号接受邀请 if identifyImg.look_for_template_for_a_moment_return_boolean( "continuous_invited_flag.png", 3, 0.85): mouse_click(xiaohao_invite_coordinate['x'] - 170, xiaohao_invite_coordinate['y'] + 10) print("yuhun.py :检测到小号发来的默认邀请,仅点击对号接受本次邀请") time.sleep(0.2) break # 如果没找到默认邀请的标志,那么就是普通邀请 mouse_click(xiaohao_invite_coordinate['x'] - 95, xiaohao_invite_coordinate['y'] + 10) print("检测到小号发来的普通邀请,点击对号接受本次邀请") time.sleep(0.2) break time.sleep(0.1) # 打完突破(如果打了)之后,切换小号观察大号是否进来,如是,开始战斗。如不是,重新邀请 windowTools.switch_window(list(omyuji_hwnd_info.keys())[1]) time.sleep(0.3) headportrait_of_main_account_filename = "headportrait_of_main_account_team_interface.png" headportrait_of_main_account_coordinate = \ identifyImg.identify_find_template_or_not(headportrait_of_main_account_filename, 0.85) if headportrait_of_main_account_coordinate.__len__() > 0: # 看开始战斗按钮是否可用,如有,则进行下一轮循环,直到打满输入次数 common_team_start_battle_button_filename = "common_team_start_battle_button.png" start_battle_button_is_availeable_coordinate = \ identifyImg.identify_find_template_or_not(common_team_start_battle_button_filename, 0.85) if start_battle_button_is_availeable_coordinate.__len__() > 0: print("邀请成功,退出invite_main_account_for_yuhun()") # 点击开始战斗 mouse_click(start_battle_button_is_availeable_coordinate['x'], start_battle_button_is_availeable_coordinate['y']) else: # 邀请大号,返回开始战斗图标坐标 start_battle_button_is_availeable_coordinate = invitationTask.invite_main_account_for_yuhun( omyuji_hwnd_info) # 点击开始战斗 mouse_click(start_battle_button_is_availeable_coordinate['x'], start_battle_button_is_availeable_coordinate['y'])
def city_of_sun(): # 点日轮之城活动主界面 identifyImg.look_for_template_to_click("sun_index.png", 0.85) # 10秒内等轮回秘境 identifyImg.wait_for_a_moment_and_click_template("lun_hui_mi_jing.png", 10, 0.85) # 等待出现轮回重置按钮出现,代表页面读取完毕 if identifyImg.look_for_template_for_a_moment_return_boolean( "reset_lunhui.png", 10, 0.85): # 开始打秘境大循环 while True: print("开始外层大循环,缓冲几秒") sleep(1) print("开始读取每一格坐标") # 如果有资源选取意愿,先点击御魂资源 identifyImg.look_for_template_to_click( "lunhuimijing_yuhun_ziyuan.png", 0.85) # 开始读取每个板块坐标 battle_list = identifyImg.multi_template_coordinate( "cityofsun.png", 0.9) # 逻辑:优先看资源格子、下一层,如果什么都没发现就开始正常翻格子遍历 # 下面的遍历是以每个板块坐标为单位 for i in battle_list: sleep(0.5) # 如果有资源选取意愿,先点击御魂资源 resources_button = identifyImg.identify_find_template_or_not( "lunhuimijing_yuhun_ziyuan.png", 0.85) if resources_button: mouse_click(resources_button['x'], resources_button['y']) identifyImg.wait_for_a_moment_and_click_template( "common_confirm.png", 3, 0.85) # 先看有没有宝箱 box = identifyImg.multi_template_coordinate( "lunhuimijing_box.png", 0.85) if box: count = box.__len__() print("有宝箱,拾取%d个宝箱" % count) for j in box: mouse_click(j[0], j[1]) # 等待箱子开完,点击屏幕取消掉奖励 identifyImg.wait_for_a_moment_and_click_template( "battle_win_continue.png", 5, 0.85) # 判断是否取消掉屏幕,如果没有,直接点到看不到达摩弹出的金币奖励图标为止 while identifyImg.identify_find_template_or_not( "money_ico.png", 0.9): print("持续点击到没有金币为止") identifyImg.look_for_template_to_click( "battle_win_continue.png", 0.85) # 再看有没有时曲碎片 shiqusuipian = identifyImg.multi_template_coordinate( "lunhuimijing_shiqusuipian.png", 0.9) if shiqusuipian: count = shiqusuipian.__len__() print("有碎片,拾取%d个碎片" % count) for k in shiqusuipian: mouse_click(k[0], k[1]) sleep(1) # 再看有没有下一层 sleep(0.5) next_floor = identifyImg.identify_find_template_or_not( "lunhuimijing_next_floor.png", 0.85) if next_floor: print("发现下一层了,直接进入下一层") mouse_click(next_floor['x'], next_floor['y']) # 点击下一层的时候有2种情况 # 第一种是第一次点击,出现BOSS战斗界面 sleep(1) boss_battle_button = identifyImg.identify_find_template_or_not( "lunhuimijing_start_battle.png", 0.85) if boss_battle_button: mouse_click(boss_battle_button['x'], boss_battle_button['y']) fight.fight("reset_lunhui.png") print("打完下一层BOSS了,等待2秒缓冲去下一层") sleep(2) # 第二种是打完boss了,弹出是否进入下一层,会现common的确定按钮,直接点击进入下一层 common_confirm_button = identifyImg.identify_find_template_or_not( "common_confirm_button.png", 0.85) if common_confirm_button: mouse_click(common_confirm_button['x'], common_confirm_button['y']) continue # 如果特殊资源格子都没发现,那么就开始正常点击每个板块翻 mouse_click(i[0], i[1]) sleep(0.3) # 找单人挑战的按钮 start_battle_button_cd = identifyImg.identify_find_template_or_not( "lunhuimijing_start_battle.png", 0.85) if start_battle_button_cd: mouse_click(start_battle_button_cd['x'], start_battle_button_cd['y']) fight.fight("reset_lunhui.png") else: continue
def check_whether_start(): return not identifyImg.look_for_template_for_a_moment_return_boolean( "check_breakthrough_start.png", 2, 0.85)