5

用溪流 WarKey 辅助红警开局快捷操作 - 溪流

 1 year ago
source link: https://www.cnblogs.com/Streamlet/p/17061039.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

自从发现红警除了 ddraw 补丁可以在最新的系统里玩后,就开始怀旧了。但是由于手残,遇到别人抢地盘基本上直接崩了。偶然有一次发现像 08 这样的高手点 30 个坦克使用工具的。那么,我开局用工具造兵营、碉堡,是不是显得不那么可耻了呢?

说干就干,我有支持 lua 脚本的溪流 WayKey,理论上都能做到。

实现一次性点 30 个坦克

这个场景没有手速要求,只是为了不麻烦,所以我们实现地简单些:要求先把鼠标放好位置,然后设定快捷键,直接给点击 N 次。

实现很简单,30 次这个次数作为参数传进来,主函数里就是 PressMouseButton(Mouse.LBUTTON)、ReleaseMouseButton(Mouse.LBUTTON) 来 30 下:

Extension =
{
    Application   = "xlWarKey",
    Version       = "3.0",
    NameSpace     = "http://www.streamlet.org/Software/xlWarKey/",

    ExtensionName = "鼠标连点",
    Author        = "溪流",
    Description   = "该脚本可以用来在红警2中一次性造多个单位。",

    Configuration =
    {
        Count    =
        {
            Type  = "number",
            Desc  = "连点次数"
        }
    },

    Entrance      = function (id)

        local config = Extension.Configuration;
        --config.Count 就是用户在软件界面上设置的连点次数

        for i = 1, config.Count, 1
        do 
            PressMouseButton(Mouse.LBUTTON);
            ReleaseMouseButton(Mouse.LBUTTON);
        end

        return true;
    end
};

(脚本文档见 https://www.streamlet.org/software/xlwarkey/)

保存为 .lua 文件放到溪流 WarKey 目录下的 Scripts 下,退出溪流 WarKey 重新打开,即可看到脚本生效。

因为溪流 WarKey 本是为魔兽写的,因此默认会勾上“仅在魔兽争霸中应用”,要去掉它。

90455-20230119090230310-866996624.png

然后改键动作选择“鼠标连点”脚本,并配置参数 Count 为 30 即可:

90455-20230119090249878-907142622.png

实现快速造兵营、碉堡

难点主要是在定位按钮的位置。

90455-20230119090258584-1758501232.png

我们在不同分辨率下截几张图,发现一个规律:不管分辨率如何,面板宽度总是固定为 168 像素,面板内部的各个组件大小也是固定的。这就好办了。经过测量,得出如下结论:

  • 顶部到按钮区域高度:227
  • 面板宽度 168,左右空隙 20、22,按钮区域宽度126
  • 按钮大小 63x50
90455-20230119090306729-2049979102.png

所以,对于第 r 行、第 c 列(r、c 均从 0 开始)的按钮,其中心坐标的计算公式为

x = WIDTH - 168 + 20 + 63 * c + 63/2
y = 227 + r * 50 + 50/2

点击面板按钮可以组织成一个函数:

ClickPanel = function(row, column, count)
    if count == nil then
        count = 1
    end
    local width, height = GetClientSize()
    local target_x = width - 168 + 20 + 63 * column + 32
    local target_y = 227 + row * 50 + 25
    MoveMouse(target_x, target_y)
    for i = 1, count, 1
    do 
        ClickMouse()
        Delay(10)
    end
end

有了 ClickPanel,我们可以写出造任何东西的代码了。完整脚本如下:

Extension =
{
    Application   = "xlWarKey",
    Version       = "3.0",
    NameSpace     = "http://www.streamlet.org/Software/xlWarKey/",

    ExtensionName = "红警开局快速操作",
    Author        = "溪流",
    Description   = "帮助红警手残党不要一开始就被抢死,提高游戏体验",

    Configuration =
    {
        Type =
        {
            Type  = "number",
            Desc  = "1=造电厂,2=造兵营,3=造矿场碉堡1工程师,4=造碉堡,5=造3条狗,6=造10个兵"
        }
    },

    Entrance = function (id)

        ClickKey = function (key)
            PressKey(key)
            ReleaseKey(key)
        end

        ClickMouse = function ()
            PressMouseButton(Mouse.LBUTTON)
            ReleaseMouseButton(Mouse.LBUTTON)
        end

        ClickPanel = function(row, column, count)
            if count == nil then
                count = 1
            end
            local width, height = GetClientSize()
            -- 红警面板总是在右侧固定宽度位置 168 像素,其中
            -- 内边框左侧 20 像素,右侧 22 像素,中间 126 像素为按钮,分两列,每列 63px
            -- 顶部到按钮高度 227 像素,按钮高度 50 像素
            local target_x = width - 168 + 20 + 63 * column + 32
            local target_y = 227 + row * 50 + 25
            MoveMouse(target_x, target_y)
            for i = 1, count, 1
            do 
                ClickMouse()
                Delay(10)
            end
        end

        local config = Extension.Configuration
        local start_x, start_y = GetCursorPosition()

        if config.Type == 1 then
            -- 造电厂
            ClickKey(Keys.VK_Q)
            ClickPanel(0, 0)
            MoveMouse(start_x, start_y)
        elseif config.Type == 2 then
            -- 造兵营
            ClickKey(Keys.VK_Q)
            ClickPanel(1, 0)
            MoveMouse(start_x, start_y)
        elseif config.Type == 3 then
            -- 造矿场
            ClickKey(Keys.VK_Q)
            ClickPanel(0, 1)
            MoveMouse(start_x, start_y)
        elseif config.Type == 4 then
            -- 造碉堡
            ClickKey(Keys.VK_W)
            ClickPanel(0, 1)
            MoveMouse(start_x, start_y)
        elseif config.Type == 5 then
            -- 造3条狗
            ClickKey(Keys.VK_Q)
            ClickPanel(1, 0, 3)
            MoveMouse(start_x, start_y)
        elseif config.Type == 6 then
            -- 造10个兵
            ClickKey(Keys.VK_Q)
            ClickPanel(0, 0, 10)
            MoveMouse(start_x, start_y)
        end

        return true
    end
}

因为面板按钮会随着游戏进行而会有变化,所以上述脚本只适用于开局。


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK