aboutsummaryrefslogtreecommitdiff
path: root/go/game/artifact.go
blob: 6edc975a7334b77d6fd69259c03851971a9bf72f (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
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{newPermanentBase(card, tile, owner), 0}

	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) IsDestroyed() bool {
	return a.Solid > 0 && a.Damage() >= a.Solid
}

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