improve item.go 1
This commit is contained in:
@@ -68,8 +68,12 @@ func (gd *GameReader) Inventory(rawPlayerUnits RawPlayerUnits, hover data.HoverD
|
|||||||
item *data.Item
|
item *data.Item
|
||||||
position int // Store X position
|
position int // Store X position
|
||||||
}
|
}
|
||||||
|
type baseItemInfo struct {
|
||||||
|
item *data.Item
|
||||||
|
numSockets int
|
||||||
|
}
|
||||||
socketedItemsMap := make(map[data.UnitID][]socketInfo, 120) // Up to ~120 items could be socketable
|
socketedItemsMap := make(map[data.UnitID][]socketInfo, 120) // Up to ~120 items could be socketable
|
||||||
baseItemsMap := make(map[data.UnitID]*data.Item, 120) // Same number of potential base items
|
baseItemsMap := make(map[data.UnitID]baseItemInfo, 120) // Same number of potential base items
|
||||||
allItems := make([]*data.Item, 0, 800) // max capacity: 600 (stashes) + 91 (DLC tabs) + 40 (inv) + 12 (cube) + 12 (equipped) + 16 (belt) + headroom
|
allItems := make([]*data.Item, 0, 800) // max capacity: 600 (stashes) + 91 (DLC tabs) + 40 (inv) + 12 (cube) + 12 (equipped) + 16 (belt) + headroom
|
||||||
|
|
||||||
// Pre-allocate buffers for repeated use
|
// Pre-allocate buffers for repeated use
|
||||||
@@ -444,7 +448,7 @@ func (gd *GameReader) Inventory(rawPlayerUnits RawPlayerUnits, hover data.HoverD
|
|||||||
} else {
|
} else {
|
||||||
// Check if item has sockets
|
// Check if item has sockets
|
||||||
if numSockets, _ := itm.Stats.FindStat(stat.NumSockets, 0); numSockets.Value > 0 {
|
if numSockets, _ := itm.Stats.FindStat(stat.NumSockets, 0); numSockets.Value > 0 {
|
||||||
baseItemsMap[itm.UnitID] = itm
|
baseItemsMap[itm.UnitID] = baseItemInfo{item: itm, numSockets: numSockets.Value}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -460,18 +464,13 @@ func (gd *GameReader) Inventory(rawPlayerUnits RawPlayerUnits, hover data.HoverD
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Link sockets to base items
|
// Link sockets to base items
|
||||||
for baseUnitID, baseItem := range baseItemsMap {
|
for baseUnitID, baseInfo := range baseItemsMap {
|
||||||
numSockets, _ := baseItem.Stats.FindStat(stat.NumSockets, 0)
|
|
||||||
if numSockets.Value == 0 {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get socket list for this base item
|
// Get socket list for this base item
|
||||||
sockets := socketedItemsMap[baseUnitID]
|
sockets := socketedItemsMap[baseUnitID]
|
||||||
if len(sockets) == 0 {
|
if len(sockets) == 0 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if len(sockets) > numSockets.Value {
|
if len(sockets) > baseInfo.numSockets {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -483,6 +482,7 @@ func (gd *GameReader) Inventory(rawPlayerUnits RawPlayerUnits, hover data.HoverD
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Validate socket positions and build final list in one pass (allow partial sockets)
|
// Validate socket positions and build final list in one pass (allow partial sockets)
|
||||||
|
baseItem := baseInfo.item
|
||||||
baseItem.Sockets = make([]data.Item, 0, len(sockets))
|
baseItem.Sockets = make([]data.Item, 0, len(sockets))
|
||||||
for i, socket := range sockets {
|
for i, socket := range sockets {
|
||||||
if socket.position != i {
|
if socket.position != i {
|
||||||
@@ -695,18 +695,10 @@ func updateMaxReqFromAffixes(currentMax int, affixes data.ItemAffixes) int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func staffModLevelRequirement(itm *data.Item, baseDesc item.Description) int {
|
func staffModLevelRequirement(itm *data.Item, baseDesc item.Description) int {
|
||||||
eligibleTypes := map[string]bool{
|
switch baseDesc.Type {
|
||||||
item.TypeScepter: true,
|
case item.TypeScepter, item.TypeWand, item.TypeStaff, item.TypeOrb,
|
||||||
item.TypeWand: true,
|
item.TypeHandtoHand, item.TypeHandtoHand2, item.TypePelt, item.TypePrimalHelm:
|
||||||
item.TypeStaff: true,
|
default:
|
||||||
item.TypeOrb: true,
|
|
||||||
item.TypeHandtoHand: true,
|
|
||||||
item.TypeHandtoHand2: true,
|
|
||||||
item.TypePelt: true,
|
|
||||||
item.TypePrimalHelm: true,
|
|
||||||
}
|
|
||||||
|
|
||||||
if !eligibleTypes[baseDesc.Type] {
|
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -776,10 +768,12 @@ func calculateItemLevelReq(itm *data.Item, baseDesc item.Description) int {
|
|||||||
|
|
||||||
// Find the original item tier by looking up the unique/set item
|
// Find the original item tier by looking up the unique/set item
|
||||||
var originalCode string
|
var originalCode string
|
||||||
|
specificLevelReq := 0
|
||||||
if itm.Quality == item.QualityUnique {
|
if itm.Quality == item.QualityUnique {
|
||||||
for _, uniqueInfo := range item.UniqueItems {
|
for _, uniqueInfo := range item.UniqueItems {
|
||||||
if uniqueInfo.ID == int(itm.UniqueSetID) {
|
if uniqueInfo.ID == int(itm.UniqueSetID) {
|
||||||
originalCode = uniqueInfo.Code
|
originalCode = uniqueInfo.Code
|
||||||
|
specificLevelReq = uniqueInfo.LevelReq
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -787,6 +781,7 @@ func calculateItemLevelReq(itm *data.Item, baseDesc item.Description) int {
|
|||||||
for _, setItemInfo := range item.SetItems {
|
for _, setItemInfo := range item.SetItems {
|
||||||
if setItemInfo.ID == int(itm.UniqueSetID) {
|
if setItemInfo.ID == int(itm.UniqueSetID) {
|
||||||
originalCode = setItemInfo.Code
|
originalCode = setItemInfo.Code
|
||||||
|
specificLevelReq = setItemInfo.LevelReq
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -807,26 +802,8 @@ func calculateItemLevelReq(itm *data.Item, baseDesc item.Description) int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check unique/set specific level requirement
|
// Check unique/set specific level requirement
|
||||||
if itm.Identified {
|
if itm.Identified && specificLevelReq > maxReq {
|
||||||
if itm.Quality == item.QualityUnique {
|
maxReq = specificLevelReq
|
||||||
for _, uniqueInfo := range item.UniqueItems {
|
|
||||||
if uniqueInfo.ID == int(itm.UniqueSetID) {
|
|
||||||
if uniqueInfo.LevelReq > maxReq {
|
|
||||||
maxReq = uniqueInfo.LevelReq
|
|
||||||
}
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if itm.Quality == item.QualitySet {
|
|
||||||
for _, setItemInfo := range item.SetItems {
|
|
||||||
if setItemInfo.ID == int(itm.UniqueSetID) {
|
|
||||||
if setItemInfo.LevelReq > maxReq {
|
|
||||||
maxReq = setItemInfo.LevelReq
|
|
||||||
}
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user