Skip to content

Commit

Permalink
Merge remote-tracking branch 'davidfvsilva/main' into feature/followe…
Browse files Browse the repository at this point in the history
…r-run
  • Loading branch information
davidfvsilva committed Feb 20, 2025
2 parents b50b7a7 + 015e607 commit 0f8ade5
Show file tree
Hide file tree
Showing 8 changed files with 353 additions and 134 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

---

Koolo is a small bot for Diablo II: Resurrected (Expension). Koolo project was built for informational and educational purposes
Koolo is a small bot for Diablo II: Resurrected (Expansion). Koolo project was built for informational and educational purposes
only, it's not intended for online usage. Feel free to contribute opening pull requests with new features or bugfixes.
Koolo reads game memory and interacts with the game injecting clicks/keystrokes to the game window. As good as it can.

Expand Down
16 changes: 15 additions & 1 deletion internal/action/stash.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,9 +290,23 @@ func stashItemAction(i data.Item, rule string, ruleFile string, skipLogging bool
}
}

dropLocation := "unknown"

// log the contents of picked up items
ctx.Logger.Info(fmt.Sprintf("Picked up items: %v", ctx.CurrentGame.PickedUpItems))

if _, found := ctx.CurrentGame.PickedUpItems[int(i.UnitID)]; found {
areaId := ctx.CurrentGame.PickedUpItems[int(i.UnitID)]
dropLocation = area.ID(ctx.CurrentGame.PickedUpItems[int(i.UnitID)]).Area().Name

if slices.Contains(ctx.Data.TerrorZones, area.ID(areaId)) {
dropLocation += " (terrorized)"
}
}

// Don't log items that we already have in inventory during first run or that we don't want to notify about (gems, low runes .. etc)
if !skipLogging && shouldNotifyAboutStashing(i) && ruleFile != "" {
event.Send(event.ItemStashed(event.WithScreenshot(ctx.Name, fmt.Sprintf("Item %s [%d] stashed", i.Name, i.Quality), screenshot), data.Drop{Item: i, Rule: rule, RuleFile: ruleFile}))
event.Send(event.ItemStashed(event.WithScreenshot(ctx.Name, fmt.Sprintf("Item %s [%d] stashed", i.Name, i.Quality), screenshot), data.Drop{Item: i, Rule: rule, RuleFile: ruleFile, DropLocation: dropLocation}))
}

return true
Expand Down
1 change: 1 addition & 0 deletions internal/action/step/pickup_item.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ func PickupItem(it data.Item) error {
currentItem, exists := findItemOnGround(targetItem.UnitID)
if !exists {
ctx.Logger.Info(fmt.Sprintf("Picked up: %s [%s]", targetItem.Desc().Name, targetItem.Quality.ToString()))
ctx.CurrentGame.PickedUpItems[int(targetItem.UnitID)] = int(ctx.Data.PlayerUnit.Area.Area().ID)
return nil // Success!
}

Expand Down
4 changes: 4 additions & 0 deletions internal/bot/bot.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ func (b *Bot) Run(ctx context.Context, firstRun bool, runs []run.Run) error {

// Let's make sure we have updated game data also fully loaded before performing anything
b.ctx.WaitForGameToLoad()

// Cleanup the current game helper structure
b.ctx.Cleanup()

// Switch to legacy mode if configured
action.SwitchToLegacyMode()
b.ctx.RefreshGameData()
Expand Down
20 changes: 18 additions & 2 deletions internal/context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ type Debug struct {

type CurrentGameHelper struct {
BlacklistedItems []data.Item
PickedUpItems map[int]int
AreaCorrection struct {
Enabled bool
ExpectedArea area.ID
Expand All @@ -81,7 +82,7 @@ func NewContext(name string) *Status {
PriorityPause: {},
PriorityStop: {},
},
CurrentGame: &CurrentGameHelper{},
CurrentGame: NewGameHelper(),
}
botContexts[getGoroutineID()] = &Status{Priority: PriorityNormal, Context: ctx}

Expand All @@ -90,7 +91,9 @@ func NewContext(name string) *Status {

func NewGameHelper() *CurrentGameHelper {
return &CurrentGameHelper{
PickupItems: true,
PickupItems: true,
PickedUpItems: make(map[int]int),
BlacklistedItems: []data.Item{},
}
}

Expand Down Expand Up @@ -168,3 +171,16 @@ func (ctx *Context) WaitForGameToLoad() {
// Add a small buffer to ensure everything is fully loaded
time.Sleep(300 * time.Millisecond)
}

func (ctx *Context) Cleanup() {
ctx.Logger.Debug("Resetting blacklisted items")

// Remove all items from the blacklisted items list
ctx.CurrentGame.BlacklistedItems = []data.Item{}

// Remove all items from the picked up items map if it exceeds 200 items
if len(ctx.CurrentGame.PickedUpItems) > 200 {
ctx.Logger.Debug("Resetting picked up items map due to exceeding 200 items")
ctx.CurrentGame.PickedUpItems = make(map[int]int)
}
}
40 changes: 40 additions & 0 deletions internal/game/area.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package game

import (
"slices"

"github.com/hectorgimenez/d2go/pkg/data"
"github.com/hectorgimenez/d2go/pkg/data/area"
)
Expand All @@ -18,3 +20,41 @@ type AreaData struct {
func (ad AreaData) IsInside(pos data.Position) bool {
return pos.X > ad.OffsetX && pos.Y > ad.OffsetY && pos.X < ad.OffsetX+ad.Width && pos.Y < ad.OffsetY+ad.Height
}

var _85Zones = []area.ID{
area.Mausoleum,
area.UndergroundPassageLevel2,
area.PitLevel1,
area.PitLevel2,
area.StonyTombLevel1,
area.StonyTombLevel2,
area.MaggotLairLevel3,
area.AncientTunnels,
area.SwampyPitLevel1,
area.SwampyPitLevel2,
area.SwampyPitLevel3,
area.SpiderCave,
area.SewersLevel1Act3,
area.SewersLevel2Act3,
area.DisusedFane,
area.RuinedTemple,
area.ForgottenReliquary,
area.ForgottenTemple,
area.RuinedFane,
area.DisusedReliquary,
area.RiverOfFlame,
area.ChaosSanctuary,
area.Abaddon,
area.PitOfAcheron,
area.InfernalPit,
area.DrifterCavern,
area.IcyCellar,
area.TheWorldStoneKeepLevel1,
area.TheWorldStoneKeepLevel2,
area.TheWorldStoneKeepLevel3,
area.ThroneOfDestruction,
}

func (ad AreaData) Is85Zone() bool {
return slices.Contains(_85Zones, ad.Area.Area().ID)
}
2 changes: 1 addition & 1 deletion internal/run/spider_cavern.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func (run SpiderCavern) Run() error {
monsterFilter := data.MonsterAnyFilter()

// Update filter if we selected to clear only elites
if run.ctx.CharacterCfg.Game.DrifterCavern.FocusOnElitePacks {
if run.ctx.CharacterCfg.Game.SpiderCavern.FocusOnElitePacks {
monsterFilter = data.MonsterEliteFilter()
}

Expand Down
Loading

0 comments on commit 0f8ade5

Please sign in to comment.