update code
This commit is contained in:
@@ -17,7 +17,8 @@ type Inventory struct {
|
||||
}
|
||||
|
||||
func isMatchOwner(owner UnitID, it Item) bool {
|
||||
if it.Location.LocationType == item.LocationGround {
|
||||
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 {
|
||||
@@ -29,14 +30,32 @@ func isMatchOwner(owner UnitID, it Item) bool {
|
||||
|
||||
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)) {
|
||||
if strings.EqualFold(string(it.Name), string(name)) && isMatchOwner(i.PlayerID, it) {
|
||||
// If no locations are specified, return the first item found
|
||||
if len(locations) == 0 {
|
||||
return it, true
|
||||
}
|
||||
|
||||
for _, l := range locations {
|
||||
if it.Location.LocationType == l && isMatchOwner(i.PlayerID, it) {
|
||||
if it.Location.LocationType == l {
|
||||
return it, true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return Item{}, false
|
||||
}
|
||||
|
||||
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 len(locations) == 0 {
|
||||
return it, true
|
||||
}
|
||||
|
||||
for _, l := range locations {
|
||||
if it.Location.LocationType == l {
|
||||
return it, true
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user