From 6cfdaa9d0ad33f2781a232f00d77f8486a3a11c0 Mon Sep 17 00:00:00 2001 From: Rutherther Date: Wed, 15 Feb 2023 20:31:27 +0100 Subject: [PATCH] chore: update dependencies --- .../NosSmooth.LocalBinding.csproj | 2 +- ...ndHandler.cs => MateWalkCommandHandler.cs} | 22 ++++----- .../Extensions/ServiceCollectionExtensions.cs | 2 +- .../NosSmooth.LocalClient.csproj | 7 +-- .../NosSmooth.ChatCommands.csproj | 2 +- .../NosSmooth.Extensions.SharedBinding.csproj | 11 +++-- .../NosSmooth.Injector.csproj | 2 +- .../ExternalBrowser/ExternalBrowser.csproj | 3 +- .../SimplePiiBot/SimplePiiBot.csproj | 4 +- .../InterceptNameChanger.csproj | 4 +- .../LowLevel/SimpleChat/SimpleChat.csproj | 2 +- .../WalkCommands/Commands/WalkCommands.cs | 49 +++++++++++++++---- .../LowLevel/WalkCommands/WalkCommands.csproj | 18 +++++-- 13 files changed, 84 insertions(+), 44 deletions(-) rename src/Core/NosSmooth.LocalClient/CommandHandlers/Walk/{PetWalkCommandHandler.cs => MateWalkCommandHandler.cs} (80%) diff --git a/src/Core/NosSmooth.LocalBinding/NosSmooth.LocalBinding.csproj b/src/Core/NosSmooth.LocalBinding/NosSmooth.LocalBinding.csproj index 5194206..38a661c 100644 --- a/src/Core/NosSmooth.LocalBinding/NosSmooth.LocalBinding.csproj +++ b/src/Core/NosSmooth.LocalBinding/NosSmooth.LocalBinding.csproj @@ -12,7 +12,7 @@ - + diff --git a/src/Core/NosSmooth.LocalClient/CommandHandlers/Walk/PetWalkCommandHandler.cs b/src/Core/NosSmooth.LocalClient/CommandHandlers/Walk/MateWalkCommandHandler.cs similarity index 80% rename from src/Core/NosSmooth.LocalClient/CommandHandlers/Walk/PetWalkCommandHandler.cs rename to src/Core/NosSmooth.LocalClient/CommandHandlers/Walk/MateWalkCommandHandler.cs index fb2fb29..09b991b 100644 --- a/src/Core/NosSmooth.LocalClient/CommandHandlers/Walk/PetWalkCommandHandler.cs +++ b/src/Core/NosSmooth.LocalClient/CommandHandlers/Walk/MateWalkCommandHandler.cs @@ -1,5 +1,5 @@ // -// PetWalkCommandHandler.cs +// MateWalkCommandHandler.cs // // Copyright (c) František Boháček. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. @@ -20,7 +20,7 @@ namespace NosSmooth.LocalClient.CommandHandlers.Walk; /// /// Handles . /// -public class PetWalkCommandHandler : ICommandHandler +public class MateWalkCommandHandler : ICommandHandler { /// /// Group that is used for . @@ -35,7 +35,7 @@ public class PetWalkCommandHandler : ICommandHandler private readonly WalkCommandHandlerOptions _options; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The pet walk hook. /// The pet manager list. @@ -43,7 +43,7 @@ public class PetWalkCommandHandler : ICommandHandler /// The user action detector. /// The nostale client. /// The options. - public PetWalkCommandHandler + public MateWalkCommandHandler ( IPetWalkHook petWalkHook, PetManagerList petManagerList, @@ -62,13 +62,13 @@ public class PetWalkCommandHandler : ICommandHandler } /// - public async Task HandleCommand(PetWalkCommand command, CancellationToken ct = default) + public async Task HandleCommand(MateWalkCommand command, CancellationToken ct = default) { - if (_petManagerList.Length < command.PetSelector + 1) + PetManager? selectedPet = _petManagerList.FirstOrDefault(x => x.Pet.Id == command.MateId); + if (selectedPet is null) { - return new NotFoundError("Could not find the pet using the given selector."); + return new NotFoundError($"Mate with id {command.MateId} was not found in the pet manager list."); } - var petManager = _petManagerList[command.PetSelector]; var handler = new ControlCommandWalkHandler ( @@ -78,11 +78,11 @@ public class PetWalkCommandHandler : ICommandHandler ( () => _userActionDetector.NotUserAction> ( - () => _petWalkHook.WrapperFunction.Get()(petManager, (ushort)x, (ushort)y) + () => _petWalkHook.WrapperFunction.Get()(selectedPet, (ushort)x, (ushort)y) ), ct ), - petManager, + selectedPet, _options ); @@ -92,7 +92,7 @@ public class PetWalkCommandHandler : ICommandHandler command.TargetY, command.ReturnDistanceTolerance, command, - PetWalkControlGroup + "_" + command.PetSelector, + PetWalkControlGroup + "_" + command.MateId, ct ); } diff --git a/src/Core/NosSmooth.LocalClient/Extensions/ServiceCollectionExtensions.cs b/src/Core/NosSmooth.LocalClient/Extensions/ServiceCollectionExtensions.cs index 7f988af..b4acac1 100644 --- a/src/Core/NosSmooth.LocalClient/Extensions/ServiceCollectionExtensions.cs +++ b/src/Core/NosSmooth.LocalClient/Extensions/ServiceCollectionExtensions.cs @@ -33,7 +33,7 @@ public static class ServiceCollectionExtensions .AddTakeControlCommand() .AddCommandHandler() .AddCommandHandler() - .AddCommandHandler(); + .AddCommandHandler(); serviceCollection.TryAddSingleton(); serviceCollection.TryAddSingleton(p => p.GetRequiredService()); diff --git a/src/Core/NosSmooth.LocalClient/NosSmooth.LocalClient.csproj b/src/Core/NosSmooth.LocalClient/NosSmooth.LocalClient.csproj index 0f32468..02f36d2 100644 --- a/src/Core/NosSmooth.LocalClient/NosSmooth.LocalClient.csproj +++ b/src/Core/NosSmooth.LocalClient/NosSmooth.LocalClient.csproj @@ -5,8 +5,8 @@ enable 10 net7.0 - 2.0.1 - Add support for optional hooks and bindings. + 2.1.0 + Add support for new MateWalkCommand. @@ -14,8 +14,9 @@ - + + diff --git a/src/Extensions/NosSmooth.ChatCommands/NosSmooth.ChatCommands.csproj b/src/Extensions/NosSmooth.ChatCommands/NosSmooth.ChatCommands.csproj index 8b7c97d..3eabcef 100644 --- a/src/Extensions/NosSmooth.ChatCommands/NosSmooth.ChatCommands.csproj +++ b/src/Extensions/NosSmooth.ChatCommands/NosSmooth.ChatCommands.csproj @@ -10,7 +10,7 @@ - + diff --git a/src/Extensions/NosSmooth.Extensions.SharedBinding/NosSmooth.Extensions.SharedBinding.csproj b/src/Extensions/NosSmooth.Extensions.SharedBinding/NosSmooth.Extensions.SharedBinding.csproj index 3849922..5236226 100644 --- a/src/Extensions/NosSmooth.Extensions.SharedBinding/NosSmooth.Extensions.SharedBinding.csproj +++ b/src/Extensions/NosSmooth.Extensions.SharedBinding/NosSmooth.Extensions.SharedBinding.csproj @@ -4,14 +4,15 @@ net7.0 enable enable - 1.0.1 - Add support for optional hooks and bindings. + 1.0.2 + Update dependencies. - - - + + + + diff --git a/src/Inject/NosSmooth.Injector/NosSmooth.Injector.csproj b/src/Inject/NosSmooth.Injector/NosSmooth.Injector.csproj index 6cabb63..a248383 100644 --- a/src/Inject/NosSmooth.Injector/NosSmooth.Injector.csproj +++ b/src/Inject/NosSmooth.Injector/NosSmooth.Injector.csproj @@ -10,7 +10,7 @@ - + diff --git a/src/Samples/External/ExternalBrowser/ExternalBrowser.csproj b/src/Samples/External/ExternalBrowser/ExternalBrowser.csproj index faed576..56dab40 100644 --- a/src/Samples/External/ExternalBrowser/ExternalBrowser.csproj +++ b/src/Samples/External/ExternalBrowser/ExternalBrowser.csproj @@ -12,7 +12,8 @@ - + + diff --git a/src/Samples/HighLevel/SimplePiiBot/SimplePiiBot.csproj b/src/Samples/HighLevel/SimplePiiBot/SimplePiiBot.csproj index 363f381..4afc0bf 100644 --- a/src/Samples/HighLevel/SimplePiiBot/SimplePiiBot.csproj +++ b/src/Samples/HighLevel/SimplePiiBot/SimplePiiBot.csproj @@ -10,9 +10,9 @@ - + - + diff --git a/src/Samples/LowLevel/InterceptNameChanger/InterceptNameChanger.csproj b/src/Samples/LowLevel/InterceptNameChanger/InterceptNameChanger.csproj index 5320b18..2a77234 100644 --- a/src/Samples/LowLevel/InterceptNameChanger/InterceptNameChanger.csproj +++ b/src/Samples/LowLevel/InterceptNameChanger/InterceptNameChanger.csproj @@ -18,8 +18,8 @@ - - + + diff --git a/src/Samples/LowLevel/SimpleChat/SimpleChat.csproj b/src/Samples/LowLevel/SimpleChat/SimpleChat.csproj index 97766fe..bb0f0bf 100644 --- a/src/Samples/LowLevel/SimpleChat/SimpleChat.csproj +++ b/src/Samples/LowLevel/SimpleChat/SimpleChat.csproj @@ -18,7 +18,7 @@ - + diff --git a/src/Samples/LowLevel/WalkCommands/Commands/WalkCommands.cs b/src/Samples/LowLevel/WalkCommands/Commands/WalkCommands.cs index b288a16..4ba9662 100644 --- a/src/Samples/LowLevel/WalkCommands/Commands/WalkCommands.cs +++ b/src/Samples/LowLevel/WalkCommands/Commands/WalkCommands.cs @@ -10,6 +10,8 @@ using NosSmooth.Core.Commands; using NosSmooth.Core.Commands.Walking; using NosSmooth.Core.Extensions; using NosSmooth.Extensions.Pathfinding; +using NosSmooth.LocalBinding; +using NosSmooth.LocalBinding.Structs; using NosSmooth.Packets.Enums; using NosSmooth.Packets.Enums.Chat; using NosSmooth.Packets.Enums.Entities; @@ -26,6 +28,7 @@ namespace WalkCommands.Commands; public class WalkCommands : CommandGroup { private readonly ManagedNostaleClient _client; + private readonly PetManagerList _petManagerList; private readonly WalkManager _walkManager; private readonly FeedbackService _feedbackService; @@ -33,11 +36,13 @@ public class WalkCommands : CommandGroup /// Initializes a new instance of the class. /// /// The nostale client. + /// The pet manager list. /// The walk manager. /// The feedback service. - public WalkCommands(ManagedNostaleClient client, WalkManager walkManager, FeedbackService feedbackService) + public WalkCommands(ManagedNostaleClient client, PetManagerList petManagerList, WalkManager walkManager, FeedbackService feedbackService) { _client = client; + _petManagerList = petManagerList; _walkManager = walkManager; _feedbackService = feedbackService; } @@ -71,12 +76,16 @@ public class WalkCommands : CommandGroup return receiveResult; } + var pets = petSelectors + .Select(i => _petManagerList[i].Entity.Id) + .Select(id => (id, x, y)); + var command = new WalkCommand ( x, y, - petSelectors.Select(i => (i, x, y)).ToArray(), 2, + pets.ToArray(), AllowUserCancel: isCancellable ); var walkResult = await _client.SendCommandAsync(command, CancellationToken); @@ -127,25 +136,45 @@ public class WalkCommands : CommandGroup { return receiveResult; } + + var pets = petSelectors + .Select(i => _petManagerList[i].Entity.Id) + .Select(id => (id, x, y)); + + var tasks = new List>(); - var walkResult = await _walkManager.GoToAsync + tasks.Add(_walkManager.PlayerGoToAsync ( x, y, isCancellable, - CancellationToken, - petSelectors.Select(i => (i, x, y)).ToArray() - ); - if (!walkResult.IsSuccess) + CancellationToken + )); + + foreach (var pet in pets) + { + tasks.Add(_walkManager.MateWalkToAsync(pet.id, pet.x, pet.y, isCancellable, CancellationToken)); + } + + var results = await Task.WhenAll(tasks); + var errorfulResults = results.Where(x => !x.IsSuccess).OfType().ToArray(); + if (errorfulResults.Length > 0) { - await _feedbackService.SendErrorMessageAsync - ($"Could not finish walking. {walkResult.ToFullString()}", CancellationToken); await _client.ReceivePacketAsync ( new SayPacket(EntityType.Map, 1, SayColor.Red, "Could not finish walking."), CancellationToken ); - return walkResult; + + var result = errorfulResults.Length switch + { + 1 => (Result)errorfulResults[0], + _ => new AggregateError(errorfulResults) + }; + await _feedbackService.SendErrorMessageAsync + ($"Could not finish walking. {result.ToFullString()}", CancellationToken); + + return result; } return await _client.ReceivePacketAsync diff --git a/src/Samples/LowLevel/WalkCommands/WalkCommands.csproj b/src/Samples/LowLevel/WalkCommands/WalkCommands.csproj index 0e9b81f..725383c 100644 --- a/src/Samples/LowLevel/WalkCommands/WalkCommands.csproj +++ b/src/Samples/LowLevel/WalkCommands/WalkCommands.csproj @@ -31,25 +31,33 @@ 7.0.0 - 4.0.2 + 5.0.0 - 2.2.1 + 2.3.0 - 1.2.0 + 2.0.0 - 3.5.1 + 3.6.0 7.2.3 - + + + + ..\..\..\..\..\NosSmooth\Core\NosSmooth.Core\bin\Debug\net7.0\NosSmooth.Core.dll + + + ..\..\..\..\..\NosSmooth\Packets\NosSmooth.Packets\bin\Debug\net7.0\NosSmooth.Packets.dll + + \ No newline at end of file -- 2.48.1