GO语言,半自动打怪

仅供学习参考,切勿用于商业用途

go 复制代码
package main

import (
    "fmt"
    "github.com/go-vgo/robotgo"
    "math/rand"
    "time"
)

const (
    taskNum = 7
)

type Task struct {
    Name       string
    SleepTime1 int
    SleepTime2 int
    Func       func()
}

func main() {
    for i := 1; i <= 32; i++ {
        tasks := []Task{
            {
                Name:       "第1图",
                SleepTime1: 3000,
                SleepTime2: 100,
                Func:       Task1,
            },
            {
                Name:       "第2图",
                SleepTime1: 1,
                SleepTime2: 1,
                Func:       Task2,
            },
            {
                Name:       "第3图",
                SleepTime1: 1,
                SleepTime2: 1,
                Func:       Task3,
            },
            {
                Name:       "第4图",
                SleepTime1: 1500,
                SleepTime2: 80,
                Func:       Task4,
            },
            {
                Name:       "第5图",
                SleepTime1: 1500,
                SleepTime2: 80,
                Func:       Task5,
            },
            {
                Name:       "第6图",
                SleepTime1: 1500,
                SleepTime2: 80,
                Func:       Task6,
            },
            {
                Name:       "第7图",
                SleepTime1: 1500,
                SleepTime2: 80,
                Func:       Task7,
            },
        }

        for i := 1; i <= taskNum; i++ {
            task := tasks[i-1]
            fmt.Printf("开始执行任务:%s\n", task.Name)
            time.Sleep(time.Duration(task.SleepTime1) * time.Millisecond)
            time.Sleep(time.Duration(rand.Intn(task.SleepTime2)) * time.Millisecond)
            task.Func()
            fmt.Printf("任务%s已完成\n", task.Name)
        }

    }
}

func Task1() {
    robotgo.MoveClick(367, 270, `left`, true)
    time.Sleep(2000)
    robotgo.KeyTap("right")
    robotgo.MilliSleep(10)
    robotgo.KeyToggle("right", "down")
    time.Sleep(6 * time.Second)
    robotgo.KeyToggle("right", "up")
    time.Sleep(100)
    fmt.Printf("第1图通关,")
}

func Task2() {
    robotgo.KeyTap("s")
    time.Sleep(2 * time.Second)
    robotgo.KeyTap("a")
    robotgo.MilliSleep(20)

    //向下移动3秒向上移动1秒
    robotgo.KeyToggle("up", "down")
    time.Sleep(2 * time.Second)
    robotgo.KeyToggle("up", "up")
    robotgo.MilliSleep(50)

    robotgo.KeyTap("g")
    robotgo.MilliSleep(50)
    robotgo.KeyTap("w")

    time.Sleep(9 * time.Second)

    robotgo.KeyToggle("down", "down")
    time.Sleep(1 * time.Second)
    robotgo.KeyToggle("down", "up")
    robotgo.MilliSleep(50)
    fmt.Printf("第二图通关,")
}

func Task3() {
    robotgo.MilliSleep(50)
    robotgo.KeyTap("right")
    robotgo.MilliSleep(10)
    robotgo.KeyToggle("right", "down")
    time.Sleep(2 * time.Second)
    robotgo.KeyToggle("right", "up")
    fmt.Printf("进入第3图")

    robotgo.MilliSleep(50)
    robotgo.KeyTap("h")
    time.Sleep(3 * time.Second)
    time.Sleep(6 * time.Second)

    robotgo.KeyToggle("up", "down")
    time.Sleep(2 * time.Second)
    robotgo.KeyToggle("up", "up")
    robotgo.MilliSleep(50)

    robotgo.KeyToggle("down", "down")
    time.Sleep(1 * time.Second)
    robotgo.KeyToggle("down", "up")
    robotgo.MilliSleep(50)

    robotgo.KeyToggle("right", "down")
    time.Sleep(2 * time.Second)
    robotgo.KeyToggle("right", "up")
    robotgo.MilliSleep(50)

    fmt.Printf("第3通关")

}

func Task4() {
    robotgo.KeyTap("right")
    robotgo.MilliSleep(50)
    robotgo.KeyToggle("right", "down")
    time.Sleep(5 * time.Second)
    robotgo.KeyToggle("right", "up")
    robotgo.MilliSleep(50)

    time.Sleep(20 * time.Second)

    robotgo.KeyToggle("right", "down")
    time.Sleep(2 * time.Second)
    robotgo.KeyToggle("right", "up")
    robotgo.MilliSleep(50)

    robotgo.KeyToggle("up", "down")
    time.Sleep(2 * time.Second)
    robotgo.KeyToggle("up", "up")
    robotgo.MilliSleep(50)

    robotgo.KeyToggle("down", "down")
    time.Sleep(1 * time.Second)
    robotgo.KeyToggle("down", "up")
    robotgo.MilliSleep(50)

    fmt.Printf("第4图通关")
}

func Task5() {

    //向上移动1秒
    fmt.Print("****准备进入5图")

    //向上移动1秒
    robotgo.KeyTap("right")
    robotgo.MilliSleep(50)
    robotgo.KeyToggle("right", "down")
    time.Sleep(5 * time.Second)
    robotgo.KeyToggle("right", "up")
    robotgo.MilliSleep(50)
    time.Sleep(20 * time.Second)

    robotgo.KeyToggle("right", "down")
    time.Sleep(2 * time.Second)
    robotgo.KeyToggle("right", "up")
    robotgo.MilliSleep(50)

    robotgo.KeyToggle("up", "down")
    time.Sleep(2 * time.Second)
    robotgo.KeyToggle("up", "up")
    robotgo.MilliSleep(50)

    robotgo.KeyToggle("down", "down")
    time.Sleep(1 * time.Second)
    robotgo.KeyToggle("down", "up")
    robotgo.MilliSleep(50)

    fmt.Printf("第5图通关")
}

func Task6() {
    fmt.Print("****准备进入6图")
    robotgo.KeyTap("right")
    robotgo.MilliSleep(50)
    robotgo.KeyToggle("right", "down")
    robotgo.KeyToggle("down", "down")
    time.Sleep(5 * time.Second)
    robotgo.KeyToggle("right", "up")
    robotgo.KeyToggle("down", "up")
    robotgo.MilliSleep(50)

    robotgo.KeyTap("w")
    robotgo.MilliSleep(50)
    robotgo.KeyTap("a")
    fmt.Print("****进入6图")

    robotgo.KeyTap("w")
    time.Sleep(20 * time.Second)
    fmt.Printf("最后通关1")
    robotgo.KeyTap("w")
    time.Sleep(30 * time.Second)
    fmt.Printf("最后通关2")
    robotgo.KeyTap("w")
    time.Sleep(20 * time.Second)


    fmt.Printf("全图通关")
}

func Task7() {
    fmt.Printf("开始捡完物品")

    robotgo.KeyTap("v")
    time.Sleep(3 * time.Second)

    //修装备
    //time.Sleep(time.Duration(sleepTime2) * time.Millisecond)
    //robotgo.KeyTap("s")
    //time.Sleep(time.Duration(sleepTime2) * time.Millisecond)
    //robotgo.KeyTap("s")
    //time.Sleep(time.Duration(sleepTime2) * time.Millisecond)
    //robotgo.KeyTap("enter")
    //time.Sleep(1 * time.Second)

    //捡东西
    time.Sleep(3 * time.Second)
    fmt.Printf("第一个图捡完物品")

    robotgo.MilliSleep(2000)
    robotgo.MoveClick(10, 10, `left`, true)
    robotgo.MilliSleep(50)
    robotgo.MoveClick(10, 10, `left`, true)

    time.Sleep(2 * time.Second)
	robotgo.KeyTap("enter")
	time.Sleep(2 * time.Second)
	robotgo.KeyTap("shift")
    
    robotgo.MilliSleep(50)
    robotgo.KeyTap("/")
    robotgo.MilliSleep(50)
    robotgo.KeyTap("/")
    robotgo.MilliSleep(50)
    robotgo.KeyTap("shift")
    robotgo.MilliSleep(50)
    robotgo.KeyTap("y")
    robotgo.MilliSleep(50)
    robotgo.KeyTap("i")
    robotgo.MilliSleep(50)
    robotgo.KeyTap("d")
    robotgo.MilliSleep(50)
    robotgo.KeyTap("o")
    robotgo.MilliSleep(50)
    robotgo.KeyTap("n")
    robotgo.MilliSleep(50)
    robotgo.KeyTap("g")
    robotgo.MilliSleep(50)
    robotgo.KeyTap("w")
    robotgo.MilliSleep(50)
    robotgo.KeyTap("u")
    robotgo.MilliSleep(50)
    robotgo.KeyTap("p")
    robotgo.MilliSleep(50)
    robotgo.KeyTap("i")
    robotgo.MilliSleep(50)
    robotgo.KeyTap("n")
    robotgo.MilliSleep(50)
    robotgo.KeyTap("space")
    robotgo.MilliSleep(50)
    robotgo.KeyTap("enter")
    robotgo.MilliSleep(50)
    time.Sleep(3 * time.Second)
    fmt.Printf("第一个图捡完物品")

    robotgo.MilliSleep(2000)
    robotgo.MoveClick(1377, 71, `left`, true)
    robotgo.MilliSleep(50)
    robotgo.MoveClick(1377, 71, `left`, true)
    robotgo.MilliSleep(50)
    robotgo.KeyTap("enter")
    robotgo.MilliSleep(50)
    robotgo.KeyTap("shift")
    robotgo.MilliSleep(50)
    robotgo.KeyTap("/")
    robotgo.MilliSleep(50)
    robotgo.KeyTap("/")
    robotgo.MilliSleep(50)
    robotgo.KeyTap("shift")
    robotgo.MilliSleep(50)
    robotgo.KeyTap("y")
    robotgo.MilliSleep(50)
    robotgo.KeyTap("i")
    robotgo.MilliSleep(50)
    robotgo.KeyTap("d")
    robotgo.MilliSleep(50)
    robotgo.KeyTap("o")
    robotgo.MilliSleep(50)
    robotgo.KeyTap("n")
    robotgo.MilliSleep(50)
    robotgo.KeyTap("g")
    robotgo.MilliSleep(50)
    robotgo.KeyTap("w")
    robotgo.MilliSleep(50)
    robotgo.KeyTap("u")
    robotgo.MilliSleep(50)
    robotgo.KeyTap("p")
    robotgo.MilliSleep(50)
    robotgo.KeyTap("i")
    robotgo.MilliSleep(50)
    robotgo.KeyTap("n")
    robotgo.MilliSleep(50)
    robotgo.KeyTap("space")
    robotgo.MilliSleep(50)
    robotgo.KeyTap("enter")
    robotgo.MilliSleep(50)
    time.Sleep(3 * time.Second)

    robotgo.MilliSleep(50)
    robotgo.MoveClick(10, 10, `left`, true)
    robotgo.MilliSleep(100)

    robotgo.KeyTap("esc")
    time.Sleep(1 * time.Second)
    robotgo.KeyTap("f10")
    robotgo.MilliSleep(50)
    robotgo.KeyTap("f10")
    time.Sleep(3 * time.Second)
}

func randInt(min, max int) int {
    rand.Seed(time.Now().UnixNano())
    return rand.Intn(max-min+1) + min
}
相关推荐
IT技术分享社区20 分钟前
C#实战:使用腾讯云识别服务轻松提取火车票信息
开发语言·c#·云计算·腾讯云·共识算法
极客代码23 分钟前
【Python TensorFlow】入门到精通
开发语言·人工智能·python·深度学习·tensorflow
疯一样的码农30 分钟前
Python 正则表达式(RegEx)
开发语言·python·正则表达式
代码之光_198031 分钟前
保障性住房管理:SpringBoot技术优势分析
java·spring boot·后端
ajsbxi36 分钟前
苍穹外卖学习记录
java·笔记·后端·学习·nginx·spring·servlet
疯狂的程需猿41 分钟前
一个百度、必应搜索引擎图片获取下载的工具包
golang·图搜索
&岁月不待人&1 小时前
Kotlin by lazy和lateinit的使用及区别
android·开发语言·kotlin
StayInLove1 小时前
G1垃圾回收器日志详解
java·开发语言
无尽的大道1 小时前
Java字符串深度解析:String的实现、常量池与性能优化
java·开发语言·性能优化
爱吃生蚝的于勒1 小时前
深入学习指针(5)!!!!!!!!!!!!!!!
c语言·开发语言·数据结构·学习·计算机网络·算法