⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 npcscriptcmd.pas

📁 M2server 的功能插件 值得研究 此插件支持最新英雄M2
💻 PAS
字号:
unit NpcScriptCmd;

interface
uses
  Windows, SysUtils, Classes, EngineAPI, EngineType, PlugShare;
const
  szString = '@@InPutString';
  szInteger = '@@InPutInteger';

  nSC_CHECKONLINEPLAYCOUNT = 10000;
  sSC_CHECKONLINEPLAYCOUNT = 'CHECKONLINEPLAYCOUNT';

  nSC_CHECKPLAYDIELVL = 10001; //杀人后检测
  sSC_CHECKPLAYDIELVL = 'CHECKPLAYDIELVL';
  nSC_CHECKPLAYDIEJOB = 10002;
  sSC_CHECKPLAYDIEJOB = 'CHECKPLAYDIEJOB';
  nSC_CHECKPLAYDIESEX = 10003;
  sSC_CHECKPLAYDIESEX = 'CHECKPLAYDIESEX';

  nSC_CHECKKILLPLAYLVL = 10004; //死亡后检测
  sSC_CHECKKILLPLAYLVL = 'CHECKKILLPLAYLVL';
  nSC_CHECKKILLPLAYJOB = 10005;
  sSC_CHECKKILLPLAYJOB = 'CHECKKILLPLAYJOB';
  nSC_CHECKKILLPLAYSEX = 10006;
  sSC_CHECKKILLPLAYSEX = 'CHECKKILLPLAYSEX';

  nSC_CHECKMAPGUILDCOUNT = 10007;
  sSC_CHECKMAPGUILDCOUNT = 'CHECKMAPGUILDCOUNT';

procedure InitNpcScriptCmd();
procedure UnInitNpcScriptCmd();
function ScriptActionCmd(pszCmd: PChar): Integer; stdcall;
function ScriptConditionCmd(pszCmd: PChar): Integer; stdcall;
function ConditionOfCheckOnlinePlayCount(Npc: TObject; pszParam1: PChar; nCount: Integer): Boolean;
procedure ScriptAction(Npc: TObject; PlayObject: TObject; nCmdCode: Integer; pszParam1: PChar;
  nParam1: Integer; pszParam2: PChar; nParam2: Integer;
  pszParam3: PChar; nParam3: Integer; pszParam4: PChar;
  nParam4: Integer; pszParam5: PChar; nParam5: Integer;
  pszParam6: PChar; nParam6: Integer); stdcall;

function ScriptCondition(Npc: TObject; PlayObject: TObject; nCmdCode: Integer; pszParam1: PChar;
  nParam1: Integer; pszParam2: PChar; nParam2: Integer;
  pszParam3: PChar; nParam3: Integer; pszParam4: PChar;
  nParam4: Integer; pszParam5: PChar; nParam5: Integer;
  pszParam6: PChar; nParam6: Integer): Boolean; stdcall;

procedure CheckUserSelect(Merchant: TMerchant; PlayObject: TPlayObject; pszLabel, pszData: PChar); stdcall;

function ConditionOfCheckPlaylvl(PlayObject: TObject; pszParam1: PChar; nParam1: Integer): Boolean;
function ConditionOfCheckPlaySex(PlayObject: TObject; pszParam1: PChar): Boolean;
function ConditionOfCheckPlayJob(PlayObject: TObject; pszParam1: PChar): Boolean;
function ConditionOfCheckPlayMapGuildCount(PlayObject: TObject; pszParam1: PChar; nParam2: Integer): Boolean;
var
  OldScriptActionCmd: _TSCRIPTCMD;
  OldScriptConditionCmd: _TSCRIPTCMD;
  OldScriptAction: _TSCRIPTACTION;
  OldScriptCondition: _TSCRIPTCONDITION;
  OldUserSelelt: _TOBJECTACTIONUSERSELECT;
implementation
uses HUtil32, PlayUser;
procedure InitNpcScriptCmd();
begin
  OldScriptActionCmd := TNormNpc_GetScriptActionCmd();
  OldScriptConditionCmd := TNormNpc_GetScriptConditionCmd();
  OldScriptAction := TNormNpc_GetScriptAction();
  OldScriptCondition := TNormNpc_GetScriptCondition();
  OldUserSelelt := TMerchant_GetCheckUserSelect();
  TNormNpc_SetScriptActionCmd(ScriptActionCmd);
  TNormNpc_SetScriptConditionCmd(ScriptConditionCmd);
  TNormNpc_SetScriptAction(ScriptAction);
  TNormNpc_SetScriptCondition(ScriptCondition);
  TMerchant_SetCheckUserSelect(CheckUserSelect);
end;

procedure UnInitNpcScriptCmd();
begin
  TNormNpc_SetScriptActionCmd(OldScriptActionCmd);
  TNormNpc_SetScriptConditionCmd(OldScriptConditionCmd);
  TNormNpc_SetScriptAction(OldScriptAction);
  TNormNpc_SetScriptCondition(OldScriptCondition);
  TMerchant_SetCheckUserSelect(OldUserSelelt);
end;

function ConditionOfCheckPlayMapGuildCount(PlayObject: TObject; pszParam1: PChar; nParam2: Integer): Boolean;
var
  szParam1: String;
  cMethod: Char;
  Envir: TEnvirnoment;
  BaseObjectList: Classes.TList;
  I: Integer;
  BaseObject: TPlayObject;
  btRaceServer: Byte;
  nGuildCount: Integer;
  Guild: TGuild;
  GuildList: Classes.TList;
  procedure AddGuild(Guild: TGuild);
  var
    I: Integer;
  begin
    for I := 0 to GuildList.Count - 1 do begin
      if TGuild(GuildList.Items[I]) = Guild then begin
        Exit;
      end;
    end;
    GuildList.Add(Guild);
  end;
begin
  Result := False;
  Envir := TBaseObject_PEnvir(PlayObject)^;
  if Envir <> nil then begin
    BaseObjectList := Classes.TList.Create;
    if TEnvirnoment_GetRangeBaseObject(Envir, 200, 200, 1000, True, BaseObjectList) > 0 then begin
      nGuildCount := 0;
      GuildList := Classes.TList.Create;
      for I := 0 to BaseObjectList.Count - 1 do begin
        BaseObject := TBaseObject(BaseObjectList.Items[I]);
        btRaceServer := TBaseObject_btRaceServer(BaseObject)^;
        if btRaceServer = RC_PLAYOBJECT then begin
          Guild := TBaseObject_MyGuild(BaseObject);
          if Guild <> nil then begin
            AddGuild(Guild);
          end;
        end;
      end;
      nGuildCount := GuildList.Count;
      GuildList.Free;
      szParam1 := StrPas(pszParam1);
      if szParam1 <> '' then begin
        cMethod := szParam1[1];
        case cMethod of
          '=': if nGuildCount = nParam2 then Result := True;
          '>': if nGuildCount > nParam2 then Result := True;
          '<': if nGuildCount < nParam2 then Result := True;
        else if nGuildCount >= nParam2 then Result := True;
        end;
      end;
    end;
    BaseObjectList.Free;
  end;
end;

function ConditionOfCheckPlaylvl(PlayObject: TObject; pszParam1: PChar; nParam1: Integer): Boolean;
var
  KillPlayObject: TObject;
  m_Abil: _TABILITY;
  btType: Byte;
  cMethod: Char;
begin
  Result := False;
  if TBaseObject_LastHiter(PlayObject) <> nil then begin
    KillPlayObject := TBaseObject_LastHiter(PlayObject)^;
    btType := TBaseObject_btRaceServer(KillPlayObject)^;
    if btType = RC_PLAYOBJECT then begin
      if TBaseObject_WAbility(KillPlayObject) <> nil then begin
        m_Abil := TBaseObject_WAbility(KillPlayObject)^;
        cMethod := StrPas(pszParam1)[1];
        case cMethod of
          '=': if m_Abil.wLevel = nParam1 then Result := True;
          '>': if m_Abil.wLevel > nParam1 then Result := True;
          '<': if m_Abil.wLevel < nParam1 then Result := True;
        else if m_Abil.wLevel >= nParam1 then Result := True;
        end;
      end;
    end;
  end;
end;

function ConditionOfCheckPlaySex(PlayObject: TObject; pszParam1: PChar): Boolean;
var
  KillPlayObject: TObject;
  m_Abil: _TABILITY;
  btType: Byte;
  btSex: Byte;
  sParam1: string;
const
  MAN = 'MAN';
  WOMAN = 'WOMAN';
begin
  Result := False;
  if TBaseObject_LastHiter(PlayObject) <> nil then begin
    KillPlayObject := TBaseObject_LastHiter(PlayObject)^;
    btType := TBaseObject_btRaceServer(KillPlayObject)^;
    if btType = RC_PLAYOBJECT then begin
      sParam1 := StrPas(pszParam1);
      btSex := TBaseObject_btGender(KillPlayObject)^;
      case btSex of
        0: if CompareText(sParam1, MAN) = 0 then Result := True;
        1: if CompareText(sParam1, WOMAN) = 0 then Result := True;
      else Result := False;
      end;
    end;
  end;
end;

function ConditionOfCheckPlayJob(PlayObject: TObject; pszParam1: PChar): Boolean;
var
  KillPlayObject: TObject;
  m_Abil: _TABILITY;
  btType: Byte;
  btJob: Byte;
  sParam1: string;
const
  WARRIOR = 'WARRIOR';
  WIZARD = 'WIZARD';
  TAOIST = 'TAOIST';
begin
  Result := False;
  if TBaseObject_LastHiter(PlayObject) <> nil then begin
    KillPlayObject := TBaseObject_LastHiter(PlayObject)^;
    btType := TBaseObject_btRaceServer(KillPlayObject)^;
    if btType = RC_PLAYOBJECT then begin
      sParam1 := StrPas(pszParam1);
      btJob := TBaseObject_btJob(KillPlayObject)^;
      case btJob of
        0: if CompareText(sParam1, WARRIOR) = 0 then Result := True;
        1: if CompareText(sParam1, WIZARD) = 0 then Result := True;
        2: if CompareText(sParam1, TAOIST) = 0 then Result := True;
      else Result := False;
      end;
    end;
  end;
end;

procedure CheckUserSelect(Merchant: TMerchant; PlayObject: TPlayObject; pszLabel, pszData: PChar);
var
  sLabel, sData: string;
  nData: Integer;
  nLength: Integer;
begin
  try
    sLabel := StrPas(pszLabel);
    nLength := CompareText(sLabel, szString);
    if nLength > 0 then begin
      sLabel := Copy(sLabel, length(szString) + 1, nLength);
      sData := StrPas(pszData);
      //if not IsFilterMsg(sData) then begin
        TPlayObject_SetUserInPutString(PlayObject, pszData);
        TNormNpc_GotoLable(Merchant, PlayObject, PChar('@InPutString' + sLabel));
      //end else begin
        //TNormNpc_GotoLable(Merchant, PlayObject, PChar('@MsgFilter'));
      //end;
      Exit;
    end else
      nLength := CompareText(sLabel, szInteger);
    if nLength > 0 then begin
      sLabel := Copy(sLabel, length(szInteger) + 1, nLength);
      sData := StrPas(pszData);
      nData := Str_ToInt(sData, -1);
      TPlayObject_SetUserInPutInteger(PlayObject, nData);
      TNormNpc_GotoLable(Merchant, PlayObject, PChar('@InPutInteger' + sLabel));
      Exit;
    end else begin
      if Assigned(OldUserSelelt) then begin
        OldUserSelelt(Merchant, PlayObject, pszLabel, pszData);
      end;
    end;
  except
    if Assigned(OldUserSelelt) then begin
      OldUserSelelt(Merchant, PlayObject, pszLabel, pszData);
    end;
  end;
end;

function ScriptActionCmd(pszCmd: PChar): Integer; stdcall;
begin
  {if StrIComp(pszCmd, sSC_CHECKONLINEPLAYCOUNT) = 0 then begin
    Result := nGIVEUSERITEM;
  end else
    if StrIComp(pszCmd, szTAKEUSERITEM) = 0 then begin
    Result := nTAKEUSERITEM;
  end else begin
    Result := -1;
  end; }
  if (Result < 0) and Assigned(OldScriptActionCmd) then begin
    Result := OldScriptActionCmd(pszCmd);
  end;
end;

function ScriptConditionCmd(pszCmd: PChar): Integer; stdcall;
begin
  if StrIComp(pszCmd, sSC_CHECKONLINEPLAYCOUNT) = 0 then begin
    Result := nSC_CHECKONLINEPLAYCOUNT;
  end else
    if StrIComp(pszCmd, sSC_CHECKMAPGUILDCOUNT) = 0 then begin
    Result := nSC_CHECKMAPGUILDCOUNT;
  end else begin
    Result := -1;
  end;
  if (Result < 0) and Assigned(OldScriptConditionCmd) then begin
    //调用下一个插件处理函数
    Result := OldScriptConditionCmd(pszCmd);
  end;
end;

procedure ActionOfGiveUserItem(Npc: TObject; PlayObject: TObject; pszItemName: PChar; nCount: Integer);
begin

end;

procedure ActionOfTakeUserItem(Npc: TObject; PlayObject: TObject; pszItemName: PChar; nCount: Integer);
begin

end;

function ConditionOfCheckOnlinePlayCount(Npc: TObject; pszParam1: PChar; nCount: Integer): Boolean;
var
  cMethod: Char;
  szParam1: string;
begin
  Result := False;
  szParam1 := StrPas(pszParam1);
  cMethod := szParam1[1];
  case cMethod of
    '=': if TUserEngine_GetPlayObjectCount = nCount then Result := True;
    '>': if TUserEngine_GetPlayObjectCount > nCount then Result := True;
    '<': if TUserEngine_GetPlayObjectCount < nCount then Result := True;
  else if TUserEngine_GetPlayObjectCount >= nCount then Result := True;
  end;
end;

procedure ScriptAction(Npc: TObject; PlayObject: TObject; nCmdCode: Integer; pszParam1: PChar;
  nParam1: Integer; pszParam2: PChar; nParam2: Integer;
  pszParam3: PChar; nParam3: Integer; pszParam4: PChar;
  nParam4: Integer; pszParam5: PChar; nParam5: Integer;
  pszParam6: PChar; nParam6: Integer); stdcall;
begin
  {case nCmdCode of
    nGIVEUSERITEM: ActionOfGiveUserItem(Npc, PlayObject, pszParam1, nParam2);
    nTAKEUSERITEM: ActionOfTakeUserItem(Npc, PlayObject, pszParam1, nParam2);
  end; }
end;

function ScriptCondition(Npc: TObject; PlayObject: TObject; nCmdCode: Integer; pszParam1: PChar;
  nParam1: Integer; pszParam2: PChar; nParam2: Integer;
  pszParam3: PChar; nParam3: Integer; pszParam4: PChar;
  nParam4: Integer; pszParam5: PChar; nParam5: Integer;
  pszParam6: PChar; nParam6: Integer): Boolean; stdcall;
begin
  Result := True;
  try
    case nCmdCode of
      nSC_CHECKONLINEPLAYCOUNT: if not ConditionOfCheckOnlinePlayCount(Npc, pszParam1, nParam2) then Result := False;
      nSC_CHECKPLAYDIELVL,
        nSC_CHECKKILLPLAYLVL: if not ConditionOfCheckPlaylvl(PlayObject, pszParam1, nParam1) then Result := False;
      nSC_CHECKPLAYDIEJOB,
        nSC_CHECKKILLPLAYJOB: if not ConditionOfCheckPlayJob(PlayObject, pszParam1) then Result := False;
      nSC_CHECKPLAYDIESEX,
        nSC_CHECKKILLPLAYSEX: if not ConditionOfCheckPlaySex(PlayObject, pszParam1) then Result := False;
      nSC_CHECKMAPGUILDCOUNT: if not ConditionOfCheckPlayMapGuildCount(PlayObject, pszParam1, nParam2) then Result := False;
    end;
  except
    Result := False;
  end;
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -