diff --git a/NWN.Anvil.Tests/src/main/Services/Scheduler/SchedulerServiceTests.cs b/NWN.Anvil.Tests/src/main/Services/Scheduler/SchedulerServiceTests.cs index 2e2ca23ef..488a925f4 100644 --- a/NWN.Anvil.Tests/src/main/Services/Scheduler/SchedulerServiceTests.cs +++ b/NWN.Anvil.Tests/src/main/Services/Scheduler/SchedulerServiceTests.cs @@ -39,7 +39,7 @@ public async Task ScheduleDelayRunsTaskAfterDelay(int delayMs) [TestCase(500)] [TestCase(1000)] [TestCase(5000)] - public async Task ScheduleAndCancelDoesNotRunTask(int delayMs) + public Task ScheduleAndCancelDoesNotRunTask(int delayMs) { TimeSpan delay = TimeSpan.FromMilliseconds(delayMs); @@ -49,7 +49,7 @@ public async Task ScheduleAndCancelDoesNotRunTask(int delayMs) }, delay); task.Cancel(); - await NwTask.Delay(delay + TimeSpan.FromSeconds(1)); + return NwTask.Delay(delay + TimeSpan.FromSeconds(1)); } [Test(Description = "Scheduling a repeating task correctly schedules and runs the task with the specified interval.")] diff --git a/NWN.Anvil/src/main/API/Async/NwTask.cs b/NWN.Anvil/src/main/API/Async/NwTask.cs index 160da6446..6aecb12f4 100644 --- a/NWN.Anvil/src/main/API/Async/NwTask.cs +++ b/NWN.Anvil/src/main/API/Async/NwTask.cs @@ -27,10 +27,10 @@ public static class NwTask /// /// How long to wait. /// A cancellation token that should be used to cancel the work. - public static async Task Delay(TimeSpan delay, CancellationToken? cancellationToken = null) + public static Task Delay(TimeSpan delay, CancellationToken? cancellationToken = null) { Stopwatch stopwatch = Stopwatch.StartNew(); - await RunAndAwait(() => delay < stopwatch.Elapsed, cancellationToken); + return RunAndAwait(() => delay < stopwatch.Elapsed, cancellationToken); } /// @@ -38,9 +38,9 @@ public static async Task Delay(TimeSpan delay, CancellationToken? cancellationTo /// /// The number of frames to wait. /// A cancellation token that should be used to cancel the work. - public static async Task DelayFrame(int frames, CancellationToken? cancellationToken = null) + public static Task DelayFrame(int frames, CancellationToken? cancellationToken = null) { - await RunAndAwait(() => + return RunAndAwait(() => { bool retVal = frames <= 0; frames--; @@ -51,9 +51,9 @@ await RunAndAwait(() => /// /// Waits until the next server frame/loop. /// - public static async Task NextFrame() + public static Task NextFrame() { - await DelayFrame(1); + return DelayFrame(1); } /// @@ -88,9 +88,9 @@ public static IAwaitable SwitchToMainThread() /// /// The test expression. /// A cancellation token that should be used to cancel the work. - public static async Task WaitUntil(Func test, CancellationToken? cancellationToken = null) + public static Task WaitUntil(Func test, CancellationToken? cancellationToken = null) { - await RunAndAwait(test, cancellationToken); + return RunAndAwait(test, cancellationToken); } /// @@ -98,10 +98,10 @@ public static async Task WaitUntil(Func test, CancellationToken? cancellat /// /// The watched value source. /// A cancellation token that should be used to cancel the work. - public static async Task WaitUntilValueChanged(Func valueSource, CancellationToken? cancellationToken = null) + public static Task WaitUntilValueChanged(Func valueSource, CancellationToken? cancellationToken = null) { T currentVal = valueSource(); - await RunAndAwait(() => !Equals(currentVal, valueSource()), cancellationToken); + return RunAndAwait(() => !Equals(currentVal, valueSource()), cancellationToken); } /// diff --git a/NWN.Anvil/src/main/API/Nui/NuiWindowEventService.cs b/NWN.Anvil/src/main/API/Nui/NuiWindowEventService.cs index 81a44a80d..a40b69719 100644 --- a/NWN.Anvil/src/main/API/Nui/NuiWindowEventService.cs +++ b/NWN.Anvil/src/main/API/Nui/NuiWindowEventService.cs @@ -24,14 +24,10 @@ public void Subscribe(NuiWindowToken token, Action hand eventHandlers[token.Player] = playerHandlers; } - if (playerHandlers.ContainsKey(token.Token)) + if (!playerHandlers.TryAdd(token.Token, handler)) { playerHandlers[token.Token] += handler; } - else - { - playerHandlers[token.Token] = handler; - } } public void Unsubscribe(NuiWindowToken token, Action handler) diff --git a/NWN.Anvil/src/main/API/Objects/NwCreature.cs b/NWN.Anvil/src/main/API/Objects/NwCreature.cs index b40c824dc..6d685b046 100644 --- a/NWN.Anvil/src/main/API/Objects/NwCreature.cs +++ b/NWN.Anvil/src/main/API/Objects/NwCreature.cs @@ -1084,18 +1084,18 @@ public async Task ActionInteractObject(NwPlaceable placeable) /// Instructs this creature to approach and lock the specified door. /// /// The door to lock. - public async Task ActionLockObject(NwDoor door) + public Task ActionLockObject(NwDoor door) { - await DoActionLockObject(door); + return DoActionLockObject(door); } /// /// Instructs this creature to approach and lock the specified placeable. /// /// The placeable to lock. - public async Task ActionLockObject(NwPlaceable placeable) + public Task ActionLockObject(NwPlaceable placeable) { - await DoActionLockObject(placeable); + return DoActionLockObject(placeable); } /// @@ -1216,18 +1216,18 @@ public async Task ActionUnequipItem(NwItem item) /// Instructs this creature to approach and unlock the specified door. /// /// The door to unlock. - public async Task ActionUnlockObject(NwDoor door) + public Task ActionUnlockObject(NwDoor door) { - await DoActionUnlockObject(door); + return DoActionUnlockObject(door); } /// /// Instructs this creature to approach and unlock the specified placeable. /// /// The placeable to unlock. - public async Task ActionUnlockObject(NwPlaceable placeable) + public Task ActionUnlockObject(NwPlaceable placeable) { - await DoActionUnlockObject(placeable); + return DoActionUnlockObject(placeable); } /// diff --git a/NWN.Anvil/src/main/API/Objects/NwGameObject.cs b/NWN.Anvil/src/main/API/Objects/NwGameObject.cs index 6e5992133..a4fa326e5 100644 --- a/NWN.Anvil/src/main/API/Objects/NwGameObject.cs +++ b/NWN.Anvil/src/main/API/Objects/NwGameObject.cs @@ -366,9 +366,9 @@ public async void EndConversation() /// Rotates this object to face towards target. /// /// The target object to face. - public async Task FaceToObject(NwGameObject target) + public Task FaceToObject(NwGameObject target) { - await FaceToPoint(target.Position); + return FaceToPoint(target.Position); } /// diff --git a/NWN.Anvil/src/main/API/Objects/NwStationary.cs b/NWN.Anvil/src/main/API/Objects/NwStationary.cs index 71a5da0d2..b666e81d8 100644 --- a/NWN.Anvil/src/main/API/Objects/NwStationary.cs +++ b/NWN.Anvil/src/main/API/Objects/NwStationary.cs @@ -109,10 +109,10 @@ public void CreateTrap(TrapBaseType trap, string disarm = "", string triggered = NWScript.CreateTrapOnObject((int)trap, this, sOnDisarmScript: disarm, sOnTrapTriggeredScript: triggered); } - public override async Task FaceToPoint(Vector3 point) + public override Task FaceToPoint(Vector3 point) { Vector3 direction = Vector3.Normalize(point - Position); - await base.FaceToPoint(Position - direction); + return base.FaceToPoint(Position - direction); } ///