blob: 4dcfad415a892ce37f6a0c94e14ffbb89c3b749e (
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
|
package game
import (
"log"
)
type Equipment struct {
Artifact
Durability int
}
func newEquipmentFromPath(cardPath string, containing any, owner *Player) *Equipment {
card := NewCard(cardPath)
return newEquipment(card, containing, owner)
}
func newEquipment(card *Card, containing any, owner *Player) *Equipment {
e := &Equipment{
*NewArtifact(card, nil, owner),
int(card.Values["durability"].(uint64)),
}
if containing != nil {
switch containing := containing.(type) {
case *Tile:
e.tile = containing
case *Unit:
addPermanentToPile(containing, e)
default:
log.Panicf("unhandled containing type: %t\n", containing)
}
}
return e
}
func (e *Equipment) onDrop(p Permanent) {
e.permanentBase.onDrop(p)
e.Durability--
if e.Durability < 1 {
e.Controller().gameState.destroyPermanent(e)
return
}
}
|