From d434e50897ff8510315687961baf39e1b2f9c24e Mon Sep 17 00:00:00 2001 From: Kistaro Windrider Date: Sat, 8 Apr 2023 18:18:00 -0700 Subject: [PATCH] Shuffle cards back by default. If no After function is provided for a SwitchingCard, it uses ShuffleIntoBottomHalf. This also modifies Then to be callable with a nil `o`, which it recognizes as "nothing happened but we need cleanup anyway", in preparation for the incoming "make cards sometimes not drawable" feature. --- koboldsim/cardtypes.go | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/koboldsim/cardtypes.go b/koboldsim/cardtypes.go index d2b04d0..c35f7b0 100644 --- a/koboldsim/cardtypes.go +++ b/koboldsim/cardtypes.go @@ -96,18 +96,24 @@ func (s *SwitchingCard) Options(player *Player) ([]CardOption, error) { // Then implements Card. func (s *SwitchingCard) Then(p *Player, o CardOption) error { - newPolicy := o.(Policy) var errs cardsim.ErrorCollector - if s.lastPolicy != nil && !newPolicy.Is(s.lastPolicy) { - err := s.lastPolicy.Unenact(p) - if cardsim.IsSeriousError(err) { - return err + if o != nil { + newPolicy := o.(Policy) + if s.lastPolicy != nil && !newPolicy.Is(s.lastPolicy) { + err := s.lastPolicy.Unenact(p) + if cardsim.IsSeriousError(err) { + return err + } + errs.Add(err) } - errs.Add(err) + s.lastPolicy = o.(Policy) } - s.lastPolicy = o.(Policy) if s.After != nil { errs.Add(s.After(s, p, o)) + } else { + // Fallback: Shuffle the card back into the bottom half of the deck. + errs.Add(ShuffleIntoBottomHalf(s, p, o)) + } return errs.Emit() }