Skip to content

Commit

Permalink
Add counter (genshinsim#417)
Browse files Browse the repository at this point in the history
* add counter
* rename and fix checking normal counter
  • Loading branch information
t3201v authored Apr 12, 2022
1 parent 932ea0b commit 9e0599e
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 0 deletions.
4 changes: 4 additions & 0 deletions internal/tmpl/character/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@ func (c *Tmpl) AdvanceNormalIndex() {
c.NormalCounter = 0
}
}

func (c *Tmpl) NextNormalCounter() int {
return c.NormalCounter + 1
}
2 changes: 2 additions & 0 deletions internal/tmpl/queue/conditions.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ func (q *Queuer) evalCond(cond core.Condition) (bool, error) {
return q.evalInfusion(cond)
case ".construct":
return q.evalConstruct(cond)
case ".normal":
return q.evalNormal(cond)
}
return false, nil
}
Expand Down
23 changes: 23 additions & 0 deletions internal/tmpl/queue/counter.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package queue

import (
"errors"
"strings"

"github.com/genshinsim/gcsim/pkg/core"
)

func (q *Queuer) evalNormal(cond core.Condition) (bool, error) {
//.normal.X (X = character)
if len(cond.Fields) < 2 {
return false, errors.New("eval normal counter: unexpected short field, expected at least 2")
}
name := strings.TrimPrefix(cond.Fields[1], ".")
key := core.CharNameToKey[name]
char, ok := q.core.CharByName(key)
if !ok {
return false, errors.New("eval normal counter: invalid char in condition")
}
e := char.NextNormalCounter()
return compInt(cond.Op, e, cond.Value), nil
}
1 change: 1 addition & 0 deletions pkg/core/character.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ type Character interface {
Snapshot(a *AttackInfo) Snapshot
PreDamageSnapshotAdjust(*AttackEvent, Target) []interface{}
ResetNormalCounter()
NextNormalCounter() int
}

type ZoneType int
Expand Down

0 comments on commit 9e0599e

Please sign in to comment.