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

move MultipleRefreshNoRemove stacks to a separate package #2266

Merged
merged 2 commits into from
Nov 22, 2024
Merged
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
5 changes: 3 additions & 2 deletions internal/characters/clorinde/asc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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")
Expand Down Expand Up @@ -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)
}

Expand Down
5 changes: 3 additions & 2 deletions internal/characters/clorinde/clorinde.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -30,7 +31,7 @@ func init() {
type Weapon struct {
Index int
char *character.CharWrapper
stackTracker *stackTracker
stackTracker *stacks.MultipleRefreshNoRemove
buffStack float64
mBuff []float64
}
Expand All @@ -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),
}
Expand Down
53 changes: 0 additions & 53 deletions internal/weapons/claymore/fangofthemountainking/stacks.go

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package clorinde
package stacks

import "testing"

Expand All @@ -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
Expand Down Expand Up @@ -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]
}
Loading