Fixes secret only adding game rules, not starting them (#11005)

This commit is contained in:
Kara
2022-09-03 18:40:00 -07:00
committed by GitHub
parent 547af7c7e8
commit 3e409528ce
3 changed files with 55 additions and 1 deletions

View File

@@ -0,0 +1,53 @@
using System;
using System.Linq;
using System.Threading.Tasks;
using Content.Server.GameTicking;
using Content.Server.GameTicking.Rules;
using NUnit.Framework;
using Robust.Shared.GameObjects;
using Robust.Shared.Prototypes;
namespace Content.IntegrationTests.Tests.GameRules;
[TestFixture]
public sealed class SecretStartsTest
{
/// <summary>
/// Tests that when secret is started, all of the game rules it successfully adds are also started.
/// </summary>
[Test]
public async Task TestSecretStarts()
{
await using var pairTracker = await PoolManager.GetServerClient(new PoolSettings()
{
NoClient = true,
Dirty = true,
});
var server = pairTracker.Pair.Server;
await server.WaitIdleAsync();
var protoMan = server.ResolveDependency<IPrototypeManager>();
var gameTicker = server.ResolveDependency<IEntitySystemManager>().GetEntitySystem<GameTicker>();
await server.WaitAssertion(() =>
{
gameTicker.StartGameRule(protoMan.Index<GameRulePrototype>("Secret"));
});
// Wait three ticks for any random update loops that might happen
await server.WaitRunTicks(3);
await server.WaitAssertion(() =>
{
foreach (var rule in gameTicker.AddedGameRules)
{
Assert.That(gameTicker.StartedGameRules.Contains(rule));
}
// End all rules
gameTicker.ClearGameRules();
});
await pairTracker.CleanReturnAsync();
}
}

View File

@@ -41,6 +41,7 @@ public sealed class StartEndGameRulesTest
} }
Assert.That(gameTicker.AddedGameRules, Has.Count.EqualTo(rules.Count)); Assert.That(gameTicker.AddedGameRules, Has.Count.EqualTo(rules.Count));
Assert.That(gameTicker.AddedGameRules, Has.Count.EqualTo(gameTicker.StartedGameRules.Count));
}); });
// Wait three ticks for any random update loops that might happen // Wait three ticks for any random update loops that might happen

View File

@@ -37,7 +37,7 @@ public sealed class SecretRuleSystem : GameRuleSystem
foreach (var rule in _prototypeManager.Index<GamePresetPrototype>(preset).Rules) foreach (var rule in _prototypeManager.Index<GamePresetPrototype>(preset).Rules)
{ {
_ticker.AddGameRule(_prototypeManager.Index<GameRulePrototype>(rule)); _ticker.StartGameRule(_prototypeManager.Index<GameRulePrototype>(rule));
} }
} }
} }