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.
This commit is contained in:
Kistaro Windrider 2023-04-08 18:18:00 -07:00
parent 95a30cb522
commit d434e50897
Signed by: kistaro
SSH Key Fingerprint: SHA256:TBE2ynfmJqsAf0CP6gsflA0q5X5wD5fVKWPsZ7eVUg8

View File

@ -96,18 +96,24 @@ func (s *SwitchingCard) Options(player *Player) ([]CardOption, error) {
// Then implements Card. // Then implements Card.
func (s *SwitchingCard) Then(p *Player, o CardOption) error { func (s *SwitchingCard) Then(p *Player, o CardOption) error {
newPolicy := o.(Policy)
var errs cardsim.ErrorCollector var errs cardsim.ErrorCollector
if s.lastPolicy != nil && !newPolicy.Is(s.lastPolicy) { if o != nil {
err := s.lastPolicy.Unenact(p) newPolicy := o.(Policy)
if cardsim.IsSeriousError(err) { if s.lastPolicy != nil && !newPolicy.Is(s.lastPolicy) {
return err 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 { if s.After != nil {
errs.Add(s.After(s, p, o)) 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() return errs.Emit()
} }