Skip to content

Commit

Permalink
Fixes and stuff (#689)
Browse files Browse the repository at this point in the history
  • Loading branch information
artosimonyan authored Feb 21, 2025
1 parent 8ff9266 commit 523a6a0
Show file tree
Hide file tree
Showing 7 changed files with 110 additions and 64 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require (
github.com/bwmarrin/discordgo v0.28.1
github.com/go-telegram-bot-api/telegram-bot-api/v5 v5.5.1
github.com/gorilla/websocket v1.5.3
github.com/hectorgimenez/d2go v0.0.0-20250119163231-415ac29ab1ab
github.com/hectorgimenez/d2go v0.0.0-20250221161127-5455fd977276
github.com/inkeliz/gowebview v1.0.1
github.com/lxn/win v0.0.0-20210218163916-a377121e959e
github.com/otiai10/copy v1.14.0
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ github.com/hectorgimenez/d2go v0.0.0-20250106015039-8bce23b03973 h1:dRqPFWAf0yb1
github.com/hectorgimenez/d2go v0.0.0-20250106015039-8bce23b03973/go.mod h1:EOVayMaK8D13wsZiZ6n8AK3+Qflm1wHZsCqnzlVIci0=
github.com/hectorgimenez/d2go v0.0.0-20250119163231-415ac29ab1ab h1:vrZ5hlN1qnUXPHjVRCvSuWyjfauNopuMLU+/YmBge2c=
github.com/hectorgimenez/d2go v0.0.0-20250119163231-415ac29ab1ab/go.mod h1:EOVayMaK8D13wsZiZ6n8AK3+Qflm1wHZsCqnzlVIci0=
github.com/hectorgimenez/d2go v0.0.0-20250219111533-438f80b9113e h1:upmLVX6I3rYRJZXwVJ0ZDv0O0zcSpVLUKeCucbuHjyg=
github.com/hectorgimenez/d2go v0.0.0-20250219111533-438f80b9113e/go.mod h1:EOVayMaK8D13wsZiZ6n8AK3+Qflm1wHZsCqnzlVIci0=
github.com/hectorgimenez/d2go v0.0.0-20250221161127-5455fd977276 h1:A4LnLo5dsLmUzoDtndegivn5hx2TfiXL/18bepMxW70=
github.com/hectorgimenez/d2go v0.0.0-20250221161127-5455fd977276/go.mod h1:EOVayMaK8D13wsZiZ6n8AK3+Qflm1wHZsCqnzlVIci0=
github.com/inkeliz/gowebview v1.0.1 h1:4gpLE2qt4kV3DB+xHkHKUeLLiGPN5Xw3or9A3hVqYyA=
github.com/inkeliz/gowebview v1.0.1/go.mod h1:4SNjXp/fogE11MwvJD67kMBmSObY2BBqinEgH8+8eM8=
github.com/inkeliz/w32 v1.0.2 h1:Es8Bmw9ApOY0PVRpGs7wsqIKdK5C3xBkP5TOATfVmtU=
Expand Down
99 changes: 63 additions & 36 deletions internal/action/repair.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,40 +82,67 @@ func Repair() error {
}

func RepairRequired() bool {
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
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
}

func IsEquipmentBroken() bool {
ctx := context.Get()
ctx.SetLastAction("EquipmentBroken")

for _, i := range ctx.Data.Inventory.ByLocation(item.LocationEquipped) {

// Check if the item is ethereal
if i.Ethereal {
continue
}

// Check if the item is indestructible
_, indestructible := i.FindStat(stat.Indestructible, 0)
if indestructible {
continue
}

// Check if the item is broken
if i.IsBroken {
ctx.Logger.Debug("Equipment is broken, returning to town", "item", i.Name)
return true
}
}

return false
}
2 changes: 1 addition & 1 deletion internal/bot/bot.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ func (b *Bot) Run(ctx context.Context, firstRun bool, runs []run.Run) error {

// Check if we need to go back to town (no pots or merc died)
if (b.ctx.CharacterCfg.BackToTown.NoHpPotions && !healingPotsFound ||
b.ctx.CharacterCfg.BackToTown.EquipmentBroken && action.RepairRequired() ||
b.ctx.CharacterCfg.BackToTown.EquipmentBroken && action.IsEquipmentBroken() ||
b.ctx.CharacterCfg.BackToTown.NoMpPotions && !manaPotsFound ||
b.ctx.CharacterCfg.BackToTown.MercDied && b.ctx.Data.MercHPPercent() <= 0 && b.ctx.CharacterCfg.Character.UseMerc) &&
!b.ctx.Data.PlayerUnit.Area.IsTown() {
Expand Down
5 changes: 4 additions & 1 deletion internal/run/terror_zone.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,13 @@ func (tz TerrorZone) Name() string {
}

func (tz TerrorZone) Run() error {

availableTzs := tz.AvailableTZs()
if len(availableTzs) == 0 {
return nil
}

switch tz.ctx.Data.TerrorZones[0] {
switch availableTzs[0] {
case area.PitLevel1:
return NewPit().Run()
case area.Tristram:
Expand Down Expand Up @@ -102,6 +103,7 @@ func (tz TerrorZone) Run() error {
}

func (tz TerrorZone) AvailableTZs() []area.ID {
tz.ctx.RefreshGameData()
var availableTZs []area.ID
for _, tzone := range tz.ctx.Data.TerrorZones {
for _, tzArea := range tz.ctx.CharacterCfg.Game.TerrorZone.Areas {
Expand Down Expand Up @@ -177,6 +179,7 @@ func (tz TerrorZone) tzAreaGroups(firstTZ area.ID) [][]area.ID {
}

func (tz TerrorZone) customTZEnemyFilter() data.MonsterFilter {

return func(m data.Monsters) []data.Monster {
var filteredMonsters []data.Monster
monsterFilter := data.MonsterAnyFilter()
Expand Down
2 changes: 2 additions & 0 deletions internal/server/http_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,8 @@ func qualityClass(quality string) string {
return "rare-quality"
case "Unique":
return "unique-quality"
case "Crafted":
return "crafted-quality"
default:
return "unknown-quality"
}
Expand Down
60 changes: 35 additions & 25 deletions internal/server/templates/drops.gohtml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
.set-quality { color: #10B981; }
.rare-quality { color: #FBBF24; }
.unique-quality { color: #bfa969; }
.crafted-quality { color: #FFA500; }
.unknown-quality { color: #000000; }

/* Drop location style */
Expand Down Expand Up @@ -258,7 +259,11 @@
<div class="d2-tooltip foldable">
<div class="item-header">
<div class="item-name {{ .Item.Quality.ToString | qualityClass }}">
{{ .Item.Name }}
{{ if .Item.IdentifiedName }}
{{ .Item.IdentifiedName }}
{{ else }}
{{ .Item.Name }}
{{ end }}
</div>
<div class="fold-indicator">▶</div>
</div>
Expand All @@ -268,38 +273,43 @@
<div class="italic">Unidentified</div>
</div>
{{ else }}
<!-- Defense -->
{{ range .Item.Stats }}
{{ if eq .ID 31 }}
<div class="item-stats text-gray-300">
Defense: {{ .Value }}
</div>
<!-- Defense and Durability -->
<div class="item-stats text-gray-300">
{{ range .Item.Stats }}
{{ if eq .ID 31 }}
<div>Defense: {{ .Value }}</div>
{{ end }}
{{ end }}
{{ end }}

<!-- Durability -->
{{ $currentDur := 0 }}
{{ $maxDur := 0 }}
{{ range .Item.Stats }}
{{ if eq .ID 72 }}
{{ $currentDur = .Value }}

{{ $currentDur := 0 }}
{{ $maxDur := 0 }}
{{ range .Item.Stats }}
{{ if eq .ID 72 }}
{{ $currentDur = .Value }}
{{ end }}
{{ if eq .ID 73 }}
{{ $maxDur = .Value }}
{{ end }}
{{ end }}
{{ if eq .ID 73 }}
{{ $maxDur = .Value }}
{{ if and (ne $currentDur 0) (ne $maxDur 0) }}
<div>Durability: {{ $currentDur }} of {{ $maxDur }}</div>
{{ end }}
{{ end }}
{{ if and (ne $currentDur 0) (ne $maxDur 0) }}
<div class="item-stats text-gray-300">
Durability: {{ $currentDur }} of {{ $maxDur }}
</div>
{{ end }}
</div>

<!-- Stats -->
<div class="item-stats text-gray-300">

<!-- First show stat ID 92 if it's not 0 -->
{{ range .Item.Stats }}
{{ if eq .ID 92 }}
{{ if ne .Value 0 }}
<div>{{ .String }}</div>
{{ end }}
{{ end }}
{{ end }}

<!-- Ignore stats that have been handled (defense, durability, level requirement) -->
{{ range .Item.Stats }}
{{ if and (ne .ID 31) (ne .ID 72) (ne .ID 73)}}
{{ if and (ne .ID 31) (ne .ID 72) (ne .ID 73) (ne .ID 21) (ne .ID 22) (ne .ID 23) (ne .ID 24) (ne .ID 68) (ne .ID 92) }}
<div>{{ .String }}</div>
{{ end }}
{{ end }}
Expand Down

0 comments on commit 523a6a0

Please sign in to comment.