From ea54efacae089aa3644cfe00c8e180d5cc2c8d9e Mon Sep 17 00:00:00 2001 From: Florian Fischer Date: Sat, 4 Feb 2023 14:37:15 +0100 Subject: support crewing * Introduce new callback for leaving a pile without beeing dropped * Fix equipment contrsuctor * Implement attack inheritance --- go/game/permanent.go | 52 ++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 40 insertions(+), 12 deletions(-) (limited to 'go/game/permanent.go') diff --git a/go/game/permanent.go b/go/game/permanent.go index 36c5e1ba..91aa0cda 100644 --- a/go/game/permanent.go +++ b/go/game/permanent.go @@ -28,19 +28,23 @@ type Permanent interface { AvailActions() []Action IsAvailableTile(*Tile) bool + SetContainingPerm(p Permanent) AddPermanentToPile(p Permanent) - OnPile(containing Permanent) - OnDrop(containing Permanent) + RemovePermanentFromPile(p Permanent) + onPile(containing Permanent) + onUnpile(containing Permanent) + onDrop(containing Permanent) } type PermanentBase struct { - card *Card - tile *Tile - damage int - pile []Permanent - controller *Player - owner *Player - tmpEffects []string + card *Card + tile *Tile + damage int + pile []Permanent + containingPerm Permanent + controller *Player + owner *Player + tmpEffects []string } func NewPermanentBase(card *Card, tile *Tile, owner *Player) PermanentBase { @@ -134,13 +138,37 @@ func (p *PermanentBase) IsAvailableTile(tile *Tile) bool { return tile.IsAvailableForCard(p.card) } +func (p *PermanentBase) SetContainingPerm(containing Permanent) { + p.containingPerm = containing +} + 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 (p *PermanentBase) RemovePermanentFromPile(rm Permanent) { + for i, piled := range p.pile { + if piled != rm { + continue + } + + p.pile[i] = p.pile[len(p.pile)-1] + p.pile = p.pile[:len(p.pile)-1] + return + } +} +func (b *PermanentBase) onPile(p Permanent) { p.Card().Impl.onPile(p) } +func (b *PermanentBase) onUnpile(p Permanent) { p.Card().Impl.onUnpile(p) } +func (b *PermanentBase) onDrop(p Permanent) { p.Card().Impl.onDrop(p) } func AddPermanentToPile(containing, p Permanent) { + p.SetContainingPerm(containing) containing.AddPermanentToPile(p) - p.OnPile(p) + p.onPile(p) +} + +func RemovePermanentFromPile(containing, rm Permanent) { + containing.RemovePermanentFromPile(rm) + rm.onUnpile(containing) + rm.SetContainingPerm(nil) } -- cgit v1.2.3