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

📄 envir.pas

📁 乐都SQL版传奇全套代码,绝对可编译
💻 PAS
📖 第 1 页 / 共 5 页
字号:
            end;
          end;                                              //004B5FB5
        end;                                                //004B5FB5
      end;
    end;
  end;                                                      //004B5FBD
end;

constructor TMapManager.Create;
begin
  inherited Create;
end;

destructor TMapManager.Destroy;
var
  i                                     : Integer;
begin
  for i := 0 to Count - 1 do
  begin
    TEnvirnoment(Items[i]).Free;
  end;
  inherited;
end;
//Envir:TEnvirnoment

function TMapManager.FindMap(sMapName: string): TEnvirnoment; //4B7350
var
  Map                                   : TEnvirnoment;
  i                                     : Integer;
begin
  Result := nil;
  Lock;
  try
    for i := 0 to Count - 1 do
    begin
      Map := TEnvirnoment(Items[i]);
      if CompareText(Map.sMapName, sMapName) = 0 then
      begin
        Result := Map;
        break;
      end;
    end;
  finally
    UnLock;
  end;
end;

function TMapManager.GetMapInfo(nServerIdx: Integer; sMapName: string):
  TEnvirnoment;                                             //004B7424
var
  i                                     : Integer;
  Envir                                 : TEnvirnoment;
begin
  Result := nil;
  Lock;
  try
    for i := 0 to Count - 1 do
    begin
      Envir := Items[i];
      if (Envir.nServerIndex = nServerIdx) and (CompareText(Envir.sMapName,
        sMapName) = 0) then
      begin
        Result := Envir;
        break;
      end;
    end;                                                    //004B74C8
  finally
    UnLock;
  end;
end;

function TEnvirnoment.DeleteFromMap(nX, nY: Integer; btType: Byte;
  pRemoveObject: TObject): Integer;                         //004B6710
var
  MapCellInfo                           : pTMapCellinfo;
  OSObject                              : pTOSObject;
  n18                                   : Integer;
  btRaceServer                          : Byte;
resourcestring
  sExceptionMsg1                        =
    '[Exception] TEnvirnoment::DeleteFromMap -> Except 1 ** %d';
  sExceptionMsg2                        =
    '[Exception] TEnvirnoment::DeleteFromMap -> Except 2 ** %d';
begin
  Result := -1;
  try
    if GetMapCellInfo(nX, nY, MapCellInfo) then
    begin
      if MapCellInfo <> nil then
      begin
        try
          if MapCellInfo.ObjList <> nil then
          begin
            n18 := 0;
            while (True) do
            begin
              if MapCellInfo.ObjList.Count <= n18 then
                break;
              OSObject := MapCellInfo.ObjList.Items[n18];
              if OSObject <> nil then
              begin
                if (OSObject.btType = btType) and (OSObject.CellObj =
                  pRemoveObject) then
                begin
                  MapCellInfo.ObjList.Delete(n18);
                  DisPose(OSObject);
                  Result := 1;
                  //减地图人物怪物计数
                  if (btType = OS_MOVINGOBJECT) and (not TBaseObject(pRemoveObject).m_boDelFormMaped) then
                  begin
                    TBaseObject(pRemoveObject).m_boDelFormMaped := True;
                    TBaseObject(pRemoveObject).m_boAddToMaped := False;
                    btRaceServer := TBaseObject(pRemoveObject).m_btRaceServer;
                    if btRaceServer = RC_PLAYOBJECT then
                      Inc(m_nHumCount);
                    if btRaceServer >= RC_ANIMAL then
                      Inc(m_nMonCount);
                  end;

                  if MapCellInfo.ObjList.Count > 0 then
                    Continue;

                  MapCellInfo.ObjList.Free;
                  MapCellInfo.ObjList := nil;

                  break;

                end
              end
              else
              begin
                if n18<MapCellInfo.ObjList.Count then
                   MapCellInfo.ObjList.Delete(n18);
                if MapCellInfo.ObjList.Count > 0 then
                  Continue;
                MapCellInfo.ObjList.Free;
                MapCellInfo.ObjList := nil;
                break;
              end;
              Inc(n18);
            end;
          end
          else
          begin
            Result := -2;
          end;
        except
//          OSObject := nil;
          MainOutMessage(format(sExceptionMsg1, [btType]));
        end;
      end
      else
        Result := -3;
    end
    else
      Result := 0;
  except
    MainOutMessage(format(sExceptionMsg2, [btType]));
  end;
end;

function TEnvirnoment.GetItem(nX, nY: Integer): PTMapItem;  //004B5B0C
var
  i                                     : Integer;
  MapCellInfo                           : pTMapCellinfo;
  OSObject                              : pTOSObject;
  BaseObject                            : TBaseObject;
begin
  Result := nil;
  bo2C := False;
  if GetMapCellInfo(nX, nY, MapCellInfo) and (MapCellInfo.chFlag = 0) then
  begin
    bo2C := True;
    if MapCellInfo.ObjList <> nil then
    begin
      for i := 0 to MapCellInfo.ObjList.Count - 1 do
      begin
        OSObject := MapCellInfo.ObjList.Items[i];
        if OSObject.btType = OS_ITEMOBJECT then
        begin
          Result := PTMapItem(OSObject.CellObj);
          exit;
        end;
        if OSObject.btType = OS_GATEOBJECT then
          bo2C := False;
        if OSObject.btType = OS_MOVINGOBJECT then
        begin
          BaseObject := TBaseObject(OSObject.CellObj);
          if not BaseObject.m_boDeath then
            bo2C := False;
        end;
      end;
    end;
  end;
end;

function TMapManager.GetMapOfServerIndex(sMapName: string): Integer; //004B7510
var
  i                                     : Integer;
  Envir                                 : TEnvirnoment;
begin
  Result := 0;
  Lock;
  try
    for i := 0 to Count - 1 do
    begin
      Envir := Items[i];
      if (CompareText(Envir.sMapName, sMapName) = 0) then
      begin
        Result := Envir.nServerIndex;
        break;
      end;
    end;
  finally
    UnLock;
  end;
end;

procedure TMapManager.LoadMapDoor;                          //004B6FFC
var
  i                                     : Integer;
begin
  for i := 0 to Count - 1 do
  begin
    TEnvirnoment(Items[i]).AddDoorToMap;
  end;
end;

procedure TMapManager.ProcessMapDoor;
begin

end;

procedure TMapManager.ReSetMinMap;
var
  i, ii                                 : Integer;
  Envirnoment                           : TEnvirnoment;
begin
  for i := 0 to Count - 1 do
  begin
    Envirnoment := TEnvirnoment(Items[i]);
    for ii := 0 to MiniMapList.Count - 1 do
    begin
      if CompareText(MiniMapList.Strings[ii], Envirnoment.sMapName) = 0 then
      begin
        Envirnoment.nMinMap := Integer(MiniMapList.Objects[ii]);
        break;
      end;
    end;
  end;
end;

function TEnvirnoment.IsCheapStuff: Boolean;                //004B6E24
begin
  if m_QuestList.Count > 0 then
    Result := True
  else
    Result := False;
end;

function TEnvirnoment.AddToMapMineEvent(nX, nY: Integer; nType: Integer; Event:
  TObject): TObject;                                        //004B6600
var
  MapCellInfo                           : pTMapCellinfo;
  OSObject                              : pTOSObject;
  bo19, bo1A                            : Boolean;
resourcestring
  sExceptionMsg                           =
    '[Exception] TEnvirnoment::AddToMapMineEvent ';
begin
  Result := nil;
  try
    bo19 := GetMapCellInfo(nX, nY, MapCellInfo);
    bo1A := False;
    if bo19 and (MapCellInfo.chFlag <> 0) then
    begin
      if MapCellInfo.ObjList = nil then
        MapCellInfo.ObjList := TMyList.create;
      if not bo1A then
      begin
        New(OSObject);
        if OSObject<>nil then
        Begin
          OSObject.btType := nType;
          OSObject.CellObj := Event;
          OSObject.dwAddTime := GetTickCount();
          MapCellInfo.ObjList.Add(OSObject);
          Result := Event;
        end;
      end;
    end;
  except
    MainOutMessage(sExceptionMsg);
  end;
end;

procedure TEnvirnoment.VerifyMapTime(nX, nY: Integer; BaseObject: TObject);
//004B6980
var
  i                                     : Integer;
  MapCellInfo                           : pTMapCellinfo;
  OSObject                              : pTOSObject;
  boVerify                              : Boolean;
resourcestring
  sExceptionMsg                           =
    '[Exception] TEnvirnoment::VerifyMapTime';
begin
  try
    boVerify := False;
    if GetMapCellInfo(nX, nY, MapCellInfo) and (MapCellInfo <> nil) and
      (MapCellInfo.ObjList <> nil) then
    begin
      for i := 0 to MapCellInfo.ObjList.Count - 1 do
      begin
        OSObject := MapCellInfo.ObjList.Items[i];
        if (OSObject.btType = OS_MOVINGOBJECT) and (OSObject.CellObj =
          BaseObject) then
        begin
          OSObject.dwAddTime := GetTickCount();
          boVerify := True;
          break;
        end;
      end;
    end;
    if not boVerify then
      AddToMap(nX, nY, OS_MOVINGOBJECT, BaseObject);
  except
    MainOutMessage(sExceptionMsg);
  end;
end;

constructor TEnvirnoment.Create;                            //004B5318
begin
//  Pointer(MapCellArray) := nil;
  Setlength(MapCellArray,0);
  sMapName := '';
  nServerIndex := 0;
  nMinMap := 0;
  m_nWidth := 0;
  m_nHeight := 0;
  m_boDARK := False;
  m_boDAY := False;
  m_nMonCount := 0;
  m_nHumCount := 0;

  m_DoorList := TMyList.create;
  m_QuestList := TMyList.create;
  m_MineList := TMyList.Create;
end;

destructor TEnvirnoment.Destroy;
var
  i                                     : Integer;
  MapCellInfo                           : pTMapCellinfo;
  OSObject                              : pTOSObject;
  nX, nY                                : Integer;
  DoorInfo                              : pTDoorInfo;
begin
  for nX := 0 to m_nWidth - 1 do
  begin
    for nY := 0 to m_nHeight - 1 do
    begin
      if GetMapCellInfo(nX, nY, MapCellInfo) and (MapCellInfo.ObjList <> nil)
        then
      begin
        for i := 0 to MapCellInfo.ObjList.Count - 1 do
        begin
          OSObject := MapCellInfo.ObjList.Items[i];
          case OSObject.btType of
            OS_ITEMOBJECT: DisPose(PTMapItem(OSObject.CellObj));
            OS_GATEOBJECT: DisPose(pTGateObj(OSObject.CellObj));
            OS_EVENTOBJECT: TEvent(OSObject.CellObj).Free;

⌨️ 快捷键说明

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