aboutsummaryrefslogtreecommitdiff
path: root/go/game/equipment.go
blob: 32bb358ca5663f77b825079b4207c09f5544b57d (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
package game

type Equipment struct {
	Artifact
	Durability int
}

func newEquipmentFromPath(cardPath string, containing interface{}, owner *Player) *Equipment {
	card := NewCard(cardPath)
	return newEquipment(card, containing, owner)
}

func newEquipment(card *Card, containing interface{}, owner *Player) *Equipment {
	e := &Equipment{
		*NewArtifact(card, nil, owner),
		card.Values["durability"].(int),
	}

	if containing != nil {
		switch containing := containing.(type) {
		case *Tile:
			e.tile = containing
		case *Unit:
			addPermanentToPile(containing, e)
		}
	}

	return e
}

func (e *Equipment) onDrop(p Permanent) {
	e.permanentBase.onDrop(p)
	e.Durability--
	if e.Durability < 1 {
		e.Controller().gameState.destroyPermanent(e)
		return
	}
}