/// <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)); } }
/// <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); }