diff --git a/internal/characters/clorinde/asc.go b/internal/characters/clorinde/asc.go index 3346381713..a6dd096e4f 100644 --- a/internal/characters/clorinde/asc.go +++ b/internal/characters/clorinde/asc.go @@ -9,6 +9,7 @@ import ( "github.com/genshinsim/gcsim/pkg/core/event" "github.com/genshinsim/gcsim/pkg/core/glog" "github.com/genshinsim/gcsim/pkg/core/player/character" + "github.com/genshinsim/gcsim/pkg/core/stacks" "github.com/genshinsim/gcsim/pkg/enemy" "github.com/genshinsim/gcsim/pkg/modifier" ) @@ -30,7 +31,7 @@ func (c *char) a1() { c.a1BuffPercent = c2A1PercentBuff c.a1Cap = c2A1FlatDmg } - c.a1stacks = newStackTracker(3, c.QueueCharTask, &c.Core.F) + c.a1stacks = stacks.NewMultipleRefreshNoRemove(3, c.QueueCharTask, &c.Core.F) // on electro reaction, add buff; 3 stacks independent c.Core.Events.Subscribe(event.OnElectroCharged, c.a1CB, "clorinde-a1-ec") c.Core.Events.Subscribe(event.OnSuperconduct, c.a1CB, "clorinde-a1-superconduct") @@ -83,7 +84,7 @@ func (c *char) a4Init() { if c.Base.Ascension < 4 { return } - c.a4stacks = newStackTracker(2, c.QueueCharTask, &c.Core.F) + c.a4stacks = stacks.NewMultipleRefreshNoRemove(2, c.QueueCharTask, &c.Core.F) c.a4bonus = make([]float64, attributes.EndStatType) } diff --git a/internal/characters/clorinde/clorinde.go b/internal/characters/clorinde/clorinde.go index b9078461e5..11fe5db3f5 100644 --- a/internal/characters/clorinde/clorinde.go +++ b/internal/characters/clorinde/clorinde.go @@ -7,6 +7,7 @@ import ( "github.com/genshinsim/gcsim/pkg/core/info" "github.com/genshinsim/gcsim/pkg/core/keys" "github.com/genshinsim/gcsim/pkg/core/player/character" + "github.com/genshinsim/gcsim/pkg/core/stacks" "github.com/genshinsim/gcsim/pkg/model" ) @@ -18,10 +19,10 @@ type char struct { *tmpl.Character normalSCounter int - a1stacks *stackTracker + a1stacks *stacks.MultipleRefreshNoRemove a1BuffPercent float64 a1Cap float64 - a4stacks *stackTracker + a4stacks *stacks.MultipleRefreshNoRemove a4bonus []float64 c6Stacks int diff --git a/internal/weapons/claymore/fangofthemountainking/fangofthemountainking.go b/internal/weapons/claymore/fangofthemountainking/fangofthemountainking.go index 93597f7d5c..6cc3b3c1a7 100644 --- a/internal/weapons/claymore/fangofthemountainking/fangofthemountainking.go +++ b/internal/weapons/claymore/fangofthemountainking/fangofthemountainking.go @@ -11,6 +11,7 @@ import ( "github.com/genshinsim/gcsim/pkg/core/info" "github.com/genshinsim/gcsim/pkg/core/keys" "github.com/genshinsim/gcsim/pkg/core/player/character" + "github.com/genshinsim/gcsim/pkg/core/stacks" "github.com/genshinsim/gcsim/pkg/enemy" "github.com/genshinsim/gcsim/pkg/modifier" ) @@ -30,7 +31,7 @@ func init() { type Weapon struct { Index int char *character.CharWrapper - stackTracker *stackTracker + stackTracker *stacks.MultipleRefreshNoRemove buffStack float64 mBuff []float64 } @@ -45,7 +46,7 @@ func (w *Weapon) Init() error { return nil } func NewWeapon(c *core.Core, char *character.CharWrapper, p info.WeaponProfile) (info.Weapon, error) { w := &Weapon{ char: char, - stackTracker: newStackTracker(6, char.QueueCharTask, &c.F), + stackTracker: stacks.NewMultipleRefreshNoRemove(6, char.QueueCharTask, &c.F), buffStack: 0.10 + float64(p.Refine-1)*0.025, mBuff: make([]float64, attributes.EndStatType), } diff --git a/internal/weapons/claymore/fangofthemountainking/stacks.go b/internal/weapons/claymore/fangofthemountainking/stacks.go deleted file mode 100644 index 9ea762aa1f..0000000000 --- a/internal/weapons/claymore/fangofthemountainking/stacks.go +++ /dev/null @@ -1,53 +0,0 @@ -package fangofthemountainking - -type queuer func(cb func(), delay int) - -type stackTracker struct { - queuer - stacks []*int - max int - frame *int -} - -func newStackTracker(maxstacks int, queue queuer, frame *int) *stackTracker { - s := &stackTracker{ - queuer: queue, - stacks: make([]*int, maxstacks), - max: maxstacks, - frame: frame, - } - return s -} - -func (s *stackTracker) Count() int { - count := 0 - for _, v := range s.stacks { - if v != nil { - count++ - } - } - return count -} - -func (s *stackTracker) Add(duration int) { - idx := 0 - for i := 0; i < s.max; i++ { - if s.stacks[i] == nil { - idx = i - break - } - if *s.stacks[i] < *s.stacks[idx] { - idx = i - } - } - - src := *s.frame - s.stacks[idx] = &src - - s.queuer(func() { - if s.stacks[idx] != &src { - return - } - s.stacks[idx] = nil - }, duration) -} diff --git a/internal/characters/clorinde/stacks.go b/pkg/core/stacks/refresh.go similarity index 61% rename from internal/characters/clorinde/stacks.go rename to pkg/core/stacks/refresh.go index c79f261bda..161c74a93d 100644 --- a/internal/characters/clorinde/stacks.go +++ b/pkg/core/stacks/refresh.go @@ -1,25 +1,23 @@ -package clorinde +package stacks type queuer func(cb func(), delay int) -type stackTracker struct { +type MultipleRefreshNoRemove struct { queuer stacks []*int - max int frame *int } -func newStackTracker(maxstacks int, queue queuer, frame *int) *stackTracker { - s := &stackTracker{ +func NewMultipleRefreshNoRemove(maxstacks int, queue queuer, frame *int) *MultipleRefreshNoRemove { + s := &MultipleRefreshNoRemove{ queuer: queue, stacks: make([]*int, maxstacks), - max: maxstacks, frame: frame, } return s } -func (s *stackTracker) Count() int { +func (s *MultipleRefreshNoRemove) Count() int { count := 0 for _, v := range s.stacks { if v != nil { @@ -29,9 +27,9 @@ func (s *stackTracker) Count() int { return count } -func (s *stackTracker) Add(duration int) { +func (s *MultipleRefreshNoRemove) Add(duration int) { idx := 0 - for i := 0; i < s.max; i++ { + for i := 0; i < len(s.stacks); i++ { if s.stacks[i] == nil { idx = i break diff --git a/internal/characters/clorinde/stacks_test.go b/pkg/core/stacks/refresh_test.go similarity index 91% rename from internal/characters/clorinde/stacks_test.go rename to pkg/core/stacks/refresh_test.go index 01b2f92a84..653990522b 100644 --- a/internal/characters/clorinde/stacks_test.go +++ b/pkg/core/stacks/refresh_test.go @@ -1,4 +1,4 @@ -package clorinde +package stacks import "testing" @@ -8,7 +8,7 @@ func TestStackTracker(t *testing.T) { frame: &f, } - st := newStackTracker(3, tq.queue, &f) + st := NewMultipleRefreshNoRemove(3, tq.queue, &f) // add up to 3 st.Add(10) // expires at f = 10 @@ -66,5 +66,9 @@ func (t *testqueue) clear(f int) { } t.queued[n] = v t.delay[n] = t.delay[i] + n++ } + + t.queued = t.queued[:n] + t.delay = t.delay[:n] }