CardOption.Enable
Make it possible for a card to display an option but not actually allow it to be selected. It's up to the UI layer to decide how to display options that are not enabled. The option text should probably contiain a note on why the option cannot be selected...
This commit is contained in:
@ -277,9 +277,10 @@ func (p *Player[C]) HasUrgentCards() bool {
|
||||
// EnactCardUnchecked executes a card choice, removes it from the hand, and
|
||||
// decrements the ActionsRemaining. It does not check for conflicting Urgent
|
||||
// cards or already being out of actions. If no such card or card choice
|
||||
// exists, this returns nil and ErrInvalidCard/ErrInvalidChoice. Otherwise, this returns
|
||||
// the result of enacting the card. If enacting the card causes an error,
|
||||
// the State becomes GameCrashed.
|
||||
// exists, or the specified choice is not enabled, this returns nil and
|
||||
// ErrInvalidCard/ErrInvalidChoice without changing anything. Otherwise, this
|
||||
// returns the result of enacting the card. If enacting the card causes a
|
||||
// serious error, the State becomes GameCrashed.
|
||||
func (p *Player[C]) EnactCardUnchecked(cardIdx, choiceIdx int) (Message, error) {
|
||||
if cardIdx < 0 || cardIdx >= len(p.Hand) {
|
||||
return nil, fmt.Errorf("%w: no card #%d when %d cards in hand", ErrInvalidCard, cardIdx, len(p.Hand))
|
||||
@ -293,7 +294,13 @@ func (p *Player[C]) EnactCardUnchecked(cardIdx, choiceIdx int) (Message, error)
|
||||
}
|
||||
errs.Add(err)
|
||||
if choiceIdx < 0 || choiceIdx > len(options) {
|
||||
errs.Add(fmt.Errorf("%w: no option #%d on card #%d with %d options", ErrInvalidCard, choiceIdx, cardIdx, len(options)))
|
||||
errs.Add(fmt.Errorf("%w: no option #%d on card #%d with %d options", ErrInvalidChoice, choiceIdx, cardIdx, len(options)))
|
||||
return nil, errs.Emit()
|
||||
}
|
||||
|
||||
chosen := options[choiceIdx]
|
||||
if !chosen.Enabled(p) {
|
||||
errs.Add(fmt.Errorf("%w: option %d on card %d was not enabled", ErrInvalidChoice, choiceIdx, cardIdx))
|
||||
return nil, errs.Emit()
|
||||
}
|
||||
|
||||
@ -335,9 +342,10 @@ func (p *Player[C]) EnactCard(cardIdx, choiceIdx int) (Message, error) {
|
||||
// EnactPermanentActionUnchecked executes a permanently-available action and
|
||||
// decrements the ActionsRemaining. It does not check for conflicting Urgent
|
||||
// cards or already being out of actions. If no such action or card option
|
||||
// exists, this returns nil and ErrInvalidCard/ErrInvalidChoice. Otherwise, this returns
|
||||
// the result of enacting the permanent action. If enacting the card causes an error,
|
||||
// the State becomes GameCrashed.
|
||||
// exists, or the option is not enabled, this returns nil and ErrInvalidCard
|
||||
// or ErrInvalidChoice without changing anything. Otherwise, this returns the
|
||||
// result of enacting the permanent action. If enacting the card causes a
|
||||
// serious error, the State becomes GameCrashed.
|
||||
func (p *Player[C]) EnactPermanentActionUnchecked(actionIdx, choiceIdx int) (Message, error) {
|
||||
if actionIdx < 0 || actionIdx >= len(p.PermanentActions) {
|
||||
return nil, fmt.Errorf("%w: no action #%d when %d permanent actions exist", ErrInvalidCard, actionIdx, len(p.PermanentActions))
|
||||
@ -354,17 +362,22 @@ func (p *Player[C]) EnactPermanentActionUnchecked(actionIdx, choiceIdx int) (Mes
|
||||
errs.Add(fmt.Errorf("%w: no option #%d on permanent action #%d with %d options", ErrInvalidChoice, choiceIdx, actionIdx, len(options)))
|
||||
return nil, errs.Emit()
|
||||
}
|
||||
chosen := options[choiceIdx]
|
||||
if !chosen.Enabled(p) {
|
||||
errs.Add(fmt.Errorf("%w: option #%d on permanent action #%d is not enabled", ErrInvalidChoice, choiceIdx, actionIdx))
|
||||
return nil, errs.Emit()
|
||||
}
|
||||
|
||||
p.ActionsRemaining--
|
||||
|
||||
ret, err := options[choiceIdx].Enact(p)
|
||||
ret, err := chosen.Enact(p)
|
||||
errs.Add(err)
|
||||
if IsSeriousError(err) {
|
||||
p.State = GameCrashed
|
||||
return ret, errs.Emit()
|
||||
}
|
||||
|
||||
err = card.Then(p, options[choiceIdx])
|
||||
err = card.Then(p, chosen)
|
||||
errs.Add(err)
|
||||
if IsSeriousError(err) {
|
||||
p.State = GameCrashed
|
||||
|
Reference in New Issue
Block a user