//
// PlayerWalkCommandHandler.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.
using Microsoft.Extensions.Options;
using NosSmooth.Core.Client;
using NosSmooth.Core.Commands;
using NosSmooth.Core.Commands.Control;
using NosSmooth.Core.Commands.Walking;
using NosSmooth.Core.Extensions;
using NosSmooth.LocalBinding.Objects;
using Remora.Results;
namespace NosSmooth.LocalClient.CommandHandlers.Walk;
///
/// Handles .
///
public class PlayerWalkCommandHandler : ICommandHandler
{
///
/// Group that is used for .
///
public const string PlayerWalkControlGroup = "PlayerWalk";
private readonly PlayerManagerBinding _playerManagerBinding;
private readonly UserActionDetector _userActionDetector;
private readonly INostaleClient _nostaleClient;
private readonly WalkCommandHandlerOptions _options;
///
/// Initializes a new instance of the class.
///
/// The character object binding.
/// The user action detector.
/// The nostale client.
/// The options.
public PlayerWalkCommandHandler
(
PlayerManagerBinding playerManagerBinding,
UserActionDetector userActionDetector,
INostaleClient nostaleClient,
IOptions options
)
{
_options = options.Value;
_playerManagerBinding = playerManagerBinding;
_userActionDetector = userActionDetector;
_nostaleClient = nostaleClient;
}
///
public async Task HandleCommand(PlayerWalkCommand command, CancellationToken ct = default)
{
var handler = new ControlCommandWalkHandler
(
_nostaleClient,
async (x, y, ct) =>
await _userActionDetector.NotUserWalkAsync(_playerManagerBinding, x, y, ct),
_playerManagerBinding.PlayerManager,
_options
);
return await handler.HandleCommand
(
command.TargetX,
command.TargetY,
command.ReturnDistanceTolerance,
command,
PlayerWalkControlGroup,
ct
);
}
}