Skip to content

Commit f2a58ea

Browse files
authored
CanUse for ultimates (#329)
* Function signature * Function signature * Implementation * mock regen * Added proper check for ult usability * regen mocks
1 parent 5fbf30a commit f2a58ea

File tree

6 files changed

+169
-57
lines changed

6 files changed

+169
-57
lines changed

pkg/engine/engine.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,9 @@ type Info interface {
211211
// Check if the character can use the skill (enough Skill Points and not blocked by Skill.CanUse,
212212
// see implementation of each character)
213213
CanUseSkill(target key.TargetID) (bool, error)
214+
215+
// Check if the character can use the Ult (Energy is equal to max energy of char OR fulfills Ult.canUse)
216+
CanUseUlt(target key.TargetID) (bool, error)
214217
}
215218

216219
type Target interface {

pkg/engine/target/character/config.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ type SkillInfo struct {
5050
}
5151

5252
type SkillValidateFunc func(engine engine.Engine, char info.CharInstance) bool
53+
type UltValidateFunc func(engine engine.Engine, char info.CharInstance) bool
5354

5455
type Attack struct {
5556
SPAdd int
@@ -64,6 +65,7 @@ type Skill struct {
6465

6566
type Ult struct {
6667
TargetType model.TargetType
68+
CanUse UltValidateFunc `exhaustruct:"optional"`
6769
}
6870

6971
type Technique struct {

pkg/mock/mock_engine.go

Lines changed: 127 additions & 56 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/simulation/action.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,11 @@ func (sim *Simulation) ultCheck() error {
6565
return err
6666
}
6767
for _, act := range ults {
68-
if sim.Attr.FullEnergy(act.Target) {
68+
canuse, err := sim.CanUseUlt(act.Target)
69+
if err != nil {
70+
return err
71+
}
72+
if canuse {
6973
sim.InsertUlt(act)
7074
sim.Attr.SetEnergy(info.ModifyAttribute{
7175
Key: "ult",

pkg/simulation/info.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,20 @@ func (sim *Simulation) CanUseSkill(id key.TargetID) (bool, error) {
3030
check := skillInfo.Skill.CanUse
3131
return sim.SP() >= skillInfo.Skill.SPNeed && (check == nil || check(sim, char)), nil
3232
}
33+
34+
func (sim *Simulation) CanUseUlt(id key.TargetID) (bool, error) {
35+
skillInfo, err := sim.Char.SkillInfo(id)
36+
if err != nil {
37+
return false, err
38+
}
39+
char, err := sim.Char.Get(id)
40+
if err != nil {
41+
return false, err
42+
}
43+
44+
check := skillInfo.Ult.CanUse
45+
if check == nil {
46+
return sim.EnergyRatio(id) == 1, nil
47+
}
48+
return check(sim, char), nil
49+
}

0 commit comments

Comments
 (0)