Seraph脚本之-------乐土Online常用脚本
代码如下
1
#[HOTKEY]END2
# 在此定义全局变量3
/*4
此脚本由evan开发,转载请保留作者信息5
evan脚本源代码及说明:www.jevan.com.cn6

7
作者blog:jevan.cnblogs.com8
版本: 0.29
开发时间: 2008-11-2910
*/11
# 在此定义全局变量12
/*13
12月1日更新:14
1,优化关闭对话框函数 ------------ 优化成功15
12月2日更新:16
1,优化上下走动,是人物尽量在原地 ----------优化成功17
2,修改找怪超时的bug, --------------成功18
12月3日更新:19
1,优化战斗判断算法 ------------待测试20
*/21
//基础相关变量22
dim baseX = 1062 //开发电脑基础坐标X23
dim baseY = 661 //开发电脑基础坐标Y24

25
dim currentX ,currentY //当前电脑基准坐标x,y26
dim width1, height1 //窗口大小27

28
//基础相关变量配置完29

30
//调试输出31
dim debug = 0 //1为输出32
dim isBattleMode = "ispet" //是不是战斗判断类型33
dim isBattleTimer //是不是在战斗计时器ID34
dim isclear = 1 //是不是删除log ,1为删除35

36

37
dim checkBattleTime = 3000 //检查战斗间隔时间,修改小心38
dim battleNum=1 //战斗次数计数39

40
dim overTime = 50000 //超时时间41

42
//日志文件43
dim logFile = "letu-log-03.txt" 44

45
function main46
# 在此添加由向导创建或录制的代码47
48
// ClearLog(logFile )49
50
testBattleByFindText()51

52

53
end function54

55
# 在此添加子函数56
function testBattleByFindText57
58
dim front = 0 59
dim leftState = 060
dim moveOneFront = 061
dim ttime62
dim tempt = 063
64
//加载游戏状态函数65
GameState()66
67
//超时控制68
StartTime=GetTime()69
70
//记时器用于判断是不是战斗71
isBattleTimer=SetTimer("CloseAll", 60000, true)72
do73

74
Wait(500)75
76
//超时控制77
StartTime=GetTime()78
79
do //循环80
81
if FindText(Color(255,165,0), 10, 10, ChangeX(327), ChangeY(203), ChangeX(1039), ChangeY(636), 0, 0, true, FoundX, FoundY) then82
83
MouseLeftClick(FoundX+6, FoundY+4) 84
85
end if86
87
//超时检查88
if GetTime() - StartTime > overTime then89
WriteLog(logFile ,"FindMonster超时,退出函数。") 90
//StartTime=GetTime()91
if leftState = 0 then92
leftState = 193
end if94
95
//关闭所有打开页面96
CloseAll()97
98
exit do99
end if100
101
//加0.2秒延时以控制CPU占用102
Wait(500)103
104
//直到图像"红色的字"出现105
loop until FindText(Color(255,0,0), 20, 12, ChangeX(332), ChangeY(198), ChangeX(1000), ChangeY(610), 0, 0, true, FoundX, FoundY)106
//此时FoundX和FoundY的值分别为找到的图像的左上角X,Y坐标107
108
//循环,等待战斗结束109
do 110
if debug = 1 then 111
Print("等待战斗结束!")112
end if113
//加0.5秒延时以控制CPU占用114
Wait(1000)115
//直到图像"带宝宝版战斗图标.sel"不出现116
loop while FindText(Color(255,0,0), 20, 12, ChangeX(332), ChangeY(198), ChangeX(1000), ChangeY(610), 0, 0, true, FoundX, FoundY)117
118
119
//次120
if moveOneFront = 1 then121
ttime = (overTime/10) *2122
else123
ttime = overTime/10124
end if125
126
//判断要不要走127
if leftState = 1 then128
129
//走的方向130
if tempt = 0 then131
findTime = GetTime()132
do133
KeyPress("w")134
Wait(300)135
loop until GetTime() - findTime > ttime136
137
//方向改变138
tempt = 1139
140
//走的状态改变,走过了,则leftState = 0 极为不走141
leftState = 0142
143
//是不是第一次走,不是的话,则复制144
if moveOneFront = 0 then145
moveOneFront = 1146
end if147
else148
findTime = GetTime()149
do150
KeyPress("s")151
Wait(300)152
loop until GetTime() - findTime > ttime 153
154
//方向改变155
tempt = 0156
157
//走的状态改变,走过了,则leftState = 0 极为不走158
leftState = 0159
160
//走的方向的时间判断161
//如果第一次州的话,则把moveOneFront = 1162
if moveOneFront = 0 then163
moveOneFront = 1164
end if165
166
end if167

168
end if169
170

171
172
Wait(500)173
174
175
//调用宝宝加血函数176
PetAddFood("5",0.5,"hp")177
178
//日志记录179
WriteLog(logFile ,"第"&battleNum&"次战斗结束!") 180
battleNum = battleNum +1181
182
//Print("第"&battleNum&"次战斗结束!")183
184
185
loop186
End function187

188
//游戏状态189
function GameState190
191
//日志192
if isclear = 1 then193
ClearLog(logFile)194
end if 195
//取得当前窗口的大小196
GetActiveWindowSize(width1, height1)197
198
if FindImageEx("切换.Sel",Color(30,30,30) ,0,0,width1, height1,true,currentX,currentY) then199

200
//日志记录201
WriteLog(logFile ,"脚本开始运行!") 202
203
end if204
end function 205

206
//关闭对话框207
function CloseAll208
209
//关闭悄悄话对话框210
MouseLeftClick(ChangeX(872), ChangeY(227))211
// MouseMove(674, 487)212
//关闭确定,取消对话框。213
MouseLeftClick(ChangeX(674), ChangeY(487))214
//MouseMove()215
MouseLeftClick(ChangeX(593), ChangeY(485))216
217
218
//MouseMove()219
MouseLeftClick(ChangeX(635), ChangeY(484))220
221
end function222

223

224
//宠物加血,key为加血快捷键,sc为百分比,type判断模式,hp或mp225
function PetAddFood(key,sc,type)226
227
dim flag = 0 //控制flag228
dim by //基准坐标Y229
dim tColor //零时用参数230
//dim petLong = 100 //血长。231
232
dim hpColor,mpColor //红、蓝的颜色233
234
//超时控制235
StartTime=GetTime()236
237
GetPixel(ChangeX(185) , ChangeY(261) , true, hpColor)238
GetPixel(ChangeX(185) , ChangeY(268) , true, mpColor)239
240
GetPixel(ChangeX(185+100 * sc) , ChangeY(261) , true, mColor)241
242
if debug = 1 then243
Print(hpColor)244
Print(mpColor)245
Print(mColor)246
end if 247
248
//模式判断及相关变量赋值249
if type = "hp" then250
by = 261251
tColor = hpColor252
elseif type = "mp" then253
by = 268254
tColor = mpColor 255
if debug = 1 then 256
Print("tColor = mpColor")257
end if258
end if259
260
//只要屏幕坐标(x, x)的颜色不等于(0, 0, 0)261
//如果屏幕坐标(185, 261)的颜色等于(37, 215, 77) 那么262
if CheckColor(ChangeX(185+100 * sc), ChangeY(by), tColor, 30) then263
//就循环做此操作264
WriteLog(logFile ,"宝宝不用加血!") 265
else 266
if debug = 1 then 267
Print("宝宝加血函数")268
end if269
270
KeyPress(key)271
//加0.3秒延时以控制CPU占用272
Wait(300)273
274
WriteLog(logFile ,"宝宝加完一次红!") 275
//否则276

277
end if278
279
end function280

281
//检查有没有对话框282
function IsDialog(byref x,byref y)283
284
//1:判断是不是有那个笑的图标285
//如果找到图像"xiao.sel"286
if FindImageEx("xiao.sel", Color(30, 30, 30), ChangeX(356), ChangeY(514), ChangeX(478), ChangeY(588), true, FoundX, FoundY) then287
//此时FoundX和FoundY的值分别为找到的图像的左上角X,Y坐标288
289
//以下为录制代码290
//MouseLeftClick(876, 232)291
x = FoundX + 4 + 852-387292
y = FoundY + 4 + 600-266293
294
IsDialog = true295
Print(1)296
exit function297
else298
IsDialog = false299
end if300
301
//2:判断是不是有那个X的图标302
//如果找到图像"x.sel"303
if FindImageEx("x.sel", Color(30, 30, 30), ChangeX(386), ChangeY(200), ChangeX(999),ChangeY(440), true, FoundX, FoundY) then304
//此时FoundX和FoundY的值分别为找到的图像的左上角X,Y坐标305
306
//MouseLeftClick(FoundX+3, FoundY+3)307
x = FoundX+3308
y = FoundY+3309
310
IsDialog = true311
Print(2)312
exit function313
else314
IsDialog = false315
end if316
317
//3:判断是不是有那个颜色块318
//如果448×20的一块颜色(222, 224, 215)在此时出现319
if FindBlockEx(Color(222, 224, 215), 400, 20, 20, ChangeX(368), ChangeY(180), ChangeX(932), ChangeY(293), 1, 1, true, FoundX, FoundY) then320
//如找到,此时FoundX和FoundY分别为找到色块的左上角坐标321
Print(3)322
Print(FoundX)323
Print(FoundY)324
//在屏幕坐标(FoundX+10, FoundY+10)按下鼠标左键325
MouseLeftDown(ChangeX(FoundX+10), ChangeY(FoundY+10))326
327
Wait(500)328
//移动329
MouseMove(ChangeX(FoundX+10-70), ChangeY(FoundY+10))330
331
Wait(500)332
//在屏幕坐标(FoundX+10-100, FoundY+10)放开鼠标左键333
MouseLeftUp(ChangeX(FoundX+10-70), ChangeY(FoundY+10))334
335
IsDialog = true336
x = FoundX+3337
y = FoundY+3338
else339
IsDialog = false340
end if341
342
//4:判断是不是有黑色的字343
//如果高度为10,颜色为(0, 0, 0)的一串文字在此时出现344
if FindText(Color(0, 0, 0), 20, 10, ChangeX(322), ChangeY(200), ChangeX(978), ChangeY(354), 0, 0, true, FoundX, FoundY) then345
//如找到,此时FoundX和FoundY分别为找到文字的中心点坐标346
Print(4)347
//在屏幕坐标(FoundX+10, FoundY+10)按下鼠标左键348
MouseLeftDown(ChangeX(FoundX+10), ChangeY(FoundY+10))349
350
Wait(500)351
//移动352
MouseMove(ChangeX(FoundX+10-70), ChangeY(FoundY+10))353
354
Wait(500)355
//在屏幕坐标(FoundX+10-100, FoundY+10)放开鼠标左键356
MouseLeftUp(ChangeX(FoundX+10-70), ChangeY(FoundY+10))357
358
IsDialog = true359
x = FoundX+3360
y = FoundY+3361
else362
IsDialog = false363
end if364
end function365

366
//x坐标转换函数367
Function ChangeX(x)368
ChangeX = x - baseX + currentX369
End Function370
//y坐标转换函数371
Function ChangeY(y)372
ChangeY = y - baseY + currentY373
End Function374

375
function OnEnd376
377
WriteLog(logFile ,"evan版乐土脚本结束!") 378
379
end function380

浙公网安备 33010602011771号