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

📄 usrengn.pas

📁 原版翎风(LF)引擎(M2)源码(Delphi)
💻 PAS
📖 第 1 页 / 共 5 页
字号:
          if not FrontEngine.IsFull and not IsLogined(m_LoadPlayList.Strings[i]) then
          begin
            UserOpenInfo := pTUserOpenInfo(m_LoadPlayList.Objects[i]);

            PlayObject := MakeNewHuman(UserOpenInfo);


            if PlayObject <> nil then
            begin
              //PlayObject.m_boClientFlag:=UserOpenInfo.LoadUser.boClinetFlag; //将客户端标志传到人物数据中
              m_PlayObjectList.AddObject(m_LoadPlayList.Strings[i], PlayObject);
              SendServerGroupMsg(SS_201, nServerIndex, PlayObject.m_sCharName);
              m_NewHumanList.Add(PlayObject);
            end;

          end else
          begin //004B0BF9
            KickOnlineUser(m_LoadPlayList.Strings[i]);
            UserOpenInfo := pTUserOpenInfo(m_LoadPlayList.Objects[i]);
            m_ListOfGateIdx.Add(Pointer(UserOpenInfo.LoadUser.nGateIdx)); //004B0C39
            m_ListOfSocket.Add(Pointer(UserOpenInfo.LoadUser.nSocket));
          end;
          Dispose(pTUserOpenInfo(m_LoadPlayList.Objects[i]));
        end; //004B0C96
        m_LoadPlayList.Clear;
        for i := 0 to m_ChangeHumanDBGoldList.Count - 1 do
        begin
          GoldChangeInfo := m_ChangeHumanDBGoldList.Items[i];
          PlayObject := GetPlayObject(GoldChangeInfo.sGameMasterName);
          if PlayObject <> nil then
          begin
            PlayObject.GoldChange(GoldChangeInfo.sGetGoldUser, GoldChangeInfo.nGold);
          end;
          Dispose(GoldChangeInfo);
        end;
        m_ChangeHumanDBGoldList.Clear;
      finally
        LeaveCriticalSection(m_LoadPlaySection);
      end;

      //004B0D4A
      for i := 0 to m_NewHumanList.Count - 1 do
      begin
        PlayObject := TPlayObject(m_NewHumanList.Items[i]);

        RunSocket.SetGateUserList(PlayObject.m_nGateIdx, PlayObject.m_nSocket, PlayObject);

      end;
      m_NewHumanList.Clear;


      for i := 0 to m_ListOfGateIdx.Count - 1 do
      begin

        RunSocket.CloseUser(Integer(m_ListOfGateIdx.Items[i]), Integer(m_ListOfSocket.Items[i])); //GateIdx,nSocket

      end;
      m_ListOfGateIdx.Clear;
      m_ListOfSocket.Clear;
    except
      on E: Exception do
      begin
        MainOutMessage(Format(sExceptionMsg1, [0]));
        MainOutMessage(E.Message);
      end;
    end;
  end; //004B0E1E


  try
    for i := 0 to m_PlayObjectFreeList.Count - 1 do
    begin
      PlayObject := TPlayObject(m_PlayObjectFreeList.Items[i]);
      if (GetTickCount - PlayObject.m_dwGhostTick) > g_Config.dwHumanFreeDelayTime {5 * 60 * 1000} then
      begin
        try
          TPlayObject(m_PlayObjectFreeList.Items[i]).Free;
        except
          MainOutMessage(sExceptionMsg2);
        end;

        m_PlayObjectFreeList.Delete(i);
        Break;
      end else
      begin
        if PlayObject.m_boSwitchData and (PlayObject.m_boRcdSaved) then
        begin
          if SendSwitchData(PlayObject, PlayObject.m_nServerIndex) or (PlayObject.m_nWriteChgDataErrCount > 20) then
          begin
            PlayObject.m_boSwitchData := False;
            PlayObject.m_boSwitchDataSended := True;
            PlayObject.m_dwChgDataWritedTick := GetTickCount();
          end else Inc(PlayObject.m_nWriteChgDataErrCount);
        end;
        if PlayObject.m_boSwitchDataSended and ((GetTickCount - PlayObject.m_dwChgDataWritedTick) > 100) then
        begin
          PlayObject.m_boSwitchDataSended := False;
          SendChangeServer(PlayObject, PlayObject.m_nServerIndex);
        end;
      end;
    end;
  except
    MainOutMessage(sExceptionMsg3);
  end; //004B0F91


  boCheckTimeLimit := False; //004B0F91
  try
    dwCurTick := GetTickCount();
    nIdx := m_nProcHumIDx;
    while True do
    begin
      if m_PlayObjectList.Count <= nIdx then Break;
      PlayObject := TPlayObject(m_PlayObjectList.Objects[nIdx]);
      if Integer(dwCurTick - PlayObject.m_dwRunTick) > PlayObject.m_nRunTime then
      begin
        PlayObject.m_dwRunTick := dwCurTick;
        if not PlayObject.m_boGhost then
        begin
          if not PlayObject.m_boLoginNoticeOK then
          begin
{$IF CATEXCEPTION = TRYEXCEPTION}
            try
{$IFEND}
              PlayObject.RunNotice();
{$IF CATEXCEPTION = TRYEXCEPTION}
            except
              MainOutMessage(sExceptionMsg4);
            end;
{$IFEND}
          end else
          begin //004B1058
            try
              if not PlayObject.m_boReadyRun then
              begin
                PlayObject.m_boReadyRun := True; //004B1075
                PlayObject.UserLogon; //BaseObject.0FFFEh;
              end else
              begin
                if (GetTickCount() - PlayObject.m_dwSearchTick) > PlayObject.m_dwSearchTime then
                begin
                  PlayObject.m_dwSearchTick := GetTickCount();
                  PlayObject.SearchViewRange;
                  PlayObject.GameTimeChanged;
                end; //004B10C4

                if (GetTickCount() - PlayObject.m_dwShowLineNoticeTick) > g_Config.dwShowLineNoticeTime then
                begin
                  PlayObject.m_dwShowLineNoticeTick := GetTickCount();
                  if LineNoticeList.Count > PlayObject.m_nShowLineNoticeIdx then
                  begin

                    LineNoticeMsg := g_ManageNPC.GetLineVariableText(PlayObject, LineNoticeList.Strings[PlayObject.m_nShowLineNoticeIdx]);

                     //PlayObject.SysMsg(g_Config.sLineNoticePreFix + ' '+ LineNoticeList.Strings[PlayObject.m_nShowLineNoticeIdx],g_nLineNoticeColor);

                    case LineNoticeMsg[1] of
                      'R': PlayObject.SysMsg(Copy(LineNoticeMsg, 2, Length(LineNoticeMsg) - 1), c_Red, t_Notice);
                      'G': PlayObject.SysMsg(Copy(LineNoticeMsg, 2, Length(LineNoticeMsg) - 1), c_Green, t_Notice);
                      'B': PlayObject.SysMsg(Copy(LineNoticeMsg, 2, Length(LineNoticeMsg) - 1), c_Blue, t_Notice);
                    else
                      begin
                        PlayObject.SysMsg(LineNoticeMsg, TMsgColor(g_Config.nLineNoticeColor) {c_Blue}, t_Notice);
                      end;
                    end;
                  end;
                  Inc(PlayObject.m_nShowLineNoticeIdx);
                  if (LineNoticeList.Count <= PlayObject.m_nShowLineNoticeIdx) then
                    PlayObject.m_nShowLineNoticeIdx := 0;
                end;

                PlayObject.Run();

                if not FrontEngine.IsFull and ((GetTickCount() - PlayObject.m_dwSaveRcdTick) > g_Config.dwSaveHumanRcdTime) then
                begin
                  PlayObject.m_dwSaveRcdTick := GetTickCount();

                  PlayObject.DealCancelA();

                  SaveHumanRcd(PlayObject);

                end;
              end; //004B119F
            except
              on E: Exception do
              begin
                MainOutMessage(Format(sExceptionMsg5, [0]));
                MainOutMessage(E.Message);
              end;
            end;
          end;
        end else
        begin //if not PlayObject.boIsGhost then begin  //CODE:004B11C5
          try
            m_PlayObjectList.Delete(nIdx);
            nCheck30 := 2;

            PlayObject.Disappear();

            nCheck30 := 3;
          except
            on E: Exception do
            begin
              MainOutMessage(Format(sExceptionMsg6, [nCheck30]));
              MainOutMessage(E.Message);
            end;
          end; //004B1232
          try

            AddToHumanFreeList(PlayObject);

            nCheck30 := 4;
            PlayObject.DealCancelA();

            SaveHumanRcd(PlayObject);

            RunSocket.CloseUser(PlayObject.m_nGateIdx, PlayObject.m_nSocket);

          except
            MainOutMessage(Format(sExceptionMsg7, [nCheck30]));
          end; //004B12BA

          SendServerGroupMsg(SS_202, nServerIndex, PlayObject.m_sCharName);
          Continue;
        end;
      end; //if (dwTime14 - PlayObject.dw368) > PlayObject.dw36C then begin
      Inc(nIdx); //004B12E6
      if (GetTickCount - dwCheckTime) > g_dwHumLimit then
      begin
        boCheckTimeLimit := True;
        m_nProcHumIDx := nIdx;
        Break;
      end;
    end; //while True do begin
    if not boCheckTimeLimit then m_nProcHumIDx := 0;
  except
    MainOutMessage(sExceptionMsg8);
  end;
  Inc(nProcessHumanLoopTime);
  g_nProcessHumanLoopTime := nProcessHumanLoopTime;
  if m_nProcHumIDx = 0 then
  begin
    nProcessHumanLoopTime := 0;
    g_nProcessHumanLoopTime := nProcessHumanLoopTime;
    dwUsrRotTime := GetTickCount - g_dwUsrRotCountTick;
    dwUsrRotCountMin := dwUsrRotTime;
    g_dwUsrRotCountTick := GetTickCount();
    if dwUsrRotCountMax < dwUsrRotTime then dwUsrRotCountMax := dwUsrRotTime;
  end;
  g_nHumCountMin := GetTickCount - dwCheckTime;
  if g_nHumCountMax < g_nHumCountMin then g_nHumCountMax := g_nHumCountMin;
end;

procedure TUserEngine.ProcessMerchants; //004B1B8C
var
  dwRunTick, dwCurrTick: LongWord;
  i: Integer;
  MerchantNPC: TMerchant;
  boProcessLimit: Boolean;
resourcestring
  sExceptionMsg = '[Exception] TUserEngine::ProcessMerchants';
begin
  dwRunTick := GetTickCount();
  boProcessLimit := False;
  try
    dwCurrTick := GetTickCount();
    m_MerchantList.Lock;
    try
      for i := nMerchantPosition to m_MerchantList.Count - 1 do
      begin
        MerchantNPC := m_MerchantList.Items[i];
        if not MerchantNPC.m_boGhost then
        begin
          if Integer(dwCurrTick - MerchantNPC.m_dwRunTick) > MerchantNPC.m_nRunTime then
          begin
            if (GetTickCount - MerchantNPC.m_dwSearchTick) > MerchantNPC.m_dwSearchTime then
            begin
              MerchantNPC.m_dwSearchTick := GetTickCount();
              MerchantNPC.SearchViewRange();
            end; //004B1C3C
            if Integer(dwCurrTick - MerchantNPC.m_dwRunTick) > MerchantNPC.m_nRunTime then
            begin
              MerchantNPC.m_dwRunTick := dwCurrTick;
              MerchantNPC.Run; {FFFFB}
            end;
          end; //004B1C6B
        end else
        begin //004B1C6B
          if (GetTickCount - MerchantNPC.m_dwGhostTick) > 60 * 1000 then
          begin
            MerchantNPC.Free;
            m_MerchantList.Delete(i);
            Break;
          end;
        end;
        if (GetTickCount - dwRunTick) > g_dwNpcLimit then
        begin
          nMerchantPosition := i;
          boProcessLimit := True;
          Break;
        end; //004B1C8C
      end; //004B1C98
    finally
      m_MerchantList.UnLock;
    end;
    if not boProcessLimit then
    begin
      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);

⌨️ 快捷键说明

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