diff options
| author | Florian Fischer <florian.fischer@muhq.space> | 2025-09-08 15:38:07 +0200 |
|---|---|---|
| committer | Florian Fischer <florian.fischer@muhq.space> | 2025-09-08 15:41:45 +0200 |
| commit | a3ca136cd776ff0089dc33e401d1fc474dc17138 (patch) | |
| tree | 1968a8ff318c7f021e2cc94df5a057eeee39b099 /go/game/action.go | |
| parent | ee605fa7fa48803756b0c3216afc4bd692ec144a (diff) | |
| download | muhqs-game-a3ca136cd776ff0089dc33e401d1fc474dc17138.tar.gz muhqs-game-a3ca136cd776ff0089dc33e401d1fc474dc17138.zip | |
support explicitly winning and implement Approach Supremacy!
Diffstat (limited to 'go/game/action.go')
| -rw-r--r-- | go/game/action.go | 45 |
1 files changed, 32 insertions, 13 deletions
diff --git a/go/game/action.go b/go/game/action.go index ab38f238..b9201d4a 100644 --- a/go/game/action.go +++ b/go/game/action.go @@ -316,18 +316,29 @@ var ( equipmentPlayActionTarget = TargetDesc{"available spawn tile", "?"} ) -func NewPlayActionCostFunc(player *Player, cost int, card *Card) ActionCostFunc { +func NewPlayActionCostFunc(a *PlayAction, cost int) ActionCostFunc { + player := a.source.(*Player) + s := player.gameState + card := a.Card + return func(*LocalState) bool { if player.Resource < cost { return false } + if additionalCosts := getCardImplementation(card).additionalPlayCosts(a); additionalCosts != nil { + if !additionalCosts(s) { + return false + } + } player.Resource -= cost player.Hand.RemoveCard(card) return true } } -func NewPlayAction(p *Player, c *Card, args ...any) *PlayAction { +// _newPlayAction returns a new PlayAction controlled by the player for a certain card. +// It is important that the returned PlayAction has no cost function yet. +func _newPlayAction(p *Player, c *Card) *PlayAction { a := &PlayAction{ ActionBase{ source: p, @@ -336,17 +347,7 @@ func NewPlayAction(p *Player, c *Card, args ...any) *PlayAction { -1, } - if len(args) > 0 { - if costFunc, ok := args[0].(ActionCostFunc); ok { - a.costFunc = costFunc - } - } - s := p.gameState - if a.costFunc == nil { - a.costFunc = NewPlayActionCostFunc(p, c.PlayCosts.Costs(s), c) - } - if c.IsPermanent() { if c.Type == CardTypes.Equipment { a.targets = newTargets(newTarget(s, equipmentPlayActionTarget, a)) @@ -366,8 +367,26 @@ func NewPlayAction(p *Player, c *Card, args ...any) *PlayAction { return a } +func newPlayActionWithCostFunc(p *Player, c *Card, costFunc ActionCostFunc) *PlayAction { + a := _newPlayAction(p, c) + a.costFunc = costFunc + return a +} + +func NewPlayAction(p *Player, c *Card) *PlayAction { + a := _newPlayAction(p, c) + + s := p.gameState + if a.costFunc == nil { + a.costFunc = NewPlayActionCostFunc(a, c.PlayCosts.Costs(s)) + } + + return a +} + func NewPlayActionVariadicCosts(p *Player, c *Card, variadicCosts int) *PlayAction { - a := NewPlayAction(p, c, NewPlayActionCostFunc(p, c.PlayCosts.Costs(p.gameState, variadicCosts), c)) + a := _newPlayAction(p, c) + a.costFunc = NewPlayActionCostFunc(a, c.PlayCosts.Costs(p.gameState, variadicCosts)) a.ChoosenVariadicCost = variadicCosts return a } |
