update code

This commit is contained in:
vietdungdev
2026-05-20 23:48:50 +07:00
parent aa4a6f02a9
commit e1679a2d11

View File

@@ -17,7 +17,8 @@ type Inventory struct {
} }
func isMatchOwner(owner UnitID, it Item) bool { 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 return true
} }
if it.Location.LocationType != item.LocationMercenary && it.Owner == 1 { 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) { func (i Inventory) Find(name item.Name, locations ...item.LocationType) (Item, bool) {
for _, it := range i.AllItems { 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 no locations are specified, return the first item found
if len(locations) == 0 { if len(locations) == 0 {
return it, true return it, true
} }
for _, l := range locations { 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 return it, true
} }
} }