📄 objrobot.pas
字号:
unit ObjRobot;
interface
uses
Windows, Classes, SysUtils, DateUtils, ObjBase, Grobal2 ,mylist;
const
sROAUTORUN = '#AUTORUN';
sRONPCLABLEJMP = 'NPC';
nRONPCLABLEJMP = 100;
sRODAY = 'DAY';
nRODAY = 200;
sROHOUR = 'HOUR';
nROHOUR = 201;
sROMIN = 'MIN';
nROMIN = 202;
sROSEC = 'SEC';
nROSEC = 203;
sRUNONWEEK = 'RUNONWEEK'; //指定星期几运行
nRUNONWEEK = 300;
sRUNONDAY = 'RUNONDAY'; //指定几日运行
nRUNONDAY = 301;
sRUNONHOUR = 'RUNONHOUR'; //指定小时运行
nRUNONHOUR = 302;
sRUNONMIN = 'RUNONMIN'; //指定分钟运行
nRUNONMIN = 303;
sRUNONSEC = 'RUNONSEC';
nRUNONSEC = 304;
type
TOpType = (o_NPC);
TAutoRunInfo = record
dwRunTick: LongWord; //上一次运行时间记录
dwRunTimeLen: LongWord; //运行间隔时间长
nRunCmd: Integer; //自动运行类型
nMoethod: Integer;
sParam1: string; //运行脚本标签
sParam2: string; //传送到脚本参数内容
sParam3: string;
sParam4: string;
nParam1: Integer;
nParam2: Integer;
nParam3: Integer;
nParam4: Integer;
boStatus: Boolean;
end;
pTAutoRunInfo = ^TAutoRunInfo;
TRobotObject = class(TPlayObject)
m_sScriptFileName: string;
m_AutoRunList: TMyList;
private
m_boRunOnWeek: Boolean; //是否已执行操作;
procedure LoadScript();
procedure ClearScript();
procedure ProcessAutoRun();
procedure AutoRun(AutoRunInfo: pTAutoRunInfo);
procedure AutoRunOfOnWeek(AutoRunInfo: pTAutoRunInfo);
procedure AutoRunOfOnDay(AutoRunInfo: pTAutoRunInfo);
procedure AutoRunOfOnHour(AutoRunInfo: pTAutoRunInfo);
procedure AutoRunOfOnMin(AutoRunInfo: pTAutoRunInfo);
procedure AutoRunOfOnSec(AutoRunInfo: pTAutoRunInfo);
public
constructor Create(); override;
destructor Destroy; override;
procedure SendSocket(DefMsg: pTDefaultMessage; sMsg: string); override;
procedure ReloadScript();
procedure Run(); override;
end;
TRobotManage = class
RobotHumanList: TStringList;
private
procedure LoadRobot();
procedure UnLoadRobot();
public
constructor Create();
destructor Destroy; override;
procedure RELOADROBOT();
procedure Run;
end;
implementation
uses M2Share, HUtil32;
{ TRobotObject }
procedure TRobotObject.AutoRun(AutoRunInfo: pTAutoRunInfo);
resourcestring
sExceptionMsg = '[Exception] TRobotManage:: AutoRun';
begin
if g_RobotNPC = nil then
begin
exit;
end;
Try
if GetTickCount - AutoRunInfo.dwRunTick > AutoRunInfo.dwRunTimeLen then
begin
case AutoRunInfo.nRunCmd of //
nRONPCLABLEJMP:
begin
case AutoRunInfo.nMoethod of //
nRODAY:
begin
if GetTickCount - AutoRunInfo.dwRunTick > 24 * 60 * 60 * 1000 *
LongWord(AutoRunInfo.nParam1) then
begin
AutoRunInfo.dwRunTick := GetTickCount();
g_RobotNPC.GotoLable(self, AutoRunInfo.sParam2, False);
end;
end;
nROHOUR:
begin
if GetTickCount - AutoRunInfo.dwRunTick > 60 * 60 * 1000 *
LongWord(AutoRunInfo.nParam1) then
begin
AutoRunInfo.dwRunTick := GetTickCount();
g_RobotNPC.GotoLable(self, AutoRunInfo.sParam2, False);
end;
end;
nROMIN:
begin
if GetTickCount - AutoRunInfo.dwRunTick > 60 * 1000 *LongWord(AutoRunInfo.nParam1) then
// if GetTickCount - AutoRunInfo.dwRunTick > LongWord(AutoRunInfo.nParam1) then
begin
AutoRunInfo.dwRunTick := GetTickCount();
g_RobotNPC.GotoLable(self, AutoRunInfo.sParam2, False);
end;
end;
nROSEC:
begin
if GetTickCount - AutoRunInfo.dwRunTick > 1000 *
LongWord(AutoRunInfo.nParam1) then
begin
AutoRunInfo.dwRunTick := GetTickCount();
g_RobotNPC.GotoLable(self, AutoRunInfo.sParam2, False);
end;
end;
nRUNONWEEK: AutoRunOfOnWeek(AutoRunInfo);
nRUNONDAY: AutoRunOfOnDay(AutoRunInfo);
nRUNONHOUR: AutoRunOfOnHour(AutoRunInfo);
nRUNONMIN: AutoRunOfOnMin(AutoRunInfo);
nRUNONSEC: AutoRunOfOnSec(AutoRunInfo);
end; // case
end;
1: ;
2: ;
3: ;
end; // case
end;
except
on E: Exception do
begin
MainOutMessage(sExceptionMsg);
{$IF SHowErr = 1}
MainOutMessage(E.Message);
{$IFEND}
end;
end;
end;
procedure TRobotObject.AutoRunOfOnDay(AutoRunInfo: pTAutoRunInfo);
var
nMIN, nHOUR, nWeek : Integer;
wWeek, wHour, wMin, wSec, wMSec : Word;
sMIN, sHOUR, sWeek : string;
sLineText, sLabel : string;
begin
sLineText := AutoRunInfo.sParam1;
sLineText := GetValidStr3(sLineText, sHOUR, [':']);
sLineText := GetValidStr3(sLineText, sMIN, [':']);
nHOUR := Str_ToInt(sHOUR, -1);
nMIN := Str_ToInt(sMIN, -1);
sLabel := AutoRunInfo.sParam2;
DecodeTime(Time, wHour, wMin, wSec, wMSec);
if (nHOUR in [0..24]) and (nMIN in [0..60]) then
begin
if (wHour = nHOUR) then
begin
if (wMin = nMIN) then
begin
if not AutoRunInfo.boStatus then
begin
g_RobotNPC.GotoLable(self, AutoRunInfo.sParam2, False);
// MainOutMessage('RUNONWEEK Test ' + AutoRunInfo.sParam1);
AutoRunInfo.boStatus := True;
end;
end
else
begin
AutoRunInfo.boStatus := False;
end;
end;
end;
end;
procedure TRobotObject.AutoRunOfOnHour(AutoRunInfo: pTAutoRunInfo);
begin
end;
procedure TRobotObject.AutoRunOfOnMin(AutoRunInfo: pTAutoRunInfo);
begin
end;
procedure TRobotObject.AutoRunOfOnSec(AutoRunInfo: pTAutoRunInfo);
begin
end;
procedure TRobotObject.AutoRunOfOnWeek(AutoRunInfo: pTAutoRunInfo);
var
nMIN, nHOUR, nWeek : Integer;
wWeek, wHour, wMin, wSec, wMSec : Word;
sMIN, sHOUR, sWeek : string;
sLineText, sLabel : string;
begin
if AutoRuninfo=nil then exit;
sLineText := AutoRunInfo.sParam1;
sLineText := GetValidStr3(sLineText, sWeek, [':']);
sLineText := GetValidStr3(sLineText, sHOUR, [':']);
sLineText := GetValidStr3(sLineText, sMIN, [':']);
nWeek := Str_ToInt(sWeek, -1);
nHOUR := Str_ToInt(sHOUR, -1);
nMIN := Str_ToInt(sMIN, -1);
sLabel := AutoRunInfo.sParam2;
DecodeTime(Time, wHour, wMin, wSec, wMSec);
wWeek := DayOfTheWeek(Now);
if (nWeek in [1..7]) and (nHOUR in [0..24]) and (nMIN in [0..60]) then
begin
if (wWeek = nWeek) and (wHour = nHOUR) then
begin
if (wMin = nMIN) then
begin
if not AutoRunInfo.boStatus then
begin
g_RobotNPC.GotoLable(self, AutoRunInfo.sParam2, False);
// MainOutMessage('RUNONWEEK Test ' + AutoRunInfo.sParam1);
AutoRunInfo.boStatus := True;
end;
end
else
begin
AutoRunInfo.boStatus := False;
end;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -