diff --git a/internal/action/step/attack.go b/internal/action/step/attack.go index 62edc0eb..5b112029 100644 --- a/internal/action/step/attack.go +++ b/internal/action/step/attack.go @@ -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" ) @@ -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 @@ -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) } } diff --git a/internal/pather/path_finder.go b/internal/pather/path_finder.go index ad52dd91..3277b3bb 100644 --- a/internal/pather/path_finder.go +++ b/internal/pather/path_finder.go @@ -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 {