public void UpdateMyGridColor(bool bCanPutTemp = true) { List <Int2> moveToGrids = m_Core.GetMovetoRoomGridPos(m_posMapGrid); if (!bCanPutTemp) { TouchMoveManager.SetGridsBgStates(moveToGrids, CanvasUnitState.CanntPut, true); return; } if (PutCanvasM.CheckCanPut(m_Core, m_posMapGrid)) { TouchMoveManager.SetGridsBgStates(moveToGrids, CanvasUnitState.CanPut, true); } else { TouchMoveManager.SetGridsBgStates(moveToGrids, CanvasUnitState.CanntPut, true); } if (null != m_ExchangeTouch) { moveToGrids = m_ExchangeTouch.MyCore().GetMovetoRoomGridPos(m_orgPosMapGrid); if (PutCanvasM.CheckCanPut(m_ExchangeTouch.MyCore(), m_orgPosMapGrid)) { TouchMoveManager.SetGridsBgStates(moveToGrids, CanvasUnitState.CanPut, false); } else { TouchMoveManager.SetGridsBgStates(moveToGrids, CanvasUnitState.CanntPut, false); } } }
/// <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); }
/// <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); }
/// <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); }