public void SplitAndJoinGroups() { Player player = new Player(); player.Name = "GoodGuy"; player.IsComputerPlayer = true; GameManager.Instance.GameData.InitAllData(); Game game = GameManager.Instance.CreateGame(player, "test game"); GameManager.Instance.GameData.LoadGameScenario("test", game); Group group = new Group(); BaseUnit unitMain = player.GetUnitById("tag:main"); Assert.IsNotNull(unitMain, "Unit should not be null"); BaseUnit unit2 = GameManager.Instance.GameData.CreateUnit(player, group, "arleighburke", "Bulke", unitMain.Position.Offset(new PositionOffset(3000, 3000)), true); BaseUnit unit3 = GameManager.Instance.GameData.CreateUnit(player, group, "arleighburke", "Brande", unitMain.Position.Offset(new PositionOffset(3000, 2800)), true); unit2.SetActualSpeed(20); unit3.SetActualSpeed(20); group.AutoAssignUnitsToFormation(); //TEST: Some units in a group should be joined into an existing group. Group groupSag = player.GetGroupById(unitMain.GroupId); Assert.IsNotNull(groupSag, "groupSag should not be null"); UnitOrder order = new UnitOrder(TTG.NavalWar.NWComms.GameConstants.UnitOrderType.JoinGroups, unit2.Id); order.SecondId = groupSag.Id; player.HandleMessageFromClient(order); //unit2.JoinNewGroupAllUnits(groupSag.Id); Assert.IsTrue(unit2.Orders.Count > 0, "There should be at least 1 unit orders for Unit2."); unit2.ExecuteOrders(); Assert.IsTrue(unit2.GroupId == groupSag.Id, "Unit2 should be member of new group."); //TEST: Split some members of a group out into a separate, new group var unitList = new List <string>(); unitList.Add(unit2.Id); unitList.Add(unit3.Id); groupSag.SplitGroup(unitList); Assert.IsTrue(unit2.GroupId != groupSag.Id, "Unit2 should no longer be member of GroupSag."); var newGroup = player.GetGroupById(unit2.GroupId); Assert.IsNotNull(newGroup, "New group should not be null."); var joinUnitOrder = OrderFactory.CreateJoinGroupOrder(groupSag.Id, unit2.Id, unitList); var joinBaseOrder = GameManager.Instance.Game.GetBaseOrderFromUnitOrder(joinUnitOrder); Assert.IsNotNull(joinBaseOrder, "Join BaseOrder should not be null."); Assert.IsTrue(joinBaseOrder.SecondId == groupSag.Id, "Group sag should be the group to join"); unit2.JoinNewGroup(joinBaseOrder); Assert.IsTrue(unit2.GroupId == groupSag.Id, "Unit2 should again be a member of GroupSag."); Assert.IsTrue(unit3.GroupId == groupSag.Id, "Unit3 should again be a member of GroupSag."); //TEST: Units that are not members of any group should join an existing group groupSag.RemoveUnit(unit2); Assert.IsTrue(string.IsNullOrEmpty(unit2.GroupId), "Unit2 should no longer be member of ANY group."); unitList = new List <string>(); unitList.Add(unit2.Id); joinUnitOrder = OrderFactory.CreateJoinGroupOrder(groupSag.Id, unit2.Id, unitList); joinBaseOrder = GameManager.Instance.Game.GetBaseOrderFromUnitOrder(joinUnitOrder); Assert.IsNotNull(joinBaseOrder, "Join BaseOrder should not be null."); unit2.JoinNewGroup(joinBaseOrder); Assert.IsTrue(unit2.GroupId == groupSag.Id, "Unit2 should again be a member of GroupSag."); //TEST: Units that are not members of any group should join a NEW group groupSag.RemoveUnit(unit2); Assert.IsTrue(string.IsNullOrEmpty(unit2.GroupId), "Unit2 should no longer be member of ANY group."); unitList = new List <string>(); unitList.Add(unit2.Id); joinUnitOrder = OrderFactory.CreateJoinGroupOrder(string.Empty, unit2.Id, unitList); joinBaseOrder = GameManager.Instance.Game.GetBaseOrderFromUnitOrder(joinUnitOrder); Assert.IsNotNull(joinBaseOrder, "Join BaseOrder should not be null."); unit2.JoinNewGroup(joinBaseOrder); Assert.IsTrue(!string.IsNullOrEmpty(unit2.GroupId), "Unit2 should now be a member of NEW group."); Assert.IsTrue(unit2.GroupId != groupSag.Id, "Unit2 should no longer be member of GroupSag."); }