Combat + Skip updates
authorLiza Carvelli <liza@carvel.li>
Sat, 27 Jul 2024 15:37:08 +0000 (17:37 +0200)
committerLiza Carvelli <liza@carvel.li>
Sat, 27 Jul 2024 15:37:08 +0000 (17:37 +0200)
Questionable.Model/V1/SkipStepConditions.cs
Questionable/Controller/CombatController.cs
Questionable/Controller/Steps/Interactions/Combat.cs
Questionable/Controller/Steps/Shared/SkipCondition.cs
Questionable/Controller/Utils/QuestWorkUtils.cs
Questionable/QuestionablePlugin.cs

index 97222ebd760c7ab9b09df5e498b3c3c89a76692d..480f8d11f442d47fa4c5a27ace093c038b9ffdcf 100644 (file)
@@ -21,6 +21,8 @@ public sealed class SkipStepConditions
 
     public bool HasSkipConditions()
     {
-        return Never || Flying != null || Chocobo != null || InTerritory.Count > 0 || NotInTerritory.Count > 0 || Item != null;
+        if (Never)
+            return false;
+        return Flying != null || Chocobo != null || InTerritory.Count > 0 || NotInTerritory.Count > 0 || Item != null;
     }
 }
index 7e5ed36adb7ad8016f6f03f88dce00426178361d..923b7c866a1dadb9a8cb064177f7b90b1e998620 100644 (file)
@@ -9,6 +9,7 @@ using Dalamud.Game.ClientState.Objects.Types;
 using Dalamud.Plugin.Services;
 using FFXIVClientStructs.FFXIV.Client.Game;
 using FFXIVClientStructs.FFXIV.Client.Game.Object;
+using FFXIVClientStructs.FFXIV.Client.Game.UI;
 using FFXIVClientStructs.FFXIV.Common.Math;
 using Microsoft.Extensions.Logging;
 using Questionable.Controller.CombatModules;
@@ -211,23 +212,42 @@ internal sealed class CombatController : IDisposable
             if (battleNpc.BattleNpcKind is BattleNpcSubKind.BattleNpcPart or BattleNpcSubKind.Enemy)
             {
                 var gameObjectStruct = (GameObject*)gameObject.Address;
-                if (gameObjectStruct->NamePlateIconId is 60093 or 60732) // npc that starts a fate or does turn-ins; not sure why they're marked as hostile
+
+                // npc that starts a fate or does turn-ins; not sure why they're marked as hostile
+                if (gameObjectStruct->NamePlateIconId is 60093 or 60732)
                     return 0;
 
-                var enemyData = _currentFight?.Data.ComplexCombatDatas.FirstOrDefault(x => x.DataId == battleNpc.DataId);
+                var enemyData =
+                    _currentFight?.Data.ComplexCombatDatas.FirstOrDefault(x => x.DataId == battleNpc.DataId);
                 if (enemyData is { IgnoreQuestMarker: true })
-                    return battleNpc.StatusFlags.HasFlag(StatusFlags.InCombat) ? 20 : 0;
+                {
+                    if (battleNpc.StatusFlags.HasFlag(StatusFlags.InCombat))
+                        return 20;
+                }
                 else
-                    return gameObjectStruct->NamePlateIconId != 0 ? 30 : 0;
+                {
+                    if (gameObjectStruct->NamePlateIconId != 0)
+                        return 30;
+                }
             }
 
             // stuff trying to kill us
             if (battleNpc.TargetObjectId == _clientState.LocalPlayer?.GameObjectId)
                 return 10;
 
-        }
+            // stuff on our enmity list that's not necessarily targeting us
+            var haters = UIState.Instance()->Hater;
+            for (int i = 0; i < haters.HaterCount; ++i)
+            {
+                var hater = haters.Haters[i];
+                if (hater.EntityId == battleNpc.GameObjectId)
+                    return 5;
+            }
 
-        return 0;
+            return 0;
+        }
+        else
+            return 0;
     }
 
     public void Stop()
index c8a7e9290220e844b3ef1e9f70a4929b84e0a1d9..52ab696f667537c5fb7bcecf02d929820381dde0 100644 (file)
@@ -113,7 +113,9 @@ internal static class Combat
                 if (questWork == null)
                     return ETaskResult.StillRunning;
 
-                if (!QuestWorkUtils.MatchesQuestWork(_completionQuestVariableFlags, questWork.Value, false))
+                if (QuestWorkUtils.MatchesQuestWork(_completionQuestVariableFlags, questWork.Value, false))
+                    return ETaskResult.TaskComplete;
+                else
                     return ETaskResult.StillRunning;
             }
 
index 04f338a793d0479e802305d4f589e060ee942ea7..68982ebbf91214423f7d0095598242f2cfbdf322 100644 (file)
@@ -22,23 +22,23 @@ internal static class SkipCondition
         public ITask? CreateTask(Quest quest, QuestSequence sequence, QuestStep step)
         {
             var skipConditions = step.SkipConditions?.StepIf;
-            if (skipConditions == null || skipConditions.Never)
+            if (skipConditions is { Never: true })
                 return null;
 
-            if (skipConditions.HasSkipConditions() &&
-                step.CompletionQuestVariablesFlags.Count == 0 &&
+            if ((skipConditions == null || !skipConditions.HasSkipConditions()) &&
+                !QuestWorkUtils.HasCompletionFlags(step.CompletionQuestVariablesFlags) &&
                 step.RequiredQuestVariables.Count == 0 &&
                 step.PickUpQuestId == null &&
                 step.NextQuestId == null)
                 return null;
 
-            return serviceProvider.GetRequiredService<CheckTask>()
-                .With(step, skipConditions, quest.QuestId);
+            return serviceProvider.GetRequiredService<CheckSkip>()
+                .With(step, skipConditions ?? new(), quest.QuestId);
         }
     }
 
-    internal sealed class CheckTask(
-        ILogger<CheckTask> logger,
+    internal sealed class CheckSkip(
+        ILogger<CheckSkip> logger,
         GameFunctions gameFunctions,
         IClientState clientState) : ITask
     {
index 360007ed34995028cbad956bae54b1ae332fbc6a..33edd498163ba7513bbf27f109d508eaf32c0d41 100644 (file)
@@ -50,7 +50,7 @@ internal static class QuestWorkUtils
     }
 
     public static bool MatchesRequiredQuestWorkConfig(List<List<QuestWorkValue>?> requiredQuestVariables,
-        QuestWork questWork, ILogger<SkipCondition.CheckTask> logger)
+        QuestWork questWork, ILogger<SkipCondition.CheckSkip> logger)
     {
         if (requiredQuestVariables.Count != 6 || requiredQuestVariables.All(x => x == null || x.Count == 0))
         {
index f9318b706c7fc35aad2f1ae3e3f9482bb846f640..3b230b84b174ea66008fdf856b5506b7050e5279 100644 (file)
@@ -105,7 +105,7 @@ public sealed class QuestionablePlugin : IDalamudPlugin
         // task factories
         serviceCollection.AddTaskWithFactory<StepDisabled.Factory, StepDisabled.Task>();
         serviceCollection.AddTaskWithFactory<AetheryteShortcut.Factory, AetheryteShortcut.UseAetheryteShortcut>();
-        serviceCollection.AddTaskWithFactory<SkipCondition.Factory, SkipCondition.CheckTask>();
+        serviceCollection.AddTaskWithFactory<SkipCondition.Factory, SkipCondition.CheckSkip>();
         serviceCollection.AddTaskWithFactory<AethernetShortcut.Factory, AethernetShortcut.UseAethernetShortcut>();
         serviceCollection.AddTaskWithFactory<WaitAtStart.Factory, WaitAtStart.WaitDelay>();
         serviceCollection.AddTaskWithFactory<Move.Factory, Move.MoveInternal, Move.ExpectToBeNearDataId, Move.Land>();