Example #1
0
    /// <summary>
    /// 检测该位置是否适合放置,新建摆放对象和显示可放不可放状态时使用
    /// </summary>
    public static bool CheckCanPut(CanvasCore Core, Int2 posMapGrid)
    {
        if (Core == null)
        {
            return(false);
        }
        ShipPlan P = ShipPlanDC.GetCurShipPlan();

        if (P == null)
        {
            return(false);
        }
        ShipPutInfo Info = P.GetShipBuildInfo(Core);

        if (Info == null)
        {
            return(false);
        }

        RoomGrid grid = RoomMap.FindRoomGrid(posMapGrid, XYSYS.MapGrid);

        if (grid != null)
        {
            bool result = BattleEnvironmentM.BuildInShape(grid.mPosRoomGrid);
            if (!result)
            {
                return(false);
            }
        }


        if (Core.m_type == ShipBuildType.BuildRoom)
        {
            List <Int2> AddList = Core.GetMovetoRoomGridPos(posMapGrid);
            if (Core.IsDeckRoom == false)
            {
                List <Int2> oldList = Core.GetPutRoomGridPos();
                if (Core.IsNewCreate)
                {
                    oldList.Clear();//新建连接房间没位置
                }
                //连接房判定是否可放
                bool bLinkOK = RoomMap.CheckLinkToGoldRoom(oldList, AddList, Core.IsNewCreate);
                if (bLinkOK)
                {
                    List <RoomGrid> listRoomGrid       = RoomMap.GetPutRoomGrid(Core);
                    List <RoomGrid> listMovetoRoomGrid = RoomMap.GetMovetoRoomGrid(Core, posMapGrid);
                    if (listRoomGrid.Count != listMovetoRoomGrid.Count)
                    {
                        return(false);
                    }
                    int nMoveToCount = listMovetoRoomGrid.Count;
                    int nMoveCnt     = 0;
                    for (nMoveCnt = 0; nMoveCnt < nMoveToCount; nMoveCnt++)
                    {
                        RoomGrid   roomGrid  = listMovetoRoomGrid[nMoveCnt];
                        CanvasCore buildCore = roomGrid.GetBuildRoom();
                        //所放的地方有其它的连接房或甲板房则不能临时放
                        if (buildCore.m_ID != RoomGrid.EMPTYGRIDID && buildCore.m_ID != Core.m_ID && buildCore.m_type == ShipBuildType.BuildRoom)
                        {
                            return(false);
                        }
                    }
                    return(bLinkOK);
                }
            }
            else
            {
                //甲板房放置判定
                return(RoomMap.CheckCanPutDeckBuild(Core.m_ID, AddList));
            }
        }
        else if (Core.m_type == ShipBuildType.BuildStair)
        {
            //楼梯需保证在活动范围内移动。
            Int2 Area = RoomMap.GetStairActiveArea(Info.cyMapGrid, Info.cxMapGrid);
            if (posMapGrid.Unit < Area.Layer || posMapGrid.Unit > Area.Unit)
            {
                return(false);
            }
            if (posMapGrid.Layer != Info.cyMapGrid)
            {
                return(false);
            }
            RoomMap.RemoveMapPosition(Core, RoomMap.GetPutRoomGridPosition(Core));
            RoomMap.AddMapPosition(Core, RoomMap.GetPutRoomGridPosition(Core));
            return(true);
        }
        else if (Core.m_type == ShipBuildType.Soldier)
        {
            //原占有先移除
            if (!Core.IsNewCreate)
            {
                RoomMap.RemoveMapPosition(Core, RoomMap.GetPutRoomGridPosition(Core));
            }
            //new
            bool ret = RoomMap.CheckMapPosition(RoomMap.GetMovetoRoomGridPosition(Core, posMapGrid));
            //原占有复原
            if (!Core.IsNewCreate)
            {
                RoomMap.AddMapPosition(Core, RoomMap.GetPutRoomGridPosition(Core));
            }
            return(ret);
        }
        return(false);
    }
Example #2
0
    /// <summary>
    /// 检测是否可临时放置(只要空白空间够就可以)
    /// </summary>
    public static bool CheckCanTempPut(CanvasCore Core, Int2 posMapGrid)
    {
        if (Core == null)
        {
            return(false);
        }
        ShipPlan P = ShipPlanDC.GetCurShipPlan();

        if (P == null)
        {
            return(false);
        }
        ShipPutInfo Info = P.GetShipBuildInfo(Core);

        if (Info == null)
        {
            return(false);
        }

        //是否在设计图方案区域内.
        RoomGrid grid = RoomMap.FindRoomGrid(posMapGrid, XYSYS.MapGrid);

        if (grid != null)
        {
            bool result = BattleEnvironmentM.BuildInShape(grid.mPosRoomGrid);
            if (!result)
            {
                return(false);
            }
        }


        if (Core.m_type == ShipBuildType.BuildRoom)
        {
            List <RoomGrid> listRoomGrid       = RoomMap.GetPutRoomGrid(Core);
            List <RoomGrid> listMovetoRoomGrid = RoomMap.GetMovetoRoomGrid(Core, posMapGrid);
            if (listRoomGrid.Count != listMovetoRoomGrid.Count)
            {
                return(false);
            }
            int nMoveToCount = listMovetoRoomGrid.Count;
            int nMoveCnt     = 0;
            for (nMoveCnt = 0; nMoveCnt < nMoveToCount; nMoveCnt++)
            {
                RoomGrid   roomGrid  = listMovetoRoomGrid[nMoveCnt];
                CanvasCore buildCore = roomGrid.GetBuildRoom();
                //所放的地方有其它的连接房或甲板房则不能临时放
                if (buildCore.m_ID != RoomGrid.EMPTYGRIDID && buildCore.m_ID != Core.m_ID && buildCore.m_type == ShipBuildType.BuildRoom)
                {
                    return(false);
                }
                //普通房间(非甲板房)不能放在有炮弹兵甲板上
                if (buildCore.m_ID == RoomGrid.EMPTYGRIDID)
                {
                    List <CanvasCore> childrenCore = roomGrid.GetOtherBuild();
                    foreach (CanvasCore childCore in childrenCore)
                    {
                        if (childCore.m_type == ShipBuildType.Soldier)
                        {
                            return(false);
                        }
                    }
                }
            }
            return(true);
        }
        else if (Core.m_type == ShipBuildType.BuildStair)
        {
            //楼梯需保证在活动范围内移动。
            Int2 Area = RoomMap.GetStairActiveArea(Info.cyMapGrid, Info.cxMapGrid);
            if (posMapGrid.Unit < Area.Layer || posMapGrid.Unit > Area.Unit)
            {
                return(false);
            }
            if (posMapGrid.Layer != Info.cyMapGrid)
            {
                return(false);
            }
            RoomMap.RemoveMapPosition(Core, RoomMap.GetPutRoomGridPosition(Core));
            RoomMap.AddMapPosition(Core, RoomMap.GetPutRoomGridPosition(Core));
            return(true);
        }
        else if (Core.m_type == ShipBuildType.Soldier)
        {
            //原占有先移除
            if (!Core.IsNewCreate)
            {
                RoomMap.RemoveMapPosition(Core, RoomMap.GetPutRoomGridPosition(Core));
            }
            //new
            bool ret = RoomMap.CheckMapPosition(RoomMap.GetMovetoRoomGridPosition(Core, posMapGrid));
            //原占有复原
            if (!Core.IsNewCreate)
            {
                RoomMap.AddMapPosition(Core, RoomMap.GetPutRoomGridPosition(Core));
            }
            if (!ret)
            {
                List <RoomGrid> lRoomGrid = RoomMap.GetMovetoRoomGrid(Core, posMapGrid);
                if (null != lRoomGrid && null != lRoomGrid[0])
                {
                    //所在位置是连接房则上面已经判定不能放就是不能临时放
                    if (lRoomGrid[0].GetBuildRoom().m_ID == RoomGrid.EMPTYGRIDID)
                    {
                        ret = true;
                    }
                }
            }
            return(ret);
        }
        return(false);
    }