Item refactor and more (#1)
This commit is contained in:
@@ -8,14 +8,43 @@ import (
|
||||
)
|
||||
|
||||
type Items struct {
|
||||
Belt Belt
|
||||
Inventory Inventory
|
||||
Shop []Item
|
||||
Ground []Item
|
||||
Equipped []Item
|
||||
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 Inventory []Item
|
||||
type UnitID int
|
||||
|
||||
type Item struct {
|
||||
@@ -23,11 +52,11 @@ type Item struct {
|
||||
Name item.Name
|
||||
Quality item.Quality
|
||||
Position Position
|
||||
Location item.Location
|
||||
Ethereal bool
|
||||
IsHovered bool
|
||||
Stats map[stat.ID]stat.Data
|
||||
Identified bool
|
||||
IsVendor bool
|
||||
}
|
||||
|
||||
func (i Item) Type() string {
|
||||
@@ -47,6 +76,17 @@ func (i Item) IsHealingPotion() bool {
|
||||
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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user