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

📄 envir.pas

📁 乐都SQL版传奇全套代码,绝对可编译
💻 PAS
📖 第 1 页 / 共 5 页
字号:
          end;
          DisPose(OSObject);
        end;
        MapCellInfo.ObjList.Free;
        MapCellInfo.ObjList := nil;
      end;
    end;
  end;

  for i := 0 to m_DoorList.Count - 1 do
  begin
    DoorInfo := m_DoorList.Items[i];
    Dec(DoorInfo.Status.nRefCount);
    if DoorInfo.Status.nRefCount <= 0 then
      DisPose(DoorInfo.Status);

    DisPose(DoorInfo);
  end;
  m_DoorList.Free;
  for i := 0 to m_QuestList.Count - 1 do
  begin
    DisPose(pTMapQuestInfo(m_QuestList.Items[i]));
  end;
  m_QuestList.Free;
  Setlength(MapCellArray,0);
  inherited;
end;



function TEnvirnoment.LoadMapData(sMapFile: string): Boolean; //004B54E0
var
  fHandle                               : Integer;
  Header                                : TMapHeader;
  nMapSize                              : Integer;
  n24, nW, nH                           : Integer;
  MapBuffer                             : pTMap;
  Point                                 : Integer;
  Door                                  : pTDoorInfo;
  i                                     : Integer;
  MapCellInfo                           : pTMapCellinfo;
  IniFile                               : TIniFile;
  MineList                              : TStringList;
  MapMineInfo                           : pMapMineInfo;
begin
  Result := False;
  if FileExists(sMapFile) then
  begin
    fHandle := FileOpen(sMapFile, fmOpenRead or fmShareExclusive);
    if fHandle > 0 then
    begin
      FileRead(fHandle, Header, SizeOf(TMapHeader));
      m_nWidth := Header.wWidth;
      m_nHeight := Header.wHeight;
      Initialize(m_nWidth, m_nHeight);
      nMapSize := m_nWidth * SizeOf(TMapUnitInfo) * m_nHeight;

      MapBuffer := AllocMem(nMapSize);
      FileRead(fHandle, MapBuffer^, nMapSize);

      for nW := 0 to m_nWidth - 1 do
      begin
        n24 := nW * m_nHeight;
        for nH := 0 to m_nHeight - 1 do
        begin
          if (MapBuffer[n24 + nH].wBkImg) and $8000 <> 0 then
          begin
            MapCellInfo := @MapCellArray[n24 + nH];
            MapCellInfo.chFlag := 1;
          end;                                              //004B5601
          if MapBuffer[n24 + nH].wFrImg and $8000 <> 0 then
          begin
            MapCellInfo := @MapCellArray[n24 + nH];
            MapCellInfo.chFlag := 2;
          end;                                              //004B562C
          if MapBuffer[n24 + nH].btDoorIndex and $80 <> 0 then
          begin
            Point := (MapBuffer[n24 + nH].btDoorIndex and $7F);
            if Point > 0 then
            begin
              New(Door);
              if Door=nil  then continue;

              Door.nX := nW;
              Door.nY := nH;
              Door.n08 := Point;
              Door.Status := nil;
              for i := 0 to m_DoorList.Count - 1 do
              begin
                if abs(pTDoorInfo(m_DoorList.Items[i]).nX - Door.nX) <= 10 then
                begin
                  if abs(pTDoorInfo(m_DoorList.Items[i]).nY - Door.nY) <= 10
                    then
                  begin
                    if pTDoorInfo(m_DoorList.Items[i]).n08 = Point then
                    begin
                      Door.Status := pTDoorInfo(m_DoorList.Items[i]).Status;
                      Inc(Door.Status.nRefCount);
                      break;
                    end;
                  end;
                end;
              end;                                          //004B5730
              if Door.Status = nil then
              begin
                New(Door.Status);
                if Door.Status<>nil then
                Begin

                    Door.Status.boOpened := False;
                    Door.Status.bo01 := False;
                    Door.Status.n04 := 0;
                    Door.Status.dwOpenTick := 0;
                    Door.Status.nRefCount := 1;
                end;
              end;
              m_DoorList.Add(Door);
            end;                                            //004B5780
          end;
        end;                                                //004B578C
      end;                                                  //004B5798
      //Dispose(MapBuffer);

      FreeMem(MapBuffer);

      FileClose(fHandle);
      Result := True;
    end;                                                    //004B57B1

    IniFile:=TIniFile.Create(g_Config.sEnvirDir+'MapofMine.txt');
    if IniFile.SectionExists(m_sMapFileName) then
    begin
       try
        MineList:=TStringList.Create;
        IniFile.ReadSection(m_sMapFileName,MineList);
        for i:=0 to MineList.Count-1 do
        begin
            New(MapMineInfo);
            if MapMineinfo=nil then continue;

            MapMineInfo.MineName:=MineList[i];
            MapMineInfo.MineRate:=IniFile.ReadInteger(m_sMapFileName,MineList[i],0);
            m_MineList.Add(MapMineInfo);
        end;
       finally
        MineList.Free;
        IniFile.Free;
       End;
    End;



  end;                                                      //004B57B1
end;

procedure TEnvirnoment.Initialize(nWidth, nHeight: Integer); //004B53FC
var
  nW, nH                                : Integer;
  MapCellInfo                           : pTMapCellinfo;
begin
  if (nWidth > 1) and (nHeight > 1) then
  begin
    if MapCellArray <> nil then
    begin
      for nW := 0 to m_nWidth - 1 do
      begin
        for nH := 0 to m_nHeight - 1 do
        begin
          MapCellInfo := @MapCellArray[nW * m_nHeight + nH];
          if MapCellInfo.ObjList <> nil then
          begin
            MapCellInfo.ObjList.Free;
            MapCellInfo.ObjList := nil;
          end;
        end;
      end;
      //FreeMem(MapCellArray);
      //Pointer(MapCellArray) := nil;
       Setlength(MapCellArray,0);
    end;                                                    //004B54AF
    m_nWidth := nWidth;
    m_nHeight := nHeight;
    SetLength(MapCellArray,m_nWidth * m_nHeight);
    //Pointer(MapCellArray) := AllocMem((m_nWidth * m_nHeight) *  SizeOf(TMapCellinfo));
  end;                                                      //004B54DB
end;

//nFlag,boFlag,Monster,Item,Quest,boGrouped

function TEnvirnoment.CreateQuest(nFlag, nValue: Integer; s24, s28, s2C: string;
  boGrouped: Boolean): Boolean;                             //004B6C3C
var
  MapQuest                              : pTMapQuestInfo;
  MapMerchant                           : TMerchant;
begin
  Result := False;
  if nFlag < 0 then
    exit;
  New(MapQuest);
  if MapQuest=nil then exit;
  MapQuest.nFlag := nFlag;
  if nValue > 1 then
    nValue := 1;
  MapQuest.nValue := nValue;
  if s24 = '*' then
    s24 := '';
  MapQuest.s08 := s24;
  if s28 = '*' then
    s28 := '';
  MapQuest.s0C := s28;
  if s2C = '*' then
    s2C := '';

  MapQuest.bo10 := boGrouped;
  MapMerchant := TMerchant.Create;
  MapMerchant.m_sMapName := '0';
  MapMerchant.m_nCurrX := 0;
  MapMerchant.m_nCurrY := 0;
  MapMerchant.m_sCharName := s2C;
  MapMerchant.m_nFlag := 0;
  MapMerchant.m_wAppr := 0;
  MapMerchant.m_sFilePath := 'MapQuest_def\';
  MapMerchant.m_boIsHide := True;
  MapMerchant.m_boIsQuest := False;

  UserEngine.QuestNPCList.Add(MapMerchant);
  MapQuest.NPC := MapMerchant;
  m_QuestList.Add(MapQuest);
  Result := True;
end;

function TEnvirnoment.GetXYObjCount(nX, nY: Integer): Integer; //004B5DB0
var
  i                                     : Integer;
  MapCellInfo                           : pTMapCellinfo;
  OSObject                              : pTOSObject;
  BaseObject                            : TBaseObject;
begin
  Result := 0;
  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];
      if OSObject.btType = OS_MOVINGOBJECT then
      begin
        BaseObject := TBaseObject(OSObject.CellObj);
        if BaseObject <> nil then
        begin
          if not BaseObject.m_boGhost and
            BaseObject.bo2B9 and
            not BaseObject.m_boDeath and
            not BaseObject.m_boFixedHideMode and
            not BaseObject.m_boObMode then
          begin
            Inc(Result);
          end;
        end;
      end;
    end;
  end;
end;
//004B2A6C

function TEnvirnoment.GetNextPosition(sX, sY, nDir, nFlag: Integer; var snx:
  Integer; var sny: Integer): Boolean;
begin
  snx := sX;
  sny := sY;
  case nDir of
    DR_UP: if sny > nFlag - 1 then
        Dec(sny, nFlag);
    DR_DOWN: if sny < (m_nHeight - nFlag) then
        Inc(sny, nFlag);
    DR_LEFT: if snx > nFlag - 1 then
        Dec(snx, nFlag);
    DR_RIGHT: if snx < (m_nWidth - nFlag) then
        Inc(snx, nFlag);
    DR_UPLEFT:
      begin
        if (snx > nFlag - 1) and (sny > nFlag - 1) then
        begin
          Dec(snx, nFlag);
          Dec(sny, nFlag);
        end;
      end;
    DR_UPRIGHT:
      begin                                                 //004B2B77
        if (snx > nFlag - 1) and (sny < (m_nHeight - nFlag)) then
        begin
          Inc(snx, nFlag);
          Dec(sny, nFlag);
        end;
      end;
    DR_DOWNLEFT:
      begin                                                 //004B2BAC
        if (snx < (m_nWidth - nFlag)) and (sny > nFlag - 1) then
        begin
          Dec(snx, nFlag);
          Inc(sny, nFlag);
        end;
      end;
    DR_DOWNRIGHT:
      begin
        if (snx < (m_nWidth - nFlag)) and (sny < (m_nHeight - nFlag)) then
        begin
          Inc(snx, nFlag);
          Inc(sny, nFlag);
        end;
      end;
  end;
  if (snx = sX) and (sny = sY) then
    Result := False
  else
    Result := True;

end;

function TEnvirnoment.CanSafeWalk(nX, nY: Integer): Boolean; //004B609C
var
  i                                     : Integer;
  MapCellInfo                           : pTMapCellinfo;
  OSObject                              : pTOSObject;
begin
  Result := True;
  if GetMapCellInfo(nX, nY, MapCellInfo) and (MapCellInfo.ObjList <> nil) then
  begin
    for i := MapCellInfo.ObjList.Count - 1 downto 0 do
    begin
      OSObject := MapCellInfo.ObjList.Items[i];
      if OSObject.btType = OS_EVENTOBJECT then
      begin
        if TEvent(OSObject.CellObj).m_nDamage > 0 then
          Result := False;
      end;
    end;
  end;
end;

function TEnvirnoment.ArroundDoorOpened(nX, nY: Integer): Boolean; //004B6B48
var
  i                                     : Integer;
  Door                                  : pTDoorInfo;
resourcestring
  sExceptionMsg                           =
    '[Exception] TEnvirnoment::ArroundDoorOpened ';
begin
  Result := True;
  try
    for i := 0 to m_DoorList.Count - 1 do
    begin
      Door := m_DoorList.Items[i];
      if (abs(Door.nX - nX) <= 1) and ((abs(Door.nY - nY) <= 1)) then
      begin
        if not Door.Status.boOpened then
        begin
          Result := False;
          break;
        end;
      end;
    end;
  except
    MainOutMessage(sExceptionMsg);
  end;
end;

function TEnvirnoment.GetMovingObject(nX, nY: Integer; boFlag: Boolean):
  Pointer;
//004B5838
var
  i                                     : Integer;
  MapCellInfo                           : pTMapCellinfo;

⌨️ 快捷键说明

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