update item data

This commit is contained in:
vietdungdev
2026-05-09 15:30:36 +07:00
parent 070e47e460
commit 21cfba7a22
3 changed files with 37 additions and 11 deletions

View File

@@ -100,6 +100,13 @@ func (r Room) IsInside(p Position) bool {
return false return false
} }
func (d Data) MercHPPercent() int {
if d.Mercenary.Found {
return d.Mercenary.HPPercent
}
return 0
}
type RosterMember struct { type RosterMember struct {
Name string Name string
Area area.ID Area area.ID

View File

@@ -13,17 +13,21 @@ 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)
PlayerID UnitID // Number of shared stash units detected (3=non-DLC, 5+=DLC)
} }
func isPlayerItem(owner UnitID, it Item) bool { func isMatchOwner(owner UnitID, it Item) bool {
if it.Location.LocationType != item.LocationMercenary && (owner == it.Owner || it.Owner == 1) { if it.Location.LocationType == item.LocationGround {
return true
}
if it.Location.LocationType != item.LocationMercenary && it.Owner == 1 {
return true return true
} }
return false return owner == it.Owner
} }
func (i Inventory) Find(owner UnitID, name item.Name, locations ...item.LocationType) (Item, bool) { func (i Inventory) Find(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
@@ -32,7 +36,7 @@ func (i Inventory) Find(owner UnitID, name item.Name, locations ...item.Location
} }
for _, l := range locations { for _, l := range locations {
if it.Location.LocationType == l || it.Owner == owner { if it.Location.LocationType == l && isMatchOwner(i.PlayerID, it) {
return it, true return it, true
} }
} }
@@ -42,9 +46,9 @@ func (i Inventory) Find(owner UnitID, name item.Name, locations ...item.Location
return Item{}, false return Item{}, false
} }
func (i Inventory) FindByID(owner UnitID, unitID UnitID) (Item, bool) { func (i Inventory) FindByID(unitID UnitID) (Item, bool) {
for _, it := range i.AllItems { for _, it := range i.AllItems {
if it.UnitID == unitID || it.Owner == owner { if it.UnitID == unitID && isMatchOwner(i.PlayerID, it) {
return it, true return it, true
} }
} }
@@ -52,12 +56,12 @@ func (i Inventory) FindByID(owner UnitID, unitID UnitID) (Item, bool) {
return Item{}, false return Item{}, false
} }
func (i Inventory) ByLocation(owner UnitID, locations ...item.LocationType) []Item { func (i Inventory) ByOwnerLocation(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 || it.Owner == owner { if it.Location.LocationType == l && isMatchOwner(owner, it) {
items = append(items, it) items = append(items, it)
} }
} }
@@ -66,9 +70,23 @@ func (i Inventory) ByLocation(owner UnitID, locations ...item.LocationType) []It
return items return items
} }
func (i Inventory) Matrix(owner UnitID) [4][10]bool { func (i Inventory) ByLocation(locations ...item.LocationType) []Item {
var items []Item
for _, it := range i.AllItems {
for _, l := range locations {
if it.Location.LocationType == l && isMatchOwner(i.PlayerID, it) {
items = append(items, it)
}
}
}
return items
}
func (i Inventory) Matrix() [4][10]bool {
invMatrix := [4][10]bool{} // false = empty, true = occupied invMatrix := [4][10]bool{} // false = empty, true = occupied
for _, itm := range i.ByLocation(owner, item.LocationInventory) { for _, itm := range i.ByLocation(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

View File

@@ -54,6 +54,7 @@ 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),
PlayerID: rawPlayerUnits.GetMainPlayer().UnitID,
} }
belt := data.Belt{} belt := data.Belt{}