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