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

📄 envir1.pas

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

function TEnvirnoment.AllowStdItems(sItemName: string): Boolean; //是否允许使用物品
var
  I: Integer;
begin
  Result := True;
  if (not m_boUnAllowStdItems) or (m_UnAllowStdItemsList = nil) then Exit;
  m_UnAllowStdItemsList.Lock;
  try
    for I := 0 to m_UnAllowStdItemsList.Count - 1 do begin
      if CompareText(m_UnAllowStdItemsList.Strings[I], sItemName) = 0 then begin
        Result := False;
        break;
      end;
    end;
  finally
    m_UnAllowStdItemsList.UnLock;
  end;
end;

function TEnvirnoment.AllowStdItems(nItemIdx: Integer): Boolean; //是否允许使用物品
var
  I: Integer;
begin
  Result := True;
  if (not m_boUnAllowStdItems) or (m_UnAllowStdItemsList = nil) then Exit;
  m_UnAllowStdItemsList.Lock;
  try
    for I := 0 to m_UnAllowStdItemsList.Count - 1 do begin
      if Integer(m_UnAllowStdItemsList.Objects[I]) = nItemIdx then begin
        Result := False;
        break;
      end;
    end;
  finally
    m_UnAllowStdItemsList.UnLock;
  end;
end;

procedure TEnvirnoment.AddDoorToMap();
var
  I: Integer;
  Door: pTDoorInfo;
begin
  for I := 0 to m_DoorList.Count - 1 do begin
    Door := m_DoorList.Items[I];
    AddToMap(Door.nX, Door.nY, OS_DOOR, TObject(Door));
  end;
end;

function TEnvirnoment.GetMapCellInfo(nX, nY: Integer; var MapCellInfo: pTMapCellinfo): Boolean; //004B57D8
begin
  try
    if (nX >= 0) and (nX < m_nWidth) and (nY >= 0) and (nY < m_nHeight) then begin
      MapCellInfo := @MapCellArray[nX * m_nHeight + nY];
      Result := True;
    end else begin
      Result := False;
    end;
  except
    Result := False;
  end;
end;

function TEnvirnoment.MoveToMovingObject(nCX, nCY: Integer; Cert: TObject; nX, nY: Integer; boFlag: Boolean): Integer; //004B612C
var
  MapCellInfo: pTMapCellinfo;
  BaseObject: TBaseObject;
  OSObject: pTOSObject;
  I: Integer;
  bo1A: Boolean;
  nCheckCode: Integer;
resourcestring
  sExceptionMsg = '[Exception] TEnvirnoment::MoveToMovingObject';
label
  Loop, Over;
begin
  Result := 0;
  try
    bo1A := True;
    nCheckCode := 0;
    if not boFlag and GetMapCellInfo(nX, nY, MapCellInfo) then begin
      nCheckCode := 1;
      if (MapCellInfo <> nil) and (not MapCellInfo.boListDisPose) then begin
        if MapCellInfo.chFlag = 0 then begin
          if (MapCellInfo.ObjList <> nil) and (MapCellInfo.ObjList.Count > 0) then begin
            nCheckCode := 2;
            for I := 0 to MapCellInfo.ObjList.Count - 1 do begin
              nCheckCode := 3;
              OSObject := pTOSObject(MapCellInfo.ObjList.Items[I]);
              nCheckCode := 4;
              if (OSObject <> nil) and (not OSObject.boObjectDisPose) then begin
                if OSObject.btType = OS_MOVINGOBJECT then begin
                  if OSObject.CellObj <> nil then begin
                    BaseObject := TBaseObject(pTOSObject(OSObject.CellObj));
                    nCheckCode := 5;
                    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
                        bo1A := False;
                        break;
                      end;
                    end;
                  end;
                end;
              end;
            end;
          end;
        end else begin //   if MapCellInfo.chFlag = 0 then begin
          Result := -1;
          bo1A := False;
        end;
      end;
    end;
    if bo1A then begin
      if GetMapCellInfo(nX, nY, MapCellInfo) and (MapCellInfo <> nil) and (MapCellInfo.chFlag <> 0) and (not MapCellInfo.boListDisPose) then begin
        Result := -1;
      end else begin
        if GetMapCellInfo(nCX, nCY, MapCellInfo) and (MapCellInfo <> nil) and (MapCellInfo.ObjList <> nil) and (not MapCellInfo.boListDisPose) then begin
          I := 0;
          while (True) do begin
            if MapCellInfo.ObjList.Count <= I then break;
            if MapCellInfo.ObjList.Count <= 0 then break;
            OSObject := pTOSObject(MapCellInfo.ObjList.Items[I]);
            if (OSObject <> nil) and (not OSObject.boObjectDisPose) then begin
              nCheckCode := 6;
              if OSObject.btType = OS_MOVINGOBJECT then begin
                nCheckCode := 7;
                if (TBaseObject(OSObject.CellObj) <> nil) and (TBaseObject(OSObject.CellObj) = TBaseObject(Cert)) and (TBaseObject(Cert) <> nil) then begin
                  if not OSObject.boObjectDisPose then begin
                    OSObject.boObjectDisPose := True;
                    try
                      DisPose(OSObject);
                    except
                      OSObject := nil;
                    end;
                  end;
                  MapCellInfo.ObjList.Delete(I);
                  if MapCellInfo.ObjList.Count > 0 then Continue;
                  nCheckCode := 11;
                  if not MapCellInfo.boListDisPose then begin
                    MapCellInfo.boListDisPose := True;
                    MapCellInfo.ObjList.Free;
                    MapCellInfo.ObjList := nil;
                    nCheckCode := 12;
                  end;
                  break;
                end;
              end;
            end;
            Inc(I);
          end;
        end;
        nCheckCode := 13;
        if GetMapCellInfo(nX, nY, MapCellInfo) then begin
          if (MapCellInfo.ObjList = nil) or (MapCellInfo.boListDisPose) then begin
            MapCellInfo.ObjList := TList.Create;
            MapCellInfo.boListDisPose := False;
          end;
          New(OSObject);
          OSObject.btType := OS_MOVINGOBJECT;
          OSObject.CellObj := Cert;
          OSObject.dwAddTime := GetTickCount;
          OSObject.boObjectDisPose := False;
          MapCellInfo.ObjList.Add(OSObject);
          Result := 1;
        end;
      end;
    end;
  except
    on E: Exception do begin
      {MainOutMessage(sExceptionMsg + ' '+IntToStr(nCheckCode));
      MainOutMessage(E.Message);}
    end;
  end;
  //  pMapCellInfo = GetMapCellInfo(nX, nY);
end;
//======================================================================
//检查地图指定座标是否可以移动
//boFlag  如果为TRUE 则忽略座标上是否有角色
//返回值 True 为可以移动,False 为不可以移动
//======================================================================
function TEnvirnoment.CanWalk(nX, nY: Integer; boFlag: Boolean): Boolean; //004B5ED0
var
  MapCellInfo: pTMapCellinfo;
  OSObject: pTOSObject;
  BaseObject: TBaseObject;
  I: Integer;
begin
  Result := False;
  if GetMapCellInfo(nX, nY, MapCellInfo) and (MapCellInfo.chFlag = 0) then begin
    Result := True;
    if not boFlag and (MapCellInfo.ObjList <> nil) and (not MapCellInfo.boListDisPose) and (MapCellInfo.ObjList.Count > 0) then begin
      for I := 0 to MapCellInfo.ObjList.Count - 1 do begin
        OSObject := MapCellInfo.ObjList.Items[I];
        if (OSObject <> nil) and (not OSObject.boObjectDisPose) then begin
          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
                Result := False;
                break;
              end;
            end;
          end;
        end;
      end;
    end;
  end;
end;

//======================================================================
//检查地图指定座标是否可以移动
//boFlag  如果为TRUE 则忽略座标上是否有角色
//返回值 True 为可以移动,False 为不可以移动
//======================================================================
function TEnvirnoment.CanWalkOfItem(nX, nY: Integer; boFlag, boItem: Boolean): Boolean;
var
  MapCellInfo: pTMapCellinfo;
  OSObject: pTOSObject;
  BaseObject: TBaseObject;
  I: Integer;
begin
  Result := True;
  if GetMapCellInfo(nX, nY, MapCellInfo) and (MapCellInfo.chFlag = 0) then begin
    if (MapCellInfo.ObjList <> nil) and (MapCellInfo.ObjList.Count > 0) and (not MapCellInfo.boListDisPose) then begin
      for I := 0 to MapCellInfo.ObjList.Count - 1 do begin
        OSObject := MapCellInfo.ObjList.Items[I];
        if (OSObject <> nil) and (not OSObject.boObjectDisPose) then begin
          if not boFlag and (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
                Result := False;
                break;
              end;
            end;
          end;
        end;
        if not boItem and (OSObject.btType = OS_ITEMOBJECT) then begin
          Result := False;
          break;
        end;
      end;
    end;
  end;
end;

function TEnvirnoment.CanWalkEx(nX, nY: Integer; boFlag: Boolean): Boolean;
var
  MapCellInfo: pTMapCellinfo;
  OSObject: pTOSObject;
  BaseObject: TBaseObject;
  I: Integer;
  Castle: TUserCastle;
begin
  Result := False;
  if GetMapCellInfo(nX, nY, MapCellInfo) and (MapCellInfo.chFlag = 0) then begin
    Result := True;
    if not boFlag and (MapCellInfo.ObjList <> nil) and (not MapCellInfo.boListDisPose) and (MapCellInfo.ObjList.Count > 0) then begin
      for I := 0 to MapCellInfo.ObjList.Count - 1 do begin
        OSObject := MapCellInfo.ObjList.Items[I];
        if (OSObject <> nil) and (not OSObject.boObjectDisPose) then begin
          if OSObject.btType = OS_MOVINGOBJECT then begin
            BaseObject := TBaseObject(OSObject.CellObj);
            if BaseObject <> nil then begin
              {//01/25 多城堡 控制
              if g_Config.boWarDisHumRun and UserCastle.m_boUnderWar and
                UserCastle.InCastleWarArea(BaseObject.m_PEnvir,BaseObject.m_nCurrX,BaseObject.m_nCurrY) then begin
              }
              Castle := g_CastleManager.InCastleWarArea(BaseObject);
              if g_Config.boWarDisHumRun and (Castle <> nil) and (Castle.m_boUnderWar) then begin
              end else begin
                if BaseObject.m_btRaceServer = RC_PLAYOBJECT then begin
                  if g_Config.boRUNHUMAN or m_boRUNHUMAN then Continue;
                end else begin
                  if BaseObject.m_btRaceServer = RC_NPC then begin
                    if g_Config.boRunNpc then Continue;
                  end else begin
                    if BaseObject.m_btRaceServer in [RC_GUARD, RC_ARCHERGUARD] then begin
                      if g_Config.boRunGuard then Continue;
                    end else begin
                      if BaseObject.m_btRaceServer <> 55 then begin //不允许穿过练功师
                        if g_Config.boRUNMON or m_boRUNMON then Continue;
                      end;
                    end;
                  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;
          end;
        end;
      end;
    end;
  end;
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;

function TMapManager.GetMainMap(Envir: TEnvirnoment): string;
begin
  if Envir.m_boMainMap then Result := Envir.sMainMapName
  else Result := Envir.sMapName;
end;

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

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

function TEnvirnoment.DeleteFromMap(nX, nY: Integer; btType: Byte;
  pRemoveObject: TObject): Integer;
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) and (not MapCellInfo.boListDisPose) and (MapCellInfo.ObjList.Count > 0) then begin
            n18 := 0;
            while (True) do begin
              if MapCellInfo.ObjList.Count <= n18 then break;
              if MapCellInfo.ObjList.Count <= 0 then break;
              OSObject := pTOSObject(MapCellInfo.ObjList.Items[n18]);
              if (OSObject <> nil) and (not OSObject.boObjectDisPose) then begin
                if (OSObject.btType = btType) and (OSObject.CellObj = pRemoveObject) then begin
                  if not OSObject.boObjectDisPose then begin
                    OSObject.boObjectDisPose := True;
                    try
                      DisPose(OSObject);
                    except
                      OSObject := nil;
                    end;
                  end;
                  MapCellInfo.ObjList.Delete(n18);
                  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 Dec(m_nHumCount);
                    if btRaceServer >= RC_ANIMAL then Dec(m_nMonCount);

⌨️ 快捷键说明

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