liasica / JiaGuoMengTrainer

家国梦辅助脚本
Mozilla Public License 2.0
66 stars 30 forks source link

大佬 能不能适配下云手机的分辨率 #13

Open jiaowowuwu opened 5 years ago

jiaowowuwu commented 5 years ago

现在主要刷火车凌晨 半夜爬起来电脑有点伤

liasica commented 5 years ago

分辨率是啥?目前规划是上线1.0的时候设置分辨率为1920*1080,同时做一个模拟分辨率功能,你有兴趣可以帮忙测试。

xiao94 commented 5 years ago

分辨率是啥?目前规划是上线1.0的时候设置分辨率为1920*1080,同时做一个模拟分辨率功能,你有兴趣可以帮忙测试。

我改了一个1920*1080的,模拟器上用好像目前没问题 Import "ShanHai.lua"

// 获取屏幕分辨率 If GetScreenX() <> 1080 Or GetScreenY() <> 1920 Then ShowMessage "请将模拟器分辨率设为 1080 × 1920" EndScript End If

While Sys.AppIsFront("com.tencent.jgm") = False TracePrint "等待游戏运行" ShowMessage "等待游戏运行" RunApp "com.tencent.jgm" Delay 1000 Wend

// 需要: 分辨率 1080 × 1920 If EnableFastCapture(true) Then TracePrint "开启快速取色" End If

// 坐标系 (从左往右, 从下往上, 从0开始) // 0,1坐标 2收货 3升级 Dim edit = Array(487, 574) Dim buildings(8, 3) Dim buildingsStr = "360,1248 622,1124 856,1012 364,1004 606,880 864,754 370,748 608,628 866,498"

// 生成坐标系 Dim buildingsArr = Split(buildingsStr, " ") For i = 0 To UBound(buildingsArr) Dim pos = GetPosition(buildingsArr(i)) buildings(i, 0) = pos(0) buildings(i, 1) = pos(1) // 读取配置 buildings(i, 2) = ReadUIConfig("goods" & (i + 1)) buildings(i, 3) = ReadUIConfig("update" & (i + 1)) Dim g = "否", u = "否" If buildings(i, 2) Then g = "是" End If If buildings(i, 3) Then u = "是" End If TracePrint "建筑" & (i + 1) & " 收货 ->" & g & " 升级 ->" & u Next

// 自动收割金币 Dim mowing = ReadUIConfig("mowing", True)

// 升级次数 Dim autoLevelUpTimes = 0

// 自定义升级间隔 (单位: 秒) Dim autoUpdateInterval = Int(ReadUIConfig("update_time")) TracePrint "升级间隔: " & autoUpdateInterval & "秒"

// 跳过货物后是否重启游戏 Dim ignoreAfter = ReadUIConfig("ignore", 0), ignoreOP = "等待"

If ignoreAfter = 2 Then ignoreOP = "重启游戏" ElseIf ignoreAfter = 1 ignoreOP = "飞行模式" End If

Delay 200

ShowMessage "货物跳过后操作: " & ignoreOP

// 货物坐标 Dim goodsList = Array("668,1634", "824,1566", "976,1484") Dim goodsDecide = Array("682,1684", "838,1602", "990,1516")

// 升级政策 Dim policyTimes = 0 Dim policyInterval = 120

// 防假死 Dim stuckTimes = 0, preventStuck = ReadUIConfig("prevent_stuck", True)

// 火车货物检测 Dim trainGoods = Array(False, False, False)

TracePrint "开始循环"

While True // TracePrint "新循环" ClickOKButton Delay 200 Tap 58, 1874 Delay 200 Tap 58, 1874 Delay 200 Dim same = CmpColor(958, 1118, "3EC6FF", 0.9) If same = 0 Then // 防弹窗 Tap 58, 1874 // 收集货物 FindTrain Dim hasGoods = CheckHasGoods(), goodsTimes = 0 // 有火车先送火车 Do While hasGoods FindTrain hasGoods = CheckHasGoods() goodsTimes = goodsTimes + 1 Delay 100 If goodsTimes >= 6 Then TracePrint ignoreAfter If ignoreAfter = 1 Then BackgroundGame ElseIf ignoreAfter = 2 RestartGame End If hasGoods = False End If Loop If mowing Then // 收集金币 GetGold End If // 自动升级 AutoLevelUp // 自动升级政策 // PolicyLevelUp Delay 100 Else If preventStuck Then stuckTimes = stuckTimes + 1 StuckDecide Delay 1000 End If End If Wend

// 检测 "好的" 按钮并自动点击 Function ClickOKButton Dim x, y FindPic 0, 0, 0, 0, "Attachment:btn.png", "000000", 0, 1, x, y // TracePrint x & " " & y If x > -1 And y > -1 Then Tap x, y End If End Function

// 获取金币 Function GetGold For i = 0 To UBOUND(buildings) Tap buildings(i, 0), buildings(i, 1) Delay 200 Next End Function

Function CheckHasGoods If trainGoods(0) = False And trainGoods(1) = False And trainGoods(2) = False Then CheckHasGoods = False Else CheckHasGoods = True End If End Function

// 查找火车 Function FindTrain() For i = 0 To 2 If FindGoods(i) Then DragGoods (i) Delay 1000 End If Next End Function

// 查找货物 Function FindGoods(index) Tap 58, 1874 Dim zb = GetPosition(goodsDecide(index)) Dim intX, intY Dim text = index + 1, msg = "找到货物" & text

Dim cp = CmpColor(zb(0), zb(1), "FFFFFF", 1)

// TracePrint index & " -> " & cp

If cp > -1 Then
    TracePrint msg
    trainGoods(index) = True
    FindGoods = True
Else 
    trainGoods(index) = False

// TracePrint "未找到货物" & text FindGoods = False End If

End Function

// 拖拽货物 Function DragGoods(index) Dim pos = GetPosition(goodsList(index)) Dim x, y, msg, needGoods = False

// 获取当前颜色
Dim beforeColor(), target
KeepCapture 
For m = 0 To UBOUND(buildings)
    Dim color = GetPixelColor(buildings(m, 0), buildings(m, 1))
    beforeColor(m) = color
Next
ReleaseCapture 

// 按下货物
TouchUp 1
TouchDown pos(0), pos(1), 1
Delay 100

KeepCapture 
For n = 0 To UBound(buildings)
    Dim afterColor = GetPixelColor(buildings(n, 0), buildings(n, 1))
    // 比较颜色差值
    Dim diff = ColorDiff(beforeColor(n), afterColor)
    TracePrint "货物:" & (index + 1) & " -> " & (n + 1) & " 的差值是:"& diff
    If diff > 100 Then 
        TracePrint "货物:" & (index + 1) & "的目标是:"& (n + 1) & ", 差值是: " & diff 
        If buildings(n, 2) Then 
            needGoods = True
            target = n
            msg = "货物:" & (index + 1) & "的目标是:"& (n + 1)
            TracePrint msg
            x = buildings(n, 0)
            y = buildings(n, 1)
        Else 
            needGoods = False
            TracePrint "货物跳过"
            // ShowMessage "货物跳过"
        End If
        Exit For
    End If
Next
ReleaseCapture 

If needGoods Then 
    msg = "移动货物到: " & (target + 1)
    TracePrint msg
    // ShowMessage msg
    // 拖动货物
    TouchMove x - 40, y - 60, 1, 100
    TouchUp 1
    Delay 500
End If
TouchUp 1

End Function

// 自动升级 Function AutoLevelUp() Dim t = TickCount(), needLevelUp = False If autoUpdateInterval > 0 And Int(t / autoUpdateInterval / 1000) - 0.1 > autoLevelUpTimes Then Dim editClicked = False For i = 0 To Ubound(buildings) If buildings(i, 3) Then If editClicked = False Then Tap edit(0), edit(1) editClicked = True End If needLevelUp = True Delay 100 Tap buildings(i, 0), buildings(i, 1) Delay 300 Tap 880, 1752 Delay 100 End If Next If needLevelUp Then autoLevelUpTimes = autoLevelUpTimes + 1 TracePrint "结束自动升级, 升级了" & autoLevelUpTimes & "次" Tap edit(0), edit(1) Delay 200 End If End If End Function

// 重启游戏 Function RestartGame TracePrint "重启游戏" KillApp "com.tencent.jgm" stuckTimes = 0 Delay 200 RunApp "com.tencent.jgm" Delay 3000 End Function

// 将游戏转入后台并开启飞行模式 Function BackgroundGame TracePrint "进入飞行模式" KeyPress "Home" ShanHai.OpenAirplane ShanHai.CloseAirplane RunApp "com.tencent.jgm" Delay 3000 End Function

// 判断假死并重启游戏 Function StuckDecide If stuckTimes > 60 Then TracePrint "检测到游戏卡死, 重启游戏" RestartGame End If End Function

// 获取坐标 Function GetPosition(str) GetPosition = Split(Replace(str, " ", ""), ",") End Function

jiaowowuwu commented 5 years ago

分辨率是啥?目前规划是上线1.0的时候设置分辨率为1920 * 1080,同时做一个模拟分辨率功能,你有兴趣可以帮忙测试。

都是720*1280 还有刚有小伙伴说断网有几率点到左下角