From 70ba0dd84e9b131287279c6dd5b33fe0fe82b367 Mon Sep 17 00:00:00 2001 From: Rutherther Date: Sun, 23 Jan 2022 21:15:43 +0100 Subject: [PATCH] feat(samples): update CombatCommands to work with the new unit manager binding --- .../WalkCommands/Commands/CombatCommands.cs | 47 +++++++++++++++---- 1 file changed, 38 insertions(+), 9 deletions(-) diff --git a/Samples/WalkCommands/Commands/CombatCommands.cs b/Samples/WalkCommands/Commands/CombatCommands.cs index 89eeef7..abfef31 100644 --- a/Samples/WalkCommands/Commands/CombatCommands.cs +++ b/Samples/WalkCommands/Commands/CombatCommands.cs @@ -6,7 +6,9 @@ using NosSmooth.ChatCommands; using NosSmooth.Core.Client; +using NosSmooth.LocalBinding; using NosSmooth.LocalBinding.Objects; +using NosSmooth.LocalBinding.Structs; using Remora.Commands.Attributes; using Remora.Commands.Groups; using Remora.Results; @@ -18,19 +20,28 @@ namespace WalkCommands.Commands; /// public class CombatCommands : CommandGroup { - private readonly SceneManagerBinding _sceneManagerBinding; + private readonly UnitManagerBinding _unitManagerBinding; + private readonly ExternalNosBrowser _nosBrowser; private readonly PlayerManagerBinding _playerManagerBinding; private readonly FeedbackService _feedbackService; /// /// Initializes a new instance of the class. /// - /// The scene manager binding. + /// The scene manager binding. + /// The nostale browser. /// The character binding. /// The feedback service. - public CombatCommands(SceneManagerBinding sceneManagerBinding, PlayerManagerBinding playerManagerBinding, FeedbackService feedbackService) + public CombatCommands + ( + UnitManagerBinding unitManagerBinding, + ExternalNosBrowser nosBrowser, + PlayerManagerBinding playerManagerBinding, + FeedbackService feedbackService + ) { - _sceneManagerBinding = sceneManagerBinding; + _unitManagerBinding = unitManagerBinding; + _nosBrowser = nosBrowser; _playerManagerBinding = playerManagerBinding; _feedbackService = feedbackService; } @@ -43,7 +54,19 @@ public class CombatCommands : CommandGroup [Command("focus")] public Task HandleFocusAsync(int entityId) { - return Task.FromResult(_sceneManagerBinding.FocusEntity(entityId)); + var sceneManagerResult = _nosBrowser.GetSceneManager(); + if (!sceneManagerResult.IsSuccess) + { + return Task.FromResult(Result.FromError(sceneManagerResult)); + } + + var entityResult = sceneManagerResult.Entity.FindEntity(entityId); + if (!entityResult.IsSuccess) + { + return Task.FromResult(Result.FromError(entityResult)); + } + + return Task.FromResult(_unitManagerBinding.FocusEntity(entityResult.Entity)); } /// @@ -54,13 +77,19 @@ public class CombatCommands : CommandGroup [Command("follow")] public Task HandleFollowAsync(int entityId) { - var entity = _sceneManagerBinding.FindEntity(entityId); - if (!entity.IsSuccess) + var sceneManagerResult = _nosBrowser.GetSceneManager(); + if (!sceneManagerResult.IsSuccess) + { + return Task.FromResult(Result.FromError(sceneManagerResult)); + } + + var entityResult = sceneManagerResult.Entity.FindEntity(entityId); + if (!entityResult.IsSuccess) { - return Task.FromResult(Result.FromError(entity)); + return Task.FromResult(Result.FromError(entityResult)); } - return Task.FromResult(_playerManagerBinding.FollowEntity(entity.Entity)); + return Task.FromResult(_playerManagerBinding.FollowEntity(entityResult.Entity)); } /// -- 2.49.0