Skip to content

Commit

Permalink
Fix repair loop indestructible item
Browse files Browse the repository at this point in the history
  • Loading branch information
elobo91 authored Dec 16, 2024
1 parent 48e7374 commit 7df91ec
Showing 1 changed file with 21 additions and 26 deletions.
47 changes: 21 additions & 26 deletions internal/action/repair.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 7df91ec

Please sign in to comment.