From 74f229a725a727f92ca8cc96ac8e143a5afc2a36 Mon Sep 17 00:00:00 2001 From: Hector Gimenez Date: Sun, 24 Mar 2024 21:52:25 +0900 Subject: [PATCH] fix buff timer --- internal/action/buff.go | 15 +++++++++++---- internal/container/container.go | 1 + internal/manager.go | 1 + 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/internal/action/buff.go b/internal/action/buff.go index ceb85804..04d14fa4 100644 --- a/internal/action/buff.go +++ b/internal/action/buff.go @@ -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) { @@ -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 } @@ -57,7 +64,7 @@ func (b *Builder) Buff() *StepChainAction { return nil }), ) - lastBuffedAt = time.Now() + lastBuffedAt[b.Supervisor] = time.Now() } return steps @@ -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 } diff --git a/internal/container/container.go b/internal/container/container.go index 52829f56..5a4a017a 100644 --- a/internal/container/container.go +++ b/internal/container/container.go @@ -9,6 +9,7 @@ import ( ) type Container struct { + Supervisor string Logger *slog.Logger Reader *game.MemoryReader HID *game.HID diff --git a/internal/manager.go b/internal/manager.go index b3fb85fb..215be001 100644 --- a/internal/manager.go +++ b/internal/manager.go @@ -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,