improve 2

This commit is contained in:
vietdungdev
2026-05-25 11:29:08 +07:00
parent 1e3cd850d8
commit 340189b2b2

View File

@@ -572,28 +572,49 @@ func (r Rule) ValidateStats() error {
}
func evaluateClassSkillsSum(it data.Item) int {
// Check all class skills stats
totalClassSkills := 0
for layer := 0; layer <= maxClassSkillsLayer; layer++ {
if itemStat, found := it.FindStat(stat.AddClassSkills, layer); found && itemStat.Value > 0 {
totalClassSkills += itemStat.Value
}
}
return totalClassSkills
return evaluatePositiveStatSum(it, stat.AddClassSkills, maxClassSkillsLayer)
}
func evaluateSkillTabSum(it data.Item) int {
// Check all skill tab stats
totalSkillTabs := 0
for layer := 0; layer <= maxSkillTabLayer; layer++ {
if itemStat, found := it.FindStat(stat.AddSkillTab, layer); found && itemStat.Value > 0 {
totalSkillTabs += itemStat.Value
func evaluateSkillTabSum(it data.Item) int {
return evaluatePositiveStatSum(it, stat.AddSkillTab, maxSkillTabLayer)
}
const aggregateLayerFastPathLimit = 64
func evaluatePositiveStatSum(it data.Item, statID stat.ID, maxLayer int) int {
// Current aggregate aliases fit in a small stack bitmap; retain the general
// lookup path if additional layers later exceed that bound.
if maxLayer >= aggregateLayerFastPathLimit {
total := 0
for layer := 0; layer <= maxLayer; layer++ {
if itemStat, found := it.FindStat(statID, layer); found && itemStat.Value > 0 {
total += itemStat.Value
}
}
return total
}
return totalSkillTabs
var foundLayers [aggregateLayerFastPathLimit]bool
total := 0
for _, itemStat := range it.Stats {
if itemStat.ID != statID || itemStat.Layer < 0 || itemStat.Layer > maxLayer || foundLayers[itemStat.Layer] {
continue
}
foundLayers[itemStat.Layer] = true
if itemStat.Value > 0 {
total += itemStat.Value
}
}
for _, itemStat := range it.BaseStats {
if itemStat.ID != statID || itemStat.Layer < 0 || itemStat.Layer > maxLayer || foundLayers[itemStat.Layer] {
continue
}
foundLayers[itemStat.Layer] = true
if itemStat.Value > 0 {
total += itemStat.Value
}
}
return total
}
func maxAliasLayer(statID stat.ID) int {