Add Location struct and fixed possible panic
This commit is contained in:
@@ -1,19 +1,22 @@
|
|||||||
package item
|
package item
|
||||||
|
|
||||||
type Location string
|
type LocationType string
|
||||||
|
|
||||||
|
type Location struct {
|
||||||
|
LocationType
|
||||||
|
Page int
|
||||||
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
LocationEquipped Location = "equipped"
|
LocationEquipped LocationType = "equipped"
|
||||||
LocationStash Location = "stash"
|
LocationStash LocationType = "stash"
|
||||||
LocationSharedStash1 Location = "shared_stash_1"
|
LocationSharedStash LocationType = "shared_stash"
|
||||||
LocationSharedStash2 Location = "shared_stash_2"
|
LocationBelt LocationType = "belt"
|
||||||
LocationSharedStash3 Location = "shared_stash_3"
|
LocationInventory LocationType = "inventory"
|
||||||
LocationBelt Location = "belt"
|
LocationCube LocationType = "cube"
|
||||||
LocationInventory Location = "inventory"
|
LocationVendor LocationType = "vendor"
|
||||||
LocationCube Location = "cube"
|
LocationGround LocationType = "ground"
|
||||||
LocationVendor Location = "vendor"
|
LocationSocket LocationType = "socket"
|
||||||
LocationGround Location = "ground"
|
LocationUnknown LocationType = "unknown"
|
||||||
LocationSocket Location = "socket"
|
LocationCursor LocationType = "cursor"
|
||||||
LocationUnknown Location = "unknown"
|
|
||||||
LocationCursor Location = "cursor"
|
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -33,12 +33,12 @@ func (i Inventory) Find(name item.Name, locations ...item.Location) (Item, bool)
|
|||||||
return Item{}, false
|
return Item{}, false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i Inventory) ByLocation(locations ...item.Location) []Item {
|
func (i Inventory) ByLocation(locations ...item.LocationType) []Item {
|
||||||
var items []Item
|
var items []Item
|
||||||
|
|
||||||
for _, it := range i.AllItems {
|
for _, it := range i.AllItems {
|
||||||
for _, l := range locations {
|
for _, l := range locations {
|
||||||
if it.Location == l {
|
if it.Location.LocationType == l {
|
||||||
items = append(items, it)
|
items = append(items, it)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -56,7 +56,6 @@ type Item struct {
|
|||||||
Quality item.Quality
|
Quality item.Quality
|
||||||
Position Position
|
Position Position
|
||||||
Location item.Location
|
Location item.Location
|
||||||
Page int // Used for shared stash
|
|
||||||
Ethereal bool
|
Ethereal bool
|
||||||
IsHovered bool
|
IsHovered bool
|
||||||
BaseStats stat.Stats
|
BaseStats stat.Stats
|
||||||
|
|||||||
@@ -33,6 +33,9 @@ func (gd *GameReader) Inventory(rawPlayerUnits RawPlayerUnits, hover data.HoverD
|
|||||||
stashedGold := [4]int{}
|
stashedGold := [4]int{}
|
||||||
stashedGold[0] = mainPlayerStashedGold.Value
|
stashedGold[0] = mainPlayerStashedGold.Value
|
||||||
for i, puKey := range stashPlayerUnitOrder {
|
for i, puKey := range stashPlayerUnitOrder {
|
||||||
|
if i > 3 {
|
||||||
|
break
|
||||||
|
}
|
||||||
stashGold, _ := stashPlayerUnits[puKey].BaseStats.FindStat(stat.StashGold, 0)
|
stashGold, _ := stashPlayerUnits[puKey].BaseStats.FindStat(stat.StashGold, 0)
|
||||||
stashedGold[i+1] = stashGold.Value
|
stashedGold[i+1] = stashGold.Value
|
||||||
}
|
}
|
||||||
@@ -93,17 +96,19 @@ func (gd *GameReader) Inventory(rawPlayerUnits RawPlayerUnits, hover data.HoverD
|
|||||||
location := item.LocationUnknown
|
location := item.LocationUnknown
|
||||||
switch itemLoc {
|
switch itemLoc {
|
||||||
case 0:
|
case 0:
|
||||||
// Offline only
|
|
||||||
if itemOwnerNPC == 2 || itemOwnerNPC == uint(stashPlayerUnits[stashPlayerUnitOrder[0]].UnitID) {
|
if itemOwnerNPC == 2 || itemOwnerNPC == uint(stashPlayerUnits[stashPlayerUnitOrder[0]].UnitID) {
|
||||||
location = item.LocationSharedStash1
|
location = item.LocationSharedStash
|
||||||
|
invPage = 1
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
if itemOwnerNPC == 3 || itemOwnerNPC == uint(stashPlayerUnits[stashPlayerUnitOrder[1]].UnitID) {
|
if itemOwnerNPC == 3 || itemOwnerNPC == uint(stashPlayerUnits[stashPlayerUnitOrder[1]].UnitID) {
|
||||||
location = item.LocationSharedStash2
|
location = item.LocationSharedStash
|
||||||
|
invPage = 2
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
if itemOwnerNPC == 4 || itemOwnerNPC == uint(stashPlayerUnits[stashPlayerUnitOrder[2]].UnitID) {
|
if itemOwnerNPC == 4 || itemOwnerNPC == uint(stashPlayerUnits[stashPlayerUnitOrder[2]].UnitID) {
|
||||||
location = item.LocationSharedStash3
|
location = item.LocationSharedStash
|
||||||
|
invPage = 3
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -116,6 +121,7 @@ func (gd *GameReader) Inventory(rawPlayerUnits RawPlayerUnits, hover data.HoverD
|
|||||||
}
|
}
|
||||||
if data.UnitID(itemOwnerNPC) == mainPlayer.UnitID || itemOwnerNPC == 1 {
|
if data.UnitID(itemOwnerNPC) == mainPlayer.UnitID || itemOwnerNPC == 1 {
|
||||||
location = item.LocationStash
|
location = item.LocationStash
|
||||||
|
invPage = 0
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
case 1:
|
case 1:
|
||||||
@@ -133,7 +139,10 @@ func (gd *GameReader) Inventory(rawPlayerUnits RawPlayerUnits, hover data.HoverD
|
|||||||
location = item.LocationCursor
|
location = item.LocationCursor
|
||||||
}
|
}
|
||||||
|
|
||||||
itm.Location = location
|
itm.Location = item.Location{
|
||||||
|
LocationType: location,
|
||||||
|
Page: int(invPage),
|
||||||
|
}
|
||||||
|
|
||||||
// We don't care about the inventory we don't know where they are, probably previous games or random crap
|
// We don't care about the inventory we don't know where they are, probably previous games or random crap
|
||||||
if location != item.LocationUnknown {
|
if location != item.LocationUnknown {
|
||||||
|
|||||||
Reference in New Issue
Block a user