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

📄 usrengn.pas

📁 飞尔传奇世界的引擎代码可直接编译M2Engine 请使用Delphi编译
💻 PAS
📖 第 1 页 / 共 5 页
字号:
                  Inc(PlayObject.m_nShowLineNoticeIdx);
                  if (LineNoticeList.Count <= PlayObject.m_nShowLineNoticeIdx) then
                    PlayObject.m_nShowLineNoticeIdx := 0;
                end;
                nCheck30 := 14;
                PlayObject.Run();
                nCheck30 := 15;
                if not FrontEngine.IsFull and ((GetTickCount() - PlayObject.m_dwSaveRcdTick) > g_Config.dwSaveHumanRcdTime) then begin
                  nCheck30 := 16;
                  PlayObject.m_dwSaveRcdTick := GetTickCount();
                  nCheck30 := 17;
                  PlayObject.DealCancelA();
                  nCheck30 := 18;
                  SaveHumanRcd(PlayObject);
{$IF HEROVERSION = 1}
                  SaveHeroRcd(PlayObject);
{$IFEND}
                  nCheck30 := 19;
                end;
              except
                on E: Exception do begin
                  MainOutMessage(Format(sExceptionMsg5, [nCheck30]));
                  MainOutMessage(E.Message);
                end;
              end;
            end;
          end else begin //if not PlayObject.boIsGhost then begin
            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;
            try
              AddToHumanFreeList(PlayObject);
              nCheck30 := 4;
              PlayObject.DealCancelA();
              SaveHumanRcd(PlayObject);
{$IF HEROVERSION = 1}
              SaveHeroRcd(PlayObject);
{$IFEND}
              RunSocket.CloseUser(PlayObject.m_nGateIdx, PlayObject.m_nSocket);
            except
              MainOutMessage(Format(sExceptionMsg7, [nCheck30]));
            end;
            SendServerGroupMsg(SS_202, nServerIndex, PlayObject.m_sCharName);
            Continue;
          end;
        end; //if (dwTime14 - PlayObject.dw368) > PlayObject.dw36C then begin
        Inc(nIdx);
        if (GetTickCount - dwCheckTime) > g_dwHumLimit then begin
          boCheckTimeLimit := True;
          m_nProcHumIDx := nIdx;
          Break;
        end;
      end; //while True do begin
    end;
    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;

function TUserEngine.InMerchantList(Merchant: TMerchant): Boolean;
var
  I: Integer;
begin
  Result := False;
  for I := 0 to m_MerchantList.Count - 1 do begin
    if (Merchant <> nil) and (TMerchant(m_MerchantList.Items[I]) = Merchant) then begin
      Result := True;
      Break;
    end;
  end;
end;

procedure TUserEngine.ProcessMerchants;
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
      I := nMerchantPosition;
      while True do begin // for i := nMerchantPosition to m_MerchantList.Count - 1 do begin
        if m_MerchantList.Count <= I then Break;
        MerchantNPC := m_MerchantList.Items[I];
        if MerchantNPC <> nil then begin
          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;
              if Integer(dwCurrTick - MerchantNPC.m_dwRunTick) > MerchantNPC.m_nRunTime then begin
                MerchantNPC.m_dwRunTick := dwCurrTick;
                MerchantNPC.Run;
              end;
            end;
          end else begin
            if (GetTickCount - MerchantNPC.m_dwGhostTick) > 60 * 1000 then begin
              MerchantNPC.Free;
              m_MerchantList.Delete(I);
              Break;
            end;
          end;
        end;
        if (GetTickCount - dwRunTick) > g_dwNpcLimit then begin
          nMerchantPosition := I;
          boProcessLimit := True;
          Break;
        end;
        Inc(I);
      end;
    finally
      m_MerchantList.UnLock;
    end;
    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;
begin

end;

function TUserEngine.InsMonstersList(MonGen: pTMonGenInfo; Monster: TAnimalObject): Boolean;
var
  I, II: Integer;
  MonGenInfo: pTMonGenInfo;
begin
  Result := False;
  for I := 0 to m_MonGenList.Count - 1 do begin
    MonGenInfo := m_MonGenList.Items[I];
    if (MonGenInfo <> nil) and (MonGenInfo.CertList <> nil) and (MonGen <> nil) and (MonGen = MonGenInfo) then begin
      for II := 0 to MonGenInfo.CertList.Count - 1 do begin
        if (Monster <> nil) and (TBaseObject(MonGenInfo.CertList.Items[II]) = Monster) then begin
          Result := True;
          Break;
        end;
      end;
    end;
  end;
end;

function TUserEngine.ClearMonsters(sMapName: string): Boolean;
var
  I, II: Integer;
  {MonGenInfo: pTMonGenInfo;
  Monster: TAnimalObject; }
  MonList: TList;
  Envir: TEnvirnoment;
  BaseObject: TBaseObject;
begin
  Result := False;
  MonList := TList.Create;
  for I := 0 to g_MapManager.Count - 1 do begin
    Envir := TEnvirnoment(g_MapManager.Items[I]);
    if (Envir <> nil) and ((CompareText(Envir.sMapName, sMapName) = 0)) then begin
      UserEngine.GetMapMonster(Envir, MonList);
      for II := 0 to MonList.Count - 1 do begin
        BaseObject := TBaseObject(MonList.Items[II]);
        if BaseObject <> nil then begin
          if (BaseObject.m_btRaceServer <> 110) and (BaseObject.m_btRaceServer <> 111) and
            (BaseObject.m_btRaceServer <> 111) and (BaseObject.m_btRaceServer <> RC_GUARD) and
            (BaseObject.m_btRaceServer <> RC_ARCHERGUARD) and (BaseObject.m_btRaceServer <> 55) then begin
            BaseObject.m_boNoItem := True;
            BaseObject.m_WAbil.HP := 0;
          end;
        end;
      end;
    end;
  end;
  MonList.Free;

  {for i := 0 to m_MonGenList.Count - 1 do begin
    MonGenInfo := m_MonGenList.Items[i];
    if MonGenInfo = nil then Continue;
    if CompareText(MonGenInfo.sMapName, sMapName) = 0 then begin
      if (MonGenInfo.CertList <> nil) and (MonGenInfo.CertList.Count > 0) then begin
        for ii := 0 to MonGenInfo.CertList.Count - 1 do begin
          Monster := TAnimalObject(MonGenInfo.CertList.Items[ii]);
          if Monster <> nil then begin
            if (Monster.m_btRaceServer <> 110) and (Monster.m_btRaceServer <> 111) and
              (Monster.m_btRaceServer <> 111) and (Monster.m_btRaceServer <> RC_GUARD) and
              (Monster.m_btRaceServer <> RC_ARCHERGUARD) and (Monster.m_btRaceServer <> 55) then begin
              Monster.Free;
              if nMonsterCount > 0 then Dec(nMonsterCount);
              //DisPose();
            end;
          end;
          if MonGenInfo.CertList.Count <= 0 then begin
            MonGenInfo.CertList.Clear;
          end;
        end;
      end;
    end;
  end;}
  Result := True;
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 {1000}) / g_Config.nZenFastStep {300};
      if d10 > 0 then begin
        if d10 > 6 then d10 := 6;
        Result := dwTime - Round((dwTime / 10) * d10)
      end else begin
        Result := dwTime;
      end;
    end else begin
      Result := dwTime;
    end;
  end;
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;
  nMakeMonsterCount: Integer;
  nActiveMonsterCount: Integer;
  nActiveHumCount: Integer;
  nNeedMakeMonsterCount: Integer;
  MapMonGenCount: pTMapMonGenCount;
  n10: Integer;
resourcestring
  sExceptionMsg = '[Exception] TUserEngine::ProcessMonsters %d %s';
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;
      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 g_Config.nMonGenRate <= 0 then g_Config.nMonGenRate := 10; //防止除法错误
          nGenModCount := _MAX(1, Round(_MAX(1, MonGen.nCount) / (g_Config.nMonGenRate / 10)));
          nMakeMonsterCount := nGenModCount - nGenCount;
          if nMakeMonsterCount < 0 then nMakeMonsterCount := 0;
          {===============================智能刷怪========================================}
          {nGenModCount 需要刷怪数}
          {nGenCount 已经刷怪数}
          (*if (MonGen.Envir <> nil) and MonGen.Envir.m_boAutoMakeMonster then begin
            if (MonGen.nRace <> 110) or (MonGen.nRace <> 111) and
              (MonGen.nRace <> 111) or (MonGen.nRace <> RC_GUARD) and
              (MonGen.nRace <> RC_ARCHERGUARD) or (MonGen.nRace <> 55) then begin

              nActiveMonsterCount := GetMapMonster(MonGen.Envir, nil);
              MapMonGenCount := GetMapMonGenCount(MonGen.sMapName);
              nActiveHumCount := GetMapHuman(MonGen.sMapName);
              //n10 := GetMakeMonsterCount(nNeedMakeMonsterCount, nActiveMonsterCount);
              if MapMonGenCount <> nil then begin
                if (nActiveHumCount > 0) and (not MapMonGenCount.boNotHum) then begin
                  MapMonGenCount.boNotHum := True;
                end else
                  if (nActiveHumCount <= 0) and (MapMonGenCount.boNotHum)

⌨️ 快捷键说明

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