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

refactor actions #422

Merged
merged 211 commits into from
Nov 9, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
211 commits
Select commit Hold shift + click to select a range
c7c7a18
refactor actions
hectorgimenez Aug 16, 2024
184e9e2
Unified Character Script - Adding Characters (#423)
TDLofCC Aug 17, 2024
c39829f
update d2go
hectorgimenez Aug 17, 2024
fc6b163
Refactor actions (#424)
artosimonyan Aug 17, 2024
ee6dd0a
clear level and more runs
hectorgimenez Aug 17, 2024
9a201f8
Rename Council.go (#428)
artosimonyan Aug 17, 2024
f47e027
add cows
hectorgimenez Aug 17, 2024
45476ef
Added DrifterCavern, Duriel, Eldritch runs (#429)
artosimonyan Aug 17, 2024
8752a5b
Refactored leveling chars (#425)
TDLofCC Aug 17, 2024
e6b838b
Refactored even more runs! (#431)
artosimonyan Aug 17, 2024
c9fcf77
Refactored Mephisto, Tal Tombs, Tristram (#436)
artosimonyan Aug 18, 2024
cfe4c83
Refactor diablo run (#430)
TDLofCC Aug 18, 2024
1b6a4f4
Spider cavern refactor (#438)
Farmith Aug 18, 2024
b6f2ee5
Refactored leveling scripts (#439)
TDLofCC Aug 18, 2024
c3d358c
Added full build hydra/orb sorc scripts (#440)
Farmith Aug 18, 2024
25edcea
Fix for spider cavern reference (#442)
Farmith Aug 18, 2024
6dfbcb9
Yeet tristram (#443)
Farmith Aug 18, 2024
15c287b
remove old crap, reorganized imports, fixed few bugs
hectorgimenez Aug 18, 2024
afde365
Add ContextDebug data into debugger (#444)
artosimonyan Aug 18, 2024
29acfbc
adjustments
hectorgimenez Aug 19, 2024
b5fdb11
fix tab switching when stashing
hectorgimenez Aug 19, 2024
88bf51a
implemented pause
hectorgimenez Aug 19, 2024
ce7e8f7
cleanup context when stopping
hectorgimenez Aug 19, 2024
b0a65c3
Added lower kurast chest run V2 (#437)
Farmith Aug 19, 2024
0a63d03
more fixes
hectorgimenez Aug 20, 2024
b014994
Speed up char select (#449)
artosimonyan Aug 20, 2024
0c3c7cc
Added error handling + tweaked Diablo Run (#446)
TDLofCC Aug 20, 2024
4b03cfd
upgrade d2go
hectorgimenez Aug 23, 2024
1034b89
fix mephisto check for opening chests / killing council members
hectorgimenez Aug 26, 2024
e0d6d52
fix clear level not calculating room destination properly
hectorgimenez Aug 26, 2024
7f37e82
add exception for the weird TamoeHighland/MonasteryGate
hectorgimenez Aug 26, 2024
23e5f80
Refactor Gameflow (#457)
artosimonyan Aug 27, 2024
b81ceb3
Add Lobby Games (#458)
artosimonyan Aug 27, 2024
dcabbc7
Update config load (#459)
artosimonyan Aug 28, 2024
b837a49
Update flow & data on new game (#460)
artosimonyan Aug 28, 2024
3f88957
Refresh Data when not ingame (#461)
artosimonyan Sep 1, 2024
dca51ef
Housekeeping (#463)
artosimonyan Sep 2, 2024
28c4b5d
change supervisor log names (#464)
artosimonyan Sep 2, 2024
33b8721
More housekeeping (#465)
artosimonyan Sep 2, 2024
7187d35
new pathing, still WIP
hectorgimenez Sep 3, 2024
9aec13f
remove v2 prefix
hectorgimenez Sep 3, 2024
c026012
fixed merging grids and allow diagonal direction
hectorgimenez Sep 3, 2024
fe55407
fixed repair
hectorgimenez Sep 4, 2024
87980ce
better pathing and optimize teleport distance calculation
hectorgimenez Sep 4, 2024
399343d
fixed refactor naming
hectorgimenez Sep 4, 2024
e98c86a
add retry attempts for interaction with objects/npcs
hectorgimenez Sep 4, 2024
3d20f46
add log when item is properly picked up
hectorgimenez Sep 4, 2024
e6143d6
Remote control via discord (#468)
artosimonyan Sep 5, 2024
31ea10b
Adjust item pickup (#469)
artosimonyan Sep 5, 2024
c4bf954
add missing font files?
hectorgimenez Sep 9, 2024
f5081be
things.
hectorgimenez Sep 9, 2024
a7ae4fe
Expand Cube Recipes (#473)
artosimonyan Sep 11, 2024
5cbde98
Cain identify - initial implementation (#476)
artosimonyan Sep 12, 2024
2ff081e
Fix item pickup (#474)
artosimonyan Sep 13, 2024
577d6c2
Buy tp/ident scrolls if below 20 (#477)
artosimonyan Sep 13, 2024
2223bbe
Fix character settings tempalate (#478)
artosimonyan Sep 13, 2024
febedb0
rename pkg name
hectorgimenez Sep 14, 2024
a0cbeaf
fixed wrong display life %
hectorgimenez Sep 14, 2024
7639257
force routines to shutdown when one of them fails (for example during…
hectorgimenez Sep 14, 2024
a23ef19
make pather a little bit more reliable?
hectorgimenez Sep 14, 2024
15fe4f3
reduce the soft blocker surrounding non-walkable areas
hectorgimenez Sep 14, 2024
cddf688
Character Profile Naming refactor (#479)
artosimonyan Sep 14, 2024
b287a12
Fix panic on empty run list (#480)
artosimonyan Sep 14, 2024
fac3ccf
fixed wrong path distance calculation
hectorgimenez Sep 14, 2024
7f813e8
add small delay after moving to allow character to end walking/load t…
hectorgimenez Sep 14, 2024
db3fe66
Fix ShouldStashIt (#481)
artosimonyan Sep 14, 2024
5d09849
upgrade CI to use Go 1.23
hectorgimenez Sep 15, 2024
bc4e7fe
few pather optimizations
hectorgimenez Sep 15, 2024
67665ff
astar optimization
hectorgimenez Sep 15, 2024
650c098
more pathing optimizations
hectorgimenez Sep 16, 2024
56ddf93
Attach to existing process (#482)
artosimonyan Sep 16, 2024
0e80579
Scheduler Implementation (#483)
artosimonyan Sep 17, 2024
30d0613
Fix panic on initial schedule config (#484)
artosimonyan Sep 17, 2024
f7a61d5
fix bug causing baal skipped when it was selected the kill option
hectorgimenez Sep 17, 2024
5888339
use basic distance to optimize traverse room order for now, suboptimal
hectorgimenez Sep 17, 2024
abd696b
Exclude map data from json (#485)
artosimonyan Sep 17, 2024
abb6cbd
Feed the Mosiac script some steroids (#486)
artosimonyan Sep 17, 2024
70dfe30
Consume misplaced belt potions (#487)
artosimonyan Sep 17, 2024
6facbbd
fix some runs
hectorgimenez Sep 18, 2024
7601c6f
disable pathing direction change cost addition
hectorgimenez Sep 18, 2024
f64034d
add the check to return town
hectorgimenez Sep 19, 2024
1932ead
implement stupid unstuck
hectorgimenez Sep 19, 2024
9279b01
Display recipes in grid (#488)
artosimonyan Sep 19, 2024
1027e16
improve run list (#489)
artosimonyan Sep 19, 2024
98398e6
Change Game Window Title (#490)
artosimonyan Sep 20, 2024
a57925b
Prevent Assassin from buying keys (#491)
artosimonyan Sep 21, 2024
2b4803b
Prevent repair attempts for ethereal or indestructible items (#492)
artosimonyan Sep 21, 2024
6ce8340
Add Telestomp (#493)
artosimonyan Sep 23, 2024
bcd223f
Check required key binds (#494)
artosimonyan Sep 23, 2024
a827a27
Refresh game data before keybind check (#495)
artosimonyan Sep 23, 2024
186ca75
Corrupted tremors strike Koolo
hectorgimenez Sep 23, 2024
9dd0d18
pause loop during loading screen
hectorgimenez Sep 24, 2024
77476d0
prevent injecting stuff when bot is paused (should fix the pause beha…
hectorgimenez Sep 24, 2024
0c04816
add legacy graphics check
hectorgimenez Sep 24, 2024
2c0c706
Fixed diablo run (#496)
TDLofCC Sep 25, 2024
f2cb5f7
Add Stash actions (#499)
artosimonyan Sep 28, 2024
237b538
use a fake mod to store custom game settings, this will allow bot/use…
hectorgimenez Sep 29, 2024
9381a21
Update gambling.go (#501)
elobo91 Oct 1, 2024
71b7f96
calculate inventory matrix to check for free space before picking up …
hectorgimenez Oct 2, 2024
65918f0
Berserk_barb arrives to v2 (travincal barb for now) (#506)
elobo91 Oct 3, 2024
1929999
check if character is moving before finishing MoveTo step, use WaitFo…
hectorgimenez Oct 3, 2024
b8ccfc5
Fetch map data concurrently
hectorgimenez Oct 4, 2024
d1786c6
add delay after opening chests, this will allow the animation to fini…
hectorgimenez Oct 4, 2024
e446b80
high priority loop is super fast (less than 1ms), we can execute it m…
hectorgimenez Oct 4, 2024
083afca
bugfixing on item pickup and overall interaction improvements
hectorgimenez Oct 4, 2024
79f20d4
Swap Items before Hork ( Barbarian) (#507)
elobo91 Oct 5, 2024
f5d88a0
wrap the error, so we can detect it later
hectorgimenez Oct 5, 2024
af0e461
fix movement distance detection and cow level stashing trash
hectorgimenez Oct 7, 2024
97d3457
calculate LoS during attack action
hectorgimenez Oct 11, 2024
1ff7ade
Area Correction, Character specific responsible UI ++
elobo91 Oct 8, 2024
4c0ba39
Area Correction, Character specific responsible UI ++
elobo91 Oct 8, 2024
b2881dc
Update pit.go
elobo91 Oct 9, 2024
6fbffba
fixed chicken.
elobo91 Oct 9, 2024
4840627
chick fix part 2
elobo91 Oct 9, 2024
f90dd26
fix chicken p3
elobo91 Oct 9, 2024
cfe69bb
Revert "fix chicken p3"
elobo91 Oct 9, 2024
27d7b38
Revert "chick fix part 2"
elobo91 Oct 9, 2024
a3b38e9
Revert "fixed chicken."
elobo91 Oct 9, 2024
e0e600a
fixed barb now chickening when attacking.
elobo91 Oct 9, 2024
454a0fc
put back some comments that got ereased with time.
elobo91 Oct 9, 2024
9dd9f18
AreaCorrection Extended, Foh reworked and other characters too
elobo91 Oct 12, 2024
1f552cd
Improved Nova Sorceress . Configurable option for static with valida…
elobo91 Oct 13, 2024
3a2c50b
some comments again.
elobo91 Oct 13, 2024
1ebeebe
Update character_settings.js
elobo91 Oct 13, 2024
3857b64
Update character_settings.js
elobo91 Oct 13, 2024
5188fb8
Update character_settings.js
elobo91 Oct 13, 2024
2f69679
Skip ItemPickup while fighting Bosses, resume after its dead
elobo91 Oct 13, 2024
cbaf5b9
fix nova chicken. missing PauseIfNotPriority
elobo91 Oct 13, 2024
e4ae2db
improved Foh performances on light imunes after being convicted
elobo91 Oct 13, 2024
5b9ae2b
fixed a bug with itempickup, improved nova
elobo91 Oct 13, 2024
61c7ff5
more fixes
elobo91 Oct 13, 2024
2e69f9d
Update bot.go
elobo91 Oct 13, 2024
3d31f50
more fixes for idle
elobo91 Oct 13, 2024
21b1a5c
statistics showing but not working well.
elobo91 Oct 14, 2024
afe66a4
Update single_supervisor.go
elobo91 Oct 14, 2024
df36d2f
Revert "Update single_supervisor.go"
elobo91 Oct 14, 2024
b18b43e
Revert "statistics showing but not working well."
elobo91 Oct 14, 2024
d455226
Revert "more fixes for idle"
elobo91 Oct 14, 2024
f658319
Update cows.go
elobo91 Oct 14, 2024
2e49c56
stats partially back in.
elobo91 Oct 14, 2024
f7458ec
now we get stats but only for last run on the list.
elobo91 Oct 14, 2024
6326008
removed check for berserk barb in bot.go as its done somewhere else now
elobo91 Oct 14, 2024
92c8518
a
elobo91 Oct 14, 2024
23dc345
b
elobo91 Oct 14, 2024
ab82733
run statistics are officially back in.
elobo91 Oct 14, 2024
0fcdbec
fixed pause/resume button
elobo91 Oct 14, 2024
babf283
Fixed path cant be calculated in tristam/cow.
elobo91 Oct 16, 2024
da15f2c
Update item_pickup.go
elobo91 Oct 16, 2024
2470b1c
post-reviews
elobo91 Oct 16, 2024
2b1ecb2
reverted original nova logic but kept new boss logic.
elobo91 Oct 16, 2024
81f8a5b
Update nova_sorceress.go
elobo91 Oct 16, 2024
730db71
simplified area correction
elobo91 Oct 16, 2024
3d78a2f
fixed entrance update
elobo91 Oct 16, 2024
16abee7
should be ok
elobo91 Oct 16, 2024
290b07d
additions to elb changes
hectorgimenez Oct 16, 2024
5b4aaca
fix idle on itempickup, safety check for cube
elobo91 Oct 16, 2024
e19ed7a
some comments, forgot Skip picking up gold if we can not carry more
elobo91 Oct 16, 2024
9d2f82c
force buff trav for barb
elobo91 Oct 16, 2024
1eaca6b
Clear monster around portal returntown
elobo91 Oct 16, 2024
4ca9097
Chaos skip monster out of grid and stormcasters if set to
elobo91 Oct 17, 2024
cb1c4e0
Area Correction & Berserk improvements (#514)
hectorgimenez Oct 17, 2024
5f4579a
Fix ItemPickup, Prevent StandStill to be forever active
elobo91 Oct 17, 2024
9e5d2bb
Update item_pickup.go
elobo91 Oct 17, 2024
40931c9
Diablo Run is ready, Reset monster filter when picking up items(range 3)
elobo91 Oct 18, 2024
7cb031a
fix when switching zone
hectorgimenez Oct 18, 2024
bc9ce68
Diablo Run is ready, Reset monster filter when picking up items(range 3)
elobo91 Oct 18, 2024
21d5415
update diablo.go
elobo91 Oct 18, 2024
0af2a85
Chicken fix , anti-idle mechanism during run ( outside town)
elobo91 Oct 18, 2024
19e0286
fix when switching zone (#518)
hectorgimenez Oct 20, 2024
b88e685
Diablo run improved + option to keep distance fro seal bosses,
elobo91 Oct 20, 2024
8baa35a
Merge branch 'hectorgimenez:refactor_actions' into refactor_actions
elobo91 Oct 20, 2024
ab553da
Merge remote-tracking branch 'origin/refactor_actions' into refactor_…
elobo91 Oct 20, 2024
8f0868b
reverting to previous IsMonsterSealElite
elobo91 Oct 20, 2024
d2dc941
Update clear_area.go
elobo91 Oct 20, 2024
a2361d4
Update clear_area.go
elobo91 Oct 20, 2024
6495a70
Update clear_area.go
elobo91 Oct 20, 2024
a404b06
IsKeyPressed added to keyboard.go . Fix out of grid Diablo (again)
elobo91 Oct 20, 2024
22e52dd
diablo should be ok.
elobo91 Oct 20, 2024
015b7fe
New Burst skill attack type implementation with new nova profile
elobo91 Oct 22, 2024
4df304c
Not leaving attack if theres still monster character can reach .
elobo91 Oct 22, 2024
dd8c3af
In case monster is stuck behind a wall or character is not able to r…
elobo91 Oct 22, 2024
bd2b577
attack.go now handle melee,aoe,burst .Mosaic is perfect .
elobo91 Oct 22, 2024
cb6de37
attack.go new feature for ranged characters
elobo91 Oct 23, 2024
247571a
attack.go new feature for ranged characters
elobo91 Oct 23, 2024
b99d28f
optimized Foh using built-in attack.go functions
elobo91 Oct 23, 2024
0462900
Update
elobo91 Oct 25, 2024
6bf4d5e
Revert "Update"
elobo91 Oct 26, 2024
380189b
Update 2
elobo91 Oct 26, 2024
ba3112b
increased max attack loop foh
elobo91 Oct 26, 2024
e13fdf8
burst skill (#520)
hectorgimenez Oct 29, 2024
693bd08
some optimizations?
hectorgimenez Oct 30, 2024
dbfa513
Additions to Radius clearing logic
elobo91 Oct 30, 2024
dd7cf40
let character's specific combat logic handle attack distance (no over…
elobo91 Oct 30, 2024
6940017
update
elobo91 Oct 31, 2024
dc3602d
nova
elobo91 Oct 31, 2024
ba13b2e
Burst skill draft revision (#524)
hectorgimenez Nov 1, 2024
78410ad
refactor attack + allow debugger to show last step/action based on pr…
hectorgimenez Nov 1, 2024
ee1a52c
Burst skill usage (#523)
hectorgimenez Nov 1, 2024
d383341
refactor Diablo run
hectorgimenez Nov 5, 2024
e0ad303
minor tweaks when dealing with seal elites in diablo run
hectorgimenez Nov 5, 2024
1cf92dc
add MapVirtualKey and GetWindowText to winproc pkg
hectorgimenez Nov 6, 2024
08e28f5
mod tidy
hectorgimenez Nov 6, 2024
b30188c
go 1.23
hectorgimenez Nov 6, 2024
4a5b8fd
tiny cleanup
hectorgimenez Nov 6, 2024
4f358f2
fixed diablo elite filter only considering seal elite monsters
hectorgimenez Nov 6, 2024
68d668d
decoy and necro revives are not considered enemies anymore
hectorgimenez Nov 6, 2024
e09e7ba
clear and stash cube items if there are items in there when starting …
hectorgimenez Nov 7, 2024
fee4893
try to fix the bug causing infinite movement attempts if destination …
hectorgimenez Nov 7, 2024
c86c362
don't buy TPs/IDs all the time
hectorgimenez Nov 7, 2024
b99fbab
fix walking movement issue
hectorgimenez Nov 7, 2024
1429593
add small delay and re-check when we don't properly detect the merc (…
hectorgimenez Nov 8, 2024
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
Prev Previous commit
Next Next commit
clear level and more runs
  • Loading branch information
hectorgimenez committed Aug 26, 2024
commit ee6dd0a851959825898af4026b77fe944be361dc
104 changes: 104 additions & 0 deletions internal/v2/action/clear_level.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
package action

import (
"errors"

"github.com/hectorgimenez/d2go/pkg/data"
"github.com/hectorgimenez/d2go/pkg/data/stat"
"github.com/hectorgimenez/koolo/internal/game"
"github.com/hectorgimenez/koolo/internal/v2/context"
)

func ClearCurrentLevel(openChests bool, filter data.MonsterFilter) error {
ctx := context.Get()
ctx.ContextDebug.LastAction = "ClearLevel"

for _, r := range ctx.PathFinder.OptimizeRoomsTraverseOrder() {
err := clearRoom(r, filter)
if err != nil {
ctx.Logger.Warn("Failed to clear room: %v", err)
}

if !openChests {
continue
}

for _, o := range ctx.Data.Objects {
if o.IsChest() && o.Selectable && r.IsInside(o.Position) {
err = MoveToCoords(o.Position)
if err != nil {
ctx.Logger.Warn("Failed moving to chest: %v", err)
continue
}
err = InteractObject(o, func() bool {
chest, _ := ctx.Data.Objects.FindByID(o.ID)
return !chest.Selectable
})
if err != nil {
ctx.Logger.Warn("Failed interacting with chest: %v", err)
}
}
}
}

return nil
}

func clearRoom(room data.Room, filter data.MonsterFilter) error {
ctx := context.Get()

path, _, found := ctx.PathFinder.GetClosestWalkablePath(room.GetCenter())
if !found {
return errors.New("failed to find a path to the room center")
}

err := MoveToCoords(path.To())
if err != nil {
ctx.Logger.Warn("Failed moving to room center: %v", err)
}

for monsters := getMonstersInRoom(room, filter); len(monsters) > 0; {
// Check if there are monsters that can summon new monsters, and kill them first
targetMonster := monsters[0]
for _, m := range monsters {
if m.IsMonsterRaiser() {
targetMonster = m
}
}

path, _, mPathFound := ctx.PathFinder.GetPath(targetMonster.Position)
if mPathFound {
if !ctx.Data.CanTeleport() {
for _, o := range ctx.Data.Objects {
if o.IsDoor() && o.Selectable && path.Intersects(*ctx.Data, o.Position, 4) {
ctx.Logger.Debug("Door is blocking the path to the monster, moving closer")
MoveToCoords(targetMonster.Position)
}
}
}

ctx.Char.KillMonsterSequence(func(d game.Data) (data.UnitID, bool) {
m, found := d.Monsters.FindByID(targetMonster.UnitID)
if found && m.Stats[stat.Life] > 0 {
return targetMonster.UnitID, true
}
return 0, false
}, nil)
}
}

return nil
}

func getMonstersInRoom(room data.Room, filter data.MonsterFilter) []data.Monster {
ctx := context.Get()

monstersInRoom := make([]data.Monster, 0)
for _, m := range ctx.Data.Monsters.Enemies(filter) {
if room.IsInside(m.Position) || ctx.PathFinder.DistanceFromMe(m.Position) < 30 {
monstersInRoom = append(monstersInRoom, m)
}
}

return monstersInRoom
}
45 changes: 23 additions & 22 deletions internal/v2/action/town.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ package action
import (
"github.com/hectorgimenez/d2go/pkg/data/skill"
"github.com/hectorgimenez/koolo/internal/v2/action/step"
"github.com/hectorgimenez/koolo/internal/v2/context"
)

func PreRun(firstRun bool) error {
//ctx := context.Get()
ctx := context.Get()

DropMouseItem()
step.SetSkill(skill.Vigor)
Expand All @@ -16,33 +17,33 @@ func PreRun(firstRun bool) error {
Stash(firstRun)
}

//UpdateQuestLog()
UpdateQuestLog()
IdentifyAll(firstRun)
VendorRefill(false, true)
Stash(firstRun)
Gamble()
Stash(false)
CubeRecipes()

//if ctx.CharacterCfg.Game.Leveling.EnsurePointsAllocation {
// ResetStats()
// EnsureStatPoints()
// EnsureSkillPoints()
//}
//
//if ctx.CharacterCfg.Game.Leveling.EnsureKeyBinding {
// EnsureSkillBindings()
//}
if ctx.CharacterCfg.Game.Leveling.EnsurePointsAllocation {
ResetStats()
EnsureStatPoints()
EnsureSkillPoints()
}

if ctx.CharacterCfg.Game.Leveling.EnsureKeyBinding {
EnsureSkillBindings()
}

HealAtNPC()
ReviveMerc()
//HireMerc()
HireMerc()

return Repair()
}

func InRunReturnTownRoutine() error {
//ctx := context.Get()
ctx := context.Get()

ReturnTown()
step.SetSkill(skill.Vigor)
Expand All @@ -54,18 +55,18 @@ func InRunReturnTownRoutine() error {
Stash(false)
CubeRecipes()

//if ctx.CharacterCfg.Game.Leveling.EnsurePointsAllocation {
// EnsureStatPoints()
// EnsureSkillPoints()
//}
//
//if ctx.CharacterCfg.Game.Leveling.EnsureKeyBinding {
// EnsureSkillBindings()
//}
if ctx.CharacterCfg.Game.Leveling.EnsurePointsAllocation {
EnsureStatPoints()
EnsureSkillPoints()
}

if ctx.CharacterCfg.Game.Leveling.EnsureKeyBinding {
EnsureSkillBindings()
}

HealAtNPC()
ReviveMerc()
//HireMerc()
HireMerc()
Repair()

return UsePortalInTown()
Expand Down
8 changes: 8 additions & 0 deletions internal/v2/pather/path.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,11 @@ func (p Pather) Intersects(d game.Data, position data.Position, padding int) boo

return false
}

func (p Pather) To() data.Position {
if len(p) == 0 {
return data.Position{}
}

return data.Position{X: p[len(p)-1].(*Tile).X, Y: p[len(p)-1].(*Tile).Y}
}
77 changes: 63 additions & 14 deletions internal/v2/pather/path_finder.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ func NewPathFinder(gr *game.MemoryReader, data *game.Data, hid *game.HID, cfg *c
return &PathFinder{gr: gr, hid: hid, cfg: cfg, data: data}
}

// The GetPath method definition, combined and corrected
func (pf *PathFinder) GetPath(to data.Position, blacklistedCoords ...[2]int) (path Pather, distance int, found bool) {
func (pf *PathFinder) GetPathFrom(from, to data.Position, blacklistedCoords ...[2]int) (path Pather, distance int, found bool) {
outsideCurrentLevel := outsideBoundary(pf.data, to)
collisionGrid := pf.data.CollisionGrid

Expand Down Expand Up @@ -98,7 +97,7 @@ func (pf *PathFinder) GetPath(to data.Position, blacklistedCoords ...[2]int) (pa
}

// Convert to relative coordinates (Current player position)
fromX, fromY := relativePosition(pf.data, pf.data.PlayerUnit.Position, collisionGridOffset)
fromX, fromY := relativePosition(pf.data, from, collisionGridOffset)

// Convert to relative coordinates (Target position)
toX, toY := relativePosition(pf.data, to, collisionGridOffset)
Expand Down Expand Up @@ -162,6 +161,10 @@ func (pf *PathFinder) GetPath(to data.Position, blacklistedCoords ...[2]int) (pa
return p, len(p), found
}

func (pf *PathFinder) GetPath(to data.Position, blacklistedCoords ...[2]int) (path Pather, distance int, found bool) {
return pf.GetPathFrom(pf.data.PlayerUnit.Position, to, blacklistedCoords...)
}

func ensureValueInCG(val, cgSize int) int {
if val < 0 {
return 0
Expand All @@ -175,6 +178,10 @@ func ensureValueInCG(val, cgSize int) int {
}

func (pf *PathFinder) GetClosestWalkablePath(dest data.Position, blacklistedCoords ...[2]int) (path Pather, distance int, found bool) {
return pf.GetClosestWalkablePathFrom(pf.data.PlayerUnit.Position, dest, blacklistedCoords...)
}

func (pf *PathFinder) GetClosestWalkablePathFrom(from, dest data.Position, blacklistedCoords ...[2]int) (path Pather, distance int, found bool) {
if IsWalkable(dest, pf.data.AreaOrigin, pf.data.CollisionGrid) || outsideBoundary(pf.data, dest) {
path, distance, found = pf.GetPath(dest, blacklistedCoords...)
if found {
Expand All @@ -193,7 +200,7 @@ func (pf *PathFinder) GetClosestWalkablePath(dest data.Position, blacklistedCoor
cgY := dest.Y - pf.data.AreaOrigin.Y + j
cgX := dest.X - pf.data.AreaOrigin.X + i
if cgX > 0 && cgY > 0 && len(pf.data.CollisionGrid) > cgY && len(pf.data.CollisionGrid[cgY]) > cgX && pf.data.CollisionGrid[cgY][cgX] {
return pf.GetPath(data.Position{
return pf.GetPathFrom(from, data.Position{
X: dest.X + i,
Y: dest.Y + j,
}, blacklistedCoords...)
Expand Down Expand Up @@ -235,16 +242,7 @@ func (pf *PathFinder) MoveCharacter(x, y int) {
}

func (pf *PathFinder) GameCoordsToScreenCords(destinationX, destinationY int) (int, int) {
// Calculate diff between current player position and destination
diffX := destinationX - pf.data.PlayerUnit.Position.X
diffY := destinationY - pf.data.PlayerUnit.Position.Y

// Transform cartesian movement (World) to isometric (screen)
// Helpful documentation: https://clintbellanger.net/articles/isometric_math/
screenX := int((float32(diffX-diffY) * 19.8) + float32(pf.gr.GameAreaSizeX/2))
screenY := int((float32(diffX+diffY) * 9.9) + float32(pf.gr.GameAreaSizeY/2))

return screenX, screenY
return pf.gameCoordsToScreenCords(pf.data.PlayerUnit.Position.X, pf.data.PlayerUnit.Position.Y, destinationX, destinationY)
}

func (pf *PathFinder) gameCoordsToScreenCords(playerX, playerY, destinationX, destinationY int) (int, int) {
Expand Down Expand Up @@ -274,6 +272,57 @@ func (pf *PathFinder) DistanceFromMe(p data.Position) int {
return DistanceFromPoint(pf.data.PlayerUnit.Position, p)
}

func (pf *PathFinder) OptimizeRoomsTraverseOrder() []data.Room {
distanceMatrix := make(map[data.Room]map[data.Room]int)

for _, room1 := range pf.data.Rooms {
distanceMatrix[room1] = make(map[data.Room]int)
for _, room2 := range pf.data.Rooms {
if room1 != room2 {
_, distance, found := pf.GetClosestWalkablePathFrom(room1.GetCenter(), room2.GetCenter())
if found {
distanceMatrix[room1][room2] = distance
} else {
distanceMatrix[room1][room2] = math.MaxInt
}
} else {
distanceMatrix[room1][room2] = 0
}
}
}

currentRoom := data.Room{}
for _, r := range pf.data.Rooms {
if r.IsInside(pf.data.PlayerUnit.Position) {
currentRoom = r
}
}

visited := make(map[data.Room]bool)
order := []data.Room{currentRoom}
visited[currentRoom] = true

for len(order) < len(pf.data.Rooms) {
nextRoom := data.Room{}
minDistance := math.MaxInt

// Find the nearest unvisited room
for _, room := range pf.data.Rooms {
if !visited[room] && distanceMatrix[currentRoom][room] < minDistance {
nextRoom = room
minDistance = distanceMatrix[currentRoom][room]
}
}

// Add the next room to the order of visit
order = append(order, nextRoom)
visited[nextRoom] = true
currentRoom = nextRoom
}

return order
}

func relativePosition(d *game.Data, p data.Position, cgOffset data.Position) (int, int) {
x, y := p.X-d.AreaOrigin.X, p.Y-d.AreaOrigin.Y

Expand Down
48 changes: 48 additions & 0 deletions internal/v2/run/ancient_tunnels.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package run

import (
"github.com/hectorgimenez/d2go/pkg/data"
"github.com/hectorgimenez/d2go/pkg/data/area"
"github.com/hectorgimenez/koolo/internal/config"
"github.com/hectorgimenez/koolo/internal/v2/action"
"github.com/hectorgimenez/koolo/internal/v2/context"
)

type AncientTunnels struct {
ctx *context.Status
}

func NewAncientTunnels() *AncientTunnels {
return &AncientTunnels{
ctx: context.Get(),
}
}

func (a AncientTunnels) Name() string {
return string(config.AncientTunnelsRun)
}

func (a AncientTunnels) Run() error {
openChests := a.ctx.CharacterCfg.Game.AncientTunnels.OpenChests
onlyElites := a.ctx.CharacterCfg.Game.AncientTunnels.FocusOnElitePacks
filter := data.MonsterAnyFilter()

if onlyElites {
filter = data.MonsterEliteFilter()
}

err := action.WayPoint(area.LostCity) // Moving to starting point (Lost City)
if err != nil {
return err
}

err = action.MoveToArea(area.AncientTunnels) // Travel to ancient tunnels
if err != nil {
return err
}
action.OpenTPIfLeader()

// Clear Ancient Tunnels

return action.ClearCurrentLevel(openChests, filter)
}
Loading