Update to handle sunder charms with resist handling logic.

This commit is contained in:
Polivox
2025-11-30 00:27:04 +02:00
parent f584814565
commit 4f2a29e3f1

View File

@@ -329,19 +329,27 @@ func (r Rule) Evaluate(it data.Item) (RuleResult, error) {
} }
} }
// Handle resist sums // Handle resist sums - check if item has any resist stats (including negative values)
hasAnyResist := false hasAnyResist := false
// Detect if this is a rule with a resist sum expression // Detect if this is a rule with a resist sum expression
// We need to check both for direct addition/subtraction and parenthesized expressions
isResistSum := false isResistSum := false
if strings.Contains(stage2, "resist") { if strings.Contains(stage2, "resist") {
isResistSum = strings.Contains(stage2, "+") || strings.Contains(stage2, "-") || isResistSum = strings.Contains(stage2, "+") || strings.Contains(stage2, "-") ||
(strings.Contains(stage2, "(") && strings.Contains(stage2, ")")) (strings.Contains(stage2, "(") && strings.Contains(stage2, ")"))
} }
// Check if rule ONLY checks resist sums (no other OR conditions)
hasNonResistConditions := false
for _, statName := range r.requiredStats {
if !strings.Contains(statName, "resist") {
hasNonResistConditions = true
break
}
}
if isResistSum { if isResistSum {
// Check if the item has any resist stats at all // Check if the item has any resist stats at all (including negative values like sunders)
for _, statName := range r.requiredStats { for _, statName := range r.requiredStats {
if !strings.Contains(statName, "resist") { if !strings.Contains(statName, "resist") {
continue continue
@@ -355,7 +363,8 @@ func (r Rule) Evaluate(it data.Item) (RuleResult, error) {
layer = statData[1] layer = statData[1]
} }
if itemStat, found := it.FindStat(stat.ID(statData[0]), layer); found && itemStat.Value != 0 { // Check if stat exists at all, regardless of value (including negative)
if _, found := it.FindStat(stat.ID(statData[0]), layer); found {
hasAnyResist = true hasAnyResist = true
break break
} }
@@ -386,17 +395,17 @@ func (r Rule) Evaluate(it data.Item) (RuleResult, error) {
statValue = itemStat.Value statValue = itemStat.Value
statFound = true statFound = true
} }
// Special handling for stats not found // Special handling for stats not found
if !statFound { if !statFound {
isResistStat := strings.Contains(statName, "resist") isResistStat := strings.Contains(statName, "resist")
// When the rule contains a resist-sum but the item has no resists, // Special case: Pure resist-sum rules (like sunders) should fail early if no resists exist
// dont return NoMatch—set the stat to 0 so the sum evaluates to false, // But mixed rules (resists OR other stats) should continue to check other conditions
// and let other OR conditions decide the result. if isResistStat && isResistSum && !hasAnyResist && !hasNonResistConditions {
if isResistStat && isResistSum && !hasAnyResist { // This is a pure resist rule and item has no resists - can't match
stage2Props[statName] = 0 return RuleResultNoMatch, nil
continue
} }
// For all other missing stats, default to 0 // For all other cases, default missing stats to 0 and let expression evaluate
stage2Props[statName] = 0 stage2Props[statName] = 0
} else { } else {
stage2Props[statName] = statValue stage2Props[statName] = statValue