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
|
||||
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
|
||||
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
|
||||
|
||||
// Pre-allocate buffers for repeated use
|
||||
@@ -444,7 +448,7 @@ func (gd *GameReader) Inventory(rawPlayerUnits RawPlayerUnits, hover data.HoverD
|
||||
} else {
|
||||
// Check if item has sockets
|
||||
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
|
||||
for baseUnitID, baseItem := range baseItemsMap {
|
||||
numSockets, _ := baseItem.Stats.FindStat(stat.NumSockets, 0)
|
||||
if numSockets.Value == 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
for baseUnitID, baseInfo := range baseItemsMap {
|
||||
// Get socket list for this base item
|
||||
sockets := socketedItemsMap[baseUnitID]
|
||||
if len(sockets) == 0 {
|
||||
continue
|
||||
}
|
||||
if len(sockets) > numSockets.Value {
|
||||
if len(sockets) > baseInfo.numSockets {
|
||||
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)
|
||||
baseItem := baseInfo.item
|
||||
baseItem.Sockets = make([]data.Item, 0, len(sockets))
|
||||
for i, socket := range sockets {
|
||||
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 {
|
||||
eligibleTypes := map[string]bool{
|
||||
item.TypeScepter: true,
|
||||
item.TypeWand: true,
|
||||
item.TypeStaff: true,
|
||||
item.TypeOrb: true,
|
||||
item.TypeHandtoHand: true,
|
||||
item.TypeHandtoHand2: true,
|
||||
item.TypePelt: true,
|
||||
item.TypePrimalHelm: true,
|
||||
}
|
||||
|
||||
if !eligibleTypes[baseDesc.Type] {
|
||||
switch baseDesc.Type {
|
||||
case item.TypeScepter, item.TypeWand, item.TypeStaff, item.TypeOrb,
|
||||
item.TypeHandtoHand, item.TypeHandtoHand2, item.TypePelt, item.TypePrimalHelm:
|
||||
default:
|
||||
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
|
||||
var originalCode string
|
||||
specificLevelReq := 0
|
||||
if itm.Quality == item.QualityUnique {
|
||||
for _, uniqueInfo := range item.UniqueItems {
|
||||
if uniqueInfo.ID == int(itm.UniqueSetID) {
|
||||
originalCode = uniqueInfo.Code
|
||||
specificLevelReq = uniqueInfo.LevelReq
|
||||
break
|
||||
}
|
||||
}
|
||||
@@ -787,6 +781,7 @@ func calculateItemLevelReq(itm *data.Item, baseDesc item.Description) int {
|
||||
for _, setItemInfo := range item.SetItems {
|
||||
if setItemInfo.ID == int(itm.UniqueSetID) {
|
||||
originalCode = setItemInfo.Code
|
||||
specificLevelReq = setItemInfo.LevelReq
|
||||
break
|
||||
}
|
||||
}
|
||||
@@ -807,26 +802,8 @@ func calculateItemLevelReq(itm *data.Item, baseDesc item.Description) int {
|
||||
}
|
||||
|
||||
// Check unique/set specific level requirement
|
||||
if itm.Identified {
|
||||
if itm.Quality == item.QualityUnique {
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
if itm.Identified && specificLevelReq > maxReq {
|
||||
maxReq = specificLevelReq
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user