📄 move.pas
字号:
unit Move;
{---------无影开发小组敬告:-------------------}
{ 外挂研究无罪,开放源码有理! }
{ 希望以此献给各位想研究外挂的朋友一窥外挂之容 }
{ 本代码只供研究之用,不得用于非法用途 }
interface
uses Windows,Dialogs,SendPack,UnitState,PackStruct,GameCode;
var
TagPoint : PosPoint; //目标点
MovStopFlag : Boolean=false;//强制停止标志
PatrolPA : PosPoint; //巡逻点A
PatrolPB : PosPoint; //巡逻点B
PatrolFlag : Integer=0; //巡逻控制标志
PatrolLast : Boolean=true; //是否继续巡逻的标记
function GetDist(P1:PosPoint;P2:PosPoint):Integer;
//^取得游戏中两点的距离
function GetAntiDir(Dir:Integer):Integer;
//^取得指定方向相反方向
function GetToDir(Pos:PosPoint;Tag:PosPoint):Integer;
//^确定从pos到tag的方向
function MoveToPoint(Tag:PosPoint):Integer;
//^移动到tag,由工作线程调用。
function IsRoundPoint(Tag:PosPoint):Boolean;
//^判断tag是否为当前位置的周围
procedure RunToDir(Dir:Integer);
//^向方向dir跑一步
procedure WalkToDir(Dir:Integer);
//^向方向dir走一步
procedure MoveStop();
//^强制移动停止
procedure RefreshPos();
//^刷新当然位置
function PatrolMov():Integer;
//^巡逻式移动函数,线程调用
implementation
procedure MoveStop();
begin
MovStopFlag:=true;
PatrolLast:=false;
end;
function GetDist(P1:PosPoint;P2:PosPoint):Integer;
var
xc,yc:Integer;
begin
GetDist:=0;
xc:=abs(P1.X-p2.X);
yc:=abs(p1.Y-p2.Y);
if xc>yc then
GetDist:=xc
else
GetDist:=yc;
end;
function GetAntiDir(Dir:Integer):Integer;
begin
if (Dir>7) or (Dir<0) then
begin
GetAntiDir:=-1;
exit;
end;
if Dir>3 then
GetAntiDir:=Dir-4
else
GetAntiDir:=Dir+4;
end;
function IsRoundPoint(Tag:PosPoint):Boolean;
var
xc,yc:Integer;
begin
IsRoundPoint:=true;
xc:=abs(Tag.X-CharPos.X);
yc:=abs(Tag.Y-CharPos.Y);
if (xc>1) or (yc>1) then
IsRoundPoint:=false;
end;
function GetToDir(Pos:PosPoint;Tag:PosPoint):Integer;
begin
GetToDir:=0;
if (Pos.X=Tag.X) and (Pos.Y>Tag.Y) then
GetToDir:=0;
if (Pos.X=Tag.X) and (Pos.Y<Tag.Y) then
GetToDir:=4;
if (Pos.X<Tag.X) and (Pos.Y=Tag.Y) then
GetToDir:=2;
if (Pos.X>Tag.X) and (Pos.Y=Tag.Y) then
GetToDir:=6;
if (Pos.X<Tag.X) and (Pos.Y<Tag.Y) then
GetToDir:=3;
if (Pos.X<Tag.X) and (Pos.Y>Tag.Y) then
GetToDir:=1;
if (Pos.X>Tag.X) and (Pos.Y>Tag.Y) then
GetToDir:=7;
if (Pos.X>Tag.X) and (Pos.Y<Tag.Y) then
GetToDir:=5;
end;
procedure WalkToDir(Dir:Integer);
var
pack:PackHeaderB;
begin
case Dir of
0:
begin
Pack.X:=CharPos.X;
pack.Y:=CharPos.Y-1;
end;
1:
begin
Pack.X:=CharPos.X+1;
Pack.Y:=CharPos.Y-1;
end;
2:
begin
Pack.X:=CharPos.X+1;
Pack.Y:=charPos.Y;
end;
3:
begin
Pack.X:=CharPos.X+1;
Pack.Y:=CharPos.Y+1;
end;
4:
begin
Pack.X:=CharPos.X;
Pack.Y:=CharPos.Y+1;
end;
5:
begin
Pack.X:=CharPos.X-1;
Pack.Y:=CharPos.Y+1;
end;
6:
begin
Pack.X:=CharPos.X-1;
Pack.Y:=CharPos.Y;
end;
7:
begin
Pack.X:=CharPos.X-1;
Pack.Y:=CharPos.Y-1;
end;
else
begin
ShowMessage('WalkToDir:Wrong Dir');
end
end;
pack.wcmd:=$0bc3;
pack.w1:=0;
pack.w2:=Dir;
pack.w3:=0;
SendMyPack(PChar(@pack),12);
end;
procedure RunToDir(Dir:Integer);
var
pack:PackHeaderB;
begin
case Dir of
0:
begin
Pack.X:=CharPos.X;
pack.Y:=CharPos.Y-2;
end;
1:
begin
Pack.X:=CharPos.X+2;
Pack.Y:=CharPos.Y-2;
end;
2:
begin
Pack.X:=CharPos.X+2;
Pack.Y:=charPos.Y;
end;
3:
begin
Pack.X:=CharPos.X+2;
Pack.Y:=CharPos.Y+2;
end;
4:
begin
Pack.X:=CharPos.X;
Pack.Y:=CharPos.Y+2;
end;
5:
begin
Pack.X:=CharPos.X-2;
Pack.Y:=CharPos.Y+2;
end;
6:
begin
Pack.X:=CharPos.X-2;
Pack.Y:=CharPos.Y;
end;
7:
begin
Pack.X:=CharPos.X-2;
Pack.Y:=CharPos.Y-2;
end;
else
begin
ShowMessage('RunToDir:Wrong Dir');
end
end;
pack.wcmd:=$0bc5;
pack.w1:=0;
pack.w2:=Dir;
pack.w3:=0;
SendMyPack(PChar(@pack),12);
end;
function MoveToPoint(Tag:PosPoint):Integer;
var
DelayTime : Integer;
dir,xc,yc: Integer;
begin
DelayTime:=700;
xc:=abs(CharPos.X-Tag.X);
yc:=abs(CharPos.Y-Tag.Y);
dir:=GetToDir(CharPos,Tag);
while (xc>1) or (yc>1) do
begin
if MovStopFlag=True then
begin
MovStopFlag:=false;
MoveToPoint:=-1;//强制移动停止返回值
exit;
end;
if FailCnt>5 then
begin
if dir>3 then
RunToDir(dir-1)
else
RunToDir(dir+1);
end
else
dir:=GetToDir(CharPos,Tag);
//DBGOut('ToDir=%d',[dir]);
RunToDir(dir);
WaitForSingleObject(HSignal,INFINITE);
Sleep(DelayTime);
xc:=abs(CharPos.X-Tag.X);
yc:=abs(CharPos.Y-Tag.Y);
end;
if (xc<>0) or (yc<>0) then
begin
dir:=GetToDir(CharPos,Tag);
WalkToDir(dir);
end;
MoveToPoint:=0;//移动成功返回值
RefreshPos();
end;
procedure RefreshPos();
var
pack:PackHeaderB;
begin
pack.X:=1;
pack.Y:=1;
pack.wcmd:=$0bc5;
pack.w1:=0;
pack.w2:=0;
pack.w3:=0;
SendMyPack(PChar(@pack),12);
end;
function PatrolMov():Integer;
var
Tag : PosPoint;
Next : PosPoint;
xc,yc: Integer;
T1 : PosPoint;
TIndex,i : Integer;
R : Integer;
MstName : string;
begin
case PatrolFlag of
0:
PatrolFlag:=1;
1:
PatrolFlag:=0;
end;
MovStopFlag:=false;//关闭stopflag
PatrolLast:=true;
case PatrolFlag of
0:
Tag:=PatrolPA;
1:
Tag:=PatrolPB;
end;
xc:=Tag.X-CharPos.X;
yc:=Tag.Y-CharPos.Y;
while (abs(xc)>4) or (abs(yc)>4) do
begin
if xc>0 then
Next.X:=CharPos.X+4
else if xc=0 then
Next.X:=CharPos.X
else
Next.X:=CharPos.X-4;
if yc>0 then
Next.Y:=CharPos.Y+4
else if yc=0 then
Next.Y:=CharPos.Y
else
Next.Y:=CharPos.Y-4;
R:=MoveToPoint(Next);
if R=-1 then
begin
PatrolMov:=0;//强制停止返回值 ,巡逻停止.
exit;
end;
Sleep(5000);
RefreshPos;
xc:=Tag.X-CharPos.X;
yc:=Tag.Y-CharPos.Y;
//下面是找怪的代码
TIndex:=-1;
for i:=0 to MstList1.GetCnt-1 do
begin
MstName:=MstList1.GetMstName(i);
if (MstName<>'鹿') and (MstName<>'鸡') and (MstName<>'兔') then
begin
TIndex:=i;
break;
end;
end;
if TIndex<>-1 then
begin
T1:=MstList1.GetMstPos(TIndex);
DBGOut('Goto a Mst',[]);
DBGOut('At %d,%d',[T1.X,T1.Y]);
T1.Y:=T1.Y-1;
R:=MoveToPoint(T1);
if R=-1 then
begin
if PatrolLast=true then
begin
PatrolMov:=3; //保证继续巡逻
exit;
end
else
begin
PatrolMov:=0;
exit;
end;
end
else
begin
Sleep(1000);
end;
end;
end;
MoveToPoint(Tag);
if PatrolLast=true then
PatrolMov:=3 //保证继续巡逻
else
PatrolMov:=0;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -