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

📄 usrengn.pas

📁 传奇源代码的delphi版本
💻 PAS
📖 第 1 页 / 共 5 页
字号:
      nMerchantPosition:=0;
    end;//004B1CA6
  except
    MainOutMessage(sExceptionMsg);
  end;
  dwProcessMerchantTimeMin:=GetTickCount - dwRunTick;
  if dwProcessMerchantTimeMin > dwProcessMerchantTimeMax then dwProcessMerchantTimeMax:=dwProcessMerchantTimeMin;
  if dwProcessNpcTimeMin > dwProcessNpcTimeMax then dwProcessNpcTimeMax:=dwProcessNpcTimeMin;
end;

procedure TUserEngine.ProcessMissions;
begin

end;

procedure TUserEngine.ProcessMonsters;
  function GetZenTime(dwTime:LongWord):LongWord;
  var
    r:Real;
  begin
    if dwTime < 30 * 60 * 1000 then begin
      r := (GetUserCount - g_Config.nUserFull) / g_Config.nZenFastStep;
      if r > 0 then begin
        if r > 6 then r := 6;
        Result:= dwTime - Round((dwTime / 10) * r)
      end else
        Result:=dwTime;
    end else
      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;
ResourceString
  sExceptionMsg = '[Exception] TUserEngine::ProcessMonsters %d';
begin
  tCode     := 0;
  dwRunTick := GetTickCount();
  try
    tCode          := 0;
    boProcessLimit := False;
    dwCurrentTick  := GetTickCount();
    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) > GetZenTime(MonGen.dwZenTime)) then begin
          nGenCount:=GetGenMonCount(MonGen);
          boRegened:=True;
          //if MonGen.nCount > tGenCount then begin
          //if (MonGen.nCount <= g_nMonGenRate) or (MonGen.nCount div g_nMonGenRate > tGenCount) then begin //0806 增加 控制刷怪数量比例
          nGenModCount:=_MAX(1,ROUND(_MAX(1,MonGen.nCount) / (g_Config.nMonGenRate / 10)));
          if nGenModCount > nGenCount then begin //0806 增加 控制刷怪数量比例
            boRegened:=RegenMonsters(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;
          tcode:=15;
          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
              Monster.m_dwRunTick:=dwRunTick;
              if (dwCurrentTick - Monster.m_dwSearchTick) > Monster.m_dwSearchTime then begin
                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) > 5 * 60 * 1000 then begin
              tcode:=16;
              MonGen.CertList.Delete(nProcessPosition);
              Monster.Free;
              Continue;
            end;
          end;
          tcode:=17;
          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; //while (True) do begin
        if boProcessLimit then break;
      end;//for I:= m_nMonGenListPosition to MonGenList.Count -1 do begin
      //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,[tCode]));
      MainOutMessage(E.Message);
    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');
  end;
  dwProcessNpcTimeMin:=GetTickCount - dwRunTick;
  if dwProcessNpcTimeMin > dwProcessNpcTimeMax then dwProcessNpcTimeMax:=dwProcessNpcTimeMin;
end;
//004ADE3C
function TUserEngine.RegenMonsterByName(sMap: String; nX, nY: Integer;
  sMonName: String):TBaseObject;
var
  nRace:Integer;
  BaseObject:TBaseObject;
  n18:Integer;
  MonGen:pTMonGenInfo;
begin
  nRace:=GetMonRace(sMonName);
  BaseObject:=AddBaseObject(sMap,nX,nY,nRace,sMonName);
  if BaseObject <> nil then begin
    n18:=m_MonGenList.Count - 1;
    if n18 < 0 then n18:=0;
    MonGen:=m_MonGenList.Items[n18];
    MonGen.CertList.Add(BaseObject);
    BaseObject.m_PEnvir.AddObject(BaseObject);
    BaseObject.m_boAddToMaped:=True;
//    MainOutMessage(format('MonGet Count:%d',[MonGen.CertList.Count]));
  end;

  Result:=BaseObject;
end;
function TUserEngine.RegenMonsterByName(pEnvir:TEnvirnoment; nX, nY: Integer;
  sMonName: String):TBaseObject;
var
  nRace:Integer;
  BaseObject:TBaseObject;
  n18:Integer;
  MonGen:pTMonGenInfo;
begin
  nRace:=GetMonRace(sMonName);
  BaseObject:=AddBaseObjectEx(pEnvir,nX,nY,nRace,sMonName);
  if BaseObject <> nil then begin
    n18:=m_MonGenList.Count - 1;
    if n18 < 0 then n18:=0;
    MonGen:=m_MonGenList.Items[n18];
    MonGen.CertList.Add(BaseObject);
    BaseObject.m_PEnvir.AddObject(BaseObject);
    BaseObject.m_boAddToMaped:=True;
//    MainOutMessage(format('MonGet Count:%d',[MonGen.CertList.Count]));
  end;

  Result:=BaseObject;
end;

procedure TUserEngine.Run; //004B20B8
//var
//  i:integer;
//  dwProcessTick:LongWord;
ResourceString
  sExceptionMsg = '[Exception] TUserEngine::Run';
begin
    CalceTime:=GetTickCount;
    try
      {
      ProcessHumans();
      if (GetTickCount() - dwProcessMonstersTick) > g_dwProcessMonstersTime then begin
        dwProcessMonstersTick:=GetTickCount();
        ProcessMonsters();
      end;
      dwProcessTick:=GetTickCount();
      ProcessMerchants();
      dwProcessMerchantTimeMin:=GetTickCount - dwProcessTick;
      dwProcessTick:=GetTickCount();
      ProcessNpcs();
      dwProcessNpcTimeMin:=GetTickCount - dwProcessTick;
      if (GetTickCount() - dwProcessMissionsTime) > 1000 then begin
        dwProcessMissionsTime:=GetTickCount();
        ProcessMissions();
        Process4AECFC();
        ProcessEvents();
      end;
      if (GetTickCount() - dwProcessMapDoorTick) > 500 then begin
        dwProcessMapDoorTick:=GetTickCount();
        ProcessMapDoor();
      end;
      }
      if (GetTickCount() - dwShowOnlineTick) > g_Config.dwConsoleShowUserCountTime then begin
//      if (GetTickCount() - dwShowOnlineTime) > 5000 then begin
        dwShowOnlineTick:=GetTickCount();
        NoticeManager.LoadingNotice;
//        MainOutMessage(TimeToStr(Now) + ' 在线数: ' + IntToStr(GetUserCount));
        MainOutMessage('在线人数: ' + IntToStr(GetUserCount));
//        UserCastle.Save;
        g_CastleManager.Save;
      end;
      if (GetTickCount() - dwSendOnlineHumTime) > 10000 then begin
        dwSendOnlineHumTime:=GetTickCount();
        FrmIDSoc.SendOnlineHumCountMsg(GetOnlineHumCount);
//        GuildManager.Run;
//        UserCastle.Run;
//        for i:=0 to DenySayMsgList.Count - 1 do begin
//          //
//        end;
      end;
    except
     on e: Exception do begin
      MainOutMessage(sExceptionMsg);
      MainOutMessage(E.Message);
     end;
    end;
//    dwUsrTimeMin:=GetTickCount() - CalceTime;
//    if dwUsrTimeMax < dwUsrTimeMin then dwUsrTimeMax:=dwUsrTimeMin;
      

⌨️ 快捷键说明

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