forked from julianperrott/WowClassicGrindBot
-
-
Notifications
You must be signed in to change notification settings - Fork 143
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
Add FleeGoal #636
Merged
Merged
Add FleeGoal #636
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
eda5c45
Add FleeGoal
lionaneesh 27fb028
Merge branch 'dev-upstream' of https://github.com/lionaneesh/WowClass…
lionaneesh ca04ca3
Refactor: FleeGoal: uses a slightly different implementation to bette…
Xian55 f063ae9
Added more notes
Xian55 46a178d
Refactor: GoapAgentState: no longer needed
Xian55 f1682ef
Core: FleeGoal: Added a way to custom define when the goal should be …
Xian55 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
using Core.GOAP; | ||
|
||
using Microsoft.Extensions.Logging; | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Numerics; | ||
|
||
namespace Core.Goals; | ||
|
||
public sealed class FleeGoal : GoapGoal | ||
{ | ||
public override float Cost => 4f; | ||
private readonly ILogger<CombatGoal> logger; | ||
private readonly ConfigurableInput input; | ||
private readonly ClassConfiguration classConfig; | ||
private readonly Wait wait; | ||
private readonly PlayerReader playerReader; | ||
private readonly Navigation playerNavigation; | ||
private readonly AddonBits bits; | ||
private readonly StopMoving stopMoving; | ||
private readonly CastingHandler castingHandler; | ||
private readonly IMountHandler mountHandler; | ||
private readonly CombatLog combatLog; | ||
private readonly GoapAgentState goapAgentState; | ||
public int MOB_COUNT = 1; | ||
public bool runningAway; | ||
|
||
public FleeGoal(ILogger<CombatGoal> logger, ConfigurableInput input, | ||
Wait wait, PlayerReader playerReader, StopMoving stopMoving, AddonBits bits, | ||
ClassConfiguration classConfiguration, Navigation playerNavigation, GoapAgentState state, | ||
ClassConfiguration classConfig, CastingHandler castingHandler, CombatLog combatLog, | ||
IMountHandler mountHandler) | ||
: base(nameof(CombatGoal)) | ||
{ | ||
this.logger = logger; | ||
this.input = input; | ||
|
||
this.runningAway = false; | ||
this.wait = wait; | ||
this.playerReader = playerReader; | ||
this.playerNavigation = playerNavigation; | ||
this.bits = bits; | ||
this.combatLog = combatLog; | ||
|
||
this.stopMoving = stopMoving; | ||
this.castingHandler = castingHandler; | ||
this.mountHandler = mountHandler; | ||
this.classConfig = classConfig; | ||
this.goapAgentState = state; | ||
|
||
AddPrecondition(GoapKey.incombat, true); | ||
//AddPrecondition(GoapKey.hastarget, true); | ||
//AddPrecondition(GoapKey.targetisalive, true); | ||
//AddPrecondition(GoapKey.targethostile, true); | ||
//AddPrecondition(GoapKey.targettargetsus, true); | ||
//AddPrecondition(GoapKey.incombatrange, true); | ||
|
||
//AddEffect(GoapKey.producedcorpse, true); | ||
//AddEffect(GoapKey.targetisalive, false); | ||
//AddEffect(GoapKey.hastarget, false); | ||
|
||
Keys = classConfiguration.Combat.Sequence; | ||
} | ||
|
||
private void ResetCooldowns() | ||
{ | ||
ReadOnlySpan<KeyAction> span = Keys; | ||
for (int i = 0; i < span.Length; i++) | ||
{ | ||
KeyAction keyAction = span[i]; | ||
if (keyAction.ResetOnNewTarget) | ||
{ | ||
keyAction.ResetCooldown(); | ||
keyAction.ResetCharges(); | ||
} | ||
} | ||
} | ||
|
||
public override void OnEnter() | ||
{ | ||
if (mountHandler.IsMounted()) | ||
{ | ||
mountHandler.Dismount(); | ||
} | ||
|
||
this.runningAway = false; | ||
playerNavigation.Stop(); | ||
playerNavigation.SetWayPoints(stackalloc Vector3[] { }); | ||
playerNavigation.ResetStuckParameters(); | ||
} | ||
|
||
public override void OnExit() | ||
{ | ||
if (combatLog.DamageTakenCount() > 0 && !bits.Target()) | ||
{ | ||
stopMoving.Stop(); | ||
} | ||
// clearing | ||
this.runningAway = false; | ||
playerNavigation.Stop(); | ||
playerNavigation.SetWayPoints(stackalloc Vector3[] { }); | ||
playerNavigation.ResetStuckParameters(); | ||
} | ||
|
||
public override void Update() | ||
{ | ||
wait.Update(); | ||
if (this.goapAgentState.safeLocations.Count >= MOB_COUNT && this.runningAway == false) | ||
{ | ||
|
||
bool foundPoint = false; | ||
logger.LogInformation("Flee Goal Activated. Current Pos: " + playerReader.MapPos.ToString() + ",Safe Spots: " + goapAgentState.safeLocations.Count); | ||
if (goapAgentState.safeLocations == null) | ||
{ | ||
return; | ||
} | ||
for (LinkedListNode<Vector3> point = goapAgentState.safeLocations.Last; point != null; point = point.Previous) | ||
Check warning on line 118 in Core/Goals/FleeGoal.cs GitHub Actions / build
Check warning on line 118 in Core/Goals/FleeGoal.cs GitHub Actions / build
Check warning on line 118 in Core/Goals/FleeGoal.cs GitHub Actions / build
|
||
{ | ||
Vector2 p1 = new Vector2(point.Value.X, point.Value.Y); | ||
Vector2 p2 = new Vector2(playerReader.MapPos.X, playerReader.MapPos.Y); | ||
if (Vector2.Distance(p1, p2) >= 2.2) | ||
{ | ||
// select the point far enough to lose the current mobs. | ||
input.PressClearTarget(); | ||
playerNavigation.Stop(); | ||
playerNavigation.ResetStuckParameters(); | ||
playerNavigation.SetWayPoints(stackalloc Vector3[] { (Vector3)(point.Value) }); | ||
playerNavigation.Update(); | ||
Console.WriteLine("Found point " + point.Value.ToString()); | ||
foundPoint = true; | ||
this.runningAway = true; | ||
break; | ||
} | ||
} | ||
if (foundPoint) | ||
{ | ||
logger.LogInformation("Running away to the last safe point!"); | ||
return; | ||
} | ||
else | ||
{ | ||
logger.LogInformation("Cant run away, figting!"); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In my humble opinion, making
safeLocations
as aLinkedList<Vector3>
seems like an overkill.In my humble opinion, a safe spot would be a location what the player was already stepped on in the recent past.
While the player is outside of combat, periodically
X
seconds orX
milliseconds, a location can be marked as safe.Upon entering the
FleeGoal
the goal execution would be really simple, from aStack
collection just pops safe locations until leaves combat.There should be some guard clause that the
safeLocations
should contain aboutY
seconds worth of time in order to make sure that do not run out ofsafeLocations
this can be checked in theCanRun()
.Basically
safeLocations.Count > 0
Essentially while the
safeLocations
has content we do not need to reach for theNavigation Component
.It should be a good idea to find out, after entering combat with a mob, how many seconds does it take till the enemy exit combat.