Python制作回合制手游外挂简单教程(

发布时间:2019-03-06 17:04:56编辑:auto阅读(2292)

    引入:

    每次玩回合制游戏的时候,反反复复的日常任务让人不胜其烦

    玩问道的时候,我们希望能够自动刷道,玩梦幻希望能自动做师门、捉鬼等等

     

    说明:

    该外挂只能模拟鼠标键盘操作,并不能修改游戏数据

     

    我这里使用的python2.7

    开发工具是PyCharm

     

    前期知识准备:

    首先下载autopy包,我这里PyCharm可以直接导入autopy包

    或者用利用pip进行安装:pip install autopy

     

    鼠标移动

    复制如下代码,运行

    #coding=utf-8
    
    import time
    
     
    
    import autopy
    
    #quick move
    
    autopy.mouse.move(1,1)
    
     
    
    #smooth move
    
    #autopy.mouse.smooth_move(1370,120)

    会发现鼠标瞬间移动到坐标(1,1)的位置,我的电脑是1920*1080的,最右下角的坐标就是(1920,1080)。

    将move换成smooth_move,会发现鼠标慢慢地移动到指定坐标

    官方文档的解释:

    autopy.mouse.move(x: float, y: float)

     

        Moves the mouse to the given (x, y) coordinate.

     

        Exceptions:

     

                ValueError is thrown if the point is out of index.

     

    autopy.mouse.smooth_move(x: float, y: float)

     

        Smoothly moves the mouse to the given (x, y) coordinate in a straight line.

     

        Exceptions:

     

                ValueError is thrown if the point is out of index.

    坐标超过分辨率会报异常

     

    鼠标点击

    运行代码,发现当前位置产生了点击操作

    #coding=utf-8
    
    import autopy
    
    autopy.mouse.click() # 单击

     

    键盘操作

    下面时一些常见的键值码和键的对应:

       字母和数字键 数字小键盘的键  功能键    其它键 
          键   键码      键   键码          键   键码       键      键码 
          A   65          0   96            F1   112       Backspace    8 
          B   66          1   97            F2   113       Tab       9 
          C   67          2   98            F3   114       Clear      12 
          D   68          3   99            F4   115       Enter      13 
          E   69          4   100           F5   116      Shift      16 
          F   70          5   101           F6   117      Control     17 
          G   71         6   102           F7   118      Alt       18 
          H   72         7   103           F8   119      Caps Lock    20 
          I    73          8   104          F9   120      Esc       27 
          J    74          9   105          F10  121     Spacebar    32 
          K   75         *   106           F11  122      Page Up     33 
          L   76         +   107           F12  123      Page Down    34 
          M   77        Enter 108                          End       35 
          N   78         -   109                              Home      36 
          O   79         .   110                              Left Arrow   37 
          P   80         /   111                              Up Arrow    38 
          Q   81                                                Right Arrow   39 
          R   82                                                Down Arrow    40 
          S   83                                                Insert      45 
          T   84                                                Delete      46 
          U   85                                                Help       47 
          V   86                                                Num Lock     144   
          W  87          
          X   88      
          Y   89      
          Z   90      
          0   48      
          1   49      
          2   50       
          3   51       
          4   52       
          5   53       
          6   54       
          7   55       
          8   56       
          9   57

    复制代码,运行,这里需要win32api包

    调用win32api的keybd_event方法,用过要释放按键

    #coding=utf-8
    
    import time
    
    import win32api
    
     
    
    win32api.keybd_event(18,0,0,0)  #alt键位码是18
    
    win32api.keybd_event(9,0,0,0)  #tab键位码是9
    
    time.sleep(0.5)
    
    win32api.keybd_event(13,0,0,0)  #enter键位码是13
    
     
    
    win32api.keybd_event(18,0,win32con.KEYEVENTF_KEYUP,0) #释放按键
    
    win32api.keybd_event(9,0,win32con.KEYEVENTF_KEYUP,0)
    
    win32api.keybd_event(13,0,win32con.KEYEVENTF_KEYUP,0)
    
    time.sleep(2)

     可以看到,完成了切换窗口的操作,相当于我们按alt+tab,然后回车进入

     

    开始制作外挂:

    这里以问道手游为例(回合制手游类似)

    需要夜神模拟器,并在模拟器上安装问道

    我试过蓝叠和MuMu模拟器,我用autopy移动鼠标到模拟器时鼠标就消失了,不能完成后续的自动操作,后来百度了

    说有的模拟器不受win窗口的控制。不管那么多,我们先用夜神模拟器吧!

     

     

    进入游戏,打开“活动”

     

    我们以“竞技场”活动举例说明

     

     这里我们要用到截图工具,我用的是PicPick

     个人用户免费,我主要用它来测量坐标

     

     记录下竞技场前往的坐标(1358,504)

     

     

    记录下竞技场按钮的坐标(1332,650)

     

    制作回合制脚本首先得要熟悉任务流程

    然后点击竞技场,走完这个任务流程,依次记录按钮的坐标

    竞技场任务一天可以做五次,我们对步骤循环五次

    战斗时间我们需要自己来计时,不同门派,土豪或者平民玩家时间都不一样

    我是平民玩家,大概耗时60s,点击过挑战让代码延迟60s再继续执行

     

     

    复制代码,运行

    #coding=utf-8
    
    import autopy
    
    import time
    
    import win32api
    
    import win32con
    
    #竞技场
    
    win32api.keybd_event(18,0,0,0)  #alt键位码是18
    
    win32api.keybd_event(9,0,0,0)  #tab键位码是9
    
    time.sleep(0.5)
    
    win32api.keybd_event(13,0,0,0)  #enter键位码是13
    
     
    
    win32api.keybd_event(18,0,win32con.KEYEVENTF_KEYUP,0) #释放按键
    
    win32api.keybd_event(9,0,win32con.KEYEVENTF_KEYUP,0)
    
    win32api.keybd_event(13,0,win32con.KEYEVENTF_KEYUP,0)
    
    time.sleep(2)
    
     
    
    def mousemove_click(x,y):
    
        autopy.mouse.smooth_move(x, y)
    
        autopy.mouse.click()
    
     
    
    mousemove_click(771, 203)  # 活动的坐标
    
     
    
    mousemove_click(1358,504)  # 竞技场"前往"的坐标
    
     
    
    time.sleep(20)#从天墉城城中心/其他地图走到竞技使者花费20s
    
     
    
    mousemove_click(1334, 650)  # 竞技使者对话框中的竞技场的坐标
    
     
    
     
    
    #挑战完毕会出现对话窗口
    
    for i in range(1,6,1):
    
        mousemove_click(664,706) #挑战试炼童子
    
     
    
        mousemove_click(1082,578) #确认
    
     
    
        mousemove_click(1530, 794)  # 战斗自动
    
     
    
        time.sleep(60)#挑战试炼童子预计60s

     

     效果如下:

     

     

    下一集将介绍如何实现队长模式刷道(自动组队,自动跑环接任务)

     

关键字