~ruther/NosSmooth

49b19775184488d164b50e1acd52072e4b4192c2 — František Boháček 2 years ago b6c7904
chore: add async analyzer and meet its standards
M Core/NosSmooth.Core/Client/BaseNostaleClient.cs => Core/NosSmooth.Core/Client/BaseNostaleClient.cs +2 -2
@@ 69,6 69,6 @@ public abstract class BaseNostaleClient : INostaleClient
    }

    /// <inheritdoc />
    public async Task<Result> SendCommandAsync(ICommand command, CancellationToken ct = default)
        => await _commandProcessor.ProcessCommand(this, command, ct);
    public Task<Result> SendCommandAsync(ICommand command, CancellationToken ct = default)
        => _commandProcessor.ProcessCommand(this, command, ct);
}

M Core/NosSmooth.Core/Commands/Control/ControlCommands.cs => Core/NosSmooth.Core/Commands/Control/ControlCommands.cs +2 -2
@@ 151,7 151,7 @@ public class ControlCommands
    /// <param name="waitForCancellation">Whether to wait for cancellation of non cancellable commands.</param>
    /// <param name="ct">The cancellation token for cancelling the operation.</param>
    /// <returns>A result that may or may not have succeeded.</returns>
    public async Task<Result> CancelAsync
    public Task<Result> 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<Result> FinishCommandsAsync(IEnumerable<CommandData> commandsToFinish)

M Core/NosSmooth.Core/NosSmooth.Core.csproj => Core/NosSmooth.Core/NosSmooth.Core.csproj +4 -4
@@ 15,13 15,13 @@
    </PropertyGroup>

    <ItemGroup>
      <PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.0" />
      <PackageReference Include="Remora.Results" Version="7.2.3" />
        <PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.0"/>
        <PackageReference Include="Remora.Results" Version="7.2.3"/>
    </ItemGroup>

    <ItemGroup>
      <ProjectReference Include="..\..\Packets\NosSmooth.PacketSerializer\NosSmooth.PacketSerializer.csproj" />
      <ProjectReference Include="..\..\Packets\NosSmooth.Packets\NosSmooth.Packets.csproj" />
        <ProjectReference Include="..\..\Packets\NosSmooth.PacketSerializer\NosSmooth.PacketSerializer.csproj"/>
        <ProjectReference Include="..\..\Packets\NosSmooth.Packets\NosSmooth.Packets.csproj"/>
    </ItemGroup>

</Project>

M Core/NosSmooth.Game/Apis/NostaleInventoryPacketApi.cs => Core/NosSmooth.Game/Apis/NostaleInventoryPacketApi.cs +7 -7
@@ 35,14 35,14 @@ public class NostaleInventoryPacketApi
    /// <param name="amount">The amount to drop.</param>
    /// <param name="ct">The cancellation token used for cancelling the operation.</param>
    /// <returns>A result that may or may not have succeeded.</returns>
    public async Task<Result> DropItemAsync
    public Task<Result> 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);

    /// <summary>
    /// Move the given item within one bag.


@@ 53,7 53,7 @@ public class NostaleInventoryPacketApi
    /// <param name="amount">The amount to move.</param>
    /// <param name="ct">The cancellation token used for cancelling the operation.</param>
    /// <returns>A result that may or may not have succeeded.</returns>
    public async Task<Result> MoveItemAsync
    public Task<Result> 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
    /// <param name="amount">The amount to move.</param>
    /// <param name="ct">The cancellation token used for cancelling the operation.</param>
    /// <returns>A result that may or may not have succeeded.</returns>
    public async Task<Result> MoveItemAsync
    public Task<Result> 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

M Core/NosSmooth.Game/Apis/NostaleMapPacketApi.cs => Core/NosSmooth.Game/Apis/NostaleMapPacketApi.cs +2 -2
@@ 46,8 46,8 @@ public class NostaleMapPacketApi
    /// <param name="ct">The cancellation token for cancelling the operation.</param>
    /// <returns>A result that may or may not have succeeded.</returns>
    [Unsafe("Portal position not checked.")]
    public async Task<Result> UsePortalAsync(CancellationToken ct = default)
        => await _client.SendPacketAsync(new PreqPacket(), ct);
    public Task<Result> UsePortalAsync(CancellationToken ct = default)
        => _client.SendPacketAsync(new PreqPacket(), ct);

    /// <summary>
    /// Pick up the given item.

M Core/NosSmooth.Game/Apis/NostaleMatePacketApi.cs => Core/NosSmooth.Game/Apis/NostaleMatePacketApi.cs +6 -6
@@ 41,8 41,8 @@ public class NostaleMatePacketApi
    /// <param name="mateId">The id of the mate to have company.</param>
    /// <param name="ct">The cancellation token used for cancelling the operation.</param>
    /// <returns>A result that may or may not have succeeded.</returns>
    public async Task<Result> CompanyAsync(long mateId, CancellationToken ct = default)
        => await _client.SendPacketAsync
    public Task<Result> CompanyAsync(long mateId, CancellationToken ct = default)
        => _client.SendPacketAsync
        (
            new NRunPacket
            (


@@ 67,8 67,8 @@ public class NostaleMatePacketApi
    /// <param name="mateId">The id of the mate to have company.</param>
    /// <param name="ct">The cancellation token used for cancelling the operation.</param>
    /// <returns>A result that may or may not have succeeded.</returns>
    public async Task<Result> StayAsync(long mateId, CancellationToken ct = default)
        => await _client.SendPacketAsync
    public Task<Result> StayAsync(long mateId, CancellationToken ct = default)
        => _client.SendPacketAsync
        (
            new NRunPacket
            (


@@ 90,8 90,8 @@ public class NostaleMatePacketApi
    /// <param name="mateId">The id of the mate to have company.</param>
    /// <param name="ct">The cancellation token used for cancelling the operation.</param>
    /// <returns>A result that may or may not have succeeded.</returns>
    public async Task<Result> SendBackAsync(long mateId, CancellationToken ct = default)
        => await _client.SendPacketAsync
    public Task<Result> SendBackAsync(long mateId, CancellationToken ct = default)
        => _client.SendPacketAsync
        (
            new NRunPacket
            (

M Core/NosSmooth.Game/Apis/NostaleMateSkillsPacketApi.cs => Core/NosSmooth.Game/Apis/NostaleMateSkillsPacketApi.cs +4 -4
@@ 36,7 36,7 @@ public class NostaleMateSkillsPacketApi
    /// <param name="mapX">The x coordinate of the partner.</param>
    /// <param name="mapY">The y coordinate of the partner.</param>
    /// <returns>A result that may or may not have succeeded.</returns>
    public async Task<Result> UsePetSkillAsync
    public Task<Result> 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
    /// <param name="mapX">The x coordinate of the partner.</param>
    /// <param name="mapY">The y coordinate of the partner.</param>
    /// <returns>A result that may or may not have succeeded.</returns>
    public async Task<Result> UsePartnerSkillAsync
    public Task<Result> UsePartnerSkillAsync
    (
        long partnerId,
        byte skillSlot,


@@ 79,7 79,7 @@ public class NostaleMateSkillsPacketApi
        short? mapY = default
    )
    {
        return await _client.SendPacketAsync
        return _client.SendPacketAsync
        (
            new UsePartnerSkillPacket
            (

M Core/NosSmooth.Game/Game.cs => Core/NosSmooth.Game/Game.cs +16 -16
@@ 103,7 103,7 @@ public class Game : IStatefulEntity
    /// <param name="releaseSemaphore">Whether to release the semaphore used for changing the mates.</param>
    /// <param name="ct">The cancellation token for cancelling the operation.</param>
    /// <returns>The updated mates.</returns>
    internal async Task<Mates?> CreateOrUpdateMatesAsync
    internal Task<Mates?> CreateOrUpdateMatesAsync
    (
        Func<Mates?> create,
        Func<Mates, Mates?> 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
    /// <param name="releaseSemaphore">Whether to release the semaphore used for changing the skills.</param>
    /// <param name="ct">The cancellation token for cancelling the operation.</param>
    /// <returns>The updated skills.</returns>
    internal async Task<Skills?> CreateOrUpdateSkillsAsync
    internal Task<Skills?> CreateOrUpdateSkillsAsync
    (
        Func<Skills?> create,
        Func<Skills, Skills?> 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
    /// <param name="releaseSemaphore">Whether to release the semaphore used for changing the inventory.</param>
    /// <param name="ct">The cancellation token for cancelling the operation.</param>
    /// <returns>The updated inventory.</returns>
    internal async Task<Inventory?> CreateOrUpdateInventoryAsync
    internal Task<Inventory?> CreateOrUpdateInventoryAsync
    (
        Func<Inventory?> create,
        Func<Inventory, Inventory?> 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
    /// <param name="releaseSemaphore">Whether to release the semaphore used for changing the friends.</param>
    /// <param name="ct">The cancellation token for cancelling the operation.</param>
    /// <returns>The updated friends.</returns>
    internal async Task<IReadOnlyList<Friend>?> CreateOrUpdateFriendsAsync
    internal Task<IReadOnlyList<Friend>?> CreateOrUpdateFriendsAsync
    (
        Func<IReadOnlyList<Friend>?> create,
        Func<IReadOnlyList<Friend>, IReadOnlyList<Friend>?> 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
    /// <param name="releaseSemaphore">Whether to release the semaphore used for changing the group.</param>
    /// <param name="ct">The cancellation token for cancelling the operation.</param>
    /// <returns>The updated group.</returns>
    internal async Task<Group?> CreateOrUpdateGroupAsync
    internal Task<Group?> CreateOrUpdateGroupAsync
    (
        Func<Group?> create,
        Func<Group, Group?> 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
    /// <param name="releaseSemaphore">Whether to release the semaphore used for changing the character.</param>
    /// <param name="ct">The cancellation token for cancelling the operation.</param>
    /// <returns>The updated character.</returns>
    internal async Task<Character?> CreateOrUpdateCharacterAsync
    internal Task<Character?> CreateOrUpdateCharacterAsync
    (
        Func<Character?> create,
        Func<Character, Character?> 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
    /// <param name="releaseSemaphore">Whether to release the semaphore used for changing the map.</param>
    /// <param name="ct">The cancellation token for cancelling the operation.</param>
    /// <returns>The updated character.</returns>
    internal async Task<Map?> CreateMapAsync
    internal Task<Map?> CreateMapAsync
    (
        Func<Map?> 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
    /// <param name="releaseSemaphore">Whether to release the semaphore used for changing the map.</param>
    /// <param name="ct">The cancellation token for cancelling the operation.</param>
    /// <returns>The updated character.</returns>
    internal async Task<Map?> CreateOrUpdateMapAsync
    internal Task<Map?> CreateOrUpdateMapAsync
    (
        Func<Map?> create,
        Func<Map?, Map?> update,


@@ 347,7 347,7 @@ public class Game : IStatefulEntity
        CancellationToken ct = default
    )
    {
        return await CreateOrUpdateAsync<Map?>
        return CreateOrUpdateAsync<Map?>
        (
            GameSemaphoreType.Map,
            () => CurrentMap,

M Core/NosSmooth.Game/GameSemaphores.cs => Core/NosSmooth.Game/GameSemaphores.cs +2 -2
@@ 31,9 31,9 @@ internal class GameSemaphores
    /// <param name="semaphoreType">The semaphore type.</param>
    /// <param name="ct">The cancellation token for cancelling the operation.</param>
    /// <returns>A task that may or may not have succeeded.</returns>
    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);
    }

    /// <summary>

M Core/NosSmooth.Game/PacketHandlers/Act4/FcResponder.cs => Core/NosSmooth.Game/PacketHandlers/Act4/FcResponder.cs +2 -2
@@ 30,10 30,10 @@ public class FcResponder : IPacketResponder<FcPacket>
    }

    /// <inheritdoc />
    public async Task<Result> Respond(PacketEventArgs<FcPacket> packetArgs, CancellationToken ct = default)
    public Task<Result> Respond(PacketEventArgs<FcPacket> packetArgs, CancellationToken ct = default)
    {
        var packet = packetArgs.Packet;
        return await _eventDispatcher.DispatchEvent
        return _eventDispatcher.DispatchEvent
        (
            new Act4StatusReceivedEvent
            (

M Directory.Build.props => Directory.Build.props +10 -0
@@ 17,6 17,16 @@
            <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
        </PackageReference>

        <PackageReference Include="Remora.Results.Analyzers" Version="1.0.0">
            <PrivateAssets>all</PrivateAssets>
            <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
        </PackageReference>

        <PackageReference Include="AsyncFixer" Version="1.6.0">
            <PrivateAssets>all</PrivateAssets>
            <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
        </PackageReference>
        
        <AdditionalFiles Include="$(MSBuildThisFileDirectory)stylecop.json" Link="stylecop.json"/>
    </ItemGroup>
</Project>

M Extensions/NosSmooth.Extensions.Combat/Operations/WalkOperation.cs => Extensions/NosSmooth.Extensions.Combat/Operations/WalkOperation.cs +2 -4
@@ 31,8 31,6 @@ public record WalkOperation(WalkManager WalkManager, short X, short Y) : ICombat
    }

    /// <inheritdoc />
    public async Task<Result> UseAsync(ICombatState combatState, CancellationToken ct = default)
    {
        return await WalkManager.GoToAsync(X, Y, true, ct);
    }
    public Task<Result> UseAsync(ICombatState combatState, CancellationToken ct = default)
        => WalkManager.GoToAsync(X, Y, true, ct);
}
\ No newline at end of file

M Packets/NosSmooth.PacketSerializersGenerator/Constants.cs => Packets/NosSmooth.PacketSerializersGenerator/Constants.cs +1 -1
@@ 9,7 9,7 @@ namespace NosSmooth.PacketSerializersGenerator;
/// <summary>
/// Contains constants needed for the generation.
/// </summary>
public class Constants
public static class Constants
{
    /// <summary>
    /// Gets the full name of the generate source attribute class.

M Samples/FileClient/Client.cs => Samples/FileClient/Client.cs +4 -4
@@ 97,9 97,9 @@ public class Client : BaseNostaleClient
    }

    /// <inheritdoc/>
    public override async Task<Result> SendPacketAsync(string packetString, CancellationToken ct = default)
    public override Task<Result> SendPacketAsync(string packetString, CancellationToken ct = default)
    {
        return await _packetHandler.HandlePacketAsync
        return _packetHandler.HandlePacketAsync
        (
            this,
            PacketSource.Client,


@@ 110,9 110,9 @@ public class Client : BaseNostaleClient
    }

    /// <inheritdoc/>
    public override async Task<Result> ReceivePacketAsync(string packetString, CancellationToken ct = default)
    public override Task<Result> ReceivePacketAsync(string packetString, CancellationToken ct = default)
    {
        return await _packetHandler.HandlePacketAsync
        return _packetHandler.HandlePacketAsync
        (
            this,
            PacketSource.Server,

Do not follow this link