Skip to content

Commit

Permalink
Merge pull request #661 from Xian55/fix/651_3
Browse files Browse the repository at this point in the history
Fix: While FollowRouteGoal active double check whether the unit is valid.
  • Loading branch information
Xian55 authored Jan 11, 2025
2 parents 5a228de + 2eed1b4 commit 57590a1
Show file tree
Hide file tree
Showing 15 changed files with 400 additions and 509 deletions.
31 changes: 18 additions & 13 deletions Core/AddonComponent/CombatLog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ public sealed class CombatLog : IReader
public event Action? PlayerDeath;
public event Action? TargetEvade;

public HashSet<int> DamageDone { get; } = new();
public HashSet<int> DamageTaken { get; } = new();
public HashSet<int> DamageDone { get; } = [];
public HashSet<int> DamageTaken { get; } = [];
public HashSet<int> EvadeMobs { get; } = [];

public int DamageTakenCount() => DamageTaken.Count;
public int DamageDoneCount() => DamageDone.Count;
Expand Down Expand Up @@ -59,6 +60,16 @@ public void Update(IAddonDataProvider reader)
{
bool combat = bits.Combat();

if (combat && DamageTakenGuid.Updated(reader) && DamageTakenGuid.Value > 0)
{
DamageTaken.Add(DamageTakenGuid.Value);
}

if (combat && DamageDoneGuid.Updated(reader) && DamageDoneGuid.Value > 0)
{
DamageDone.Add(DamageDoneGuid.Value);
}

if (TargetMissType.Updated(reader))
{
switch ((MissType)TargetMissType.Value)
Expand All @@ -67,21 +78,15 @@ public void Update(IAddonDataProvider reader)
TargetDodge.UpdateTime();
break;
case MissType.EVADE:
TargetEvade?.Invoke();
if (DamageDoneGuid.Value > 0)
{
EvadeMobs.Add(DamageDoneGuid.Value);
TargetEvade?.Invoke();
}
break;
}
}

if (combat && DamageTakenGuid.Updated(reader) && DamageTakenGuid.Value > 0)
{
DamageTaken.Add(DamageTakenGuid.Value);
}

if (combat && DamageDoneGuid.Updated(reader) && DamageDoneGuid.Value > 0)
{
DamageDone.Add(DamageDoneGuid.Value);
}

if (DeadGuid.Updated(reader) && DeadGuid.Value > 0)
{
int deadGuid = DeadGuid.Value;
Expand Down
8 changes: 4 additions & 4 deletions Core/ClassConfig/ClassConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public sealed partial class ClassConfiguration
public string? OverridePathFilename { get; set; } = string.Empty;
public bool PathThereAndBack { get; set; } = true;
public bool PathReduceSteps { get; set; }
public PathSettings[] Paths { get; set; } = Array.Empty<PathSettings>();
public PathSettings[] Paths { get; set; } = [];

public Mode Mode { get; init; } = Mode.Grind;

Expand All @@ -62,11 +62,11 @@ public sealed partial class ClassConfiguration
UnitClassification.Rare;

public bool CheckTargetGivesExp { get; set; }
public string[] Blacklist { get; init; } = Array.Empty<string>();
public string[] Blacklist { get; init; } = [];

public Dictionary<int, SchoolMask> NpcSchoolImmunity { get; } = new();
public Dictionary<int, SchoolMask> NpcSchoolImmunity { get; } = [];

public Dictionary<string, int> IntVariables { get; } = new();
public Dictionary<string, int> IntVariables { get; } = [];

public KeyActions Pull { get; } = new();
public KeyActions Flee { get; } = new();
Expand Down
4 changes: 3 additions & 1 deletion Core/Goals/ApproachTargetGoal.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Core.AddonComponent;
using Core.GOAP;

using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;

using System;
Expand Down Expand Up @@ -43,7 +44,8 @@ public sealed class ApproachTargetGoal : GoapGoal, IGoapEventListener
public ApproachTargetGoal(ILogger<ApproachTargetGoal> logger,
ConfigurableInput input, Wait wait,
PlayerReader playerReader, AddonBits addonBits,
StopMoving stopMoving, CombatUtil combatUtil, IBlacklist blacklist,
StopMoving stopMoving, CombatUtil combatUtil,
[FromKeyedServices("target")] IBlacklist blacklist,
IMountHandler mountHandler)
: base(nameof(ApproachTargetGoal))
{
Expand Down
8 changes: 6 additions & 2 deletions Core/Goals/BlacklistTargetGoal.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace Core.Goals;
using Microsoft.Extensions.DependencyInjection;

namespace Core.Goals;

public sealed class BlacklistTargetGoal : GoapGoal
{
Expand All @@ -12,7 +14,9 @@ public sealed class BlacklistTargetGoal : GoapGoal

public BlacklistTargetGoal(PlayerReader playerReader,
AddonBits bits,
ConfigurableInput input, IBlacklist blacklist, Wait wait)
ConfigurableInput input,
[FromKeyedServices("target")] IBlacklist blacklist,
Wait wait)
: base(nameof(BlacklistTargetGoal))
{
this.playerReader = playerReader;
Expand Down
20 changes: 15 additions & 5 deletions Core/Goals/FollowRouteGoal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Threading;
using SharedLib.Extensions;
using Game;
using Microsoft.Extensions.DependencyInjection;

#pragma warning disable 162

Expand Down Expand Up @@ -85,7 +86,7 @@ public FollowRouteGoal(
ClassConfiguration classConfig,
Navigation navigation,
IMountHandler mountHandler, TargetFinder targetFinder,
IBlacklist blacklist)
[FromKeyedServices("target")] IBlacklist targetBlacklist)
: base("Follow " + System.IO.Path.GetFileNameWithoutExtension(pathSettings.FileName))
{
this.cost = cost;
Expand All @@ -99,7 +100,7 @@ public FollowRouteGoal(
this.pathSettings = pathSettings;
this.mountHandler = mountHandler;
this.targetFinder = targetFinder;
this.targetBlacklist = blacklist;
this.targetBlacklist = targetBlacklist;

if (pathSettings.Requirements.Count > 0)
{
Expand Down Expand Up @@ -259,9 +260,18 @@ private void Thread_LookingForTarget()
{
if (targetFinder.Search(NpcNameToFind, bits.Target_NotDead, sideActivityCts.Token))
{
Log("Found target!");
sideActivityCts.Cancel();
sideActivityManualReset.Reset();
if (bits.Target() && targetBlacklist.Is())
{
Log("Blacklisted target found, clearing target");
input.PressClearTarget();
wait.Update();
}
else
{
Log("Found target!");
sideActivityCts.Cancel();
sideActivityManualReset.Reset();
}
}

sideActivityCts.Token.WaitHandle.WaitOne(1);
Expand Down
6 changes: 4 additions & 2 deletions Core/Goals/PullTargetGoal.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Core.GOAP;

using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;

using SharedLib.NpcFinder;
Expand Down Expand Up @@ -40,7 +41,8 @@ public sealed class PullTargetGoal : GoapGoal, IGoapEventListener

public PullTargetGoal(ILogger<PullTargetGoal> logger, ConfigurableInput input,
Wait wait, CombatLog combatlog, PlayerReader playerReader,
AddonBits bits, IBlacklist blacklist,
AddonBits bits,
[FromKeyedServices("target")] IBlacklist targetBlacklist,
StopMoving stopMoving, CastingHandler castingHandler,
IMountHandler mountHandler, NpcNameTargeting npcNameTargeting,
StuckDetector stuckDetector, CombatUtil combatUtil,
Expand All @@ -59,7 +61,7 @@ public PullTargetGoal(ILogger<PullTargetGoal> logger, ConfigurableInput input,
this.npcNameTargeting = npcNameTargeting;
this.stuckDetector = stuckDetector;
this.combatUtil = combatUtil;
this.targetBlacklist = blacklist;
this.targetBlacklist = targetBlacklist;
this.classConfig = classConfig;

Keys = classConfig.Pull.Sequence;
Expand Down
Loading

0 comments on commit 57590a1

Please sign in to comment.