Skip to content

Commit

Permalink
move NextQueueItemIsValid check to properly account for swap (#1993)
Browse files Browse the repository at this point in the history
  • Loading branch information
k0l11 committed Feb 8, 2024
1 parent 780c024 commit 9b50dbe
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions pkg/simulation/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,24 +149,12 @@ func queuePhase(s *Simulation) (stateFn, error) {
}
// append swap if called for char is not active
// check if NoChar incase this is some special action that does not require a character
nextQueueItemChar := s.C.Player.ActiveChar()
if next.Char != keys.NoChar && next.Char != nextQueueItemChar.Base.Key {
nextQueueItemChar, _ = s.C.Player.ByKey(next.Char)
if next.Char != keys.NoChar && next.Char != s.C.Player.ActiveChar().Base.Key {
s.queue = append(s.queue, &action.Eval{
Char: next.Char,
Action: action.ActionSwap,
})
}
// check if the next queue item is valid
// example: most sword characters can't do charge if the previous action was not attack
if err := nextQueueItemChar.NextQueueItemIsValid(next.Action, next.Param); err != nil {
switch {
case errors.Is(err, player.ErrInvalidChargeAction):
return nil, fmt.Errorf("%v: %w", nextQueueItemChar.Base.Key, player.ErrInvalidChargeAction)
default:
return nil, err
}
}
s.queue = append(s.queue, next)
return actionReadyCheckPhase, nil
}
Expand All @@ -178,6 +166,18 @@ func actionReadyCheckPhase(s *Simulation) (stateFn, error) {
}
q := s.queue[0]

// check if the next queue item is valid
// example: most sword characters can't do charge if the previous action was not attack
char, _ := s.C.Player.ByKey(q.Char)
if err := char.NextQueueItemIsValid(q.Action, q.Param); err != nil {
switch {
case errors.Is(err, player.ErrInvalidChargeAction):
return nil, fmt.Errorf("%v: %w", char.Base.Key, player.ErrInvalidChargeAction)
default:
return nil, err
}
}

//TODO: this loop should be optimized to skip more than 1 frame at a time
if err := s.C.Player.ReadyCheck(q.Action, q.Char, q.Param); err != nil {
// repeat this phase until action is ready
Expand Down

0 comments on commit 9b50dbe

Please sign in to comment.