Skip to content

Commit

Permalink
Fix issue where it cant hover entrance due to angle
Browse files Browse the repository at this point in the history
If we're in range but can't interact, try clicking once to get closer. Sometimes pathfinder end up at an angle where it cant hover the entrance

also increased radius to 4 findNearbyWalkablePosition . 3 isnt enough sometimes to find a walkable position
  • Loading branch information
elobo91 committed Feb 4, 2025
1 parent 832186a commit eb0cb7f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
22 changes: 14 additions & 8 deletions internal/action/step/interact_entrance.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ func InteractEntrance(targetArea area.ID) error {
attempts := 0
lastAttempt := time.Now()
currentMousePos := data.Position{}
hasTriedClick := false

for {
ctx.PauseIfNotPriority()
Expand All @@ -56,11 +57,6 @@ func InteractEntrance(targetArea area.ID) error {
return fmt.Errorf("failed to enter area %s after %d attempts", targetArea.Area().Name, maxAttempts)
}

if attempts > 0 && attempts%5 == 0 {
time.Sleep(200 * time.Millisecond)
currentMousePos = data.Position{} // Reset mouse position
}

if time.Since(lastAttempt) < 100*time.Millisecond {
time.Sleep(50 * time.Millisecond)
continue
Expand All @@ -71,7 +67,18 @@ func InteractEntrance(targetArea area.ID) error {
return err
}

// Handle hovering and interaction . We also need UnitType 2 here because sometimes entrances like ancient tunnel is both (unittype 2 the trap, unittype 5 to enter area)
// If we're in range but can't interact, try clicking once to get closer.
// Sometimes pathfinder end up at an angle where it cant hover the entrance
dist := ctx.PathFinder.DistanceFromMe(targetLevel.Position)
if !hasTriedClick && dist <= 4 && attempts > 10 {
baseX, baseY := ctx.PathFinder.GameCoordsToScreenCords(targetLevel.Position.X-2, targetLevel.Position.Y-2)
ctx.HID.Click(game.LeftButton, baseX, baseY)
hasTriedClick = true
time.Sleep(800 * time.Millisecond)
continue
}

// Handle hovering and interaction. We also need UnitType 2 here because sometimes entrances like ancient tunnel is both (unittype 2 the trap, unittype 5 to enter area)
if ctx.Data.HoverData.UnitType == 5 || (ctx.Data.HoverData.UnitType == 2 && ctx.Data.HoverData.IsHovered) {
ctx.HID.Click(game.LeftButton, currentMousePos.X, currentMousePos.Y)
lastAttempt = time.Now()
Expand All @@ -88,15 +95,14 @@ func InteractEntrance(targetArea area.ID) error {
time.Sleep(50 * time.Millisecond)
}
}

func moveToEntrance(ctx *context.Status, pos data.Position) error {
distance := ctx.PathFinder.DistanceFromMe(pos)
if distance <= requiredDistance {
return nil
}

var moveOpts []MoveOption
moveOpts = append(moveOpts, WithDistanceToFinish(1))
moveOpts = append(moveOpts, WithDistanceToFinish(2))

err := MoveTo(pos, moveOpts...)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion internal/pather/path_finder.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ func (pf *PathFinder) GetClosestWalkablePathFrom(from, dest data.Position) (Path

func (pf *PathFinder) findNearbyWalkablePosition(target data.Position) (data.Position, bool) {
// Search in expanding squares around the target position
for radius := 1; radius <= 3; radius++ {
for radius := 1; radius <= 4; radius++ {
for x := -radius; x <= radius; x++ {
for y := -radius; y <= radius; y++ {
if x == 0 && y == 0 {
Expand Down

0 comments on commit eb0cb7f

Please sign in to comment.