Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bowazon support (arrows only) #624

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
118 changes: 118 additions & 0 deletions internal/action/restock_arrows_or_bolts.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
package action

import (
"github.com/hectorgimenez/d2go/pkg/data"
"github.com/hectorgimenez/d2go/pkg/data/item"
"github.com/hectorgimenez/d2go/pkg/data/npc"
"github.com/hectorgimenez/d2go/pkg/data/stat"
"github.com/hectorgimenez/koolo/internal/action/step"
"github.com/hectorgimenez/koolo/internal/context"
"github.com/hectorgimenez/koolo/internal/game"
"github.com/hectorgimenez/koolo/internal/town"
"github.com/hectorgimenez/koolo/internal/ui"
"github.com/hectorgimenez/koolo/internal/utils"
"github.com/lxn/win"
)

func RestockArrowsOrBolts() error {
ctx := context.Get()
ctx.SetLastAction("RestockArrowsOrBolts")

if !RestockArrowsOrBoltsRequired() {
return nil
}

ctx.Logger.Info("Attempting to move to repair NPC to buy arrows")

// Get the repair NPC for the town
repairNPC := town.GetTownByArea(ctx.Data.PlayerUnit.Area).RepairNPC()

if repairNPC == npc.Hratli { // Act 3
MoveToCoords(data.Position{X: 5224, Y: 5045})
} else if repairNPC == npc.Larzuk { // Act 5
// TODO: Is this necessary?
MoveToCoords(data.Position{X: 5143, Y: 5041})
}

ctx.Logger.Info("Interacting with repair NPC to buy arrows")

err := InteractNPC(repairNPC)
if err != nil {
return err
}

if repairNPC != npc.Halbu {
ctx.HID.KeySequence(win.VK_HOME, win.VK_DOWN, win.VK_RETURN)
} else {
ctx.HID.KeySequence(win.VK_HOME, win.VK_RETURN)
}

utils.Sleep(100)

if repairNPC == npc.Larzuk || repairNPC == npc.Charsi {
utils.Sleep(2000)
// Switch to Misc tab
ctx.HID.Click(game.LeftButton, ui.VendorTab4X, ui.VendorTab4Y)
utils.Sleep(500)
}

town.BuyArrows()

return step.CloseAllMenus()
}

func RestockArrowsOrBoltsRequired() bool {
ctx := context.Get()

bowFound := false

// Are they using a bow?
for _, i := range ctx.Data.Inventory.ByLocation(item.LocationEquipped) {
if i.Type().IsType(item.TypeBow) || i.Type().IsType(item.TypeAmazonBow) {
bowFound = true
break
}
}

if !bowFound {
return false
}

arrowsEquipped, arrowsEquippedFound := ctx.Data.Inventory.Find("Arrows", item.LocationEquipped)

// We have arrows equipped, do we have enough?
if arrowsEquippedFound {
qtyEquipped, found := arrowsEquipped.FindStat(stat.Quantity, 0)

// We have no arrows equipped, let's buy some
if !found {
return true
}

if qtyEquipped.Value < 20 {
arrowsInventory, arrowsInventoryFound := ctx.Data.Inventory.Find("Arrows", item.LocationInventory)

// We have less than 20 equipped and none in inventory, go buy more!
if !arrowsInventoryFound {
ctx.Logger.Info("No arrows in inventory, buying more...")

return true
}

qtyInventory, _ := arrowsInventory.FindStat(stat.Quantity, 0)

// We have less than 20 arrows in inventory, let's buy more
if qtyInventory.Value < 20 {
ctx.Logger.Info("Less than 20 arrows in inventory, buying more...")

return true
}
}

return false
} else {
ctx.Logger.Info("No arrows equipped, buying some...")

return true
}
}
1 change: 1 addition & 0 deletions internal/action/town.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ func InRunReturnTownRoutine() error {
ReviveMerc()
HireMerc()
Repair()
RestockArrowsOrBolts()

return UsePortalInTown()
}
5 changes: 4 additions & 1 deletion internal/bot/bot.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,10 @@ func (b *Bot) Run(ctx context.Context, firstRun bool, runs []run.Run) error {

_, healingPotsFound := b.ctx.Data.Inventory.Belt.GetFirstPotion(data.HealingPotion)
_, manaPotsFound := b.ctx.Data.Inventory.Belt.GetFirstPotion(data.ManaPotion)
shouldBuyArrowsOrBolts := action.RestockArrowsOrBoltsRequired()

// Check if we need to go back to town (no pots or merc died)
if (b.ctx.CharacterCfg.BackToTown.NoHpPotions && !healingPotsFound ||
if (shouldBuyArrowsOrBolts || b.ctx.CharacterCfg.BackToTown.NoHpPotions && !healingPotsFound ||
b.ctx.CharacterCfg.BackToTown.EquipmentBroken && action.RepairRequired() ||
b.ctx.CharacterCfg.BackToTown.NoMpPotions && !manaPotsFound ||
b.ctx.CharacterCfg.BackToTown.MercDied && b.ctx.Data.MercHPPercent() <= 0 && b.ctx.CharacterCfg.Character.UseMerc) &&
Expand All @@ -158,6 +159,8 @@ func (b *Bot) Run(ctx context.Context, firstRun bool, runs []run.Run) error {
reason = "No mana potions found"
} else if b.ctx.CharacterCfg.BackToTown.MercDied && b.ctx.Data.MercHPPercent() <= 0 && b.ctx.CharacterCfg.Character.UseMerc {
reason = "Mercenary is dead"
} else if shouldBuyArrowsOrBolts {
reason = "Need to restock arrows or bolts"
}

b.ctx.Logger.Info("Going back to town", "reason", reason)
Expand Down
Loading