update item data
This commit is contained in:
@@ -14,23 +14,24 @@ type Inventory struct {
|
||||
StashedGold [6]int // [0]=personal, [1..5]=shared stash pages
|
||||
SharedStashPages int // Number of shared stash units detected (3=non-DLC, 5+=DLC)
|
||||
PlayerID UnitID // Number of shared stash units detected (3=non-DLC, 5+=DLC)
|
||||
MercID UnitID
|
||||
}
|
||||
|
||||
func isMatchOwner(owner UnitID, it Item) bool {
|
||||
func (i Inventory) isMatchOwner(it Item) bool {
|
||||
if it.Location.LocationType == item.LocationUnknown ||
|
||||
it.Location.LocationType == item.LocationGround || it.Location.LocationType == item.LocationVendor {
|
||||
return true
|
||||
}
|
||||
if it.Location.LocationType != item.LocationMercenary && it.Owner == 1 {
|
||||
return true
|
||||
}
|
||||
|
||||
return owner == it.Owner
|
||||
if it.Location.LocationType == item.LocationMercenary {
|
||||
return it.Owner == i.MercID
|
||||
}
|
||||
return it.Owner == i.PlayerID
|
||||
}
|
||||
|
||||
func (i Inventory) Find(name item.Name, locations ...item.LocationType) (Item, bool) {
|
||||
for _, it := range i.AllItems {
|
||||
if strings.EqualFold(string(it.Name), string(name)) && isMatchOwner(i.PlayerID, it) {
|
||||
if strings.EqualFold(string(it.Name), string(name)) && i.isMatchOwner(it) {
|
||||
// If no locations are specified, return the first item found
|
||||
if len(locations) == 0 {
|
||||
return it, true
|
||||
@@ -49,7 +50,7 @@ func (i Inventory) Find(name item.Name, locations ...item.LocationType) (Item, b
|
||||
|
||||
func (i Inventory) FindByType(t string, locations ...item.LocationType) (Item, bool) {
|
||||
for _, it := range i.AllItems {
|
||||
if it.Type().IsType(t) && isMatchOwner(i.PlayerID, it) {
|
||||
if it.Type().IsType(t) && i.isMatchOwner(it) {
|
||||
if len(locations) == 0 {
|
||||
return it, true
|
||||
}
|
||||
@@ -67,7 +68,7 @@ func (i Inventory) FindByType(t string, locations ...item.LocationType) (Item, b
|
||||
|
||||
func (i Inventory) FindByID(unitID UnitID) (Item, bool) {
|
||||
for _, it := range i.AllItems {
|
||||
if it.UnitID == unitID && isMatchOwner(i.PlayerID, it) {
|
||||
if it.UnitID == unitID && i.isMatchOwner(it) {
|
||||
return it, true
|
||||
}
|
||||
}
|
||||
@@ -75,30 +76,12 @@ func (i Inventory) FindByID(unitID UnitID) (Item, bool) {
|
||||
return Item{}, false
|
||||
}
|
||||
|
||||
func (i Inventory) ByMercLocation(mercID UnitID, locations ...item.LocationType) []Item {
|
||||
var items []Item
|
||||
|
||||
for _, it := range i.AllItems {
|
||||
for _, l := range locations {
|
||||
owner := mercID
|
||||
if l != item.LocationMercenary {
|
||||
owner = i.PlayerID
|
||||
}
|
||||
if it.Location.LocationType == l && isMatchOwner(owner, it) {
|
||||
items = append(items, it)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return items
|
||||
}
|
||||
|
||||
func (i Inventory) ByLocation(locations ...item.LocationType) []Item {
|
||||
var items []Item
|
||||
|
||||
for _, it := range i.AllItems {
|
||||
for _, l := range locations {
|
||||
if it.Location.LocationType == l && isMatchOwner(i.PlayerID, it) {
|
||||
if it.Location.LocationType == l && i.isMatchOwner(it) {
|
||||
items = append(items, it)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user