aboutsummaryrefslogtreecommitdiff
path: root/go/game/artifact.go
blob: eb9673acccf97d6c26f4f940fe55e6f7cb9c2ef9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package game

import (
	"log"
	"strconv"
	"strings"
)

type Artifact struct {
	permanentBase
	Solid int
}

func NewArtifactFromPath(cardPath string, tile *Tile, owner *Player) *Artifact {
	card := NewCard(cardPath)
	return NewArtifact(card, tile, owner)
}

func NewArtifact(card *Card, tile *Tile, owner *Player) *Artifact {
	a := &Artifact{
		permanentBase: permanentBase{card: card, owner: owner, controller: owner},
	}

	effects := card.getEffects()
	for _, e := range effects {
		if strings.HasPrefix(e, "Solid") {
			tokens := strings.Split(e, " ")
			var err error
			a.Solid, err = strconv.Atoi(tokens[1])
			if err != nil {
				log.Panicf("Invalid Solid definition %s\n", e)
			}
		}
	}

	return a
}

func (a *Artifact) String() string {
	return FmtPermanent(a)
}

func (a *Artifact) IsDestroyed() bool {
	return a.Solid > 0 && a.Damage() >= a.Solid
}

func (a *Artifact) Attackable() bool {
	return a.permanentBase.Attackable() && a.Solid > 0
}