From 9b50dbe0cba4afe59ede5cef02f89e7960881814 Mon Sep 17 00:00:00 2001 From: koli <98557316+k0l11@users.noreply.github.com> Date: Thu, 8 Feb 2024 23:42:46 +0100 Subject: [PATCH] move NextQueueItemIsValid check to properly account for swap (#1993) --- pkg/simulation/run.go | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/pkg/simulation/run.go b/pkg/simulation/run.go index e5e3551685..fc4b7a9cd2 100644 --- a/pkg/simulation/run.go +++ b/pkg/simulation/run.go @@ -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 } @@ -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