Ejemplo n.º 1
0
        public void CheckWeaponStores()
        {
            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("small", game);
            Player otherPlayer = player.Enemies[0];

            Assert.IsTrue(game.Players.Count == 2, "There should be two players in game.");
            //Assert.IsTrue(otherPlayer.Units.Count == 15, "Player 1 should have 15 units.");
            game.IsGamePlayStarted = true;             //cheat
            var    nimitz          = player.GetUnitById("tag:main");
            string nsmcName        = "jsm";
            string navalStrikeName = "Naval strike";
            string airSupName      = "Air superiority";
            //new WeaponStoreEntry("agm84harpoon", 30),
            //new WeaponStoreEntry("agm84harpoonslam", 30),
            var entry = nimitz.GetWeaponStoreEntry(nsmcName);

            Assert.IsNotNull(entry, "The Nimitz should have a store entry for jsm");
            var countNsmBefore = entry.Count;

            Assert.IsTrue(countNsmBefore > 0, "The jsm count should be > 0");
            var f35 = nimitz.AircraftHangar.Aircraft.FirstOrDefault(a => a.UnitClass.Id == "f35c" && a.CurrentWeaponLoadName == "Air superiority");

            Assert.IsNotNull(f35, "Should be an F35c on carrier");
            var StrikeWpnLoad = GameManager.Instance.GameData.GetWeaponLoadByName(f35.UnitClass.Id, navalStrikeName);

            bool CanChange = f35.CanChangeToWeaponLoad(StrikeWpnLoad, false);

            Assert.IsTrue(CanChange, "F35 should be able to change to Naval Strike");
            f35.SetWeaponLoad(navalStrikeName);
            var countNsmAfter = entry.Count;

            Assert.IsTrue(countNsmAfter < countNsmBefore, "Count of nsm missiles in store should be lower after WpnLoad change.");
            f35.SetWeaponLoad(airSupName);
            Assert.IsTrue(entry.Count == countNsmBefore, "Count of nsm missiles in store should now be same as before change.");
            entry.Count = 1;             //requires 2
            CanChange   = f35.CanChangeToWeaponLoad(StrikeWpnLoad, false);
            Assert.IsFalse(CanChange, "F35 should NOT be able to change to Naval Strike after store is reduced");
            f35.SetWeaponLoad(navalStrikeName);
            Assert.IsTrue(f35.CurrentWeaponLoadName == airSupName, "F35 should still be set to air superiority");
            var weaponClassNsm = GameManager.Instance.GetWeaponClassById(nsmcName);

            player.Credits = weaponClassNsm.AcquisitionCostAmmoCredits * 3;
            var acqOrder = OrderFactory.CreateAcquireAmmoOrder(nimitz.Id, weaponClassNsm.Id, 3);

            var acqResult = player.AcquireMoreAmmo(acqOrder);

            Assert.IsTrue(entry.Count == 4, "There should be 5 nsm's in store now.");
            Assert.IsTrue(acqResult, "Ammo acquisition should succeed.");
            acqOrder  = OrderFactory.CreateAcquireAmmoOrder(nimitz.Id, weaponClassNsm.Id, 3);
            acqResult = player.AcquireMoreAmmo(acqOrder);
            Assert.IsFalse(acqResult, "Ammo acquisition should fail (not enough credits).");
        }