From 7df91ec11b1e177bd978c7b1f184dd68ba1ac373 Mon Sep 17 00:00:00 2001 From: elb <51070858+elobo91@users.noreply.github.com> Date: Sun, 15 Dec 2024 22:09:59 -0500 Subject: [PATCH] Fix repair loop indestructible item --- internal/action/repair.go | 47 +++++++++++++++++---------------------- 1 file changed, 21 insertions(+), 26 deletions(-) diff --git a/internal/action/repair.go b/internal/action/repair.go index 88240f73..9edf8184 100644 --- a/internal/action/repair.go +++ b/internal/action/repair.go @@ -82,36 +82,31 @@ func Repair() error { } func RepairRequired() bool { - ctx := context.Get() - ctx.SetLastAction("RepairRequired") - - for _, i := range ctx.Data.Inventory.ByLocation(item.LocationEquipped) { - - _, indestructible := i.FindStat(stat.Indestructible, 0) - - if i.Ethereal || indestructible { - continue - } + ctx := context.Get() + ctx.SetLastAction("RepairRequired") - currentDurability, currentDurabilityFound := i.FindStat(stat.Durability, 0) - maxDurability, maxDurabilityFound := i.FindStat(stat.MaxDurability, 0) + for _, i := range ctx.Data.Inventory.ByLocation(item.LocationEquipped) { + // Check indestructible first + _, indestructible := i.FindStat(stat.Indestructible, 0) + if i.Ethereal || indestructible { + continue + } - durabilityPercent := -1 + currentDurability, currentDurabilityFound := i.FindStat(stat.Durability, 0) + maxDurability, maxDurabilityFound := i.FindStat(stat.MaxDurability, 0) - if maxDurabilityFound && currentDurabilityFound { - durabilityPercent = int((float64(currentDurability.Value) / float64(maxDurability.Value)) * 100) - } + // Skip if we don't have both stats + if !maxDurabilityFound || !currentDurabilityFound { + continue // Don't trigger repair if we can't properly check durability + } - // If we don't find the stats just continue - if !currentDurabilityFound && !maxDurabilityFound { - continue - } + durabilityPercent := int((float64(currentDurability.Value) / float64(maxDurability.Value)) * 100) - // Let's check if the item requires repair plus a few fail-safes - if maxDurabilityFound && !currentDurabilityFound || durabilityPercent != -1 && currentDurabilityFound && durabilityPercent <= 20 || currentDurabilityFound && currentDurability.Value <= 5 { - return true - } - } + // Only return true if we have valid durability values and they're low + if durabilityPercent <= 20 || currentDurability.Value <= 5 { + return true + } + } - return false + return false }