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

Try to fix discovering waypoint logic #100

Merged
Merged
Changes from 1 commit
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
Next Next commit
Try to fix discovering waypoint logic
  • Loading branch information
13413j1j13j5315n13 committed Mar 20, 2024
commit 43aba67a436fbc6dfd992372955cd548e563dd05
20 changes: 13 additions & 7 deletions internal/action/waypoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/hectorgimenez/koolo/internal/helper"
"log/slog"
"slices"
"sort"
)

const (
Expand Down Expand Up @@ -75,6 +76,8 @@ func (b *Builder) useWP(a area.Area) *Chain {
}
}

currentWP = area.WPAddresses[a]

// First use the previous available waypoint that we have discovered
actions = append(actions, NewStepChain(func(d data.Data) []step.Step {
return []step.Step{
Expand All @@ -98,19 +101,22 @@ func (b *Builder) useWP(a area.Area) *Chain {
// Next keep traversing all the areas from the previous available waypoint until we reach the destination, trying to discover WPs during the way
b.Logger.Info("Traversing areas to reach destination", slog.Any("areas", traverseAreas))

for i, dst := range traverseAreas {
// Areas are numbered in increasing order. Sort all traverseAreas by its number
sort.Slice(traverseAreas, func(i, j int) bool {
return traverseAreas[i] < traverseAreas[j]
})

for _, dst := range traverseAreas {
if !dst.IsTown() {
actions = append(actions,
b.Buff(),
)
}

if i > 0 {
actions = append(actions,
b.MoveToArea(dst),
b.DiscoverWaypoint(),
)
}
actions = append(actions,
b.MoveToArea(dst),
b.DiscoverWaypoint(),
)
}

return actions
Expand Down