diff options
| author | Florian Fischer <florian.fischer@muhq.space> | 2025-08-19 15:40:31 +0200 |
|---|---|---|
| committer | Florian Fischer <florian.fischer@muhq.space> | 2025-08-20 15:57:39 +0200 |
| commit | 97a80cc2cf2a5b5a8334fc42f65863651516d4cf (patch) | |
| tree | cc5f81e6765331979d059ba79c804dd8c784e847 | |
| parent | 4d7f6130a26969826d5ee6fe52279e30912afc92 (diff) | |
| download | muhqs-game-97a80cc2cf2a5b5a8334fc42f65863651516d4cf.tar.gz muhqs-game-97a80cc2cf2a5b5a8334fc42f65863651516d4cf.zip | |
implement the free discard action
| -rw-r--r-- | go/game/action.go | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/go/game/action.go b/go/game/action.go index f588dce5..dbbc8700 100644 --- a/go/game/action.go +++ b/go/game/action.go @@ -6,6 +6,8 @@ import ( "log" "regexp" "strings" + + "muhq.space/muhqs-game/go/utils" ) type ActionSpeed int @@ -90,6 +92,43 @@ func newHandCardSelection(p *Player, min, max int) Action { return a } +type FreeDiscardAction struct { + TargetSelection +} + +func NewFreeDiscardAction(p *Player) *FreeDiscardAction { + a := &FreeDiscardAction{TargetSelection: TargetSelection{player: p}} + targetDesc := TargetDesc{"hand card", "2"} + a.targets = newTargets(newTarget(p.gameState, targetDesc, a)) + return a +} + +func (a *FreeDiscardAction) PayCosts(s *LocalState) bool { + if a.targets.CheckTargets(s) != nil { + return false + } + for _, sel := range a.Target().Selection() { + card, _ := sel.(*Card) + a.player.DiscardCard(card) + } + return true +} + +func (*FreeDiscardAction) CheckTargets(*LocalState) error { return nil } + +func (a *FreeDiscardAction) resolve(*LocalState) { + a.player.gainResource(2) +} + +func (a *FreeDiscardAction) String() string { + if a.Target().RequireSelection() { + return fmt.Sprintf("%s discard two", a.player.Name) + } + + sel := utils.InterfaceSliceToTypedSlice[*Card](a.Target().Selection()) + return fmt.Sprintf("%s discard [%s,%s]", a.player.Name, sel[0].Name, sel[1].Name) +} + type DraftPick struct { player *Player pick *Card |
