Skip to content

Commit

Permalink
Fix telestomp and improve range checks (#554)
Browse files Browse the repository at this point in the history
  • Loading branch information
artosimonyan authored Dec 8, 2024
1 parent 279ee74 commit ae2576d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
24 changes: 15 additions & 9 deletions internal/action/step/attack.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/hectorgimenez/d2go/pkg/data/npc"
"github.com/hectorgimenez/d2go/pkg/data/skill"
"github.com/hectorgimenez/d2go/pkg/data/stat"
"github.com/hectorgimenez/d2go/pkg/utils"
"github.com/hectorgimenez/koolo/internal/context"
"github.com/hectorgimenez/koolo/internal/game"
)
Expand Down Expand Up @@ -268,6 +269,8 @@ func ensureEnemyIsInRange(monster data.Monster, maxDistance, minDistance int) er
ctx := context.Get()
ctx.SetLastStep("ensureEnemyIsInRange")

// TODO: Add an option for telestomp based on the char configuration

path, distance, found := ctx.PathFinder.GetPath(monster.Position)
if !found {
// We cannot reach the enemy, let's skip the attack sequence
Expand All @@ -277,23 +280,26 @@ func ensureEnemyIsInRange(monster data.Monster, maxDistance, minDistance int) er
hasLoS := ctx.PathFinder.LineOfSight(ctx.Data.PlayerUnit.Position, monster.Position)

// We have line of sight, and we are inside the attack range, we can skip
if hasLoS && distance < maxDistance {
if hasLoS && distance <= maxDistance && distance >= minDistance {
return nil
}

for i, pos := range path {
distance = len(path) - i
if distance > maxDistance {
for _, pos := range path {

// Calculate distance btween the monster and the the position from the path
distance = utils.DistanceFromPoint(ctx.Data.AreaData.RelativePosition(monster.Position), pos)

if distance > maxDistance || distance < minDistance {
continue
}

// In this case something weird is happening, just telestomp
if distance < 2 {
return MoveTo(monster.Position)
dest := data.Position{
X: pos.X + ctx.Data.AreaData.OffsetX,
Y: pos.Y + ctx.Data.AreaData.OffsetY,
}

if ctx.PathFinder.LineOfSight(pos, monster.Position) {
return MoveTo(pos)
if ctx.PathFinder.LineOfSight(dest, monster.Position) {
return MoveTo(dest)
}
}

Expand Down
3 changes: 2 additions & 1 deletion internal/pather/path_finder.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ package pather

import (
"fmt"
"math"

"github.com/hectorgimenez/d2go/pkg/data"
"github.com/hectorgimenez/d2go/pkg/data/area"
"github.com/hectorgimenez/koolo/internal/config"
"github.com/hectorgimenez/koolo/internal/game"
"github.com/hectorgimenez/koolo/internal/pather/astar"
"math"
)

type PathFinder struct {
Expand Down

0 comments on commit ae2576d

Please sign in to comment.