Update targeting logic v1.20
authorLiza Carvelli <liza@carvel.li>
Sat, 27 Jul 2024 09:19:18 +0000 (11:19 +0200)
committerLiza Carvelli <liza@carvel.li>
Sat, 27 Jul 2024 09:19:18 +0000 (11:19 +0200)
Questionable/Controller/CombatController.cs
Questionable/Questionable.csproj

index 8f0f0de8ab0f282c1b899a5a261ed3c52aaac642..7e5ed36adb7ad8016f6f03f88dce00426178361d 100644 (file)
@@ -76,20 +76,23 @@ internal sealed class CombatController : IDisposable
         var target = _targetManager.Target;
         if (target != null)
         {
-            if (GetKillPriority(target) is >= 50)
-                return true;
-
+            int currentTargetPriority = GetKillPriority(target);
             var nextTarget = FindNextTarget();
+            int nextTargetPriority = GetKillPriority(target);
+
             if (nextTarget != null && nextTarget.Equals(target))
             {
                 _currentFight.Module.Update(target);
             }
             else if (nextTarget != null)
             {
-                _logger.LogInformation("Changing next target to {TargetName} ({TargetId:X8})",
-                    nextTarget.Name.ToString(), nextTarget.GameObjectId);
-                _targetManager.Target = nextTarget;
-                _currentFight.Module.SetTarget(nextTarget);
+                if (nextTargetPriority > currentTargetPriority)
+                {
+                    _logger.LogInformation("Changing next target to {TargetName} ({TargetId:X8})",
+                        nextTarget.Name.ToString(), nextTarget.GameObjectId);
+                    _targetManager.Target = nextTarget;
+                    _currentFight.Module.SetTarget(nextTarget);
+                }
             }
             else
             {
@@ -160,14 +163,14 @@ internal sealed class CombatController : IDisposable
         }
 
         return _objectTable.Select(x => (GameObject: x, Priority: GetKillPriority(x)))
-            .Where(x => x.Priority != null)
-            .OrderByDescending(x => x.Priority!.Value)
+            .Where(x => x.Priority > 0)
+            .OrderByDescending(x => x.Priority)
             .ThenByDescending(x => Vector3.Distance(x.GameObject.Position, _clientState.LocalPlayer!.Position))
             .Select(x => x.GameObject)
             .FirstOrDefault();
     }
 
-    private unsafe int? GetKillPriority(IGameObject gameObject)
+    private unsafe int GetKillPriority(IGameObject gameObject)
     {
         if (gameObject is IBattleNpc battleNpc)
         {
@@ -177,11 +180,11 @@ internal sealed class CombatController : IDisposable
                 _currentFight.Data.ComplexCombatDatas.Count == 0)
             {
                 if (battleNpc.IsDead)
-                    return null;
+                    return 0;
             }
 
             if (!battleNpc.IsTargetable)
-                return null;
+                return 0;
 
             if (_currentFight != null)
             {
@@ -208,23 +211,23 @@ 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
-                    return null;
+                if (gameObjectStruct->NamePlateIconId is 60093 or 60732) // npc that starts a fate or does turn-ins; not sure why they're marked as hostile
+                    return 0;
 
                 var enemyData = _currentFight?.Data.ComplexCombatDatas.FirstOrDefault(x => x.DataId == battleNpc.DataId);
                 if (enemyData is { IgnoreQuestMarker: true })
-                    return battleNpc.StatusFlags.HasFlag(StatusFlags.InCombat) ? 20 : null;
+                    return battleNpc.StatusFlags.HasFlag(StatusFlags.InCombat) ? 20 : 0;
                 else
-                    return gameObjectStruct->NamePlateIconId != 0 ? 30 : null;
+                    return gameObjectStruct->NamePlateIconId != 0 ? 30 : 0;
             }
 
             // stuff trying to kill us
             if (battleNpc.TargetObjectId == _clientState.LocalPlayer?.GameObjectId)
-                return 0;
+                return 10;
 
         }
 
-        return null;
+        return 0;
     }
 
     public void Stop()
index d3dcfe2dbd2b2b9144e2bcb30913d44c6f8dbf8a..a0a0b50bdb4044acd7a278875782226f95fd7e27 100644 (file)
@@ -1,6 +1,6 @@
 <Project Sdk="Dalamud.NET.Sdk/9.0.2">
     <PropertyGroup>
-        <Version>1.19</Version>
+        <Version>1.20</Version>
         <OutputPath>dist</OutputPath>
         <PathMap Condition="$(SolutionDir) != ''">$(SolutionDir)=X:\</PathMap>
         <Platforms>x64</Platforms>