aboutsummaryrefslogtreecommitdiff
path: root/go/game/permanent.go
diff options
context:
space:
mode:
authorFlorian Fischer <florian.fischer@muhq.space>2023-02-04 14:37:15 +0100
committerFlorian Fischer <florian.fischer@muhq.space>2025-01-27 16:43:47 +0100
commitea54efacae089aa3644cfe00c8e180d5cc2c8d9e (patch)
tree8b83151059e1d7661a366d350ef18eb913f4ce3d /go/game/permanent.go
parent9fc26075aa486e6887dbb28640224bffd1d57330 (diff)
downloadmuhqs-game-ea54efacae089aa3644cfe00c8e180d5cc2c8d9e.tar.gz
muhqs-game-ea54efacae089aa3644cfe00c8e180d5cc2c8d9e.zip
support crewing
* Introduce new callback for leaving a pile without beeing dropped * Fix equipment contrsuctor * Implement attack inheritance
Diffstat (limited to 'go/game/permanent.go')
-rw-r--r--go/game/permanent.go52
1 files changed, 40 insertions, 12 deletions
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)
}