111 lines
2.0 KiB
Go
111 lines
2.0 KiB
Go
package data
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"github.com/hectorgimenez/d2go/pkg/data/item"
|
|
"github.com/hectorgimenez/d2go/pkg/data/stat"
|
|
)
|
|
|
|
type Items struct {
|
|
Belt Belt
|
|
AllItems []Item
|
|
}
|
|
|
|
func (i Items) Find(name item.Name, locations ...item.Location) (Item, bool) {
|
|
for _, it := range i.AllItems {
|
|
if strings.EqualFold(string(it.Name), string(name)) {
|
|
// If no locations are specified, return the first item found
|
|
if len(locations) == 0 {
|
|
return it, true
|
|
}
|
|
|
|
for _, l := range locations {
|
|
if it.Location == l {
|
|
return it, true
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return Item{}, false
|
|
}
|
|
|
|
func (i Items) ByLocation(locations ...item.Location) []Item {
|
|
var items []Item
|
|
|
|
for _, it := range i.AllItems {
|
|
for _, l := range locations {
|
|
if it.Location == l {
|
|
items = append(items, it)
|
|
}
|
|
}
|
|
}
|
|
|
|
return items
|
|
}
|
|
|
|
type UnitID int
|
|
|
|
type Item struct {
|
|
ID int
|
|
UnitID
|
|
Name item.Name
|
|
Quality item.Quality
|
|
Position Position
|
|
Location item.Location
|
|
Ethereal bool
|
|
IsHovered bool
|
|
Stats []stat.Data
|
|
BaseStats []stat.Data
|
|
Identified bool
|
|
Type int
|
|
}
|
|
|
|
func (i Item) Desc() item.Description {
|
|
return item.Desc[i.ID]
|
|
}
|
|
|
|
func (i Item) TypeAsString() string {
|
|
t, _ := item.TypeForItemName(string(i.Name))
|
|
|
|
return t
|
|
}
|
|
|
|
func (i Item) IsPotion() bool {
|
|
return i.IsHealingPotion() || i.IsManaPotion() || i.IsRejuvPotion()
|
|
}
|
|
|
|
func (i Item) IsHealingPotion() bool {
|
|
return strings.Contains(string(i.Name), string(HealingPotion))
|
|
}
|
|
|
|
func (i Item) IsManaPotion() bool {
|
|
return strings.Contains(string(i.Name), string(ManaPotion))
|
|
}
|
|
|
|
func (i Item) IsRejuvPotion() bool {
|
|
return strings.Contains(string(i.Name), string(RejuvenationPotion))
|
|
}
|
|
|
|
func (i Item) IsFromQuest() bool {
|
|
for _, q := range item.QuestItems {
|
|
if strings.EqualFold(string(i.Name), q) {
|
|
return true
|
|
}
|
|
}
|
|
|
|
return false
|
|
}
|
|
|
|
func (i Item) FindStat(id stat.ID, layer int) (stat.Data, bool) {
|
|
totalStats := append(i.Stats, i.BaseStats...)
|
|
for _, s := range totalStats {
|
|
if s.ID == id && s.Layer == layer {
|
|
return s, true
|
|
}
|
|
}
|
|
|
|
return stat.Data{}, false
|
|
}
|