Exemplo n.º 1
0
        public async Task RestartRoundAfterStart(bool lobbyEnabled)
        {
            var(_, server) = await StartConnectedServerClientPair(serverOptions : new ServerContentIntegrationOption
            {
                CVarOverrides =
                {
                    [CCVars.GameMap.Name] = "saltern"
                }
            });

            await server.WaitIdleAsync();

            var configManager = server.ResolveDependency <IConfigurationManager>();
            var entityManager = server.ResolveDependency <IEntityManager>();
            var gameTicker    = entityManager.EntitySysManager.GetEntitySystem <GameTicker>();

            await server.WaitRunTicks(30);

            GameTick tickBeforeRestart = default;

            server.Assert(() =>
            {
                configManager.SetCVar(CCVars.GameLobbyEnabled, lobbyEnabled);

                Assert.That(gameTicker.RunLevel, Is.EqualTo(GameRunLevel.InRound));

                tickBeforeRestart = entityManager.CurrentTick;

                var command = new RestartRoundNowCommand();
                command.Execute(null, string.Empty, Array.Empty <string>());

                if (lobbyEnabled)
                {
                    Assert.That(gameTicker.RunLevel, Is.Not.EqualTo(GameRunLevel.InRound));
                }
            });

            await server.WaitIdleAsync();

            await server.WaitRunTicks(5);

            server.Assert(() =>
            {
                var tickAfterRestart = entityManager.CurrentTick;

                Assert.That(tickBeforeRestart < tickAfterRestart);
            });

            await server.WaitRunTicks(60);
        }
        public async Task RestartRoundAfterStart(bool lobbyEnabled)
        {
            await using var pairTracker = await PoolManager.GetServerClient(new PoolSettings (){ Dirty = true });

            var server = pairTracker.Pair.Server;

            var configManager = server.ResolveDependency <IConfigurationManager>();
            var entityManager = server.ResolveDependency <IEntityManager>();
            var gameTicker    = entityManager.EntitySysManager.GetEntitySystem <GameTicker>();

            await PoolManager.RunTicksSync(pairTracker.Pair, 5);

            GameTick tickBeforeRestart = default;

            await server.WaitAssertion(() =>
            {
                Assert.That(configManager.GetCVar <bool>(CCVars.GameLobbyEnabled), Is.EqualTo(false));
                configManager.SetCVar(CCVars.GameLobbyEnabled, lobbyEnabled);

                Assert.That(gameTicker.RunLevel, Is.EqualTo(GameRunLevel.InRound));

                tickBeforeRestart = entityManager.CurrentTick;

                var command = new RestartRoundNowCommand();
                command.Execute(null, string.Empty, Array.Empty <string>());

                if (lobbyEnabled)
                {
                    Assert.That(gameTicker.RunLevel, Is.Not.EqualTo(GameRunLevel.InRound));
                }
            });

            await PoolManager.RunTicksSync(pairTracker.Pair, 15);

            await server.WaitAssertion(() =>
            {
                var tickAfterRestart = entityManager.CurrentTick;

                Assert.That(tickBeforeRestart < tickAfterRestart);
            });

            await PoolManager.RunTicksSync(pairTracker.Pair, 5);

            await pairTracker.CleanReturnAsync();
        }
Exemplo n.º 3
0
        public async Task RestartTest()
        {
            await using var pairTracker = await PoolManager.GetServerClient();

            var server = pairTracker.Pair.Server;

            var configManager = server.ResolveDependency <IConfigurationManager>();
            await server.WaitPost(() =>
            {
                configManager.SetCVar(CCVars.GameLobbyEnabled, true);
                var command = new RestartRoundNowCommand();
                command.Execute(null, string.Empty, Array.Empty <string>());
            });


            var sGameTicker = server.ResolveDependency <IEntitySystemManager>().GetEntitySystem <GameTicker>();
            var maxTimeMaxTimeRestartRuleSystem = server.ResolveDependency <IEntitySystemManager>().GetEntitySystem <MaxTimeRestartRuleSystem>();
            var sGameTiming = server.ResolveDependency <IGameTiming>();

            await server.WaitAssertion(() =>
            {
                Assert.That(sGameTicker.RunLevel, Is.EqualTo(GameRunLevel.PreRoundLobby));

                sGameTicker.StartGameRule(IoCManager.Resolve <IPrototypeManager>().Index <GameRulePrototype>(maxTimeMaxTimeRestartRuleSystem.Prototype));
                maxTimeMaxTimeRestartRuleSystem.RoundMaxTime = TimeSpan.FromSeconds(3);

                sGameTicker.StartRound();
            });

            await server.WaitAssertion(() =>
            {
                Assert.That(sGameTicker.RunLevel, Is.EqualTo(GameRunLevel.InRound));
            });

            var ticks = sGameTiming.TickRate * (int)Math.Ceiling(maxTimeMaxTimeRestartRuleSystem.RoundMaxTime.TotalSeconds * 1.1f);
            await PoolManager.RunTicksSync(pairTracker.Pair, ticks);

            await server.WaitAssertion(() =>
            {
                Assert.That(sGameTicker.RunLevel, Is.EqualTo(GameRunLevel.PostRound));
            });

            ticks = sGameTiming.TickRate * (int)Math.Ceiling(maxTimeMaxTimeRestartRuleSystem.RoundEndDelay.TotalSeconds * 1.1f);
            await PoolManager.RunTicksSync(pairTracker.Pair, ticks);

            await server.WaitAssertion(() =>
            {
                Assert.That(sGameTicker.RunLevel, Is.EqualTo(GameRunLevel.PreRoundLobby));
            });

            await PoolManager.RunTicksSync(pairTracker.Pair, 5);

            await server.WaitPost(() =>
            {
                configManager.SetCVar(CCVars.GameLobbyEnabled, false);
                var command = new RestartRoundNowCommand();
                command.Execute(null, string.Empty, Array.Empty <string>());
            });

            await PoolManager.RunTicksSync(pairTracker.Pair, 30);

            await pairTracker.CleanReturnAsync();
        }