📄 fight.ser
字号:
#[HOTKEY][EXT]MULTIPLY
#SetArgsOnCompile
#完美国际2自动打怪脚本
#游戏设置为800×600窗口模式
#另需要以下设置:
#关闭雷达地图锁定模式
#界面设置中,打开“显示周围怪物”,关闭“显示地面物品名字”
#游戏设置中,打开“A,D转向切换”
#按键设置:F1,F2技能,F3拣物,F7打坐
dim WinX,WinY
dim raidCX,raidCY
dim sitBlood,sitMP
dim pi
dim turnRate,forwardRate
#初始化全局变量
function Init
Init=false
pi = 4 * Atn(1)
GetActiveWindowXY(WinX, WinY)
raidCX=737
raidCY=58
GetActiveWindowSize(width, height)
if width<>800 or height<>600 then
Print("错误:只支持800*600的窗口模式运行游戏")
exit function
end if
sitBlood=GetConfigNumber("打坐血百分比")
sitMP=GetConfigNumber("打坐MP百分比")
turnRate=GetConfigNumber("转向速率")
forwardRate=GetConfigNumber("前进速率")
Init=true
end function
#判断一个颜色是否为怪的名字颜色
function IsMonsterNameColor(pixel)
r=GetR(pixel)
g=GetG(pixel)
b=GetB(pixel)
if r=g and g=b and r>252 then
IsMonsterNameColor = true
else
IsMonsterNameColor = false
end if
end function
#根据移动的XY差值计算当前的方向角度(按顺利针从0到2pi)
function GetAngle(fromX, fromY, toX, toY)
dim angle
if toX-fromX=0 then
if toY-fromY>0 then
GetAngle=0
else
GetAngle=pi
end if
exit function
else
angle=Atn(-(toY-fromY)/(toX-fromX))
end if
if toX-fromX <0 then
angle=angle+pi
end if
GetAngle=angle+0.5*pi
end function
#判断已有怪被选中
function IsMonsterSelected
GetPixel(WinX+338, WinY+24, true, pixel)
if pixel=Color(0,0,0) then
IsMonsterSelected=true
else
IsMonsterSelected=false
end if
end function
#判断一个颜色点所在的名字边界。返回0则不是一个字
function CalcNameRect(x, y, byref x0, byref y0, byref x1, byref y1)
x0=x
x1=x
y0=y
y1=y
pixelCount=0
#向右搜
missCount=0
curX=x
do
found=false
for j=-10 to 10
GetPixel(curX,y+j,false,pixel)
if IsMonsterNameColor(pixel) then
pixelCount=pixelCount+1
if curX>x1 then
x1=curX
end if
if y+j<y0 then
y0=y+j
end if
if y+j>y1 then
y1=y+j
end if
found=true
end if
next
if found then
missCount=0
else
missCount=missCount+1
end if
curX=curX+1
loop while missCount<3
#向左搜
missCount=0
curX=x
do
found=false
for j=-10 to 10
GetPixel(curX,y+j,false,pixel)
if IsMonsterNameColor(pixel) then
pixelCount=pixelCount+1
if curX<x0 then
x0=curX
end if
if y+j<y0 then
y0=y+j
end if
if y+j>y1 then
y1=y+j
end if
found=true
end if
next
if found then
missCount=0
else
missCount=missCount+1
end if
curX=curX-1
loop while missCount<3
#至少超过20个点
if pixelCount>20 then
CalcNameRect=true
else
CalcNameRect=false
end if
end function
#在屏幕上找怪
function FindMonster(byref x, byref y)
FindMonster=false
CopyScreen()
for y=WinY+320 to WinY+110 step -3
for x=WinX+80 to WinX+720 step 3
GetPixel(x,y,false,pixel)
if IsMonsterNameColor(pixel) then
#判断此颜色周围的相同颜色,以确认名字边界
if CalcNameRect(x,y,x0,y0,x1,y1) then
x=(x0+x1)\2
y=y1
FindMonster=true
exit function
end if
end if
next
next
end function
#在雷达上找最近的怪
function FindNearestMonsterInRaid(byref mx, byref my)
FindNearestMonsterInRaid=false
CopyScreen()
minDist=9999
mx=-1
my=-1
for y=raidCY-50 to raidCY+50
for x=raidCX-50 to raidCX+50
GetPixel(WinX+x, WinY+y, false, pixel1)
GetPixel(WinX+x+1, WinY+y+1, false, pixel2)
if pixel1=Color(207,207,207) and pixel2=Color(207,207,207) then
angle=GetAngle(raidCX, raidCY, x, y)
absAngle=angle
if absAngle>pi then
absAngle=pi*2-absAngle
end if
dist1=sqr((x-raidCX)*(x-raidCX)+(y-raidCY)*(y-raidCY))
dist=dist1+absAngle/(pi/7.2)
if dist<minDist and dist1>2 then
mx=x
my=y
minDist=dist
FindNearestMonsterInRaid=true
end if
end if
next
next
end function
#转向一个角度
function TurnToAngle(angle)
piTime=3000/turnRate
absAngle=angle
if absAngle>pi then
absAngle=pi*2-absAngle
end if
if angle<pi then
dir="D"
else
dir="A"
end if
KeyDown(dir)
Wait(absAngle/pi*piTime)
KeyUp(dir)
end function
#攻打选中的怪
function fight
do
KeyPress("F2")
Wait(1500)
if not IsMonsterSelected() then
exit do
end if
KeyPress("F1")
Wait(800)
loop while IsMonsterSelected()
#按3拣东西
KeyPress("F3")
Wait(1000)
KeyPress("F3")
Wait(1000)
KeyPress("F3")
end function
function NearColor(pixel1, pixel2, err)
NearColor=(ABS(GetR(pixel1)-GetR(pixel2))<=err and ABS(GetG(pixel1)-GetG(pixel2))<=err and ABS(GetB(pixel1)-GetB(pixel2))<=err)
end function
#判断一个颜色是血条的颜色
function IsBloodColor(pixel)
IsBloodColor=false
r=GetR(pixel)
g=GetG(pixel)
b=GetB(pixel)
if r<150 and (r<g*2 or r<b*2) then
exit function
end if
if abs(g-b)>10 then
exit function
end if
IsBloodColor=true
end function
#判断一个颜色是蓝条的颜色
function IsMPColor(pixel)
IsMPColor=NearColor(pixel, Color(0, 69, 139), 10)
end function
#取得当前的血的百分比
function GetBloodPercent()
minX=WinX+129
maxX=WinX+268
y=WinY+29
CopyScreen()
for x=minX to maxX
GetPixel(x, y, false, pixel)
if not IsBloodColor(pixel) then
exit for
end if
next
GetBloodPercent=(x-minX)/(maxX-minX+1)*100
end function
#取得当前的MP的百分比
function GetMPPercent()
minX=WinX+129
maxX=WinX+268
y=WinY+37
CopyScreen()
for x=minX to maxX
GetPixel(x, y, false, pixel)
if not IsMPColor(pixel) then
exit for
end if
next
GetMPPercent=(x-minX)/(maxX-minX+1)*100
end function
#检查血和MP,不足打坐
function CheckBloodMP
BloodPercent = GetBloodPercent()
MPPercent = GetMPPercent()
if BloodPercent<sitBlood or MPPercent<sitMP then
#打坐
KeyPress("F7")
st=GetTime()
do
wait(200)
BloodPercent = GetBloodPercent()
MPPercent = GetMPPercent()
loop while BloodPercent<99 and MPPercent<99 and GetTime()-st<30000 //30秒超时
end if
end function
function main
if not Init() then
exit function
end if
do
#检查血,不足则打坐
CheckBloodMP()
do while not IsMonsterSelected()
#没有点中怪,取消走路
KeyPress("ESC")
#屏幕上找怪
if not FindMonster(x,y) then
#当前屏幕上没有怪,在雷达上找怪
if FindNearestMonsterInRaid(mx,my) then
pixelTime=400/forwardRate
angle=GetAngle(raidCX, raidCY, mx, my)
dist=sqr((mx-raidCX)*(mx-raidCX)+(my-raidCY)*(my-raidCY))
# Print("Dist:"&dist)
# Print("Angle:"&angle)
#转向怪物
TurnToAngle(angle)
#走到适当距离
KeyDown("W")
dist=dist-4
if dist<0 then
dist=0
end if
wait(dist*pixelTime)
KeyUp("W")
end if
else
#屏幕上找到怪的名字了
MouseLeftClick(x, y+40)
Wait(500)
end if
loop
#选中怪了,开打
Fight()
#检查血,不足则打坐
CheckBloodMP()
loop while true
end function
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -