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

📄 envir.pas

📁 翎风世界..传奇服务端..DELPHI源代码 包括DBServer,LogDataServer,LoginGate,LoginSrv,M2Server等..内容齐全.
💻 PAS
📖 第 1 页 / 共 3 页
字号:
                end;
              end;
            end;

            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
              Result:=False;
              Break;
            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;
                    DelObjectCount(pRemoveObject);
                  end;

                  if MapCellInfo.ObjList.Count > 0 then Continue;
                  MapCellInfo.ObjList.Free;
                  MapCellInfo.ObjList:=nil;
                  break;
                  {//Jacky 处理防止内存泄露 有待换上
                  if MapCellInfo.ObjList.Count <= 0 then begin
                    MapCellInfo.ObjList.Free;
                    MapCellInfo.ObjList:=nil;
                  end;
                  break;
                  }
                end
              end else begin
                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:=TList.Create;
      if not bo1A then begin
        New(OSObject);
        OSObject.btType    := nType;
        OSObject.CellObj   := Event;
        OSObject.dwAddTime := GetTickCount();
        MapCellInfo.ObjList.Add(OSObject);
        Result:=Event;
      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;
  sMapName     := '';
  nServerIndex := 0;
  nMinMap      := 0;
  FillChar(Flag, SizeOf(TMapFlag), #0);
  {m_nWidth     := 0;
  m_nHeight    := 0;
  m_boDARK     := False;
  m_boDAY      := False;}
  m_nMonCount  := 0;
  m_nHumCount  := 0;
  m_DoorList   := TList.Create;
  m_QuestList  := TList.Create;

  m_dwWhisperTick := 0;
end;

destructor TEnvirnoment.Destroy;
var
  I: Integer;
  MapCellInfo:pTMapCellinfo;
  OSObject:pTOSObject;
  nX,nY:Integer;
  DoorInfo:pTDoorInfo;
begin
  for nX:= 0 to Header.wWidth - 1 do begin
    for nY:= 0 to Header.wHeight - 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;
          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;
  FreeMem(MapCellArray);
  Pointer(MapCellArray):=nil;
  inherited;
end;



function TEnvirnoment.LoadMapData(sMapFile: String):Boolean;//004B54E0
var
  fHandle:Integer;
  nMapSize:Integer;
  n24,nW,nH:Integer;
  MapBuffer:pTMap;
  Point:Integer;
  Door:pTDoorInfo;
  i,j:Integer;
  MapCellinfo:pTMapCellinfo;
begin
  Result:=False;
  if FileExists(sMapFile) then begin
    fHandle:=FileOpen (sMapFile, fmOpenRead or fmShareExclusive);
    if fHandle > 0 then begin
      FileRead (fHandle, Header, SizeOf(TMapHeader));

      Initialize(Header.wWidth,Header.wHeight);
      nMapSize:=Header.wWidth * SizeOf(TMapUnitInfo) * Header.wHeight;

      MapBuffer:=AllocMem(nMapSize);
      FileRead(fHandle,MapBuffer^,nMapSize);
            j:=0;
      for nW:=0 to Header.wWidth -1 do begin
        n24:=nW * Header.wHeight;
        for nH:=0 to Header.wHeight -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);
              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);
                Door.Status.boOpened   := False;
                Door.Status.bo01       := False;
                Door.Status.n04        := 0;
                Door.Status.dwOpenTick := 0;
                Door.Status.nRefCount  := 1;
              end;
              m_DoorList.Add(Door);
            end;//004B5780
          end;
        end;//004B578C
      end;//004B5798
      //Dispose(MapBuffer);

      FreeMem(MapBuffer);

      FileClose(fHandle);
      Result:=True;
    end;//004B57B1
  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 Header.wWidth -1 do begin
        for nH:= 0 to Header.wHeight -1 do begin
          MapCellInfo:=@MapCellArray[nW * Header.wHeight + nH];
          if MapCellInfo.ObjList <> nil then begin
            MapCellInfo.ObjList.Free;
            MapCellInfo.ObjList:=nil;
          end;
        end;
      end;
      FreeMem(MapCellArray);
      Pointer(MapCellArray):=nil;
    end;//004B54AF
    Pointer(MapCellArray):=AllocMem((Header.wWidth * Header.wHeight) * SizeOf(TMapCellinfo));
  end;//004B54DB
end;

//nFlag,boFlag,Monster,Item,Quest,boGrouped
function TEnvirnoment.CreateQuest(nFlag, nValue: Integer; sMonName, sItem, sQuest: String;
  boGrouped: Boolean): Boolean; //004B6C3C
var
  MapQuest:pTMapQuestInfo;
  MapMerchant:TMerchant;
begin
  Result:=False;
  if nFlag < 0 then exit;
  New(MapQuest);
  MapQuest.nFlag:=nFlag;

⌨️ 快捷键说明

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