Exemple #1
0
    /// <summary>
    /// 调换位置
    /// </summary>
    public static bool ExchangeRoom(CanvasCore Core1, Int2 tomapGrid1, CanvasCore Core2, Int2 tomapGrid2)
    {
        if (Core1 == null || Core1.IsNewCreate)
        {
            return(false);
        }
        if (Core2 == null || Core2.IsNewCreate)
        {
            return(false);
        }
        if (Core1.m_type != ShipBuildType.BuildRoom)
        {
            return(false);
        }
        if (Core2.m_type != ShipBuildType.BuildRoom)
        {
            return(false);
        }
        if (Core1.IsDeckRoom != Core2.IsDeckRoom)
        {
            return(false);
        }
        ShipPlan P = ShipPlanDC.GetCurShipPlan();

        if (P == null)
        {
            return(false);
        }
        //
        ShipPutInfo Info1 = P.GetShipBuildInfo(Core1);

        if (Info1 == null)
        {
            return(false);
        }
        ShipPutInfo Info2 = P.GetShipBuildInfo(Core2);

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

        Int2 Pos1 = new Int2(Info1.cxMapGrid, Info1.cyMapGrid);
        Int2 Pos2 = new Int2(Info2.cxMapGrid, Info2.cyMapGrid);
        //先子对象互换

        //先移动子对象数据。
        //core1 --> core2
        List <CanvasCore> l = PutCanvasM.GetChildByCore(Core1);

        foreach (CanvasCore c in l)
        {
            Int2        move = new  Int2(tomapGrid1.Unit - Info1.cxMapGrid, tomapGrid1.Layer - Info1.cyMapGrid);
            ShipPutInfo II   = P.GetShipBuildInfo(c);
            if (II != null)
            {
                II.cxMapGrid += move.Unit;
                II.cyMapGrid += move.Layer;
            }
        }
        //core2 --> core1
        l = PutCanvasM.GetChildByCore(Core2);
        foreach (CanvasCore c in l)
        {
            Int2        move = new  Int2(tomapGrid2.Unit - Info2.cxMapGrid, tomapGrid2.Layer - Info2.cyMapGrid);
            ShipPutInfo II   = P.GetShipBuildInfo(c);
            if (II != null)
            {
                II.cxMapGrid += move.Unit;
                II.cyMapGrid += move.Layer;
            }
        }
        //房间数据互相置换
        RoomMap.ExchangeCanvans(RoomMap.GetPutRoomGrid(Core1), RoomMap.GetMovetoRoomGrid(Core1, tomapGrid1), RoomMap.GetPutRoomGrid(Core2), RoomMap.GetMovetoRoomGrid(Core2, tomapGrid2));

        //更新金库房间
        if (Info1.IsGoldBuild() == true)
        {
            RoomMap.UpdateGoldRoomGrid(Core1.GetMovetoRoomGridPos(tomapGrid1));
        }
        if (Info2.IsGoldBuild() == true)
        {
            RoomMap.UpdateGoldRoomGrid(Core2.GetMovetoRoomGridPos(tomapGrid2));
        }

        //更新数据
        Info1.SetBuildPostion(tomapGrid1);
        Info2.SetBuildPostion(tomapGrid2);
        return(true);
    }