-
Notifications
You must be signed in to change notification settings - Fork 9
/
items.go
101 lines (81 loc) · 1.88 KB
/
items.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package data
import (
"strings"
"github.com/hectorgimenez/d2go/pkg/data/item"
"github.com/hectorgimenez/d2go/pkg/data/stat"
)
type Inventory struct {
Belt Belt
AllItems []Item
Gold int
StashedGold [4]int
}
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 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 {
return it, true
}
}
}
}
return Item{}, false
}
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 {
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
BaseStats stat.Stats
Stats stat.Stats
Identified bool
}
func (i Item) Desc() item.Description {
return item.Desc[i.ID]
}
func (i Item) Type() item.Type {
return i.Desc().GetType()
}
func (i Item) IsPotion() bool {
return i.IsHealingPotion() || i.IsManaPotion() || i.IsRejuvPotion()
}
func (i Item) IsHealingPotion() bool {
return i.Type().IsType(item.TypeHealingPotion)
}
func (i Item) IsManaPotion() bool {
return i.Type().IsType(item.TypeManaPotion)
}
func (i Item) IsRejuvPotion() bool {
return i.Type().IsType(item.TypeRejuvPotion)
}
func (i Item) IsFromQuest() bool {
return i.Type().IsType(item.TypeQuest)
}
func (i Item) FindStat(id stat.ID, layer int) (stat.Data, bool) {
st, found := i.Stats.FindStat(id, layer)
if found {
return st, true
}
return i.BaseStats.FindStat(id, layer)
}