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

Skip immunes as global setting #576

Closed
Closed
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
15 changes: 14 additions & 1 deletion internal/action/clear_area.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,27 @@ func ClearAreaAroundPosition(pos data.Position, radius int, filter data.MonsterF

return ctx.Char.KillMonsterSequence(func(d game.Data) (data.UnitID, bool) {
for _, m := range d.Monsters.Enemies(filter) {

monsterIsImmune := false
for _, resist := range ctx.Data.CharacterCfg.Runtime.ImmunityFilter {
if m.IsImmune(resist) {
monsterIsImmune = true
break
}
}

if monsterIsImmune {
continue
}

distanceToTarget := pather.DistanceFromPoint(pos, m.Position)
if ctx.Data.AreaData.IsWalkable(m.Position) && distanceToTarget <= radius {
return m.UnitID, true
}
}

return 0, false
}, nil)
})
}

func ClearThroughPath(pos data.Position, radius int, filter data.MonsterFilter) error {
Expand Down
15 changes: 14 additions & 1 deletion internal/action/clear_level.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,24 @@ func clearRoom(room data.Room, filter data.MonsterFilter) error {

ctx.Char.KillMonsterSequence(func(d game.Data) (data.UnitID, bool) {
m, found := d.Monsters.FindByID(targetMonster.UnitID)

monsterIsImmune := false
for _, resist := range ctx.Data.CharacterCfg.Runtime.ImmunityFilter {
if m.IsImmune(resist) {
monsterIsImmune = true
break
}
}

if monsterIsImmune {
return 0, false
}

if found && m.Stats[stat.Life] > 0 {
return targetMonster.UnitID, true
}
return 0, false
}, nil)
})
}
}
}
Expand Down
14 changes: 13 additions & 1 deletion internal/action/move.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,18 @@ func MoveTo(toFunc func() (data.Position, bool)) error {
continue
}

monsterIsImmune := false
for _, resist := range ctx.Data.CharacterCfg.Runtime.ImmunityFilter {
if m.IsImmune(resist) {
monsterIsImmune = true
break
}
}

if monsterIsImmune {
continue
}

dist := ctx.PathFinder.DistanceFromMe(m.Position)
appended := false
if m.IsElite() && dist <= minDistanceForElites {
Expand Down Expand Up @@ -336,7 +348,7 @@ func MoveTo(toFunc func() (data.Position, bool)) error {
if !doorIsBlocking {
ctx.Char.KillMonsterSequence(func(d game.Data) (data.UnitID, bool) {
return closestMonster.UnitID, true
}, nil)
})
}
}
}
Expand Down
25 changes: 20 additions & 5 deletions internal/character/berserk_barb.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ func (s *Berserker) IsKillingCouncil() bool {

func (s *Berserker) KillMonsterSequence(
monsterSelector func(d game.Data) (data.UnitID, bool),
skipOnImmunities []stat.Resist,
) error {

for attackAttempts := 0; attackAttempts < maxAttackAttempts; attackAttempts++ {
Expand All @@ -64,7 +63,7 @@ func (s *Berserker) KillMonsterSequence(
return nil
}

if !s.preBattleChecks(id, skipOnImmunities) {
if !s.preBattleChecks(id) {
return nil
}

Expand Down Expand Up @@ -229,13 +228,27 @@ func (s *Berserker) PreCTABuffSkills() []skill.ID {
}

func (s *Berserker) killMonster(npc npc.ID, t data.MonsterType) error {
ctx := context.Get()
return s.KillMonsterSequence(func(d game.Data) (data.UnitID, bool) {
m, found := d.Monsters.FindOne(npc, t)
if !found {
return 0, false
}

monsterIsImmune := false
for _, resist := range ctx.Data.CharacterCfg.Runtime.ImmunityFilter {
if m.IsImmune(resist) {
monsterIsImmune = true
break
}
}

if monsterIsImmune {
return 0, false
}

return m.UnitID, true
}, nil)
})
}

func (s *Berserker) KillCountess() error {
Expand Down Expand Up @@ -326,7 +339,9 @@ func (s *Berserker) KillCouncil() error {
}

func (s *Berserker) killAllCouncilMembers() error {
context.Get().DisableItemPickup()
ctx := context.Get()
ctx.DisableItemPickup()

for {
if !s.anyCouncilMemberAlive() {
return nil
Expand All @@ -339,7 +354,7 @@ func (s *Berserker) killAllCouncilMembers() error {
}
}
return 0, false
}, nil)
})

if err != nil {
return err
Expand Down
52 changes: 39 additions & 13 deletions internal/character/blizzard_sorceress.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/hectorgimenez/d2go/pkg/data/stat"
"github.com/hectorgimenez/d2go/pkg/data/state"
"github.com/hectorgimenez/koolo/internal/action/step"
"github.com/hectorgimenez/koolo/internal/context"
"github.com/hectorgimenez/koolo/internal/game"
)

Expand Down Expand Up @@ -55,7 +56,6 @@ func (s BlizzardSorceress) CheckKeyBindings() []skill.ID {

func (s BlizzardSorceress) KillMonsterSequence(
monsterSelector func(d game.Data) (data.UnitID, bool),
skipOnImmunities []stat.Resist,
) error {
completedAttackLoops := 0
previousUnitID := 0
Expand All @@ -73,7 +73,7 @@ func (s BlizzardSorceress) KillMonsterSequence(
completedAttackLoops = 0
}

if !s.preBattleChecks(id, skipOnImmunities) {
if !s.preBattleChecks(id) {
return nil
}

Expand Down Expand Up @@ -109,24 +109,50 @@ func (s BlizzardSorceress) KillMonsterSequence(
}

func (s BlizzardSorceress) killMonster(npc npc.ID, t data.MonsterType) error {
ctx := context.Get()
return s.KillMonsterSequence(func(d game.Data) (data.UnitID, bool) {
m, found := d.Monsters.FindOne(npc, t)
if !found {
return 0, false
}

monsterIsImmune := false
for _, resist := range ctx.Data.CharacterCfg.Runtime.ImmunityFilter {
if m.IsImmune(resist) {
monsterIsImmune = true
break
}
}

if monsterIsImmune {
return 0, false
}

return m.UnitID, true
}, nil)
})
}

func (s BlizzardSorceress) killMonsterByName(id npc.ID, monsterType data.MonsterType, skipOnImmunities []stat.Resist) error {
func (s BlizzardSorceress) killMonsterByName(id npc.ID, monsterType data.MonsterType) error {
ctx := context.Get()
return s.KillMonsterSequence(func(d game.Data) (data.UnitID, bool) {
if m, found := d.Monsters.FindOne(id, monsterType); found {
monsterIsImmune := false
for _, resist := range ctx.Data.CharacterCfg.Runtime.ImmunityFilter {
if m.IsImmune(resist) {
monsterIsImmune = true
break
}
}

if monsterIsImmune {
return 0, false
}

return m.UnitID, true
}

return 0, false
}, skipOnImmunities)
})
}

func (s BlizzardSorceress) BuffSkills() []skill.ID {
Expand All @@ -151,19 +177,19 @@ func (s BlizzardSorceress) PreCTABuffSkills() []skill.ID {
}

func (s BlizzardSorceress) KillCountess() error {
return s.killMonsterByName(npc.DarkStalker, data.MonsterTypeSuperUnique, nil)
return s.killMonsterByName(npc.DarkStalker, data.MonsterTypeSuperUnique)
}

func (s BlizzardSorceress) KillAndariel() error {
return s.killMonsterByName(npc.Andariel, data.MonsterTypeUnique, nil)
return s.killMonsterByName(npc.Andariel, data.MonsterTypeUnique)
}

func (s BlizzardSorceress) KillSummoner() error {
return s.killMonsterByName(npc.Summoner, data.MonsterTypeUnique, nil)
return s.killMonsterByName(npc.Summoner, data.MonsterTypeUnique)
}

func (s BlizzardSorceress) KillDuriel() error {
return s.killMonsterByName(npc.Duriel, data.MonsterTypeUnique, nil)
return s.killMonsterByName(npc.Duriel, data.MonsterTypeUnique)
}

func (s BlizzardSorceress) KillCouncil() error {
Expand All @@ -188,11 +214,11 @@ func (s BlizzardSorceress) KillCouncil() error {
}

return 0, false
}, nil)
})
}

func (s BlizzardSorceress) KillMephisto() error {
return s.killMonsterByName(npc.Mephisto, data.MonsterTypeUnique, nil)
return s.killMonsterByName(npc.Mephisto, data.MonsterTypeUnique)
}

func (s BlizzardSorceress) KillIzual() error {
Expand Down Expand Up @@ -235,11 +261,11 @@ func (s BlizzardSorceress) KillDiablo() error {
}

func (s BlizzardSorceress) KillPindle() error {
return s.killMonsterByName(npc.DefiledWarrior, data.MonsterTypeSuperUnique, s.CharacterCfg.Game.Pindleskin.SkipOnImmunities)
return s.killMonsterByName(npc.DefiledWarrior, data.MonsterTypeSuperUnique)
}

func (s BlizzardSorceress) KillNihlathak() error {
return s.killMonsterByName(npc.Nihlathak, data.MonsterTypeSuperUnique, nil)
return s.killMonsterByName(npc.Nihlathak, data.MonsterTypeSuperUnique)
}

func (s BlizzardSorceress) KillBaal() error {
Expand Down
5 changes: 2 additions & 3 deletions internal/character/character.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"strings"

"github.com/hectorgimenez/d2go/pkg/data"
"github.com/hectorgimenez/d2go/pkg/data/stat"
"github.com/hectorgimenez/koolo/internal/context"
)

Expand Down Expand Up @@ -58,12 +57,12 @@ type BaseCharacter struct {
*context.Context
}

func (bc BaseCharacter) preBattleChecks(id data.UnitID, skipOnImmunities []stat.Resist) bool {
func (bc BaseCharacter) preBattleChecks(id data.UnitID) bool {
monster, found := bc.Data.Monsters.FindByID(id)
if !found {
return false
}
for _, i := range skipOnImmunities {
for _, i := range bc.CharacterCfg.Runtime.ImmunityFilter {
if monster.IsImmune(i) {
bc.Logger.Info("Monster is immune! skipping", slog.String("immuneTo", string(i)))
return false
Expand Down
25 changes: 20 additions & 5 deletions internal/character/foh.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func (f Foh) waitForCastComplete() bool {

return false
}
func (f Foh) KillMonsterSequence(monsterSelector func(d game.Data) (data.UnitID, bool), skipOnImmunities []stat.Resist) error {
func (f Foh) KillMonsterSequence(monsterSelector func(d game.Data) (data.UnitID, bool)) error {
ctx := context.Get()
lastRefresh := time.Now()
completedAttackLoops := 0
Expand Down Expand Up @@ -107,6 +107,7 @@ func (f Foh) KillMonsterSequence(monsterSelector func(d game.Data) (data.UnitID,
}

for _, m := range ctx.Data.Monsters.Enemies() {

if ctx.Data.AreaData.IsInside(m.Position) {
dist := ctx.PathFinder.DistanceFromMe(m.Position)
if dist <= fohMaxDistance && dist >= fohMinDistance && m.Stats[stat.Life] > 0 {
Expand Down Expand Up @@ -152,7 +153,7 @@ func (f Foh) KillMonsterSequence(monsterSelector func(d game.Data) (data.UnitID,
continue
}

if !f.preBattleChecks(currentTargetID, skipOnImmunities) {
if !f.preBattleChecks(currentTargetID) {
return nil
}

Expand Down Expand Up @@ -257,7 +258,7 @@ func (f Foh) KillBossSequence(monsterSelector func(d game.Data) (data.UnitID, bo
if !found {
return nil
}
if !f.preBattleChecks(id, skipOnImmunities) {
if !f.preBattleChecks(id) {
return nil
}
monster, found := f.Data.Monsters.FindByID(id)
Expand Down Expand Up @@ -288,13 +289,27 @@ func (f Foh) PreCTABuffSkills() []skill.ID {
}

func (f Foh) killBoss(npc npc.ID, t data.MonsterType) error {
ctx := context.Get()
return f.KillBossSequence(func(d game.Data) (data.UnitID, bool) {
m, found := d.Monsters.FindOne(npc, t)
if !found || m.Stats[stat.Life] <= 0 {
return 0, false
}

monsterIsImmune := false
for _, resist := range ctx.Data.CharacterCfg.Runtime.ImmunityFilter {
if m.IsImmune(resist) {
monsterIsImmune = true
break
}
}

if monsterIsImmune {
return 0, false
}

return m.UnitID, true
}, nil)
}, ctx.CharacterCfg.Runtime.ImmunityFilter)
}

func (f Foh) KillCountess() error {
Expand Down Expand Up @@ -347,7 +362,7 @@ func (f Foh) killAllCouncilMembers() error {
}
}
return 0, false
}, nil)
})

if err != nil {
return err
Expand Down
Loading