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

Canuse attack #343

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
3 changes: 3 additions & 0 deletions pkg/engine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,9 @@ type Info interface {
// Metadata for the given enemy, such as their current level and weaknesses.
EnemyInfo(target key.TargetID) (info.Enemy, error)

// Check if the character can use attack (Either arbitrary logic defined by char implementer, or unrestricted by default)
CanUseAttack(target key.TargetID) (bool, error)

// Check if the character can use the skill (enough Skill Points and not blocked by Skill.CanUse,
// see implementation of each character)
CanUseSkill(target key.TargetID) (bool, error)
Expand Down
2 changes: 2 additions & 0 deletions pkg/engine/target/character/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,14 @@ type SkillInfo struct {
Technique Technique
}

type AttackValidateFunc func(engine engine.Engine, char info.CharInstance) bool
type SkillValidateFunc func(engine engine.Engine, char info.CharInstance) bool
type UltValidateFunc func(engine engine.Engine, char info.CharInstance) bool

type Attack struct {
SPAdd int
TargetType model.TargetType
CanUse AttackValidateFunc `exhaustruct:"optional"`
}

type Skill struct {
Expand Down
4 changes: 4 additions & 0 deletions pkg/engine/target/character/execute.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ func (mgr *Manager) ExecuteAction(id key.TargetID, isInsert bool) (target.Execut
return target.ExecutableAction{}, err
}

canUseAttack, err := mgr.engine.CanUseAttack(id)
if err != nil || !canUseAttack {
return target.ExecutableAction{}, err
}
Comment on lines +86 to +89
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might want to return a custom error message somewhere in case both canUseSkill and canUseAttack fail (which should never happen ingame)

return target.ExecutableAction{
Execute: func() {
char.Attack(primaryTarget, actionState{
Expand Down
15 changes: 15 additions & 0 deletions pkg/mock/mock_engine.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions pkg/simulation/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,20 @@ func (sim *Simulation) EnemyInfo(id key.TargetID) (info.Enemy, error) {
return sim.Enemy.Info(id)
}

func (sim *Simulation) CanUseAttack(id key.TargetID) (bool, error) {
skillInfo, err := sim.Char.SkillInfo(id)
if err != nil {
return false, err
}
char, err := sim.Char.Get(id)
if err != nil {
return false, err
}

check := skillInfo.Attack.CanUse
return (check == nil || check(sim, char)), nil
}

func (sim *Simulation) CanUseSkill(id key.TargetID) (bool, error) {
skillInfo, err := sim.Char.SkillInfo(id)
if err != nil {
Expand Down
15 changes: 15 additions & 0 deletions tests/mock/mock_engine.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading