From 49b19775184488d164b50e1acd52072e4b4192c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franti=C5=A1ek=20Boh=C3=A1=C4=8Dek?= Date: Sun, 8 Jan 2023 18:53:19 +0100 Subject: [PATCH] chore: add async analyzer and meet its standards --- .../Client/BaseNostaleClient.cs | 4 +-- .../Commands/Control/ControlCommands.cs | 4 +-- Core/NosSmooth.Core/NosSmooth.Core.csproj | 8 ++--- .../Apis/NostaleInventoryPacketApi.cs | 14 ++++---- .../Apis/NostaleMapPacketApi.cs | 4 +-- .../Apis/NostaleMatePacketApi.cs | 12 +++---- .../Apis/NostaleMateSkillsPacketApi.cs | 8 ++--- Core/NosSmooth.Game/Game.cs | 32 +++++++++---------- Core/NosSmooth.Game/GameSemaphores.cs | 4 +-- .../PacketHandlers/Act4/FcResponder.cs | 4 +-- Directory.Build.props | 10 ++++++ .../Operations/WalkOperation.cs | 6 ++-- .../Constants.cs | 2 +- Samples/FileClient/Client.cs | 8 ++--- 14 files changed, 64 insertions(+), 56 deletions(-) diff --git a/Core/NosSmooth.Core/Client/BaseNostaleClient.cs b/Core/NosSmooth.Core/Client/BaseNostaleClient.cs index 176737c..cf97ddd 100644 --- a/Core/NosSmooth.Core/Client/BaseNostaleClient.cs +++ b/Core/NosSmooth.Core/Client/BaseNostaleClient.cs @@ -69,6 +69,6 @@ public abstract class BaseNostaleClient : INostaleClient } /// - public async Task SendCommandAsync(ICommand command, CancellationToken ct = default) - => await _commandProcessor.ProcessCommand(this, command, ct); + public Task SendCommandAsync(ICommand command, CancellationToken ct = default) + => _commandProcessor.ProcessCommand(this, command, ct); } diff --git a/Core/NosSmooth.Core/Commands/Control/ControlCommands.cs b/Core/NosSmooth.Core/Commands/Control/ControlCommands.cs index 274701b..0a48357 100644 --- a/Core/NosSmooth.Core/Commands/Control/ControlCommands.cs +++ b/Core/NosSmooth.Core/Commands/Control/ControlCommands.cs @@ -151,7 +151,7 @@ public class ControlCommands /// Whether to wait for cancellation of non cancellable commands. /// The cancellation token for cancelling the operation. /// A result that may or may not have succeeded. - public async Task CancelAsync + public Task CancelAsync (ControlCommandsFilter filter, bool waitForCancellation = true, CancellationToken ct = default) { bool cancelUser = filter.HasFlag(ControlCommandsFilter.UserCancellable); @@ -164,7 +164,7 @@ public class ControlCommands || (cancelMapChanged && x.Command.CancelOnMapChange) ); - return await CancelCommandsAsync(commandsToCancel, waitForCancellation, filter, ct); + return CancelCommandsAsync(commandsToCancel, waitForCancellation, filter, ct); } private async Task FinishCommandsAsync(IEnumerable commandsToFinish) diff --git a/Core/NosSmooth.Core/NosSmooth.Core.csproj b/Core/NosSmooth.Core/NosSmooth.Core.csproj index 3980bbf..99511a1 100644 --- a/Core/NosSmooth.Core/NosSmooth.Core.csproj +++ b/Core/NosSmooth.Core/NosSmooth.Core.csproj @@ -15,13 +15,13 @@ - - + + - - + + diff --git a/Core/NosSmooth.Game/Apis/NostaleInventoryPacketApi.cs b/Core/NosSmooth.Game/Apis/NostaleInventoryPacketApi.cs index efcd3de..4bf0a1c 100644 --- a/Core/NosSmooth.Game/Apis/NostaleInventoryPacketApi.cs +++ b/Core/NosSmooth.Game/Apis/NostaleInventoryPacketApi.cs @@ -35,14 +35,14 @@ public class NostaleInventoryPacketApi /// The amount to drop. /// The cancellation token used for cancelling the operation. /// A result that may or may not have succeeded. - public async Task DropItemAsync + public Task DropItemAsync ( BagType bag, short slot, short amount, CancellationToken ct = default ) - => await _client.SendPacketAsync(new PutPacket(bag, slot, amount), ct); + => _client.SendPacketAsync(new PutPacket(bag, slot, amount), ct); /// /// Move the given item within one bag. @@ -53,7 +53,7 @@ public class NostaleInventoryPacketApi /// The amount to move. /// The cancellation token used for cancelling the operation. /// A result that may or may not have succeeded. - public async Task MoveItemAsync + public Task MoveItemAsync ( BagType bag, short sourceSlot, @@ -61,7 +61,7 @@ public class NostaleInventoryPacketApi short amount, CancellationToken ct = default ) - => await MoveItemAsync + => MoveItemAsync ( bag, sourceSlot, @@ -81,7 +81,7 @@ public class NostaleInventoryPacketApi /// The amount to move. /// The cancellation token used for cancelling the operation. /// A result that may or may not have succeeded. - public async Task MoveItemAsync + public Task MoveItemAsync ( BagType sourceBag, short sourceSlot, @@ -93,9 +93,9 @@ public class NostaleInventoryPacketApi { if (sourceBag == destinationBag) { - return await _client.SendPacketAsync(new MviPacket(sourceBag, sourceSlot, amount, destinationSlot), ct); + return _client.SendPacketAsync(new MviPacket(sourceBag, sourceSlot, amount, destinationSlot), ct); } - return await _client.SendPacketAsync(new MvePacket(sourceBag, sourceSlot, destinationBag, destinationSlot), ct); + return _client.SendPacketAsync(new MvePacket(sourceBag, sourceSlot, destinationBag, destinationSlot), ct); } } \ No newline at end of file diff --git a/Core/NosSmooth.Game/Apis/NostaleMapPacketApi.cs b/Core/NosSmooth.Game/Apis/NostaleMapPacketApi.cs index 721e3eb..ebd5014 100644 --- a/Core/NosSmooth.Game/Apis/NostaleMapPacketApi.cs +++ b/Core/NosSmooth.Game/Apis/NostaleMapPacketApi.cs @@ -46,8 +46,8 @@ public class NostaleMapPacketApi /// The cancellation token for cancelling the operation. /// A result that may or may not have succeeded. [Unsafe("Portal position not checked.")] - public async Task UsePortalAsync(CancellationToken ct = default) - => await _client.SendPacketAsync(new PreqPacket(), ct); + public Task UsePortalAsync(CancellationToken ct = default) + => _client.SendPacketAsync(new PreqPacket(), ct); /// /// Pick up the given item. diff --git a/Core/NosSmooth.Game/Apis/NostaleMatePacketApi.cs b/Core/NosSmooth.Game/Apis/NostaleMatePacketApi.cs index 1d2eb46..f2820ae 100644 --- a/Core/NosSmooth.Game/Apis/NostaleMatePacketApi.cs +++ b/Core/NosSmooth.Game/Apis/NostaleMatePacketApi.cs @@ -41,8 +41,8 @@ public class NostaleMatePacketApi /// The id of the mate to have company. /// The cancellation token used for cancelling the operation. /// A result that may or may not have succeeded. - public async Task CompanyAsync(long mateId, CancellationToken ct = default) - => await _client.SendPacketAsync + public Task CompanyAsync(long mateId, CancellationToken ct = default) + => _client.SendPacketAsync ( new NRunPacket ( @@ -67,8 +67,8 @@ public class NostaleMatePacketApi /// The id of the mate to have company. /// The cancellation token used for cancelling the operation. /// A result that may or may not have succeeded. - public async Task StayAsync(long mateId, CancellationToken ct = default) - => await _client.SendPacketAsync + public Task StayAsync(long mateId, CancellationToken ct = default) + => _client.SendPacketAsync ( new NRunPacket ( @@ -90,8 +90,8 @@ public class NostaleMatePacketApi /// The id of the mate to have company. /// The cancellation token used for cancelling the operation. /// A result that may or may not have succeeded. - public async Task SendBackAsync(long mateId, CancellationToken ct = default) - => await _client.SendPacketAsync + public Task SendBackAsync(long mateId, CancellationToken ct = default) + => _client.SendPacketAsync ( new NRunPacket ( diff --git a/Core/NosSmooth.Game/Apis/NostaleMateSkillsPacketApi.cs b/Core/NosSmooth.Game/Apis/NostaleMateSkillsPacketApi.cs index 8a8207e..d145799 100644 --- a/Core/NosSmooth.Game/Apis/NostaleMateSkillsPacketApi.cs +++ b/Core/NosSmooth.Game/Apis/NostaleMateSkillsPacketApi.cs @@ -36,7 +36,7 @@ public class NostaleMateSkillsPacketApi /// The x coordinate of the partner. /// The y coordinate of the partner. /// A result that may or may not have succeeded. - public async Task UsePetSkillAsync + public Task UsePetSkillAsync ( long petId, EntityType targetEntityType, @@ -45,7 +45,7 @@ public class NostaleMateSkillsPacketApi short? mapY = default ) { - return await _client.SendPacketAsync + return _client.SendPacketAsync ( new UsePetSkillPacket ( @@ -69,7 +69,7 @@ public class NostaleMateSkillsPacketApi /// The x coordinate of the partner. /// The y coordinate of the partner. /// A result that may or may not have succeeded. - public async Task UsePartnerSkillAsync + public Task UsePartnerSkillAsync ( long partnerId, byte skillSlot, @@ -79,7 +79,7 @@ public class NostaleMateSkillsPacketApi short? mapY = default ) { - return await _client.SendPacketAsync + return _client.SendPacketAsync ( new UsePartnerSkillPacket ( diff --git a/Core/NosSmooth.Game/Game.cs b/Core/NosSmooth.Game/Game.cs index 6e6f7d6..4a7182d 100644 --- a/Core/NosSmooth.Game/Game.cs +++ b/Core/NosSmooth.Game/Game.cs @@ -103,7 +103,7 @@ public class Game : IStatefulEntity /// Whether to release the semaphore used for changing the mates. /// The cancellation token for cancelling the operation. /// The updated mates. - internal async Task CreateOrUpdateMatesAsync + internal Task CreateOrUpdateMatesAsync ( Func create, Func update, @@ -111,7 +111,7 @@ public class Game : IStatefulEntity CancellationToken ct = default ) { - return await CreateOrUpdateAsync + return CreateOrUpdateAsync ( GameSemaphoreType.Mates, () => Mates, @@ -131,7 +131,7 @@ public class Game : IStatefulEntity /// Whether to release the semaphore used for changing the skills. /// The cancellation token for cancelling the operation. /// The updated skills. - internal async Task CreateOrUpdateSkillsAsync + internal Task CreateOrUpdateSkillsAsync ( Func create, Func update, @@ -139,7 +139,7 @@ public class Game : IStatefulEntity CancellationToken ct = default ) { - return await CreateOrUpdateAsync + return CreateOrUpdateAsync ( GameSemaphoreType.Skills, () => Skills, @@ -159,7 +159,7 @@ public class Game : IStatefulEntity /// Whether to release the semaphore used for changing the inventory. /// The cancellation token for cancelling the operation. /// The updated inventory. - internal async Task CreateOrUpdateInventoryAsync + internal Task CreateOrUpdateInventoryAsync ( Func create, Func update, @@ -167,7 +167,7 @@ public class Game : IStatefulEntity CancellationToken ct = default ) { - return await CreateOrUpdateAsync + return CreateOrUpdateAsync ( GameSemaphoreType.Inventory, () => Inventory, @@ -231,7 +231,7 @@ public class Game : IStatefulEntity /// Whether to release the semaphore used for changing the friends. /// The cancellation token for cancelling the operation. /// The updated friends. - internal async Task?> CreateOrUpdateFriendsAsync + internal Task?> CreateOrUpdateFriendsAsync ( Func?> create, Func, IReadOnlyList?> update, @@ -239,7 +239,7 @@ public class Game : IStatefulEntity CancellationToken ct = default ) { - return await CreateOrUpdateAsync + return CreateOrUpdateAsync ( GameSemaphoreType.Friends, () => Friends, @@ -259,7 +259,7 @@ public class Game : IStatefulEntity /// Whether to release the semaphore used for changing the group. /// The cancellation token for cancelling the operation. /// The updated group. - internal async Task CreateOrUpdateGroupAsync + internal Task CreateOrUpdateGroupAsync ( Func create, Func update, @@ -267,7 +267,7 @@ public class Game : IStatefulEntity CancellationToken ct = default ) { - return await CreateOrUpdateAsync + return CreateOrUpdateAsync ( GameSemaphoreType.Group, () => Group, @@ -287,7 +287,7 @@ public class Game : IStatefulEntity /// Whether to release the semaphore used for changing the character. /// The cancellation token for cancelling the operation. /// The updated character. - internal async Task CreateOrUpdateCharacterAsync + internal Task CreateOrUpdateCharacterAsync ( Func create, Func update, @@ -295,7 +295,7 @@ public class Game : IStatefulEntity CancellationToken ct = default ) { - return await CreateOrUpdateAsync + return CreateOrUpdateAsync ( GameSemaphoreType.Character, () => Character, @@ -314,14 +314,14 @@ public class Game : IStatefulEntity /// Whether to release the semaphore used for changing the map. /// The cancellation token for cancelling the operation. /// The updated character. - internal async Task CreateMapAsync + internal Task CreateMapAsync ( Func create, bool releaseSemaphore = true, CancellationToken ct = default ) { - return await CreateAsync + return CreateAsync ( GameSemaphoreType.Map, m => CurrentMap = m, @@ -339,7 +339,7 @@ public class Game : IStatefulEntity /// Whether to release the semaphore used for changing the map. /// The cancellation token for cancelling the operation. /// The updated character. - internal async Task CreateOrUpdateMapAsync + internal Task CreateOrUpdateMapAsync ( Func create, Func update, @@ -347,7 +347,7 @@ public class Game : IStatefulEntity CancellationToken ct = default ) { - return await CreateOrUpdateAsync + return CreateOrUpdateAsync ( GameSemaphoreType.Map, () => CurrentMap, diff --git a/Core/NosSmooth.Game/GameSemaphores.cs b/Core/NosSmooth.Game/GameSemaphores.cs index 2303122..ec649e5 100644 --- a/Core/NosSmooth.Game/GameSemaphores.cs +++ b/Core/NosSmooth.Game/GameSemaphores.cs @@ -31,9 +31,9 @@ internal class GameSemaphores /// The semaphore type. /// The cancellation token for cancelling the operation. /// A task that may or may not have succeeded. - public async Task AcquireSemaphore(GameSemaphoreType semaphoreType, CancellationToken ct = default) + public Task AcquireSemaphore(GameSemaphoreType semaphoreType, CancellationToken ct = default) { - await _semaphores[semaphoreType].WaitAsync(ct); + return _semaphores[semaphoreType].WaitAsync(ct); } /// diff --git a/Core/NosSmooth.Game/PacketHandlers/Act4/FcResponder.cs b/Core/NosSmooth.Game/PacketHandlers/Act4/FcResponder.cs index 1850ab7..991d684 100644 --- a/Core/NosSmooth.Game/PacketHandlers/Act4/FcResponder.cs +++ b/Core/NosSmooth.Game/PacketHandlers/Act4/FcResponder.cs @@ -30,10 +30,10 @@ public class FcResponder : IPacketResponder } /// - public async Task Respond(PacketEventArgs packetArgs, CancellationToken ct = default) + public Task Respond(PacketEventArgs packetArgs, CancellationToken ct = default) { var packet = packetArgs.Packet; - return await _eventDispatcher.DispatchEvent + return _eventDispatcher.DispatchEvent ( new Act4StatusReceivedEvent ( diff --git a/Directory.Build.props b/Directory.Build.props index 089e6a4..8707651 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -17,6 +17,16 @@ runtime; build; native; contentfiles; analyzers; buildtransitive + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + diff --git a/Extensions/NosSmooth.Extensions.Combat/Operations/WalkOperation.cs b/Extensions/NosSmooth.Extensions.Combat/Operations/WalkOperation.cs index 2ebb058..cdaef76 100644 --- a/Extensions/NosSmooth.Extensions.Combat/Operations/WalkOperation.cs +++ b/Extensions/NosSmooth.Extensions.Combat/Operations/WalkOperation.cs @@ -31,8 +31,6 @@ public record WalkOperation(WalkManager WalkManager, short X, short Y) : ICombat } /// - public async Task UseAsync(ICombatState combatState, CancellationToken ct = default) - { - return await WalkManager.GoToAsync(X, Y, true, ct); - } + public Task UseAsync(ICombatState combatState, CancellationToken ct = default) + => WalkManager.GoToAsync(X, Y, true, ct); } \ No newline at end of file diff --git a/Packets/NosSmooth.PacketSerializersGenerator/Constants.cs b/Packets/NosSmooth.PacketSerializersGenerator/Constants.cs index a7eb434..9965555 100644 --- a/Packets/NosSmooth.PacketSerializersGenerator/Constants.cs +++ b/Packets/NosSmooth.PacketSerializersGenerator/Constants.cs @@ -9,7 +9,7 @@ namespace NosSmooth.PacketSerializersGenerator; /// /// Contains constants needed for the generation. /// -public class Constants +public static class Constants { /// /// Gets the full name of the generate source attribute class. diff --git a/Samples/FileClient/Client.cs b/Samples/FileClient/Client.cs index ad94e8c..f2243eb 100644 --- a/Samples/FileClient/Client.cs +++ b/Samples/FileClient/Client.cs @@ -97,9 +97,9 @@ public class Client : BaseNostaleClient } /// - public override async Task SendPacketAsync(string packetString, CancellationToken ct = default) + public override Task SendPacketAsync(string packetString, CancellationToken ct = default) { - return await _packetHandler.HandlePacketAsync + return _packetHandler.HandlePacketAsync ( this, PacketSource.Client, @@ -110,9 +110,9 @@ public class Client : BaseNostaleClient } /// - public override async Task ReceivePacketAsync(string packetString, CancellationToken ct = default) + public override Task ReceivePacketAsync(string packetString, CancellationToken ct = default) { - return await _packetHandler.HandlePacketAsync + return _packetHandler.HandlePacketAsync ( this, PacketSource.Server, -- 2.49.0