From fea62bbe31fa69eb1061ad43d9c1aebab7ff846f Mon Sep 17 00:00:00 2001 From: vietdungdev Date: Fri, 24 Apr 2026 19:14:48 +0700 Subject: [PATCH] update item data in party --- pkg/data/items.go | 27 +++++++++++++++++++-------- pkg/memory/item.go | 7 ++++--- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/pkg/data/items.go b/pkg/data/items.go index 2296615..0dabcfd 100644 --- a/pkg/data/items.go +++ b/pkg/data/items.go @@ -8,11 +8,22 @@ import ( ) type Inventory struct { - Belt Belt - AllItems []Item - Gold int - StashedGold [6]int // [0]=personal, [1..5]=shared stash pages - SharedStashPages int // Number of shared stash units detected (3=non-DLC, 5+=DLC) + Belt Belt + AllItems []Item + Gold int + StashedGold [6]int // [0]=personal, [1..5]=shared stash pages + SharedStashPages int // Number of shared stash units detected (3=non-DLC, 5+=DLC) + MySharedStashPage int // 1-based page index belonging to the current player (0 if not in party) +} + +func (i Inventory) CheckMySharedItem(it Item) bool { + if i.MySharedStashPage == 0 { + return true + } + if it.Location.LocationType != item.LocationSharedStash { + return true + } + return it.Location.Page == i.MySharedStashPage } func (i Inventory) Find(name item.Name, locations ...item.LocationType) (Item, bool) { @@ -24,7 +35,7 @@ func (i Inventory) Find(name item.Name, locations ...item.LocationType) (Item, b } for _, l := range locations { - if it.Location.LocationType == l { + if it.Location.LocationType == l && i.CheckMySharedItem(it) { return it, true } } @@ -36,7 +47,7 @@ func (i Inventory) Find(name item.Name, locations ...item.LocationType) (Item, b func (i Inventory) FindByID(unitID UnitID) (Item, bool) { for _, it := range i.AllItems { - if it.UnitID == unitID { + if it.UnitID == unitID && i.CheckMySharedItem(it) { return it, true } } @@ -49,7 +60,7 @@ func (i Inventory) ByLocation(locations ...item.LocationType) []Item { for _, it := range i.AllItems { for _, l := range locations { - if it.Location.LocationType == l { + if it.Location.LocationType == l && i.CheckMySharedItem(it) { items = append(items, it) } } diff --git a/pkg/memory/item.go b/pkg/memory/item.go index 97836f7..ee95ef7 100644 --- a/pkg/memory/item.go +++ b/pkg/memory/item.go @@ -51,9 +51,10 @@ func (gd *GameReader) Inventory(rawPlayerUnits RawPlayerUnits, hover data.HoverD } inventory := data.Inventory{ - Gold: inventoryGold.Value, - StashedGold: stashedGold, - SharedStashPages: len(stashPlayerUnitOrder), + Gold: inventoryGold.Value, + StashedGold: stashedGold, + SharedStashPages: len(stashPlayerUnitOrder), + MySharedStashPage: int(stashUnitIDToPage[uint(mainPlayer.UnitID)]), } belt := data.Belt{}