Esempio n. 1
0
        public void MineDeploymentTest()
        {
            Player player = new Player();

            player.Name             = "GoodGuy";
            player.IsComputerPlayer = true;
            Player playerEnemy = new Player();

            playerEnemy.Name             = "BadGuy";
            playerEnemy.IsComputerPlayer = true;

            Group group1 = new Group();
            Group group2 = new Group();

            GameManager.Instance.GameData.InitAllData();
            Game game = GameManager.Instance.CreateGame(player, "test game");

            game.Players.Add(player);
            game.Players.Add(playerEnemy);
            GameManager.Instance.Game.SetAllPlayersEnemies();

            Position pos1       = new Position(60, 3, 0, 120);
            BaseUnit unitPamela = GameManager.Instance.GameData.CreateUnit(player, group1, "pamela", "Pamela", pos1, true);

            Position pos2 = new Position(60, 3.01, 500, 120);

            unitPamela.MovementOrder.AddWaypoint(new Waypoint(pos2.Clone()));
            unitPamela.SetActualSpeed(30);
            BaseUnit unitHelo = GameManager.Instance.GameData.CreateUnit(playerEnemy, group2, "sh60b", "Helo", pos2, true);

            unitHelo.SetWeaponLoad("Deploy mines");
            var wpn = unitHelo.GetSpecialWeapon(GameConstants.SpecialOrders.DropMine);

            Assert.IsNotNull(wpn, "Helo should have mine deployment weapon.");
            var unitOrder = OrderFactory.CreateMineDeploymentOrder(unitHelo.Id, pos2.GetPositionInfo(), true);
            var baseOrder = GameManager.Instance.Game.GetBaseOrderFromUnitOrder(unitOrder);

            unitHelo.Orders.Enqueue(baseOrder);
            game.IsNetworkEnabled                  = false;
            game.RealTimeCompressionFactor         = 10;
            GameManager.Instance.Game.RunGameInSec = 1;
            GameManager.Instance.Game.StartGamePlay();

            var mines = unitHelo.OwnerPlayer.Units.Where <BaseUnit>(u => u.UnitClass.UnitType == GameConstants.UnitType.Mine);

            Assert.IsTrue(mines.Count <BaseUnit>() > 0, "There is at least one mine in the game.");
            foreach (var mine in mines)
            {
                mine.ReadyInSec = 0;
            }
            var aMine = mines.First <BaseUnit>();

            Assert.IsNotNull(aMine, "Mine should be found");
            unitPamela.Position         = aMine.Position.Clone();
            unitPamela.UserDefinedSpeed = GameConstants.UnitSpeedType.Slow;
            var enemyUnits = unitHelo.OwnerPlayer.GetEnemyUnitsInAreaByUnitType(GameConstants.UnitType.SurfaceShip, aMine.Position.Coordinate, 1000);

            Assert.IsTrue(enemyUnits.Count > 0, "There should be more than one unit in area");
            Assert.IsTrue(aMine.IsMarkedForDeletion == false, "Mine should not be marked for deletion.");
            //GameManager.Instance.Game.IsGameLoopStarted = false;
            //GameManager.Instance.Game.RunGameInSec = 10;
            //GameManager.Instance.Game.StartGamePlay();
            //mines = unitHelo.OwnerPlayer.Units.Where<BaseUnit>(u => u.UnitClass.UnitType == GameConstants.UnitType.Mine);
        }