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

📄 usrengn.pas

📁 传世源码可编译的,功能齐全.是学习的好模版,会DELPHI的朋友们也可以自己修改,弄个自己的引擎.
💻 PAS
📖 第 1 页 / 共 5 页
字号:
    if not boProcessLimit then begin
      nMerchantPosition:=0;
    end;
  except
    MainOutMessage(sExceptionMsg);
  end;
  dwProcessMerchantTimeMin:=GetTickCount - dwRunTick;
  if dwProcessMerchantTimeMin > dwProcessMerchantTimeMax then dwProcessMerchantTimeMax:=dwProcessMerchantTimeMin;
  if dwProcessNpcTimeMin > dwProcessNpcTimeMax then dwProcessNpcTimeMax:=dwProcessNpcTimeMin;
end;

procedure TUserEngine.ProcessMissions;
var
  Startuphum:Tplayobject;
  sMapName:string;
  nSafePoint,nSafeX,nSafeY:integer;
  Envir:TEnvirnoment;
  SafeZoneLight:TSafeZoneLight;
  nx,ny,i:integer;
begin
  if g_bostartup then
  begin
    if g_ManageNPC <> nil then
    begin
      Startuphum:=Tplayobject.Create;
      if Startuphum<>nil then
      begin
        Startuphum.m_sCharName:='Startup';
        Startuphum.m_sMapName:='0';
        Startuphum.m_PEnvir:= g_MapManager.FindMap(Startuphum.m_sMapName);
        g_ManageNPC.GotoLable(Startuphum,'@startup',False);
        g_bostartup:=false;
        Startuphum.Free;
      end;
    end;

    if g_Config.boUseSafeZoneLight then
    begin
      try
        g_StartPointList.Lock;
        for I := 0 to g_StartPointList.Count - 1 do
        begin
          sMapName:=g_StartPointList.Strings[i];
          nSafePoint:=Integer(g_StartPointList.Objects[i]);
          nSafeX:=LoWord(nSafePoint);
          nSafeY:=HiWord(nSafePoint);
          Envir:=g_MapManager.FindMap(sMapName);
          if Envir=nil then Continue;
        /////////////
          nY:= nSafeY-g_Config.nSafeZoneSize  ;
          nX:= nSafeX-g_Config.nSafeZoneSize ;
          while nX<  nSafeX+g_Config.nSafeZoneSize do begin

             if Envir.GetEvent(nX,nY) = nil then begin
               SafeZoneLight:=TSafeZoneLight.Create(Envir,nX,nY,ET_HOLYCURTAIN,10*24*60*60*1000 ,0);
               g_EventManager.AddEvent(SafeZoneLight);
             end;
             inc(nx,2);
          end;  //while
          nx:= nSafeX+g_Config.nSafeZoneSize;
          if (Envir.GetEvent(nx,ny) = nil) and Envir.CanWalk(nX, nY,false) then begin
           SafeZoneLight:=TSafeZoneLight.Create(Envir,nX,nY,ET_HOLYCURTAIN,10*24*60*60*1000 ,0);
           g_EventManager.AddEvent(SafeZoneLight);
          end;

          nY:= nSafeY+g_Config.nSafeZoneSize  ;
          nX:= nSafeX-g_Config.nSafeZoneSize ;
          while nX<  nSafeX+g_Config.nSafeZoneSize do begin

             if (Envir.GetEvent(nX,nY) = nil) and Envir.CanWalk(nX, nY,false) then begin
               SafeZoneLight:=TSafeZoneLight.Create(Envir,nX,nY,ET_HOLYCURTAIN,10*24*60*60*1000 ,0);
               g_EventManager.AddEvent(SafeZoneLight);
             end;
             inc(nx,2);
          end;  //while
          nx:= nSafeX+g_Config.nSafeZoneSize ;
          if (Envir.GetEvent(nx,ny) = nil) and Envir.CanWalk(nX, nY,false) then begin
           SafeZoneLight:=TSafeZoneLight.Create(Envir,nX,nY,ET_HOLYCURTAIN,10*24*60*60*1000 ,0);
           g_EventManager.AddEvent(SafeZoneLight);
          end;

       // ==============
          nY:= nSafeY-g_Config.nSafeZoneSize  ;
          nX:= nSafeX-g_Config.nSafeZoneSize ;
          while ny<  nSafey+g_Config.nSafeZoneSize do begin

             if (Envir.GetEvent(nx,ny) = nil) and Envir.CanWalk(nX, nY,false) then begin
               SafeZoneLight:=TSafeZoneLight.Create(Envir,nX,nY,ET_HOLYCURTAIN,10*24*60*60*1000 ,0);
               g_EventManager.AddEvent(SafeZoneLight);
             end;
             inc(ny,4);
          end;  //while
          ny:= nSafey+g_Config.nSafeZoneSize ;
          if (Envir.GetEvent(nx,ny) = nil) and Envir.CanWalk(nX, nY,false) then begin
           SafeZoneLight:=TSafeZoneLight.Create(Envir,nX,nY,ET_HOLYCURTAIN,10*24*60*60*1000 ,0);
           g_EventManager.AddEvent(SafeZoneLight);
          end;

          nY:= nSafeY-g_Config.nSafeZoneSize  ;
          nX:= nSafeX+g_Config.nSafeZoneSize ;
          while ny<  nSafey+g_Config.nSafeZoneSize do begin
             if (Envir.GetEvent(nx,ny) = nil) and Envir.CanWalk(nX, nY,false) then begin
               SafeZoneLight:=TSafeZoneLight.Create(Envir,nX,nY,ET_HOLYCURTAIN,10*24*60*60*1000 ,0);
               g_EventManager.AddEvent(SafeZoneLight);
             end;
             inc(ny,4);
          end;  //while

          ny:= nSafey+g_Config.nSafeZoneSize  ;
          if (Envir.GetEvent(nx,ny) = nil) and Envir.CanWalk(nX, nY,false) then begin
           SafeZoneLight:=TSafeZoneLight.Create(Envir,nX,nY,ET_HOLYCURTAIN,10*24*60*60*1000 ,0);
           g_EventManager.AddEvent(SafeZoneLight);
          end;

     end; //for
     finally
      g_StartPointList.UnLock;
     end;
    end;//if  g_Config.boUseSafeZoneLight
  end;
end;

procedure TUserEngine.ProcessMonsters;
  function GetZenTime(dwTime:LongWord):LongWord;
  var
    d10:Double;
  begin
    if dwTime < 30 * 60 * 1000 then begin
      d10:= (GetUserCount - g_Config.nUserFull) / g_Config.nZenFastStep;
      if d10 > 0 then begin
        if d10 > 6 then d10:=6;
        Result:= dwTime - Round((dwTime / 10) * d10)
      end else begin//4B1616
        Result:=dwTime;
      end;
    end else begin
      Result:=dwTime;
    end;
      Result:=dwTime;
  end;
//004B1638
var
  dwCurrentTick    :LongWord;
  dwRunTick        :LongWord;
  dwMonProcTick    :LongWord;
  MonGen           :pTMonGenInfo;
  nGenCount        :Integer;
  nGenModCount     :Integer;
  boProcessLimit   :Boolean;
  boRegened        :Boolean;
  I                :Integer;
  nProcessPosition :Integer;
  Monster          :TAnimalObject;
  tCode            :Integer;
  tormoncount      :integer;
ResourceString
  sExceptionMsg = '[Exception] TUserEngine::ProcessMonsters %s %d';
begin
  tCode     := 0;
  dwRunTick := GetTickCount();
  try
    tCode          := 0;
    boProcessLimit := False;
    dwCurrentTick  := GetTickCount();    // dwCurrentTick
    MonGen         := nil;
    //刷新怪物开始

    if ((GetTickCount - dwRegenMonstersTick) > g_Config.dwRegenMonstersTime) then begin
      dwRegenMonstersTick:=GetTickCount();
      if m_nCurrMonGen < m_MonGenList.Count then begin
        MonGen:=m_MonGenList.Items[m_nCurrMonGen];
      end;

      if m_nCurrMonGen < m_MonGenList.Count - 1 then begin
        Inc(m_nCurrMonGen);
      end else begin
        m_nCurrMonGen:=0;
      end;//004B1718

      if (MonGen <> nil) and (MonGen.sMonName <> '') and not g_Config.boVentureServer then begin
        if (MonGen.dwStartTick = 0) or ((GetTickCount - MonGen.dwStartTick) >  MonGen.dwZenTime)  then begin   //  GetZenTime(MonGen.dwZenTime))
          nGenCount:=GetGenMonCount(MonGen);
          boRegened:=True;
          nGenModCount:=_MAX(1,ROUND(_MAX(1,MonGen.nCount) / (g_Config.nMonGenRate / 10)));
          if nGenModCount > nGenCount then begin //0806 增加 控制刷怪数量比例
            tormoncount:= nGenModCount - nGenCount;
            boRegened:=RegenMonsters(MonGen,tormoncount); //MonGen,nGenModCount - nGenCount

          end;//004B1798
          if boRegened then begin
            MonGen.dwStartTick:=GetTickCount();
          end;
        end;//004B17A9
        g_sMonGenInfo1:=MonGen.sMonName + ',' + IntToStr(m_nCurrMonGen) + '/' + IntToStr(m_MonGenList.Count);
      end;//004B1851

    end;//004B1851

    g_nMonGenTime:=GetTickCount - dwCurrentTick;
    if g_nMonGenTime > g_nMonGenTimeMin then g_nMonGenTimeMin:=g_nMonGenTime;
    if g_nMonGenTime > g_nMonGenTimeMax then g_nMonGenTimeMax:=g_nMonGenTime;

    //刷新怪物结束

      dwMonProcTick:=GetTickCount();
      nMonsterProcessCount:=0;
      tCode:=1;
      //004B187B
      for I:= m_nMonGenListPosition to m_MonGenList.Count -1 do begin
        MonGen:=m_MonGenList.Items[I];
        tCode:=11;
        if m_nMonGenCertListPosition < MonGen.CertList.Count then begin
          nProcessPosition:=m_nMonGenCertListPosition;
        end else begin//4B18A8
          nProcessPosition:=0;
        end;
        m_nMonGenCertListPosition:=0;
        //4B18B5
        while (True) do begin
          if nProcessPosition >= MonGen.CertList.Count then break;
          Monster:=MonGen.CertList.Items[nProcessPosition];
          tCode:=12;
          if not Monster.m_boGhost then begin
            if Integer(dwCurrentTick - Monster.m_dwRunTick) > Monster.m_nRunTime then begin  // GetTickCount
              Monster.m_dwRunTick:=GetTickCount;//dwRunTick;
              if (dwCurrentTick - Monster.m_dwSearchTick) > Monster.m_dwSearchTime then begin  //GetTickCount
                Monster.m_dwSearchTick:=GetTickCount();
                tCode:=13;
                Monster.SearchViewRange();
              end;
              tCode:=14;

{$IF PROCESSMONSTMODE = OLDMONSTERMODE}
                Monster.Run;
{$ELSE}
              if not Monster.m_boIsVisibleActive and (Monster.m_nProcessRunCount < g_Config.nProcessMonsterInterval) then begin
                Inc(Monster.m_nProcessRunCount);
              end else begin
                Monster.m_nProcessRunCount:=0;
                Monster.Run;
              end;
{$IFEND}
              Inc(nMonsterProcessCount);
            end;
            Inc(nMonsterProcessPostion);
          end else begin      //如果当前 刷怪列表中的 怪物死了。
            if (GetTickCount - Monster.m_dwGhostTick) > 1 * 60 * 1000 then begin
              MonGen.CertList.Delete(nProcessPosition);
               Monster.Free;
              Continue;
            end;
          end;

          Inc(nProcessPosition);
          if (GetTickCount - dwMonProcTick) > g_dwMonLimit then begin
            g_sMonGenInfo2:=Monster.m_sCharName + '/' + IntToStr(I) + '/' + IntToStr(nProcessPosition);
            boProcessLimit:=True;
            m_nMonGenCertListPosition:=nProcessPosition;
            break;
          end;
        end;
        if boProcessLimit then break;
      end;
      //004B1A5D

      tCode:=2;
      if m_MonGenList.Count <= I then begin
        m_nMonGenListPosition:=0;
        nMonsterCount:=nMonsterProcessPostion;
        nMonsterProcessPostion:=0;
        n84:=(n84 + nMonsterProcessCount) div 2;
      end;//4B1AAF

      if not boProcessLimit then begin
        m_nMonGenListPosition:=0;
      end else begin
        m_nMonGenListPosition:=I;
      end;
      g_nMonProcTime:=GetTickCount - dwMonProcTick;
      if g_nMonProcTime > g_nMonProcTimeMin then g_nMonProcTimeMin:=g_nMonProcTime;
      if g_nMonProcTime > g_nMonProcTimeMax then g_nMonProcTimeMax:=g_nMonProcTime;

  except
    on e: Exception do begin
      MainOutMessage(format(sExceptionMsg,[Monster.m_sCharName,tCode]));
      MainOutMessage(E.Message);  raise;
    end;
    
  end;
  g_nMonTimeMin:=GetTickCount - dwRunTick;
  if g_nMonTimeMax < g_nMonTimeMin then g_nMonTimeMax:=g_nMonTimeMin;
end;

function TUserEngine.GetGenMonCount(MonGen:pTMonGenInfo):Integer;//4AE19C
var
  I          :Integer;
  nCount     :Integer;
  BaseObject :TBaseObject;
begin
  nCount:=0;
  for I:=0 to MonGen.CertList.Count -1 do begin
    BaseObject:=TBaseObject(MonGen.CertList.Items[I]);
    if not BaseObject.m_boDeath and not BaseObject.m_boGhost then Inc(nCount);
  end;
  Result:=nCount;
end;

procedure TUserEngine.ProcessNpcs;
var
  dwRunTick,dwCurrTick:LongWord;
  i:integer;
  NPC:TNormNpc;
  boProcessLimit:Boolean;
begin
  dwRunTick:=GetTickCount();
  boProcessLimit:=False;
  try
    dwCurrTick:=GetTickCount();
    for i:=nNpcPosition to QuestNPCList.Count -1 do begin
      NPC:=QuestNPCList.Items[i];
      if not NPC.m_boGhost then begin
        if Integer(dwCurrTick - NPC.m_dwRunTick) > NPC.m_nRunTime then begin
          if (GetTickCount - NPC.m_dwSearchTick) > NPC.m_dwSearchTime then begin
            NPC.m_dwSearchTick:=GetTickCount();
            NPC.SearchViewRange();
          end;
          if Integer(dwCurrTick - NPC.m_dwRunTick) > NPC.m_nRunTime then begin
            NPC.m_dwRunTick:=dwCurrTick;
            NPC.Run;  {FFFFB}
          end;
        end;
      end else begin
        if (GetTickCount - NPC.m_dwGhostTick) > 60 * 1000 then begin
          NPC.Free;
          QuestNPCList.Delete(i);
          break;
        end;
      end;
      if (GetTickCount - dwRunTick) > g_dwNpcLimit then begin
        nNpcPosition:=i;
        boProcessLimit:=True;
        Break;
      end;
    end;
    if not boProcessLimit then begin
      nNpcPosition:=0;
    end;
  except
    MainOutMessage('[Exceptioin] TUserEngine.ProcessNpcs');

⌨️ 快捷键说明

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