Skip to content
Open
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
59 changes: 57 additions & 2 deletions internal/run/mephisto.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
package run

import (
"fmt"
"slices"
"sort"

"github.com/hectorgimenez/d2go/pkg/data"
"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"
"github.com/hectorgimenez/koolo/internal/pather"
"github.com/hectorgimenez/koolo/internal/utils"
)

Expand Down Expand Up @@ -65,11 +70,61 @@ func (m Mephisto) Run() error {
return err
}

if m.ctx.CharacterCfg.Game.Mephisto.OpenChests || m.ctx.CharacterCfg.Game.Mephisto.KillCouncilMembers {
if m.ctx.CharacterCfg.Game.Mephisto.OpenChests && m.ctx.CharacterCfg.Game.Mephisto.KillCouncilMembers {
// Clear the area with the selected options
return action.ClearCurrentLevel(m.ctx.CharacterCfg.Game.Mephisto.OpenChests, m.CouncilMemberFilter())
}
} else if m.ctx.CharacterCfg.Game.Mephisto.OpenChests {

// determine chests wanted
interactableChests := []object.Name{181, 183, 104, 105, 106, 107}

// find chests and racks
var crs []data.Object
for _, o := range m.ctx.Data.Objects {
if slices.Contains(interactableChests, o.Name) {
m.ctx.Logger.Debug("Found chest at:", "position", o.Position)
crs = append(crs, o)
}
}
m.ctx.Logger.Debug("Total chests/racks found", "count", len(crs))

// Interact with objects in the order of shortest travel
for len(crs) > 0 {

playerPos := m.ctx.Data.PlayerUnit.Position

sort.Slice(crs, func(i, j int) bool {
return pather.DistanceFromPoint(crs[i].Position, playerPos) <
pather.DistanceFromPoint(crs[j].Position, playerPos)
})

// Interact with the closest object
closestObject := crs[0]

// Move to the chest/rack
err = action.MoveToCoords(closestObject.Position)
if err != nil {
return err
}
// Clear around chest for clean interaction
action.ClearAreaAroundPlayer(7, m.ctx.Data.MonsterFilterAnyReachable())

// Interact with chest/rack/stand
err = action.InteractObject(closestObject, func() bool {
object, _ := m.ctx.Data.Objects.FindByID(closestObject.ID)
return !object.Selectable
})

if err != nil {
m.ctx.Logger.Warn(fmt.Sprintf("[%s] failed interacting with object [%v] in Area: [%s]", m.ctx.Name, closestObject.Name, m.ctx.Data.PlayerUnit.Area.Area().Name), err)
}
utils.Sleep(500) // Add small delay to allow the game to open the object and drop the content

// Remove the interacted container from the list
crs = crs[1:]
}

}
if m.ctx.CharacterCfg.Game.Mephisto.ExitToA4 {
m.ctx.Logger.Debug("Moving to bridge")
action.MoveToCoords(data.Position{X: 17588, Y: 8068})
Expand Down