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

Summoner WP Exit #642

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
29 changes: 27 additions & 2 deletions internal/action/waypoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,32 @@ import (
"log/slog"
"slices"

"github.com/hectorgimenez/d2go/pkg/data"
"github.com/hectorgimenez/d2go/pkg/data/area"
"github.com/hectorgimenez/koolo/internal/context"
"github.com/hectorgimenez/koolo/internal/game"
"github.com/hectorgimenez/koolo/internal/pather"
"github.com/hectorgimenez/koolo/internal/ui"
"github.com/hectorgimenez/koolo/internal/utils"
)

var maxWPDistanceFromCharacter = 45

func WayPoint(dest area.ID) error {
ctx := context.Get()
ctx.SetLastAction("WayPoint")

if !ctx.Data.PlayerUnit.Area.IsTown() {
//check if wp is close in current area
var closeWP []data.Object
for _, o := range ctx.Data.Objects {
if o.IsWaypoint() {
if isWPWithinMaxDistance(o, ctx.Data.PlayerUnit.Position) {
closeWP = append(closeWP, o)
}
}
}

if !ctx.Data.PlayerUnit.Area.IsTown() && len(closeWP) == 0 {
if err := ReturnTown(); err != nil {
return err
}
Expand Down Expand Up @@ -48,7 +62,13 @@ func WayPoint(dest area.ID) error {
actTabX := ui.WpTabStartX + (wpCoords.Tab-1)*ui.WpTabSizeX + (ui.WpTabSizeX / 2)
ctx.HID.Click(game.LeftButton, actTabX, ui.WpTabStartY)
}
utils.Sleep(200)
// Keep existing in town sleep option
if ctx.Data.PlayerUnit.Area.IsTown() {
utils.Sleep(200)
} else {
// Longer sleep needed outside of town for loading
utils.Sleep(500)
}
// Just to make sure no message like TZ change or public game spam prevent bot from clicking on waypoint
ClearMessages()
}
Expand Down Expand Up @@ -131,3 +151,8 @@ func useWP(dest area.ID) error {

return nil
}

func isWPWithinMaxDistance(wp data.Object, playerPosition data.Position) bool {
distance := pather.DistanceFromPoint(wp.Position, playerPosition)
return distance <= maxWPDistanceFromCharacter
}
3 changes: 3 additions & 0 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,9 @@ type CharacterCfg struct {
OpenChests bool `yaml:"openChests"`
ExitToA4 bool `yaml:"exitToA4"`
} `yaml:"mephisto"`
Summoner struct {
ExitToA4 bool `yaml:"exitToA4"`
} `yaml:"summoner"`
Tristram struct {
ClearPortal bool `yaml:"clearPortal"`
FocusOnElitePacks bool `yaml:"focusOnElitePacks"`
Expand Down
43 changes: 42 additions & 1 deletion internal/run/summoner.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package run
import (
"github.com/hectorgimenez/d2go/pkg/data/area"
"github.com/hectorgimenez/d2go/pkg/data/npc"
"github.com/hectorgimenez/d2go/pkg/data/object"
"github.com/hectorgimenez/koolo/internal/action"
"github.com/hectorgimenez/koolo/internal/config"
"github.com/hectorgimenez/koolo/internal/context"
Expand Down Expand Up @@ -42,5 +43,45 @@ func (s Summoner) Run() error {
}

// Kill Summoner
return s.ctx.Char.KillSummoner()
if err = s.ctx.Char.KillSummoner(); err != nil {
return err
}

if s.ctx.CharacterCfg.Game.Summoner.ExitToA4 {

// Move to tome for portal to canyon
s.ctx.Logger.Debug("Moving to tome")
tome, _ := s.ctx.Data.Objects.FindOne(object.YetAnotherTome)
action.MoveToCoords(tome.Position)

// Clear around tome and where red portal will spawn, monster can block tome or red portal interaction
action.ClearAreaAroundPlayer(10, s.ctx.Data.MonsterFilterAnyReachable())

// interact with tome to open red portal
action.InteractObject(tome, func() bool {
if _, found := s.ctx.Data.Objects.FindOne(object.PermanentTownPortal); found {
s.ctx.Logger.Debug("Found red portal")
return true
}
return false
})

// interact with red portal
s.ctx.Logger.Debug("Moving to red portal")
portal, _ := s.ctx.Data.Objects.FindOne(object.PermanentTownPortal)
action.MoveToCoords(portal.Position)

action.InteractObject(portal, func() bool {
return s.ctx.Data.PlayerUnit.Area == area.CanyonOfTheMagi
})

// Move to A4 if possible to shorten the run time
err = action.WayPoint(area.ThePandemoniumFortress)
if err != nil {
return err
}
}

return nil

}
1 change: 1 addition & 0 deletions internal/server/http_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -893,6 +893,7 @@ func (s *HttpServer) characterSettings(w http.ResponseWriter, r *http.Request) {
cfg.Game.Mephisto.KillCouncilMembers = r.Form.Has("gameMephistoKillCouncilMembers")
cfg.Game.Mephisto.OpenChests = r.Form.Has("gameMephistoOpenChests")
cfg.Game.Mephisto.ExitToA4 = r.Form.Has("gameMephistoExitToA4")
cfg.Game.Summoner.ExitToA4 = r.Form.Has("gameSummonerExitToA4")
cfg.Game.Tristram.ClearPortal = r.Form.Has("gameTristramClearPortal")
cfg.Game.Tristram.FocusOnElitePacks = r.Form.Has("gameTristramFocusOnElitePacks")
cfg.Game.Nihlathak.ClearArea = r.Form.Has("gameNihlathakClearArea")
Expand Down
6 changes: 6 additions & 0 deletions internal/server/templates/run_settings_components.gohtml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@
</fieldset>
{{ end }}

{{ define "summoner" }}
<fieldset>
<label><input type="checkbox" name="gameSummonerExitToA4" {{ if .Config.Game.Summoner.ExitToA4 }}checked{{ end }}> Exit to A4</label>
</fieldset>
{{ end }}

{{ define "tristram" }}
<fieldset>
<label><input type="checkbox" name="gameTristramFocusOnElitePacks" {{ if .Config.Game.Tristram.FocusOnElitePacks }}checked{{ end }}> Focus on elite packs</label>
Expand Down