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

📄 usrengn.pas

📁 传奇2...飘飘M2的源码.曾经是传奇"龙"版用得最好的M2程序.完整M2源码
💻 PAS
📖 第 1 页 / 共 5 页
字号:

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) then begin
                  MapMonGenCount.boNotHum := False;
                  MapMonGenCount.dwNotHumTimeTick := GetTickCount;
                end;
                {清怪}
                if (GetTickCount - MapMonGenCount.dwNotHumTimeTick > 1000 * 60 * 5) and not MapMonGenCount.boNotHum then begin
                  MapMonGenCount.dwNotHumTimeTick := GetTickCount;
                  if nActiveMonsterCount > 0 then begin
                    if ClearMonsters(MonGen.sMapName) then begin
                      Inc(MapMonGenCount.nClearCount);
                    end;
                  end;
                  nMakeMonsterCount := 0;
                end;
                {刷怪}
                if MapMonGenCount.boNotHum then begin

                end;
              end;
            end;
          end;*)

          if nMakeMonsterCount > 0 then begin //0806 增加 控制刷怪数量比例
            boRegened := RegenMonsters(MonGen, nMakeMonsterCount);
          end;
          if boRegened then begin
            MonGen.dwStartTick := GetTickCount();
          end;
        end;
        g_sMonGenInfo1 := MonGen.sMonName + ',' + IntToStr(m_nCurrMonGen) + '/' + IntToStr(m_MonGenList.Count);
      end;
    end;
    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;
    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
        nProcessPosition := 0;
      end;
      m_nMonGenCertListPosition := 0;
      while (True) do begin
        if nProcessPosition >= MonGen.CertList.Count then break;
        Monster := MonGen.CertList.Items[nProcessPosition];
        tCode := 12;
        if Monster <> nil then begin
          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 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;
              Inc(nMonsterProcessCount);
            end;
            Inc(nMonsterProcessPostion);
          end else begin
            if (GetTickCount - Monster.m_dwGhostTick) > 5 * 60 * 1000 then begin
              MonGen.CertList.Delete(nProcessPosition);
              Monster.Free;
              //FreeAndNil(Monster);
              Continue;
            end;
          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; //while (True) do begin
      if boProcessLimit then break;
    end; //for I:= m_nMonGenListPosition to MonGenList.Count -1 do begin
    tCode := 2;
    if m_MonGenList.Count <= i then begin
      m_nMonGenListPosition := 0;
      nMonsterCount := nMonsterProcessPostion;
      nMonsterProcessPostion := 0;
      n84 := (n84 + nMonsterProcessCount) div 2;
    end;
    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
      {if tCode = 12 then begin

⌨️ 快捷键说明

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