//用户参数设置
UserVar buildNums = 5 "待升级建筑数量,上限50"
UserVar yanchi = 1000 "网络延迟,下限200毫秒"


//检查用户参数是否合法
If buildNums > 50 or buildNums < 1 Then
    MessageBox "待升级建筑数量不合法,应为1-50之间整数"
    EndScript
End If
If yanchi < 200
    MessageBox "延迟量设置不合法,下限为200毫秒"
    EndScript
End If

//MsgBox buildNums
//获取窗口句柄,类名,标题
//Dim windowHandle,windowClass,windowTitle
//windowHandle = Plugin.Window.MousePoint()
//windowClass = Plugin.Window.GetClass(windowHandle)
//windowTitle = Plugin.Window.GetText(windowHandle)

//定义全局变量
Dim xys()      //待升级建筑物坐标

Rem start
Call getXys()
While true
	Call buildingLv()
	Delay 30 * 1000
Wend


//抓取待升级建筑物坐标
Sub	getXys()
    MsgBox "鼠标选择建筑物后,点击键盘'J'键"
    ReDim xys(buildNums-1,1)
    For i=0 To buildNums-1
        key = WaitKey()
        If key = 74 Then
            GetCursorPos xys(i,0), xys(i,1)
            MsgBox "抓取升级建筑" & i+1 & "坐标为:" & xys(i,0) & "." & xys(i,1)
        End If
    Next
    MsgBox "待升级建筑物坐标抓取完毕"
End Sub

//升级建筑物
Sub buildingLv()
    For i=0 To buildNums-1
        MoveTo xys(i,0), xys(i,1)
        Delay yanchi
        LeftClick 1
        Delay yanchi
        LeftClick 1
        FindPic 0,0,1440,900,"Attachment:\levelup.bmp",0.9,intX,intY
        If intX > 0 And intY > 0 Then
            MoveTo intX+10, intY+5
            LeftClick 1
        End If
        Delay yanchi
    Next
End Sub