From cc89a5550fd718b49226f1ccfa4dac769d2b2f4d Mon Sep 17 00:00:00 2001 From: Liza Carvelli Date: Sun, 28 Jul 2024 21:50:17 +0200 Subject: [PATCH] Pathfinding to get in melee/cast range shouldn't count as 'combat complete' --- Questionable/Controller/CombatController.cs | 38 ++++++++++++++----- Questionable/Controller/QuestController.cs | 8 ++-- .../Controller/Steps/Interactions/Combat.cs | 4 +- 3 files changed, 35 insertions(+), 15 deletions(-) diff --git a/Questionable/Controller/CombatController.cs b/Questionable/Controller/CombatController.cs index f8c38a7d3..d02def761 100644 --- a/Questionable/Controller/CombatController.cs +++ b/Questionable/Controller/CombatController.cs @@ -30,6 +30,7 @@ internal sealed class CombatController : IDisposable private readonly ILogger _logger; private CurrentFight? _currentFight; + private bool _wasInCombat; public CombatController( IEnumerable combatModules, @@ -57,7 +58,7 @@ internal sealed class CombatController : IDisposable public bool Start(CombatData combatData) { - Stop(); + Stop("Starting combat"); var combatModule = _combatModules.FirstOrDefault(x => x.IsLoaded); if (combatModule == null) @@ -76,11 +77,13 @@ internal sealed class CombatController : IDisposable return false; } - /// true if still in combat, false otherwise - public bool Update() + public EStatus Update() { - if (_currentFight == null || _movementController.IsPathfinding || _movementController.IsPathRunning) - return false; + if (_currentFight == null) + return EStatus.Complete; + + if (_movementController.IsPathfinding || _movementController.IsPathRunning) + return EStatus.Moving; var target = _targetManager.Target; if (target != null) @@ -121,7 +124,15 @@ internal sealed class CombatController : IDisposable } } - return _condition[ConditionFlag.InCombat]; + if (_condition[ConditionFlag.InCombat]) + { + _wasInCombat = true; + return EStatus.InCombat; + } + else if (_wasInCombat) + return EStatus.Complete; + else + return EStatus.InCombat; } [SuppressMessage("ReSharper", "RedundantJumpStatement")] @@ -263,8 +274,9 @@ internal sealed class CombatController : IDisposable return 0; } - public void Stop() + public void Stop(string label) { + using var scope = _logger.BeginScope(label); if (_currentFight != null) { _logger.LogInformation("Stopping current fight"); @@ -272,14 +284,15 @@ internal sealed class CombatController : IDisposable } _currentFight = null; + _wasInCombat = false; } - private void TerritoryChanged(ushort territoryId) => Stop(); + private void TerritoryChanged(ushort territoryId) => Stop("TerritoryChanged"); public void Dispose() { _clientState.TerritoryChanged -= TerritoryChanged; - Stop(); + Stop("Dispose"); } private sealed class CurrentFight @@ -297,4 +310,11 @@ internal sealed class CombatController : IDisposable public HashSet CompletedComplexDatas { get; } = new(); } + + public enum EStatus + { + InCombat, + Moving, + Complete, + } } diff --git a/Questionable/Controller/QuestController.cs b/Questionable/Controller/QuestController.cs index 6f00598f1..4838353aa 100644 --- a/Questionable/Controller/QuestController.cs +++ b/Questionable/Controller/QuestController.cs @@ -137,7 +137,7 @@ internal sealed class QuestController { Stop("HP = 0"); _movementController.Stop(); - _combatController.Stop(); + _combatController.Stop("HP = 0"); } } else if (_keyState[VirtualKey.ESCAPE]) @@ -146,7 +146,7 @@ internal sealed class QuestController { Stop("ESC pressed"); _movementController.Stop(); - _combatController.Stop(); + _combatController.Stop("ESC pressed"); } } @@ -376,7 +376,7 @@ internal sealed class QuestController _taskQueue.Clear(); _yesAlreadyIpc.RestoreYesAlready(); - _combatController.Stop(); + _combatController.Stop("ClearTasksInternal"); } public void Stop(string label, bool continueIfAutomatic = false) @@ -535,7 +535,7 @@ internal sealed class QuestController } _movementController.Stop(); - _combatController.Stop(); + _combatController.Stop("Execute next step"); var newTasks = _taskFactories .SelectMany(x => diff --git a/Questionable/Controller/Steps/Interactions/Combat.cs b/Questionable/Controller/Steps/Interactions/Combat.cs index 52ab696f6..11f5777d0 100644 --- a/Questionable/Controller/Steps/Interactions/Combat.cs +++ b/Questionable/Controller/Steps/Interactions/Combat.cs @@ -103,7 +103,7 @@ internal static class Combat public ETaskResult Update() { - if (combatController.Update()) + if (combatController.Update() != CombatController.EStatus.Complete) return ETaskResult.StillRunning; // if our quest step has any completion flags, we need to check if they are set @@ -125,7 +125,7 @@ internal static class Combat return ETaskResult.StillRunning; else { - combatController.Stop(); + combatController.Stop("Combat task complete"); return ETaskResult.TaskComplete; } }