基于uibot的自动执行脚本

458 阅读3分钟

前面介绍过uibot的创建和使用,接下来分享一下神武的自动挖图脚本。

首先我们来看下神武是怎么挖图的

image.png

image.png

接下来开始编写代码

首先判断界面上是否存在

image.png image.png 找到其中共同点是image.png,根据上下的共同点 image.png,判断存在则鼠标移动到图像上进行模拟左键点击。

Function clickBaotu
    Try
        Dim bRet
        #icon("@res:6c468d50-3856-11ee-99fe-096e70e46248.png")
        bRet = Image.Exists({"wnd":[{"cls":"GLFW30","title":"神武5逍遥外传 - 清风明月","app":"htzmain"}]},{"x": 0, "y": 0, "width": 0, "height": 0},@res"6c468d50-3856-11ee-99fe-096e70e46248.png",0.9,2000,{"bContinueOnError": false, "iDelayAfter": 0, "iDelayBefore": 100, "bSetForeground": true, "sMatchType":"GrayMatch"})
        If bRet 
            #icon("@res:7d1e3a60-3856-11ee-99fe-096e70e46248.png")
            Image.Click({"wnd":[{"cls":"GLFW30","title":"神武5逍遥外传 - 清风明月","app":"htzmain"}]},{"x": 0, "y": 0, "width": 0, "height": 0},@res"7d1e3a60-3856-11ee-99fe-096e70e46248.png",0.9,"left","click",10000, {"bContinueOnError": false, "iDelayAfter": 110, "iDelayBefore": 110, "bSetForeground": true, "sCursorPosition": "Center", "iCursorOffsetX": 0, "iCursorOffsetY": 0, "sKeyModifiers": [],"sSimulate": "simulate","sMatchType":"GrayMatch", "iSerialNo": 1})
            clickBaotu() 
        Else 
            #icon("@res:60006130-3854-11ee-99fe-096e70e46248.png")
            bRet2 = Image.Exists({"wnd":[{"cls":"GLFW30","title":"神武5逍遥外传 - 清风明月","app":"htzmain"}]},{"x": 0, "y": 0, "width": 0, "height": 0},@res"60006130-3854-11ee-99fe-096e70e46248.png",0.9,2000,{"bContinueOnError": false, "iDelayAfter": 0, "iDelayBefore": 100, "bSetForeground": true, "sMatchType":"GrayMatch"})
            If bRet2 
                    #icon("@res:68fe7920-3854-11ee-99fe-096e70e46248.png")
                Image.Click({"wnd":[{"cls":"GLFW30","title":"神武5逍遥外传 - 清风明月","app":"htzmain"}]},{"x": 0, "y": 0, "width": 0, "height": 0},@res"68fe7920-3854-11ee-99fe-096e70e46248.png",0.9,"left","click",10000, {"bContinueOnError": false, "iDelayAfter": 110, "iDelayBefore": 110, "bSetForeground": true, "sCursorPosition": "Center", "iCursorOffsetX": 0, "iCursorOffsetY": 0, "sKeyModifiers": [],"sSimulate": "simulate","sMatchType":"GrayMatch", "iSerialNo": 1})
                clickBaotu()  
            End If
        End If   
    Catch err
        
    End Try
    TracePrint(err)
    #icon("@res:6cbc1d60-3854-11ee-99fe-096e70e46248.png")
    isBtPage =  Image.Exists({"wnd":[{"cls":"GLFW30","title":"神武5逍遥外传 - 清风明月","app":"htzmain"}]},{"x": 0, "y": 0, "width": 0, "height": 0},@res"6cbc1d60-3854-11ee-99fe-096e70e46248.png",0.9,2000,{"bContinueOnError": false, "iDelayAfter": 0, "iDelayBefore": 100, "bSetForeground": true, "sMatchType":"GrayMatch"})
    If isBtPage 
        clickBaotu()   
    Else 
        clickBaotuBox()
        End If
End Function

接下来如果界面上不存在藏宝点,则模拟右键点击背包里的藏宝图 image.png,右击后进行上面的方法clickBaotu。


Function clickBaotuBox()
    Dim bRet
    #icon("@res:746fdb00-3854-11ee-99fe-096e70e46248.png")
    bRet = Image.Exists({"wnd":[{"cls":"GLFW30","title":"神武5逍遥外传 - 清风明月","app":"htzmain"}]},{"x": 0, "y": 0, "width": 0, "height": 0},@res"746fdb00-3854-11ee-99fe-096e70e46248.png",0.9,2000,{"bContinueOnError": false, "iDelayAfter": 0, "iDelayBefore": 100, "bSetForeground": true, "sMatchType":"GrayMatch"})
    If bRet 
         #icon("@res:7885d870-3854-11ee-99fe-096e70e46248.png")
        Image.Click({"wnd":[{"cls":"GLFW30","title":"神武5逍遥外传 - 清风明月","app":"htzmain"}]},{"x": 0, "y": 0, "width": 0, "height": 0},@res"7885d870-3854-11ee-99fe-096e70e46248.png",0.9,"right","click",10000, {"bContinueOnError": false, "iDelayAfter": 110, "iDelayBefore": 110, "bSetForeground": true, "sCursorPosition": "Center", "iCursorOffsetX": 0, "iCursorOffsetY": 0, "sKeyModifiers": [],"sSimulate": "simulate","sMatchType":"GrayMatch", "iSerialNo": 1})
        clickBaotu()    
    Else
         #icon("@res:7bf22860-3854-11ee-99fe-096e70e46248.png")
        isBtPage =  Image.Exists({"wnd":[{"cls":"GLFW30","title":"神武5逍遥外传 - 清风明月","app":"htzmain"}]},{"x": 0, "y": 0, "width": 0, "height": 0},@res"7bf22860-3854-11ee-99fe-096e70e46248.png",0.9,2000,{"bContinueOnError": false, "iDelayAfter": 0, "iDelayBefore": 100, "bSetForeground": true, "sMatchType":"GrayMatch"})
        If isBtPage 
            #icon("@res:7e815ec0-3854-11ee-99fe-096e70e46248.png")
            isBeibao =  Image.Exists({"wnd":[{"cls":"GLFW30","title":"神武5逍遥外传 - 清风明月","app":"htzmain"}]},{"x": 0, "y": 0, "width": 0, "height": 0},@res"7e815ec0-3854-11ee-99fe-096e70e46248.png",0.9,2000,{"bContinueOnError": false, "iDelayAfter": 0, "iDelayBefore": 100, "bSetForeground": true, "sMatchType":"GrayMatch"})
            If isBeibao 
                #icon("@res:81f501b0-3854-11ee-99fe-096e70e46248.png")
                Image.Click({"wnd":[{"cls":"GLFW30","title":"神武5逍遥外传 - 清风明月","app":"htzmain"}]},{"x": 0, "y": 0, "width": 0, "height": 0},@res"81f501b0-3854-11ee-99fe-096e70e46248.png",0.9,"left","click",10000, {"bContinueOnError": false, "iDelayAfter": 110, "iDelayBefore": 110, "bSetForeground": true, "sCursorPosition": "Center", "iCursorOffsetX": 0, "iCursorOffsetY": 0, "sKeyModifiers": [],"sSimulate": "simulate","sMatchType":"GrayMatch", "iSerialNo": 1})
                clickBaotuBox() 
            Else 
                iRet = Dialog.MsgBox("当前神武已经执行完毕,请拉起新的神武窗口,并点击确定继续,退出请点击取消","提示",5,1,0)
                If (iRet=1)
                clickBaotu()
                Else 
                Exit()
                End If  
            End If
        Else 
            openBeiBao()
        End If    
    End If
End Function

假如界面不存在藏宝点image.png和藏宝图image.png,则点击物品背包image.png

Function openBeiBao
     #icon("@res:84e48080-3854-11ee-99fe-096e70e46248.png")
    Image.Click({"wnd":[{"cls":"GLFW30","title":"神武5逍遥外传 - 清风明月","app":"htzmain"}]},{"x": 0, "y": 0, "width": 0, "height": 0},@res"84e48080-3854-11ee-99fe-096e70e46248.png",0.9,"left","click",10000, {"bContinueOnError": false, "iDelayAfter": 100, "iDelayBefore": 100, "bSetForeground": true, "sCursorPosition": "Center", "iCursorOffsetX": 0, "iCursorOffsetY": 0, "sKeyModifiers": [],"sSimulate": "simulate","sMatchType":"GrayMatch", "iSerialNo": 1})
    clickBaotu()
End Function

点击物品背包后,继续执行clickBaotu

循环执行结束后,当所有藏宝图挖完后,图像识别会超时,则弹窗提示是否继续执行。

iRet = Dialog.MsgBox("当前神武已经执行完毕,请拉起新的神武窗口,并点击确定继续,退出请点击取消","提示",5,1,0)

image.png

至此脚本结束。

欢迎大家共同交流。源码在此处获取。