Skip to content

Commit b4d9370

Browse files
committed
fix few issues and panic
1 parent 8a642b1 commit b4d9370

File tree

4 files changed

+33
-27
lines changed

4 files changed

+33
-27
lines changed

internal/action/leveling_tools.go

+17-19
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
package action
22

33
import (
4-
"github.com/hectorgimenez/koolo/internal/game"
5-
"github.com/hectorgimenez/koolo/internal/pather"
6-
"github.com/lxn/win"
74
"log/slog"
85
"slices"
96
"time"
107

8+
"github.com/hectorgimenez/koolo/internal/game"
9+
"github.com/hectorgimenez/koolo/internal/pather"
10+
"github.com/lxn/win"
11+
1112
"github.com/hectorgimenez/d2go/pkg/data"
1213
"github.com/hectorgimenez/d2go/pkg/data/area"
1314
"github.com/hectorgimenez/d2go/pkg/data/difficulty"
@@ -276,14 +277,12 @@ func (b *Builder) calculateSkillPositionInUI(d game.Data, mainSkill bool, skillI
276277
}
277278
descs[skID] = sk
278279

279-
// Main skill list grows to the left, secondary skill list grows to the right
280-
displaceSkill := targetSkill.ID < skID
281-
if mainSkill {
282-
displaceSkill = targetSkill.ID > skID
283-
}
284-
285-
if skID != targetSkill.ID && sk.Desc().ListRow == targetSkill.Desc().ListRow && displaceSkill {
286-
column++
280+
if skID != targetSkill.ID && sk.Desc().Page == targetSkill.Desc().Page {
281+
if sk.Desc().ListRow > targetSkill.Desc().ListRow {
282+
column++
283+
} else if sk.Desc().ListRow == targetSkill.Desc().ListRow && sk.Desc().Column > targetSkill.Desc().Column {
284+
column++
285+
}
287286
}
288287

289288
totalRows = append(totalRows, sk.Desc().ListRow)
@@ -298,12 +297,11 @@ func (b *Builder) calculateSkillPositionInUI(d game.Data, mainSkill bool, skillI
298297
totalRows = slices.Compact(totalRows)
299298

300299
// If we don't have any skill of a specific tree, the entire row gets one line down
301-
previousRow := 0
302-
for _, currentRow := range totalRows {
303-
if currentRow != 0 && currentRow != previousRow+1 {
304-
row--
300+
for i, currentRow := range totalRows {
301+
if currentRow == row {
302+
row = i
303+
break
305304
}
306-
previousRow = currentRow
307305
}
308306

309307
// Scrolls and charges are not in the same list
@@ -320,13 +318,13 @@ func (b *Builder) calculateSkillPositionInUI(d game.Data, mainSkill bool, skillI
320318
}
321319
}
322320

323-
skillOffsetX := ui.MainSkillListFirstSkillX
321+
skillOffsetX := ui.MainSkillListFirstSkillX - (ui.SkillListSkillOffset * column)
324322
if !mainSkill {
325-
skillOffsetX = ui.SecondarySkillListFirstSkillX
323+
skillOffsetX = ui.SecondarySkillListFirstSkillX + (ui.SkillListSkillOffset * column)
326324
}
327325

328326
return data.Position{
329-
X: skillOffsetX + ui.SkillListSkillOffset*column,
327+
X: skillOffsetX,
330328
Y: ui.SkillListFirstSkillY - ui.SkillListSkillOffset*row,
331329
}, true
332330
}

internal/game/keyboard.go

+8-6
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
package game
22

33
import (
4-
"github.com/hectorgimenez/d2go/pkg/data"
5-
"github.com/inkeliz/w32"
6-
"github.com/lxn/win"
74
"math/rand"
85
"strings"
96
"time"
7+
8+
"github.com/hectorgimenez/d2go/pkg/data"
9+
"github.com/inkeliz/w32"
10+
"github.com/lxn/win"
1011
)
1112

1213
const (
@@ -60,11 +61,12 @@ func getKeysForKB(kb data.KeyBinding) [2]byte {
6061
}
6162

6263
func (hid *HID) GetASCIICode(key string) byte {
63-
if len(key) == 1 {
64-
return strings.ToUpper(key)[0]
64+
char, found := specialChars[strings.ToLower(key)]
65+
if found {
66+
return char
6567
}
6668

67-
return specialChars[strings.ToLower(key)]
69+
return strings.ToUpper(key)[0]
6870
}
6971

7072
var specialChars = map[string]byte{

internal/pather/path_finding_tools.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@ package pather
22

33
import (
44
"fmt"
5-
"github.com/hectorgimenez/koolo/internal/game"
65
"image"
76
"image/color"
87
"image/draw"
98
"image/png"
109
"math"
1110
"os"
1211

12+
"github.com/hectorgimenez/koolo/internal/game"
13+
1314
"github.com/beefsack/go-astar"
1415
"github.com/hectorgimenez/d2go/pkg/data"
1516
"github.com/hectorgimenez/d2go/pkg/data/area"
@@ -197,5 +198,10 @@ func IsWalkable(pos data.Position, areaOriginPos data.Position, collisionGrid []
197198
indexX := pos.X - areaOriginPos.X
198199
indexY := pos.Y - areaOriginPos.Y
199200

201+
// When we are close to the level border, we need to check if monster is outside the collision grid
202+
if indexX < 0 || indexY < 0 || indexY >= len(collisionGrid) || indexX >= len(collisionGrid[indexY]) {
203+
return false
204+
}
205+
200206
return collisionGrid[indexY][indexX]
201207
}

internal/ui/coordinates.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ const (
3232
GambleRefreshButtonY = 515
3333

3434
SecondarySkillListFirstSkillX = 687
35-
MainSkillListFirstSkillX = 550
35+
MainSkillListFirstSkillX = 592
3636
SkillListFirstSkillY = 590
3737
SkillListSkillOffset = 45
3838

0 commit comments

Comments
 (0)