Esempio n. 1
0
    /// <summary>
    /// 加入一个房间。从仓库中加载。或加载方案
    /// </summary>
    /// <param name="Core">核心结构</param>
    /// <param name="TargetPos">格子坐标</param>
    public static void AddNewCore(CanvasCore Core, Int2 TargetPos)
    {
        if (Core == null)
        {
            return;
        }
        ShipPlan P = ShipPlanDC.GetCurShipPlan();

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

        if (Info == null)
        {
            return;
        }

        if (Core.IsNewCreate)
        {
            Info.SetBuildPostion(TargetPos);
            P.AddShipBuildInfo(Info, Core.m_type);
            TouchMoveManager.MoveToShip(Core);
            Core.IsNewCreate = false;
        }
        //
        if (Core.m_type == ShipBuildType.BuildRoom)
        {
            if (Core.IsDeckRoom == false)
            {
                ShapeType Shape = Info.GetPutRoomShape();
                if (Shape == null)
                {
                    return;
                }
                RoomMap.OpenCanvans(Shape.GetShapeData(new Int2(Info.cxMapGrid, Info.cyMapGrid)), Core.m_ID);
                //设置甲板区域
                RoomMap.UpdateDeckRoomGrid();
                //更新金库房间
                if (Info.IsGoldBuild() == true)
                {
                    RoomMap.UpdateGoldRoomGrid(Core.GetPutRoomGridPos());
                }
            }
            else
            {
                RoomMap.AddDeckBuild(Core.m_ID, Core.GetPutRoomGridPos());
            }
        }
        else
        {
            RoomMap.AddMapPosition(Core, RoomMap.GetPutRoomGridPosition(Core));
        }
    }
Esempio n. 2
0
    /// <summary>
    /// 移动一个房间
    /// </summary>
    public static bool MoveBuildRoom(CanvasCore Core, Int2 TargetPos)
    {
        if (Core == null || Core.IsNewCreate)
        {
            return(false);
        }
        ShipPlan P = ShipPlanDC.GetCurShipPlan();

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

        if (Info == null)
        {
            return(false);
        }
        if (TargetPos.Unit == Info.cxMapGrid && TargetPos.Layer == Info.cyMapGrid)
        {
            return(false);
        }

        if (Core.m_type == ShipBuildType.BuildRoom)
        {
            if (Core.IsDeckRoom == false)
            {
                //先移动子对象数据。
                List <CanvasCore> l = PutCanvasM.GetChildByCore(Core);
                foreach (CanvasCore c in l)
                {
                    Int2        move = new  Int2(TargetPos.Unit - Info.cxMapGrid, TargetPos.Layer - Info.cyMapGrid);
                    ShipPutInfo II   = P.GetShipBuildInfo(c);
                    if (II != null)
                    {
                        II.cxMapGrid += move.Unit;
                        II.cyMapGrid += move.Layer;
                    }
                }
                RoomMap.MoveCanvans(RoomMap.GetPutRoomGrid(Core), RoomMap.GetMovetoRoomGrid(Core, TargetPos));
                //设置甲板区域
                RoomMap.UpdateDeckRoomGrid();
                //更新金库房间
                if (Info.IsGoldBuild() == true)
                {
                    RoomMap.UpdateGoldRoomGrid(Core.GetMovetoRoomGridPos(TargetPos));
                }
            }
            else
            {
                List <Int2> lDeck = Core.GetPutRoomGridPos();
                RoomMap.RemoveDeckBuild(lDeck);
                lDeck = Core.GetMovetoRoomGridPos(TargetPos);
                RoomMap.AddDeckBuild(Core.m_ID, lDeck);
            }
        }
        else
        {
            RoomMap.RemoveMapPosition(Core, RoomMap.GetPutRoomGridPosition(Core));
            RoomMap.AddMapPosition(Core, RoomMap.GetMovetoRoomGridPosition(Core, TargetPos));
        }
        Info.SetBuildPostion(TargetPos);
        return(true);
    }
Esempio n. 3
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);
    }
Esempio n. 4
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);
    }