Add gamerule to restart the round after a max time (#2681)

* Add gamerule to restart the round after a max time

* Add test

* Set default max time to 5 minutes
This commit is contained in:
DrSmugleaf
2020-12-03 03:13:44 +01:00
committed by GitHub
parent e688014b9c
commit cd90bab35c
2 changed files with 137 additions and 0 deletions

View File

@@ -0,0 +1,66 @@
using System;
using System.Threading.Tasks;
using Content.Server.GameTicking;
using Content.Server.GameTicking.GameRules;
using Content.Server.Interfaces.GameTicking;
using NUnit.Framework;
using Robust.Shared.Interfaces.Timing;
namespace Content.IntegrationTests.Tests.GameRules
{
[TestFixture]
[TestOf(typeof(RuleMaxTimeRestart))]
public class RuleMaxTimeRestartTest : ContentIntegrationTest
{
[Test]
public async Task RestartTest()
{
var options = new ServerContentIntegrationOption
{
CVarOverrides =
{
["game.lobbyenabled"] = "true"
}
};
var server = StartServer(options);
await server.WaitIdleAsync();
var sGameTicker = server.ResolveDependency<IGameTicker>();
var sGameTiming = server.ResolveDependency<IGameTiming>();
RuleMaxTimeRestart maxTimeRule = null;
await server.WaitAssertion(() =>
{
Assert.That(sGameTicker.RunLevel, Is.EqualTo(GameRunLevel.PreRoundLobby));
maxTimeRule = sGameTicker.AddGameRule<RuleMaxTimeRestart>();
maxTimeRule.RoundMaxTime = TimeSpan.FromSeconds(3);
sGameTicker.StartRound();
});
await server.WaitAssertion(() =>
{
Assert.That(sGameTicker.RunLevel, Is.EqualTo(GameRunLevel.InRound));
});
var ticks = sGameTiming.TickRate * (int) Math.Ceiling(maxTimeRule.RoundMaxTime.TotalSeconds * 1.1f);
await server.WaitRunTicks(ticks);
await server.WaitAssertion(() =>
{
Assert.That(sGameTicker.RunLevel, Is.EqualTo(GameRunLevel.PostRound));
});
ticks = sGameTiming.TickRate * (int) Math.Ceiling(maxTimeRule.RoundEndDelay.TotalSeconds * 1.1f);
await server.WaitRunTicks(ticks);
await server.WaitAssertion(() =>
{
Assert.That(sGameTicker.RunLevel, Is.EqualTo(GameRunLevel.PreRoundLobby));
});
}
}
}