diff options
| author | Florian Fischer <florian.fischer@muhq.space> | 2023-02-24 13:48:33 +0100 |
|---|---|---|
| committer | Florian Fischer <florian.fischer@muhq.space> | 2025-01-27 16:43:51 +0100 |
| commit | 9e082b76ad5e0f90814bc88265149a6541b8fb45 (patch) | |
| tree | d32aab723a05335dba53b68023f9b70e1148c1ba /go/game/action.go | |
| parent | 7788121beb6b9dd8540d4345e8e841830ff2c490 (diff) | |
| download | muhqs-game-9e082b76ad5e0f90814bc88265149a6541b8fb45.tar.gz muhqs-game-9e082b76ad5e0f90814bc88265149a6541b8fb45.zip | |
intermeditae commit
* implement dopping piles
* implement simple spell targeting
* add some simple spells
Diffstat (limited to 'go/game/action.go')
| -rw-r--r-- | go/game/action.go | 50 |
1 files changed, 46 insertions, 4 deletions
diff --git a/go/game/action.go b/go/game/action.go index b8bc8d6e..09c3ec68 100644 --- a/go/game/action.go +++ b/go/game/action.go @@ -79,6 +79,50 @@ func (a *ActionBase) CheckTargets(s *State) error { return a.targets.CheckTargets(s) } +type PileDropAction struct { + ActionBase + pile []Permanent +} + +func (a *PileDropAction) String() string { + perm := a.source.(Permanent) + controller := perm.Controller() + if a.targets.RequireSelection() { + return fmt.Sprintf("%s drop %v", controller.Name, perm.Tile().Position) + } + + s := fmt.Sprintf("%s drop [", controller.Name) + pile := perm.Pile() + for i, t := range a.targets.ts { + s = fmt.Sprintf("%s %v@%v,", s, pile[i], t.sel[0]) + } + return s[:len(s)-1] + " ]" +} + +func (*PileDropAction) PayCosts(*State) bool { return true } + +func newPileDropAction(perm Permanent, tile *Tile, pile []Permanent) *PileDropAction { + a := &PileDropAction{ + ActionBase{ + source: perm, + }, + pile, + } + + a.resolveFunc = func(s *State) { + for i, p := range pile { + p.onDrop(p) + p.setContainingPerm(nil) + enterTileOrPile(p, a.targets.ts[i].sel[0].(*Tile)) + } + + perm.clearPile() + } + + a.targets = newPileDropTargets(perm.Controller().gameState, a) + return a +} + type PlayAction struct { ActionBase } @@ -112,10 +156,8 @@ func NewPlayAction(p *Player, c *Card, args ...interface{}) *PlayAction { s := p.gameState if c.IsPermanent() { a.targets = newTargets(newTarget(s, permanentPlayActionTarget, a)) - } else { - // TODO: implement parsing targets to play a card - // a.targets = newTargets(s, c.Impl.playTargets(s, p), a) - a.targets = newTargets() + } else if targetDesc := c.Impl.playTargets(); targetDesc != nil { + a.targets = newTargets(newTarget(s, *targetDesc, a)) } a.resolveFunc = func(s *State) { |
