aboutsummaryrefslogtreecommitdiff
path: root/go/game/permanent.go
diff options
context:
space:
mode:
Diffstat (limited to 'go/game/permanent.go')
-rw-r--r--go/game/permanent.go114
1 files changed, 80 insertions, 34 deletions
diff --git a/go/game/permanent.go b/go/game/permanent.go
index acdcd85f..21655d71 100644
--- a/go/game/permanent.go
+++ b/go/game/permanent.go
@@ -3,78 +3,124 @@ package game
import (
"fmt"
"log"
+ "strconv"
+ "strings"
+
+ "golang.org/x/exp/slices"
)
type Permanent interface {
- GetCard() *Card
- GetTile() *Tile
- GetDamage() int
- GetPile() []Permanent
- GetController() *Player
- GetOwner() *Player
+ Card() *Card
+ Tile() *Tile
+ Damage() int
+ Pile() []Permanent
+ Controller() *Player
+ Owner() *Player
+ Effects() []string
+ HasEffect(string) bool
+ XEffect(string) (int, error)
String() string
Fight(p Permanent)
AddDamage(damage int)
IsDestroyed() bool
Attackable() bool
- GetAvailActionPrototypes() []ActionPrototype
- Swimming() bool
+ AvailActionPrototypes() []ActionPrototype
}
type PermanentBase struct {
- Card *Card
- Tile *Tile
- Damage int
- Pile []Permanent
- Controller *Player
- Owner *Player
+ card *Card
+ tile *Tile
+ damage int
+ pile []Permanent
+ controller *Player
+ owner *Player
+ tmpEffects []string
}
func NewPermanentBase(card *Card, tile *Tile, owner *Player) PermanentBase {
if tile.Permanent != nil {
log.Fatalf("Tile at %v already occupied by %v", tile.Position, tile.Permanent)
}
- return PermanentBase{card, tile, 0, []Permanent{}, owner, owner}
+
+ return PermanentBase{
+ card: card,
+ tile: tile,
+ controller: owner,
+ owner: owner,
+ }
}
-func (p *PermanentBase) GetCard() *Card {
- return p.Card
+func (p *PermanentBase) Card() *Card {
+ return p.card
}
-func (p *PermanentBase) GetTile() *Tile {
- return p.Tile
+func (p *PermanentBase) Tile() *Tile {
+ return p.tile
}
-func (p *PermanentBase) GetDamage() int {
- return p.Damage
+func (p *PermanentBase) Damage() int {
+ return p.damage
}
-func (p *PermanentBase) GetPile() []Permanent {
- return p.Pile
+func (p *PermanentBase) Pile() []Permanent {
+ return p.pile
}
-func (p *PermanentBase) GetController() *Player {
- return p.Controller
+func (p *PermanentBase) Controller() *Player {
+ return p.controller
}
-func (p *PermanentBase) GetOwner() *Player {
- return p.Owner
+func (p *PermanentBase) Owner() *Player {
+ return p.owner
}
func (p *PermanentBase) String() string {
return fmt.Sprintf("%s's %s@%s",
- p.GetController().Name, p.GetCard().Name, p.GetTile().Position.String())
+ p.Controller().Name, p.Card().Name, p.Tile().Position.String())
+}
+
+func DealDamage(src, dest Permanent, damage int) {
+ actualDamage := damage
+ shield, err := dest.XEffect("shield")
+ if err != nil {
+ // TODO: implement piercing
+
+ actualDamage -= shield
+ if actualDamage < 0 {
+ actualDamage = 0
+ }
+ }
+ dest.AddDamage(actualDamage)
}
func (p *PermanentBase) AddDamage(damage int) {
- p.Damage += damage
+ p.damage += damage
}
-func (p *PermanentBase) Swimming() bool {
- if p.Card.Type == UnitType {
- return parseMovement(p.Card.getCanonicalValues("movement")).Swimming
- } else {
- return p.Card.hasEffect("swimming")
+func (p *PermanentBase) Effects() []string {
+ return append(p.card.getEffects(), p.tmpEffects...)
+}
+
+func (p *PermanentBase) HasEffect(effect string) bool {
+ return slices.Contains(p.tmpEffects, effect) || p.card.hasEffect(effect)
+}
+
+func (p *PermanentBase) XEffect(effect string) (int, error) {
+ x, err := p.card.getXEffect(effect)
+
+ for _, e := range p.tmpEffects {
+ if !strings.Contains(e, effect) {
+ continue
+ }
+
+ tokens := strings.SplitN(e, " ", 2)
+ tmpX, err := strconv.Atoi(tokens[1])
+ if err != nil {
+ return 0, err
+ }
+ x += tmpX
}
+
+ return x, err
}