improve item, them owner
This commit is contained in:
@@ -13,20 +13,17 @@ type Inventory struct {
|
|||||||
Gold int
|
Gold int
|
||||||
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)
|
||||||
MySharedStashPage int // 1-based page index belonging to the current player (0 if not in party)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i Inventory) CheckMySharedItem(it Item) bool {
|
func isPlayerItem(owner UnitID, it Item) bool {
|
||||||
if i.MySharedStashPage == 0 {
|
if it.Location.LocationType != item.LocationMercenary && (owner == it.Owner || it.Owner == 1) {
|
||||||
return true
|
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) {
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func (i Inventory) Find(owner UnitID, name item.Name, locations ...item.LocationType) (Item, bool) {
|
||||||
for _, it := range i.AllItems {
|
for _, it := range i.AllItems {
|
||||||
if strings.EqualFold(string(it.Name), string(name)) {
|
if strings.EqualFold(string(it.Name), string(name)) {
|
||||||
// If no locations are specified, return the first item found
|
// If no locations are specified, return the first item found
|
||||||
@@ -35,7 +32,7 @@ func (i Inventory) Find(name item.Name, locations ...item.LocationType) (Item, b
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, l := range locations {
|
for _, l := range locations {
|
||||||
if it.Location.LocationType == l && i.CheckMySharedItem(it) {
|
if it.Location.LocationType == l || it.Owner == owner {
|
||||||
return it, true
|
return it, true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -45,9 +42,9 @@ func (i Inventory) Find(name item.Name, locations ...item.LocationType) (Item, b
|
|||||||
return Item{}, false
|
return Item{}, false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i Inventory) FindByID(unitID UnitID) (Item, bool) {
|
func (i Inventory) FindByID(owner UnitID, unitID UnitID) (Item, bool) {
|
||||||
for _, it := range i.AllItems {
|
for _, it := range i.AllItems {
|
||||||
if it.UnitID == unitID && i.CheckMySharedItem(it) {
|
if it.UnitID == unitID || it.Owner == owner {
|
||||||
return it, true
|
return it, true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -55,12 +52,12 @@ func (i Inventory) FindByID(unitID UnitID) (Item, bool) {
|
|||||||
return Item{}, false
|
return Item{}, false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i Inventory) ByLocation(locations ...item.LocationType) []Item {
|
func (i Inventory) ByLocation(owner UnitID, locations ...item.LocationType) []Item {
|
||||||
var items []Item
|
var items []Item
|
||||||
|
|
||||||
for _, it := range i.AllItems {
|
for _, it := range i.AllItems {
|
||||||
for _, l := range locations {
|
for _, l := range locations {
|
||||||
if it.Location.LocationType == l && i.CheckMySharedItem(it) {
|
if it.Location.LocationType == l || it.Owner == owner {
|
||||||
items = append(items, it)
|
items = append(items, it)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -69,9 +66,9 @@ func (i Inventory) ByLocation(locations ...item.LocationType) []Item {
|
|||||||
return items
|
return items
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i Inventory) Matrix() [4][10]bool {
|
func (i Inventory) Matrix(owner UnitID) [4][10]bool {
|
||||||
invMatrix := [4][10]bool{} // false = empty, true = occupied
|
invMatrix := [4][10]bool{} // false = empty, true = occupied
|
||||||
for _, itm := range i.ByLocation(item.LocationInventory) {
|
for _, itm := range i.ByLocation(owner, item.LocationInventory) {
|
||||||
for k := range itm.Desc().InventoryWidth {
|
for k := range itm.Desc().InventoryWidth {
|
||||||
for j := range itm.Desc().InventoryHeight {
|
for j := range itm.Desc().InventoryHeight {
|
||||||
invMatrix[itm.Position.Y+j][itm.Position.X+k] = true
|
invMatrix[itm.Position.Y+j][itm.Position.X+k] = true
|
||||||
@@ -98,6 +95,7 @@ type ItemAffixes struct {
|
|||||||
type Item struct {
|
type Item struct {
|
||||||
ID int
|
ID int
|
||||||
UnitID
|
UnitID
|
||||||
|
Owner UnitID
|
||||||
Name item.Name
|
Name item.Name
|
||||||
Quality item.Quality
|
Quality item.Quality
|
||||||
IdentifiedName string
|
IdentifiedName string
|
||||||
|
|||||||
@@ -54,7 +54,6 @@ func (gd *GameReader) Inventory(rawPlayerUnits RawPlayerUnits, hover data.HoverD
|
|||||||
Gold: inventoryGold.Value,
|
Gold: inventoryGold.Value,
|
||||||
StashedGold: stashedGold,
|
StashedGold: stashedGold,
|
||||||
SharedStashPages: len(stashPlayerUnitOrder),
|
SharedStashPages: len(stashPlayerUnitOrder),
|
||||||
MySharedStashPage: int(stashUnitIDToPage[uint(mainPlayer.UnitID)]),
|
|
||||||
}
|
}
|
||||||
belt := data.Belt{}
|
belt := data.Belt{}
|
||||||
|
|
||||||
@@ -132,6 +131,7 @@ func (gd *GameReader) Inventory(rawPlayerUnits RawPlayerUnits, hover data.HoverD
|
|||||||
itm := &data.Item{
|
itm := &data.Item{
|
||||||
ID: int(txtFileNo),
|
ID: int(txtFileNo),
|
||||||
UnitID: data.UnitID(unitID),
|
UnitID: data.UnitID(unitID),
|
||||||
|
Owner: data.UnitID(itemOwnerNPC),
|
||||||
Name: item.GetNameByEnum(txtFileNo),
|
Name: item.GetNameByEnum(txtFileNo),
|
||||||
Quality: item.Quality(itemQuality),
|
Quality: item.Quality(itemQuality),
|
||||||
Position: data.Position{
|
Position: data.Position{
|
||||||
@@ -142,6 +142,9 @@ func (gd *GameReader) Inventory(rawPlayerUnits RawPlayerUnits, hover data.HoverD
|
|||||||
Sockets: make([]data.Item, 0),
|
Sockets: make([]data.Item, 0),
|
||||||
UniqueSetID: txtUniqueSet,
|
UniqueSetID: txtUniqueSet,
|
||||||
}
|
}
|
||||||
|
if itm.Owner == 1 {
|
||||||
|
itm.Owner = mainPlayer.UnitID
|
||||||
|
}
|
||||||
|
|
||||||
// Set item properties
|
// Set item properties
|
||||||
setProperties(itm, uint32(flags))
|
setProperties(itm, uint32(flags))
|
||||||
|
|||||||
Reference in New Issue
Block a user