Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update LootGoal to prevent bot getting stuck #639

Merged
merged 6 commits into from
Dec 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions Core/ClassConfig/ClassConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -238,9 +238,8 @@ private static void SetBaseActions(

user.Key = baseAction.Key;

//if (!string.IsNullOrEmpty(@default.Requirement))
// user.Requirement += " " + @default.Requirement;
//user.Requirements.AddRange(@default.Requirements);
if (!string.IsNullOrEmpty(baseAction.Requirement))
user.Requirement += " " + baseAction.Requirement;

if (user.BeforeCastDelay == @default.BeforeCastDelay)
user.BeforeCastDelay = baseAction.BeforeCastDelay;
Expand Down
6 changes: 4 additions & 2 deletions Core/ClassConfig/ClassConfigurationBaseActions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,16 @@ public sealed partial class ClassConfiguration
Key = "I", // Interact.Key
Name = nameof(Approach),
PressDuration = 10,
BaseAction = true
BaseAction = true,
Requirement = "!SoftTargetDead"
};

public KeyAction AutoAttack { get; } = new()
{
Key = "I", // Interact.Key
Name = nameof(AutoAttack),
BaseAction = true
BaseAction = true,
Requirement = "!AutoAttacking && !SoftTargetDead"
};

public KeyAction TargetLastTarget { get; } = new()
Expand Down
1 change: 1 addition & 0 deletions Core/Goals/CombatGoal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ private void FindNewTarget()
ResetCooldowns();

logger.LogWarning("Found new target!");
wait.Update();
return;
}

Expand Down
5 changes: 2 additions & 3 deletions Core/Goals/ConsumeCorpseGoal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@ public ConsumeCorpseGoal(ILogger<ConsumeCorpseGoal> logger,
{
AddPrecondition(GoapKey.consumablecorpsenearby, true);
}
AddPrecondition(GoapKey.pulled, false);
AddPrecondition(GoapKey.dangercombat, false);
AddPrecondition(GoapKey.incombat, false);
AddPrecondition(GoapKey.damagedone, false);
AddPrecondition(GoapKey.damagetaken, false);

AddPrecondition(GoapKey.producedcorpse, true);
AddPrecondition(GoapKey.consumecorpse, false);
Expand Down
30 changes: 21 additions & 9 deletions Core/Goals/LootGoal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public sealed partial class LootGoal : GoapGoal, IGoapEventListener

private const int MAX_TIME_TO_REACH_MELEE = 10000;
private const int MAX_TIME_TO_DETECT_LOOT = 2 * CastingHandler.GCD;
private const int MAX_TIME_TO_RESET_LOOT = 800;

private readonly ILogger<LootGoal> logger;
private readonly ConfigurableInput input;
Expand Down Expand Up @@ -68,14 +69,20 @@ public LootGoal(ILogger<LootGoal> logger,
this.state = state;

this.token = cts.Token;
AddPrecondition(GoapKey.pulled, false);
AddPrecondition(GoapKey.dangercombat, false);
AddPrecondition(GoapKey.shouldloot, true);
AddEffect(GoapKey.shouldloot, false);
}

public override void OnEnter()
{
WaitForLootReset();
float elapsedMs = WaitForLootReset();
if (elapsedMs < 0)
{
LogLootStatusDidNotChangedInTime(logger, elapsedMs);
return;
}

if (combatLog.DamageTakenCount() == 0)
{
Expand All @@ -100,9 +107,9 @@ public override void OnEnter()
ClearTargetIfNeeded();
}

private void WaitForLootReset()
private float WaitForLootReset()
{
wait.While(LootReset);
return wait.Until(MAX_TIME_TO_RESET_LOOT, LootStatusIsCorpse);
}

private void WaitForLosingTarget()
Expand All @@ -121,6 +128,7 @@ private void CaptureStateBeforeLoot()

private void CheckInventoryFull()
{
ClearTargetIfNeeded();
if (!bagReader.BagsFull())
return;

Expand All @@ -147,10 +155,8 @@ private bool TryLoot()
return true;
}
}
if (!input.KeyboardOnly) {
return LootMouse();
}
return false;

return !input.KeyboardOnly && LootMouse();
}

private void HandleSuccessfulLoot()
Expand Down Expand Up @@ -396,8 +402,8 @@ private bool MoveToTargetAndReached()
return bits.Target() && playerReader.MinRangeZero();
}

private bool LootReset() =>
(LootStatus)playerReader.LootEvent.Value != LootStatus.CORPSE;
private bool LootStatusIsCorpse() =>
(LootStatus)playerReader.LootEvent.Value == LootStatus.CORPSE;

#region Logging

Expand Down Expand Up @@ -453,5 +459,11 @@ private void LogWarning(string text)
Message = "Keyboard loot failed! Has target ? {hasTarget}")]
static partial void LogKeyboardLootFailed(ILogger logger, bool hasTarget);

[LoggerMessage(
EventId = 0137,
Level = LogLevel.Error,
Message = "LootGoal failed to start due LootStatus did not changed within the expected time window {elapsedMs}ms")]
static partial void LogLootStatusDidNotChangedInTime(ILogger logger, float elapsedMs);

#endregion
}
4 changes: 4 additions & 0 deletions Core/Requirement/RequirementFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@ public RequirementFactory(IServiceProvider sp, ClassConfiguration classConfig)
{ "TargetsPet", playerReader.TargetsPet },
{ "TargetsNone", playerReader.TargetsNone },

// Soft Target
{ "SoftTarget", bits.SoftInteract },
{ "SoftTargetDead", bits.SoftInteract_Dead },

{ AddVisible, npcNameFinder._PotentialAddsExist },
{ "InCombat", bits.Combat },

Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1642,6 +1642,8 @@ Allow requirements about what buffs/debuffs you have or the target has or in gen
| `"TargetsMe"` | The target currently targets the player |
| `"TargetsPet"` | The target currently targets the player's pet |
| `"TargetsNone"` | The target currently has not target |
| `"SoftTarget"` | The player has an available soft target |
| `"SoftTargetDead"` | The player has an available soft target which is dead |
| `"AddVisible"` | Around the target there are possible additional NPCs |
| `"InCombat"` | Player in combat. |
| `"TargetCastingSpell"` | Target casts any spell |
Expand Down