aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Fischer <florian.fischer@muhq.space>2025-08-19 15:40:31 +0200
committerFlorian Fischer <florian.fischer@muhq.space>2025-08-20 14:46:13 +0200
commitcb00701411f8781f1922c164ee0c34137366657d (patch)
treefa7dc28d505f9404ce7837ea17145486f3cb05fa
parent00bc21a84f62119649f960df702fd9191fb47090 (diff)
downloadmuhqs-game-cb00701411f8781f1922c164ee0c34137366657d.tar.gz
muhqs-game-cb00701411f8781f1922c164ee0c34137366657d.zip
implement the free discard action
-rw-r--r--go/game/action.go39
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