add belt type to calculate potion capacity
This commit is contained in:
@@ -1,6 +1,10 @@
|
|||||||
package data
|
package data
|
||||||
|
|
||||||
import "strings"
|
import (
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/hectorgimenez/d2go/pkg/data/item"
|
||||||
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
HealingPotion PotionType = "HealingPotion"
|
HealingPotion PotionType = "HealingPotion"
|
||||||
@@ -8,10 +12,13 @@ const (
|
|||||||
RejuvenationPotion PotionType = "RejuvenationPotion"
|
RejuvenationPotion PotionType = "RejuvenationPotion"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Belt []Item
|
type Belt struct {
|
||||||
|
Items []Item
|
||||||
|
Name item.Name
|
||||||
|
}
|
||||||
|
|
||||||
func (b Belt) GetFirstPotion(potionType PotionType) (Position, bool) {
|
func (b Belt) GetFirstPotion(potionType PotionType) (Position, bool) {
|
||||||
for _, i := range b {
|
for _, i := range b.Items {
|
||||||
// Ensure potion is in row 0 and one of the four columns
|
// Ensure potion is in row 0 and one of the four columns
|
||||||
if strings.Contains(string(i.Name), string(potionType)) && i.Position.Y == 0 && (i.Position.X == 0 || i.Position.X == 1 || i.Position.X == 2 || i.Position.X == 3) {
|
if strings.Contains(string(i.Name), string(potionType)) && i.Position.Y == 0 && (i.Position.X == 0 || i.Position.X == 1 || i.Position.X == 2 || i.Position.X == 3) {
|
||||||
return i.Position, true
|
return i.Position, true
|
||||||
@@ -21,4 +28,17 @@ func (b Belt) GetFirstPotion(potionType PotionType) (Position, bool) {
|
|||||||
return Position{}, false
|
return Position{}, false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (b Belt) Rows() int {
|
||||||
|
switch b.Name {
|
||||||
|
case "":
|
||||||
|
return 1
|
||||||
|
case "Sash", "LightBelt":
|
||||||
|
return 2
|
||||||
|
case "Belt", "HeavyBelt":
|
||||||
|
return 3
|
||||||
|
default:
|
||||||
|
return 4
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
type PotionType string
|
type PotionType string
|
||||||
|
|||||||
@@ -1,11 +1,12 @@
|
|||||||
package memory
|
package memory
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"sort"
|
||||||
|
|
||||||
"github.com/hectorgimenez/d2go/pkg/data"
|
"github.com/hectorgimenez/d2go/pkg/data"
|
||||||
"github.com/hectorgimenez/d2go/pkg/data/item"
|
"github.com/hectorgimenez/d2go/pkg/data/item"
|
||||||
"github.com/hectorgimenez/d2go/pkg/data/stat"
|
"github.com/hectorgimenez/d2go/pkg/data/stat"
|
||||||
"github.com/hectorgimenez/d2go/pkg/utils"
|
"github.com/hectorgimenez/d2go/pkg/utils"
|
||||||
"sort"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func (gd *GameReader) Items(playerPosition data.Position) data.Items {
|
func (gd *GameReader) Items(playerPosition data.Position) data.Items {
|
||||||
@@ -15,6 +16,7 @@ func (gd *GameReader) Items(playerPosition data.Position) data.Items {
|
|||||||
unitTableBuffer := gd.Process.ReadBytesFromMemory(baseAddr, 128*8)
|
unitTableBuffer := gd.Process.ReadBytesFromMemory(baseAddr, 128*8)
|
||||||
|
|
||||||
items := data.Items{}
|
items := data.Items{}
|
||||||
|
belt := data.Belt{}
|
||||||
for i := 0; i < 128; i++ {
|
for i := 0; i < 128; i++ {
|
||||||
itemOffset := 8 * i
|
itemOffset := 8 * i
|
||||||
itemUnitPtr := uintptr(ReadUIntFromBuffer(unitTableBuffer, uint(itemOffset), Uint64))
|
itemUnitPtr := uintptr(ReadUIntFromBuffer(unitTableBuffer, uint(itemOffset), Uint64))
|
||||||
@@ -82,8 +84,11 @@ func (gd *GameReader) Items(playerPosition data.Position) data.Items {
|
|||||||
}
|
}
|
||||||
case 1:
|
case 1:
|
||||||
items.Equipped = append(items.Equipped, itm)
|
items.Equipped = append(items.Equipped, itm)
|
||||||
|
if itm.Type() == "belt" {
|
||||||
|
belt.Name = itm.Name
|
||||||
|
}
|
||||||
case 2:
|
case 2:
|
||||||
items.Belt = append(items.Belt, itm)
|
belt.Items = append(belt.Items, itm)
|
||||||
case 3, 5:
|
case 3, 5:
|
||||||
items.Ground = append(items.Ground, itm)
|
items.Ground = append(items.Ground, itm)
|
||||||
}
|
}
|
||||||
@@ -92,6 +97,8 @@ func (gd *GameReader) Items(playerPosition data.Position) data.Items {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
items.Belt = belt
|
||||||
|
|
||||||
sort.SliceStable(items.Ground, func(i, j int) bool {
|
sort.SliceStable(items.Ground, func(i, j int) bool {
|
||||||
distanceI := utils.DistanceFromPoint(playerPosition, items.Ground[i].Position)
|
distanceI := utils.DistanceFromPoint(playerPosition, items.Ground[i].Position)
|
||||||
distanceJ := utils.DistanceFromPoint(playerPosition, items.Ground[j].Position)
|
distanceJ := utils.DistanceFromPoint(playerPosition, items.Ground[j].Position)
|
||||||
|
|||||||
Reference in New Issue
Block a user