diff options
| author | Florian Fischer <florian.fischer@muhq.space> | 2023-02-01 20:09:28 +0100 |
|---|---|---|
| committer | Florian Fischer <florian.fischer@muhq.space> | 2025-08-20 15:46:38 +0200 |
| commit | 8e0ee56128d12bc101b487cdc696abc85051a5f8 (patch) | |
| tree | 7d83f75c8dffdcd0d8c2ac3cfcd054266b083f44 | |
| parent | 2e2ad2edb01191dd4844768df883e7ef8ceec846 (diff) | |
| download | muhqs-game-8e0ee56128d12bc101b487cdc696abc85051a5f8.tar.gz muhqs-game-8e0ee56128d12bc101b487cdc696abc85051a5f8.zip | |
add equipments and pile hooks
| -rw-r--r-- | go/game/card.go | 19 | ||||
| -rw-r--r-- | go/game/cardParsing.go | 14 | ||||
| -rw-r--r-- | go/game/equipment.go | 33 | ||||
| -rw-r--r-- | go/game/permanent.go | 17 | ||||
| -rw-r--r-- | go/game/unit.go | 12 |
5 files changed, 83 insertions, 12 deletions
diff --git a/go/game/card.go b/go/game/card.go index 9013a059..23562f0c 100644 --- a/go/game/card.go +++ b/go/game/card.go @@ -75,6 +75,9 @@ type cardImplementation interface { spawnTiles(*State, *Player) []*Tile fullActions(*Unit) []*FullAction freeActions(Permanent) []*FreeAction + + onPile(Permanent) + onDrop(Permanent) } // Default implementation of the cardImplementation interface. @@ -83,17 +86,11 @@ type cardImplementation interface { // default behavior. type cardImplementationBase struct{} -func (impl *cardImplementationBase) spawnTiles(*State, *Player) []*Tile { - return nil -} - -func (impl *cardImplementationBase) fullActions(*Unit) []*FullAction { - return nil -} - -func (impl *cardImplementationBase) freeActions(Permanent) []*FreeAction { - return nil -} +func (*cardImplementationBase) spawnTiles(*State, *Player) []*Tile { return nil } +func (*cardImplementationBase) fullActions(*Unit) []*FullAction { return nil } +func (*cardImplementationBase) freeActions(Permanent) []*FreeAction { return nil } +func (*cardImplementationBase) onPile(Permanent) {} +func (*cardImplementationBase) onDrop(Permanent) {} // Map of all card implementations var cardImplementations map[string]cardImplementation diff --git a/go/game/cardParsing.go b/go/game/cardParsing.go index afdefe54..ad0b6ea8 100644 --- a/go/game/cardParsing.go +++ b/go/game/cardParsing.go @@ -12,6 +12,8 @@ type parsedCardImplementation struct { spawnTilesFunc func(*State, *Player) []*Tile genFullActions func(*Unit) []*FullAction genFreeActions func(Permanent) []*FreeAction + _onPile func(Permanent) + _onDrop func(Permanent) } func (impl *parsedCardImplementation) spawnTiles(s *State, p *Player) []*Tile { @@ -35,6 +37,18 @@ func (impl *parsedCardImplementation) freeActions(p Permanent) []*FreeAction { return nil } +func (impl *parsedCardImplementation) onPile(p Permanent) { + if impl._onPile != nil { + impl._onPile(p) + } +} + +func (impl *parsedCardImplementation) onDrop(p Permanent) { + if impl._onDrop != nil { + impl._onDrop(p) + } +} + func newParsedCardImplementation(c *Card) *parsedCardImplementation { impl := &parsedCardImplementation{card: c} for _, effect := range c.getEffects() { diff --git a/go/game/equipment.go b/go/game/equipment.go index 1b78c8ad..14e8b317 100644 --- a/go/game/equipment.go +++ b/go/game/equipment.go @@ -2,4 +2,37 @@ package game type Equipment struct { Artifact + Durability int +} + +func newEquipmentFromPath(cardPath string, containing interface{}, owner *Player) *Equipment { + card := NewCard(cardPath) + return newEquipment(card, containing, owner) +} + +func newEquipment(card *Card, containing interface{}, owner *Player) *Equipment { + e := &Equipment{ + *NewArtifact(card, nil, owner), + card.Values["durability"].(int), + } + + switch containing := containing.(type) { + case *Tile: + e.tile = containing + containing.Permanent = e + case *Unit: + AddPermanentToPile(containing, e) + } + + return e +} + +func (e *Equipment) onDrop(p Permanent) { + e.Durability-- + if e.Durability < 1 { + e.Controller().gameState.DestroyPermanent(e) + return + } + + p.Card().Impl.onDrop(p) } diff --git a/go/game/permanent.go b/go/game/permanent.go index b4090592..36c5e1ba 100644 --- a/go/game/permanent.go +++ b/go/game/permanent.go @@ -27,6 +27,10 @@ type Permanent interface { Attackable() bool AvailActions() []Action IsAvailableTile(*Tile) bool + + AddPermanentToPile(p Permanent) + OnPile(containing Permanent) + OnDrop(containing Permanent) } type PermanentBase struct { @@ -40,7 +44,7 @@ type PermanentBase struct { } func NewPermanentBase(card *Card, tile *Tile, owner *Player) PermanentBase { - if tile.Permanent != nil { + if tile != nil && tile.Permanent != nil { log.Fatalf("Tile at %v already occupied by %v", tile.Position, tile.Permanent) } @@ -129,3 +133,14 @@ func (p *PermanentBase) XEffect(effect string) (int, error) { func (p *PermanentBase) IsAvailableTile(tile *Tile) bool { return tile.IsAvailableForCard(p.card) } + +func (p *PermanentBase) AddPermanentToPile(a Permanent) { + p.pile = append(p.pile, a) +} +func (b *PermanentBase) OnPile(p Permanent) { p.Card().Impl.onPile(p) } +func (b *PermanentBase) OnDrop(p Permanent) { p.Card().Impl.onDrop(p) } + +func AddPermanentToPile(containing, p Permanent) { + containing.AddPermanentToPile(p) + p.OnPile(p) +} diff --git a/go/game/unit.go b/go/game/unit.go index 116de413..5d85ff4b 100644 --- a/go/game/unit.go +++ b/go/game/unit.go @@ -223,3 +223,15 @@ func (u *Unit) AvailActions() (actions []Action) { return actions } + +func (u *Unit) OnPile(containing Permanent) { + if _, ok := containing.(*Unit); ok { + // TODO: add attack + } +} + +func (u *Unit) OnDrop(containing Permanent) { + if _, ok := containing.(*Unit); ok { + // TODO: remove attack + } +} |
