get stashed gold

This commit is contained in:
Héctor Giménez
2024-05-15 17:23:53 +09:00
parent ffae8296af
commit 2a5f31885e
7 changed files with 48 additions and 31 deletions

View File

@@ -31,7 +31,7 @@ type Data struct {
CollisionGrid [][]bool
PlayerUnit PlayerUnit
NPCs NPCs
Items Items
Inventory Inventory
Objects Objects
AdjacentLevels []Level
Rooms []Room
@@ -163,8 +163,8 @@ func (pu PlayerUnit) MaxGold() int {
return goldPerLevel * lvl.Value
}
// TotalGold returns the amount of gold, including inventory and stash
func (pu PlayerUnit) TotalGold() int {
// TotalPlayerGold returns the amount of gold, including inventory and player stash (excluding shared stash)
func (pu PlayerUnit) TotalPlayerGold() int {
gold, _ := pu.FindStat(stat.Gold, 0)
stashGold, _ := pu.FindStat(stat.StashGold, 0)

View File

@@ -7,12 +7,14 @@ import (
"github.com/hectorgimenez/d2go/pkg/data/stat"
)
type Items struct {
Belt Belt
AllItems []Item
type Inventory struct {
Belt Belt
AllItems []Item
Gold int
StashedGold [4]int
}
func (i Items) Find(name item.Name, locations ...item.Location) (Item, bool) {
func (i Inventory) 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
@@ -31,7 +33,7 @@ func (i Items) Find(name item.Name, locations ...item.Location) (Item, bool) {
return Item{}, false
}
func (i Items) ByLocation(locations ...item.Location) []Item {
func (i Inventory) ByLocation(locations ...item.Location) []Item {
var items []Item
for _, it := range i.AllItems {
@@ -75,19 +77,19 @@ func (i Item) IsPotion() bool {
}
func (i Item) IsHealingPotion() bool {
return strings.Contains(string(i.Name), string(HealingPotion))
return i.Type().IsType(item.TypeHealingPotion)
}
func (i Item) IsManaPotion() bool {
return strings.Contains(string(i.Name), string(ManaPotion))
return i.Type().IsType(item.TypeManaPotion)
}
func (i Item) IsRejuvPotion() bool {
return strings.Contains(string(i.Name), string(RejuvenationPotion))
return i.Type().IsType(item.TypeRejuvPotion)
}
func (i Item) IsFromQuest() bool {
return i.Desc().Type == item.TypeQuest
return i.Type().IsType(item.TypeQuest)
}
func (i Item) FindStat(id stat.ID, layer int) (stat.Data, bool) {