From adb6da04bbebec3ac15cf4080690e3f2d5ceb063 Mon Sep 17 00:00:00 2001 From: Rutherther Date: Sun, 1 Jan 2023 23:19:44 +0100 Subject: [PATCH] feat(samples): add commands for focusing and following --- .../SimplePiiBot/Commands/EntityCommands.cs | 62 ++++++++++++++++--- src/Samples/HighLevel/SimplePiiBot/DllMain.cs | 3 +- src/Samples/LowLevel/WalkCommands/Startup.cs | 1 - 3 files changed, 57 insertions(+), 9 deletions(-) diff --git a/src/Samples/HighLevel/SimplePiiBot/Commands/EntityCommands.cs b/src/Samples/HighLevel/SimplePiiBot/Commands/EntityCommands.cs index 3ab9867269335cae85ed58857ac0819d9a1639d1..47fa1d299463097f110aad0200f712e54570a805 100644 --- a/src/Samples/HighLevel/SimplePiiBot/Commands/EntityCommands.cs +++ b/src/Samples/HighLevel/SimplePiiBot/Commands/EntityCommands.cs @@ -1,51 +1,99 @@ // -// CombatCommands.cs +// EntityCommands.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 NosSmooth.ChatCommands; -using NosSmooth.Core.Client; -using NosSmooth.LocalBinding; +using NosSmooth.Extensions.Combat.Errors; +using NosSmooth.Game; using NosSmooth.LocalBinding.Objects; using NosSmooth.LocalBinding.Structs; using Remora.Commands.Attributes; using Remora.Commands.Groups; using Remora.Results; -namespace WalkCommands.Commands; +namespace SimplePiiBot.Commands; /// /// Represents command group for combat commands. /// -public class CombatCommands : CommandGroup +public class EntityCommands : CommandGroup { + private readonly Game _game; private readonly UnitManagerBinding _unitManagerBinding; private readonly SceneManager _sceneManager; private readonly PlayerManagerBinding _playerManagerBinding; private readonly FeedbackService _feedbackService; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// + /// The game. /// The scene manager binding. /// The scene manager. /// The character binding. /// The feedback service. - public CombatCommands + public EntityCommands ( + Game game, UnitManagerBinding unitManagerBinding, SceneManager sceneManager, PlayerManagerBinding playerManagerBinding, FeedbackService feedbackService ) { + _game = game; _unitManagerBinding = unitManagerBinding; _sceneManager = sceneManager; _playerManagerBinding = playerManagerBinding; _feedbackService = feedbackService; } + /// + /// Show close entities. + /// + /// The range to look. + /// A task that may or may not have succeeded. + [Command("close")] + public async Task HandleCloseEntitiesAsync(int range = 10) + { + var map = _game.CurrentMap; + var character = _game.Character; + if (map is null) + { + return new MapNotInitializedError(); + } + + if (character is null) + { + return new CharacterNotInitializedError(); + } + + var position = character.Position; + if (position is null) + { + return new CharacterNotInitializedError("Position"); + } + + var entities = map.Entities + .GetEntities() + .Where(x => x.Position?.DistanceSquared(position.Value) <= range * range) + .ToList(); + + if (entities.Count == 0) + { + await _feedbackService.SendInfoMessageAsync("No entity found.", CancellationToken); + } + + foreach (var entity in entities) + { + await _feedbackService.SendInfoMessageAsync($"Found entity: {entity.Id}", CancellationToken); + } + + return Result.FromSuccess(); + } + /// /// Focus the given entity. /// diff --git a/src/Samples/HighLevel/SimplePiiBot/DllMain.cs b/src/Samples/HighLevel/SimplePiiBot/DllMain.cs index a94daf6b1b54dc93829cfcf9b852927fa8c641b8..2d40a977a083b70b52e48f1ee44fe17cf27add88 100644 --- a/src/Samples/HighLevel/SimplePiiBot/DllMain.cs +++ b/src/Samples/HighLevel/SimplePiiBot/DllMain.cs @@ -87,7 +87,8 @@ public class DllMain .AddNostaleChatCommands() .AddGameResponder() .AddCommandTree() - .WithCommandGroup(); + .WithCommandGroup() + .WithCommandGroup(); s.AddHostedService(); } ).Build(); diff --git a/src/Samples/LowLevel/WalkCommands/Startup.cs b/src/Samples/LowLevel/WalkCommands/Startup.cs index afd6fc9870780438e0b81d64fe0262dd8be6eebc..63203324d0ed3e93164fd87402f3324f026266d8 100644 --- a/src/Samples/LowLevel/WalkCommands/Startup.cs +++ b/src/Samples/LowLevel/WalkCommands/Startup.cs @@ -59,7 +59,6 @@ public class Startup collection.AddCommandTree() .WithCommandGroup() - .WithCommandGroup() .WithCommandGroup(); return collection.BuildServiceProvider(); }