Update targeting logic

This commit is contained in:
Liza 2024-07-27 11:19:18 +02:00
parent 3483d07ff2
commit b86d01bd6f
Signed by: liza
GPG Key ID: 7199F8D727D55F67
2 changed files with 22 additions and 19 deletions

View File

@ -76,20 +76,23 @@ internal sealed class CombatController : IDisposable
var target = _targetManager.Target; var target = _targetManager.Target;
if (target != null) if (target != null)
{ {
if (GetKillPriority(target) is >= 50) int currentTargetPriority = GetKillPriority(target);
return true;
var nextTarget = FindNextTarget(); var nextTarget = FindNextTarget();
int nextTargetPriority = GetKillPriority(target);
if (nextTarget != null && nextTarget.Equals(target)) if (nextTarget != null && nextTarget.Equals(target))
{ {
_currentFight.Module.Update(target); _currentFight.Module.Update(target);
} }
else if (nextTarget != null) else if (nextTarget != null)
{ {
_logger.LogInformation("Changing next target to {TargetName} ({TargetId:X8})", if (nextTargetPriority > currentTargetPriority)
nextTarget.Name.ToString(), nextTarget.GameObjectId); {
_targetManager.Target = nextTarget; _logger.LogInformation("Changing next target to {TargetName} ({TargetId:X8})",
_currentFight.Module.SetTarget(nextTarget); nextTarget.Name.ToString(), nextTarget.GameObjectId);
_targetManager.Target = nextTarget;
_currentFight.Module.SetTarget(nextTarget);
}
} }
else else
{ {
@ -160,14 +163,14 @@ internal sealed class CombatController : IDisposable
} }
return _objectTable.Select(x => (GameObject: x, Priority: GetKillPriority(x))) return _objectTable.Select(x => (GameObject: x, Priority: GetKillPriority(x)))
.Where(x => x.Priority != null) .Where(x => x.Priority > 0)
.OrderByDescending(x => x.Priority!.Value) .OrderByDescending(x => x.Priority)
.ThenByDescending(x => Vector3.Distance(x.GameObject.Position, _clientState.LocalPlayer!.Position)) .ThenByDescending(x => Vector3.Distance(x.GameObject.Position, _clientState.LocalPlayer!.Position))
.Select(x => x.GameObject) .Select(x => x.GameObject)
.FirstOrDefault(); .FirstOrDefault();
} }
private unsafe int? GetKillPriority(IGameObject gameObject) private unsafe int GetKillPriority(IGameObject gameObject)
{ {
if (gameObject is IBattleNpc battleNpc) if (gameObject is IBattleNpc battleNpc)
{ {
@ -177,11 +180,11 @@ internal sealed class CombatController : IDisposable
_currentFight.Data.ComplexCombatDatas.Count == 0) _currentFight.Data.ComplexCombatDatas.Count == 0)
{ {
if (battleNpc.IsDead) if (battleNpc.IsDead)
return null; return 0;
} }
if (!battleNpc.IsTargetable) if (!battleNpc.IsTargetable)
return null; return 0;
if (_currentFight != null) if (_currentFight != null)
{ {
@ -208,23 +211,23 @@ internal sealed class CombatController : IDisposable
if (battleNpc.BattleNpcKind is BattleNpcSubKind.BattleNpcPart or BattleNpcSubKind.Enemy) if (battleNpc.BattleNpcKind is BattleNpcSubKind.BattleNpcPart or BattleNpcSubKind.Enemy)
{ {
var gameObjectStruct = (GameObject*)gameObject.Address; var gameObjectStruct = (GameObject*)gameObject.Address;
if (gameObjectStruct->NamePlateIconId is 60093 or 60732) // npc that starts a fate or does turn-ins 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 null; 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 }) if (enemyData is { IgnoreQuestMarker: true })
return battleNpc.StatusFlags.HasFlag(StatusFlags.InCombat) ? 20 : null; return battleNpc.StatusFlags.HasFlag(StatusFlags.InCombat) ? 20 : 0;
else else
return gameObjectStruct->NamePlateIconId != 0 ? 30 : null; return gameObjectStruct->NamePlateIconId != 0 ? 30 : 0;
} }
// stuff trying to kill us // stuff trying to kill us
if (battleNpc.TargetObjectId == _clientState.LocalPlayer?.GameObjectId) if (battleNpc.TargetObjectId == _clientState.LocalPlayer?.GameObjectId)
return 0; return 10;
} }
return null; return 0;
} }
public void Stop() public void Stop()

View File

@ -1,6 +1,6 @@
<Project Sdk="Dalamud.NET.Sdk/9.0.2"> <Project Sdk="Dalamud.NET.Sdk/9.0.2">
<PropertyGroup> <PropertyGroup>
<Version>1.19</Version> <Version>1.20</Version>
<OutputPath>dist</OutputPath> <OutputPath>dist</OutputPath>
<PathMap Condition="$(SolutionDir) != ''">$(SolutionDir)=X:\</PathMap> <PathMap Condition="$(SolutionDir) != ''">$(SolutionDir)=X:\</PathMap>
<Platforms>x64</Platforms> <Platforms>x64</Platforms>