diff options
| author | Florian Fischer <florian.fischer@muhq.space> | 2024-12-26 18:52:15 +0100 |
|---|---|---|
| committer | Florian Fischer <florian.fischer@muhq.space> | 2025-01-27 16:43:57 +0100 |
| commit | 5684983b963eeb2f498028360ebc17cc2fb32564 (patch) | |
| tree | 0a9e4c95b7d38ff664190eaee7168830997efcbf /go/game/action.go | |
| parent | d1d926debe4d261e057980f325741440b3d76609 (diff) | |
| download | muhqs-game-5684983b963eeb2f498028360ebc17cc2fb32564.tar.gz muhqs-game-5684983b963eeb2f498028360ebc17cc2fb32564.zip | |
pass the PlayAction to the cards onPlay implementations
This is done to propagate the chosen variadic play cost to the
card implementation.
Diffstat (limited to 'go/game/action.go')
| -rw-r--r-- | go/game/action.go | 42 |
1 files changed, 27 insertions, 15 deletions
diff --git a/go/game/action.go b/go/game/action.go index 30bad0b1..5a8fc35b 100644 --- a/go/game/action.go +++ b/go/game/action.go @@ -192,6 +192,7 @@ func newPileDropAction(perm Permanent, tile *Tile, pile []Permanent) *PileDropAc type PlayAction struct { ActionBase + ChoosenVariadicCost int } var ( @@ -199,11 +200,24 @@ var ( equipmentPlayActionTarget = TargetDesc{"available spawn tile", "?"} ) +func NewPlayActionCostFunc(player *Player, cost int) ActionCostFunc { + return func(*State) bool { + if player.Resource < cost { + return false + } + player.Resource -= cost + return true + } +} + func NewPlayAction(p *Player, c *Card, args ...interface{}) *PlayAction { - a := &PlayAction{ActionBase{ - source: p, - Card: c, - }} + a := &PlayAction{ + ActionBase{ + source: p, + Card: c, + }, + -1, + } if len(args) > 0 { if costFunc, ok := args[0].(ActionCostFunc); ok { @@ -211,19 +225,11 @@ func NewPlayAction(p *Player, c *Card, args ...interface{}) *PlayAction { } } + s := p.gameState if a.costFunc == nil { - a.costFunc = func(s *State) bool { - cost := c.PlayCosts.Costs(s) - - if p.Resource < cost { - return false - } - p.Resource -= cost - return true - } + a.costFunc = NewPlayActionCostFunc(p, c.PlayCosts.Costs(s)) } - s := p.gameState if c.IsPermanent() { if c.Type == CardTypes.Equipment { a.targets = newTargets(newTarget(s, equipmentPlayActionTarget, a)) @@ -237,12 +243,18 @@ func NewPlayAction(p *Player, c *Card, args ...interface{}) *PlayAction { } a.resolveFunc = func(s *State) { - s.resolvePlay(p, c, a.targets) + s.resolvePlay(a) } return a } +func NewPlayActionVariadicCosts(p *Player, c *Card, variadicCosts int) *PlayAction { + a := NewPlayAction(p, c, NewPlayActionCostFunc(p, c.PlayCosts.Costs(p.gameState, variadicCosts))) + a.ChoosenVariadicCost = variadicCosts + return a +} + func (a *PlayAction) String() string { p := a.source.(*Player) if a.targets.RequireSelection() { |
