Skip to content

Commit

Permalink
Fix repair loop indestructible item (#582)
Browse files Browse the repository at this point in the history
  • Loading branch information
elobo91 authored Dec 16, 2024
1 parent a4425d2 commit 03913d0
Showing 1 changed file with 36 additions and 32 deletions.
68 changes: 36 additions & 32 deletions internal/action/repair.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,36 +82,40 @@ 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
}

currentDurability, currentDurabilityFound := i.FindStat(stat.Durability, 0)
maxDurability, maxDurabilityFound := i.FindStat(stat.MaxDurability, 0)

durabilityPercent := -1

if maxDurabilityFound && currentDurabilityFound {
durabilityPercent = int((float64(currentDurability.Value) / float64(maxDurability.Value)) * 100)
}

// If we don't find the stats just continue
if !currentDurabilityFound && !maxDurabilityFound {
continue
}

// 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
}
}

return false
ctx := context.Get()
ctx.SetLastAction("RepairRequired")

for _, i := range ctx.Data.Inventory.ByLocation(item.LocationEquipped) {
// Skip indestructible items
_, indestructible := i.FindStat(stat.Indestructible, 0)
if i.Ethereal || indestructible {
continue
}

currentDurability, currentDurabilityFound := i.FindStat(stat.Durability, 0)
maxDurability, maxDurabilityFound := i.FindStat(stat.MaxDurability, 0)

// If we have both stats, check percentage
if currentDurabilityFound && maxDurabilityFound {
durabilityPercent := int((float64(currentDurability.Value) / float64(maxDurability.Value)) * 100)
if durabilityPercent <= 20 {
return true
}
}

// If we only have current durability, check absolute value
if currentDurabilityFound {
if currentDurability.Value <= 5 {
return true
}
}

// Handle case where durability stat is missing but max durability exists
// This likely indicates the item needs repair
if maxDurabilityFound && !currentDurabilityFound {
return true
}
}

return false
}

0 comments on commit 03913d0

Please sign in to comment.