Skip to content

Commit

Permalink
fix buff timer
Browse files Browse the repository at this point in the history
  • Loading branch information
hectorgimenez committed Mar 24, 2024
1 parent df0ed98 commit 74f229a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
15 changes: 11 additions & 4 deletions internal/action/buff.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"github.com/hectorgimenez/koolo/internal/helper"
)

var lastBuffedAt = time.Time{}
var lastBuffedAt = map[string]time.Time{}

func (b *Builder) BuffIfRequired(d data.Data) *StepChainAction {
if !b.IsRebuffRequired(d) {
Expand All @@ -23,9 +23,16 @@ func (b *Builder) BuffIfRequired(d data.Data) *StepChainAction {
return b.Buff()
}

func getLastBuffedAt(supervisor string) time.Time {
if t, found := lastBuffedAt[supervisor]; found {
return t
}
return time.Time{}
}

func (b *Builder) Buff() *StepChainAction {
return NewStepChain(func(d data.Data) (steps []step.Step) {
if d.PlayerUnit.Area.IsTown() || time.Since(lastBuffedAt) < time.Second*30 {
if d.PlayerUnit.Area.IsTown() || time.Since(getLastBuffedAt(b.Supervisor)) < time.Second*30 {
return nil
}

Expand Down Expand Up @@ -57,7 +64,7 @@ func (b *Builder) Buff() *StepChainAction {
return nil
}),
)
lastBuffedAt = time.Now()
lastBuffedAt[b.Supervisor] = time.Now()
}

return steps
Expand All @@ -66,7 +73,7 @@ func (b *Builder) Buff() *StepChainAction {

func (b *Builder) IsRebuffRequired(d data.Data) bool {
// Don't buff if we are in town, or we did it recently (it prevents double buffing because of network lag)
if d.PlayerUnit.Area.IsTown() || time.Since(lastBuffedAt) < time.Second*30 {
if d.PlayerUnit.Area.IsTown() || time.Since(getLastBuffedAt(b.Supervisor)) < time.Second*30 {
return false
}

Expand Down
1 change: 1 addition & 0 deletions internal/container/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
)

type Container struct {
Supervisor string
Logger *slog.Logger
Reader *game.MemoryReader
HID *game.HID
Expand Down
1 change: 1 addition & 0 deletions internal/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ func (mng *SupervisorManager) buildSupervisor(supervisorName string, logger *slo
hm := health.NewHealthManager(logger, bm, gm, cfg)
pf := pather.NewPathFinder(gr, hidM, cfg)
c := container.Container{
Supervisor: supervisorName,
Logger: logger,
Reader: gr,
HID: hidM,
Expand Down

0 comments on commit 74f229a

Please sign in to comment.