Exemplo n.º 1
0
 /// <summary>
 /// 获取移动到目标位置所占领的房间
 /// </summary>
 /// <param name="TargetPos">目的位置</param>
 public static List <RoomGrid> GetMovetoRoomGrid(CanvasCore core, Int2 TargetPos)
 {
     if (core.Data != null)
     {
         List <RoomGrid> l     = new List <RoomGrid>();
         ShapeType       shape = core.GetPutRoomShape();
         if (shape != null)
         {
             Dictionary <Int2, ShapeValue> lshape = shape.GetShapeData(TargetPos);
             foreach (Int2 Pos in lshape.Keys)
             {
                 RoomGrid r = RoomMap.FindRoomGrid(Pos, XYSYS.RoomGrid);
                 if (r != null)
                 {
                     l.Add(r);
                 }
             }
         }
         else
         {
             RoomGrid r = RoomMap.FindRoomGrid(TargetPos, XYSYS.MapGrid);
             if (r != null)
             {
                 l.Add(r);
             }
         }
         return(l);
     }
     return(new List <RoomGrid>());
 }
Exemplo n.º 2
0
    public Int2 GetMousePosGrid()
    {
        Vector3  v3TouchScreenPos = new Vector3(Input.mousePosition.x, Input.mousePosition.y, -Camera.main.transform.position.z);
        Vector3  v3TouchWorldPos  = Camera.main.ScreenToWorldPoint(v3TouchScreenPos);
        Vector3  v3Local          = BattleEnvironmentM.World2LocalPos(v3TouchWorldPos);
        RoomGrid roomGrid         = RoomMap.FindRoomGrid(v3Local);

        if (roomGrid == null)
        {
            return(new Int2(-1, -1));
        }
        return(roomGrid.mPosRoomGrid);
    }
Exemplo n.º 3
0
    /// <summary>
    /// 获取局部坐标
    /// </summary>
    public static Vector3 GetRoomGridLocalPos(Int2 posMapGrid)
    {
        RoomGrid r = RoomMap.FindRoomGrid(posMapGrid, XYSYS.MapGrid);

        if (r != null)
        {
            Vector3 v = r.LocalPos;
            v.x += (posMapGrid.Unit % MapGrid.m_UnitRoomGridNum) * MapGrid.m_width;
            return(v);
        }
        else
        {
            return(Vector3.zero);
        }
    }
Exemplo n.º 4
0
    /// <summary>
    /// 检测格子是否是房间或者甲板
    /// </summary>
    public static bool CheckBuildOrDeckRoom(Vector3 MousePos)
    {
        Vector3  pos = U3DUtil.SetZ(MousePos, -Camera.main.transform.position.z);
        Vector3  m_v3TouchWorldPos = Camera.main.ScreenToWorldPoint(pos);
        Vector3  gridPos           = BattleEnvironmentM.World2LocalPos(m_v3TouchWorldPos);
        RoomGrid roomGrid          = RoomMap.FindRoomGrid(gridPos);

        if (roomGrid == null)
        {
            return(false);
        }
        Int2 grid = roomGrid.mPosRoomGrid;

        return(CheckBuildOrDeckRoom(grid));
    }
Exemplo n.º 5
0
    /// <summary>
    /// 获取具体对象的局部坐标
    /// </summary>
    public static Vector3 GetShipBuildLocalPos(Int2 posMapGrid, ShipBuildType Type)
    {
        RoomGrid r = RoomMap.FindRoomGrid(posMapGrid, XYSYS.MapGrid);

        if (r != null)
        {
            Vector3 v = r.LocalPos;
            if (Type == ShipBuildType.Soldier)
            {
                v.x += 3 * MapGrid.m_width;
            }
            return(v);
        }
        else
        {
            return(Vector3.zero);
        }
    }
Exemplo n.º 6
0
 /// <summary>
 /// 判断移动到目标位置,是否有出界
 /// </summary>
 /// <param name="posMapGrid">目的位置</param>
 public static bool  CheckAllInMap(CanvasCore core, Int2 posMapGrid)
 {
     if (core.Data != null)
     {
         ShapeType shape = core.GetPutRoomShape();
         if (shape != null)
         {
             Dictionary <Int2, ShapeValue> lshape = shape.GetShapeData(posMapGrid);
             foreach (Int2 posRoomGrid in lshape.Keys)
             {
                 RoomGrid r = RoomMap.FindRoomGrid(posRoomGrid, XYSYS.RoomGrid);
                 if (r == null)
                 {
                     return(false);
                 }
             }
         }
     }
     return(true);
 }
Exemplo n.º 7
0
    /// <summary>
    /// 获取移动到目标位置所占领的房间位置
    /// </summary>
    /// <param name="posMapGrid">目的位置</param>
    public static Dictionary <RoomGrid, int> GetMovetoRoomGridPosition(CanvasCore core, Int2 posMapGrid)
    {
        Dictionary <RoomGrid, int> l = new Dictionary <RoomGrid, int>();

        if (core.Data == null)
        {
            return(l);
        }
        ShapeType shape = core.GetPutRoomShape();

        if (core.Data.type == (int)ShipBuildType.Soldier)
        {
            RoomGrid r = RoomMap.FindRoomGrid(posMapGrid, XYSYS.MapGrid);
            if (r != null)
            {
                l.Add(r, (int)PutPosition.Soldier);
            }
        }
        else if (core.Data.type == (int)ShipBuildType.BuildStair)
        {
            RoomGrid r = RoomMap.FindRoomGrid(posMapGrid, XYSYS.MapGrid);
            if (r != null)
            {
                l.Add(r, (int)PutPosition.Stair);
            }
        }
        else if (shape != null)
        {
            Dictionary <Int2, ShapeValue> lshape = shape.GetShapeData(posMapGrid);
            foreach (Int2 Pos in lshape.Keys)
            {
                int      position = lshape[Pos].Position;
                RoomGrid r        = RoomMap.FindRoomGrid(Pos, XYSYS.RoomGrid);
                if (r != null)
                {
                    l.Add(r, position);
                }
            }
        }
        return(l);
    }
Exemplo n.º 8
0
    /// <summary>
    /// 检测传送门的传送点是否合法
    /// </summary>
    /// <returns></returns>
    static bool CheckTransgatePoint(Int2 grid)
    {
        RoomGrid roomGrid = RoomMap.FindRoomGrid(grid, XYSYS.MapGrid);

        return(RoomMap.CheckRoomGridInBoat(roomGrid));
    }
Exemplo n.º 9
0
    void OnMouseDown()
    {
        if (PutCanvasM.CanOperate == false)
        {
            return;
        }

        RaycastHit hit;

        if (WndManager.IsHitNGUI(out hit))//当点击到UI时不做处理
        {
            return;
        }
        if (Input.touchCount >= 2)
        {
            return;
        }
        m_bMouseDown       = true;
        m_bLongTouch       = false;
        m_bTouchMoveChange = true;
        m_fMouseDownTime   = Time.time;
        m_vtotalmouseDelta = Vector2.zero;
        m_vlastFirstTouch  = GetTouchPos(0);
        m_isDrag           = false;
        if (SystemInfo.deviceType == DeviceType.Desktop)
        {
            m_v3MouseTouchDown = Input.mousePosition;
        }
        else
        {
            m_v3MouseTouchDown = Input.GetTouch(0).position;
        }

        //获取按下时画布格子
        Vector3 m_v3TouchScreenPos = new Vector3(m_v3MouseTouchDown.x, m_v3MouseTouchDown.y, -Camera.main.transform.position.z);
        Vector3 m_v3TouchWorldPos  = Camera.main.ScreenToWorldPoint(m_v3TouchScreenPos);
        Vector3 v3dLocalPos        = BattleEnvironmentM.World2LocalPos(m_v3TouchWorldPos);

        m_roomGridTouchDown = RoomMap.FindRoomGrid(v3dLocalPos);
        if (m_roomGridTouchDown == null)
        {
            return;
        }
        m_curClickType = RoomMap.PickupShipBuildType(m_roomGridTouchDown, v3dLocalPos, m_roomGridTouchDown.mPosRoomGrid.Layer);

        CanvasCore buildRoomCoreTouchDown = m_roomGridTouchDown.GetBuildRoom();

        if (TouchMove.g_bSetParaing == true)
        {
            return;
        }

        TouchMove curTouchMove = TouchMoveManager.GetCurTouchMove();

        if (null != curTouchMove)
        {
            //如果当前选中的是房间,新选中的不管是什么都不做变更
            //如果当前选中的不是房间,但是新选中的对象和当前选中的一样则也不变量。
            if (curTouchMove.IsContainsRoomGrid(m_roomGridTouchDown))
            {
                TouchMove selNewTouchMov = PutCanvasM.GetTouchMoveByRoomGrid(m_roomGridTouchDown, m_curClickType);
                if (curTouchMove.MyCore().m_type == ShipBuildType.BuildRoom ||
                    selNewTouchMov != null && selNewTouchMov == curTouchMove)
                {
                    curTouchMove.PlayEditSelectAnimationEnd();                                     //恢复上个房间内陷阱/角色 动画
                    curTouchMove.OnMouseDown();
                    m_bTouchMoveChange = false;
                }
            }
            PutCanvasM.ClearNoLinkList();
        }
        else
        {
            //判断选中物件是否在上次保存失败的物件上,如果是则直接选择
            bool bInNoLinkList = false;
            if (buildRoomCoreTouchDown != null)
            {
                TouchMove selNewTouchMov = PutCanvasM.GetTouchMoveByCore(buildRoomCoreTouchDown);
                if (null == selNewTouchMov)
                {
                    List <CanvasCore> childCores = m_roomGridTouchDown.GetOtherBuild();
                    for (int i = 0; i < childCores.Count; i++)
                    {
                        selNewTouchMov = PutCanvasM.GetTouchMoveByCore(childCores[i]);
                        break;
                    }
                }
                if (null != selNewTouchMov && PutCanvasM.NoLinkListContain(selNewTouchMov.MyCore()))
                {
                    PutCanvasM.ClearNoLinkList();
                    TouchMoveManager.SetCurTouchMove(selNewTouchMov);
                    selNewTouchMov.PlayEditSelectAnimationEnd();                     //恢复上个房间内陷阱/角色 动画
                    selNewTouchMov.OnMouseDown();
                    m_bTouchMoveChange = false;
                    bInNoLinkList      = true;
                }
            }
            if (bInNoLinkList == false)
            {
                PutCanvasM.ClearNoLinkList();
            }
        }
    }
Exemplo n.º 10
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);
    }
Exemplo n.º 11
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);
    }