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