* do_after

Ports (most of) do_after from SS13.
Callers are expected to await the DoAfter task from the DoAfterSystem.
I had a dummy component for in-game testing which I removed for the PR so nothing in game uses do_after at the moment.
Currently only the movement cancellation is predicted client-side.

* Minor do_after doc cleanup

* do_the_shuffle

Fix nullable build errors.

* The last nullable

* Implement NeedHand

Thanks zum.

* nullable dereference

* Adjust the system query

Co-authored-by: Metal Gear Sloth <metalgearsloth@gmail.com>
This commit is contained in:
metalgearsloth
2020-08-09 02:16:13 +10:00
committed by GitHub
parent ee14d67756
commit 5b3b2e3207
14 changed files with 1186 additions and 0 deletions

View File

@@ -0,0 +1,60 @@
using System.Threading;
using System.Threading.Tasks;
using Content.Server.GameObjects.Components;
using Content.Server.GameObjects.EntitySystems;
using NUnit.Framework;
using Robust.Shared.GameObjects.Systems;
using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.Interfaces.Map;
using Robust.Shared.Interfaces.Timing;
using Robust.Shared.IoC;
using Robust.Shared.Map;
using Robust.Shared.Maths;
namespace Content.IntegrationTests.Tests.DoAfter
{
[TestFixture]
[TestOf(typeof(DoAfterComponent))]
public class DoAfterServerTest : ContentIntegrationTest
{
[Test]
public async Task Test()
{
Task<DoAfterStatus> task = null;
var server = StartServerDummyTicker();
float tickTime = 0.0f;
// That it finishes successfully
server.Post(() =>
{
tickTime = 1.0f / IoCManager.Resolve<IGameTiming>().TickRate;
var mapManager = IoCManager.Resolve<IMapManager>();
mapManager.CreateNewMapEntity(MapId.Nullspace);
var entityManager = IoCManager.Resolve<IEntityManager>();
var mob = entityManager.SpawnEntity("HumanMob_Content", MapCoordinates.Nullspace);
var cancelToken = new CancellationTokenSource();
var args = new DoAfterEventArgs(mob, tickTime / 2, cancelToken.Token);
task = EntitySystem.Get<DoAfterSystem>().DoAfter(args);
});
await server.WaitRunTicks(1);
Assert.That(task.Result == DoAfterStatus.Finished);
// That cancel works on mob move
server.Post(() =>
{
var mapManager = IoCManager.Resolve<IMapManager>();
mapManager.CreateNewMapEntity(MapId.Nullspace);
var entityManager = IoCManager.Resolve<IEntityManager>();
var mob = entityManager.SpawnEntity("HumanMob_Content", MapCoordinates.Nullspace);
var cancelToken = new CancellationTokenSource();
var args = new DoAfterEventArgs(mob, tickTime * 2, cancelToken.Token);
task = EntitySystem.Get<DoAfterSystem>().DoAfter(args);
mob.Transform.GridPosition = mob.Transform.GridPosition.Translated(new Vector2(0.1f, 0.1f));
});
await server.WaitRunTicks(1);
Assert.That(task.Result == DoAfterStatus.Cancelled);
}
}
}