update item owner
This commit is contained in:
@@ -14,18 +14,15 @@ type Inventory struct {
|
||||
StashedGold [6]int // [0]=personal, [1..5]=shared stash pages
|
||||
SharedStashPages int // Number of shared stash units detected (3=non-DLC, 5+=DLC)
|
||||
PlayerID UnitID // Number of shared stash units detected (3=non-DLC, 5+=DLC)
|
||||
MercID UnitID
|
||||
}
|
||||
|
||||
func (i Inventory) isMatchOwner(it Item) bool {
|
||||
if it.Location.LocationType == item.LocationUnknown ||
|
||||
it.Location.LocationType == item.LocationGround || it.Location.LocationType == item.LocationVendor {
|
||||
it.Location.LocationType == item.LocationGround ||
|
||||
it.Location.LocationType == item.LocationMercenary || it.Location.LocationType == item.LocationVendor {
|
||||
return true
|
||||
}
|
||||
|
||||
if it.Location.LocationType == item.LocationMercenary {
|
||||
return i.MercID != 0 && it.Owner == i.MercID
|
||||
}
|
||||
return it.Owner == i.PlayerID
|
||||
}
|
||||
|
||||
|
||||
@@ -82,15 +82,12 @@ func (gd *GameReader) GetData() data.Data {
|
||||
gd.monstersLastUpdate = now
|
||||
}
|
||||
|
||||
merc, foundMerc := gd.OwnMercenary()
|
||||
merc.Found = foundMerc
|
||||
|
||||
// Conditionally update inventory 500ms
|
||||
// Except when hovering over an item
|
||||
inventory := gd.cachedInventory
|
||||
if now.Sub(gd.inventoryLastUpdate) > 250*time.Millisecond ||
|
||||
(hover.IsHovered && hover.UnitType == 4) { // 4 = Item type
|
||||
inventory = gd.Inventory(rawPlayerUnits, merc, hover)
|
||||
inventory = gd.Inventory(rawPlayerUnits, hover)
|
||||
gd.cachedInventory = inventory
|
||||
gd.inventoryLastUpdate = now
|
||||
}
|
||||
@@ -150,6 +147,8 @@ func (gd *GameReader) GetData() data.Data {
|
||||
ActiveWeaponSlot: gd.GetActiveWeaponSlot(),
|
||||
}
|
||||
|
||||
merc, foundMerc := gd.OwnMercenary()
|
||||
merc.Found = foundMerc
|
||||
d.Mercenary = data.OwnMercenary(merc)
|
||||
return d
|
||||
}
|
||||
@@ -157,9 +156,7 @@ func (gd *GameReader) GetData() data.Data {
|
||||
func (gd *GameReader) GetInventory() data.Inventory {
|
||||
rawPlayerUnits := gd.GetRawPlayerUnits()
|
||||
hover := gd.HoveredData()
|
||||
merc, foundMerc := gd.OwnMercenary()
|
||||
merc.Found = foundMerc
|
||||
return gd.Inventory(rawPlayerUnits, merc, hover)
|
||||
return gd.Inventory(rawPlayerUnits, hover)
|
||||
}
|
||||
|
||||
func (gd *GameReader) InGame() bool {
|
||||
|
||||
@@ -13,7 +13,7 @@ import (
|
||||
"github.com/hectorgimenez/d2go/pkg/utils"
|
||||
)
|
||||
|
||||
func (gd *GameReader) Inventory(rawPlayerUnits RawPlayerUnits, merc OwnMercenary, hover data.HoverData) data.Inventory {
|
||||
func (gd *GameReader) Inventory(rawPlayerUnits RawPlayerUnits, hover data.HoverData) data.Inventory {
|
||||
mainPlayer := rawPlayerUnits.GetMainPlayer()
|
||||
baseAddr := gd.Process.moduleBaseAddressPtr + gd.offset.UnitTable + (4 * 1024)
|
||||
unitTableBuffer := gd.Process.ReadBytesFromMemory(baseAddr, 128*8)
|
||||
@@ -55,7 +55,6 @@ func (gd *GameReader) Inventory(rawPlayerUnits RawPlayerUnits, merc OwnMercenary
|
||||
StashedGold: stashedGold,
|
||||
SharedStashPages: len(stashPlayerUnitOrder),
|
||||
PlayerID: mainPlayer.UnitID,
|
||||
MercID: merc.UnitID,
|
||||
}
|
||||
belt := data.Belt{}
|
||||
|
||||
@@ -268,15 +267,26 @@ func (gd *GameReader) Inventory(rawPlayerUnits RawPlayerUnits, merc OwnMercenary
|
||||
if page, ok := stashUnitIDToPage[itemOwnerNPC]; ok {
|
||||
location = item.LocationSharedStash
|
||||
invPage = page
|
||||
|
||||
// In party mode / current memory layout:
|
||||
// shared stash page 1 belongs to the current character.
|
||||
// Other pages are other shared stash containers and should keep raw owner.
|
||||
if page == 1 {
|
||||
itm.Owner = mainPlayer.UnitID
|
||||
}
|
||||
|
||||
} else if itemOwnerNPC == 2 && len(stashUnitIDToPage) == 0 {
|
||||
location = item.LocationSharedStash
|
||||
invPage = 1
|
||||
itm.Owner = mainPlayer.UnitID
|
||||
} else if itemOwnerNPC == 3 && len(stashUnitIDToPage) == 0 {
|
||||
location = item.LocationSharedStash
|
||||
invPage = 2
|
||||
itm.Owner = mainPlayer.UnitID
|
||||
} else if itemOwnerNPC == 4 && len(stashUnitIDToPage) == 0 {
|
||||
location = item.LocationSharedStash
|
||||
invPage = 3
|
||||
itm.Owner = mainPlayer.UnitID
|
||||
} else if itemOwnerNPC == 4294967295 {
|
||||
if 0x00002000&flags != 0 {
|
||||
location = item.LocationVendor
|
||||
|
||||
Reference in New Issue
Block a user