aboutsummaryrefslogtreecommitdiff
path: root/go/game/cardImplementations.go
blob: b20b46bc357d8907be9390a2c76f70d884b318b9 (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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package game

type farmerImplementation struct {
	cardImplementationBase
}

type advisorImplementation struct {
	cardImplementationBase
}

func (impl *advisorImplementation) fullAction(u *Unit) []*FullAction {
	resolvePrototype := func(a Action) ActionResolveFunc {
		u := a.Source().(*Unit)
		return func(s *State) {
			controller := u.Controller()
			controller.DrawN(1)
			cards := controller.PromptHandCardSelection(0, 1)
			if cards != nil {
				controller.Deck.MoveCard(cards[0], s.Exile)
			}
		}
	}
	return []*FullAction{NewFullAction(u, resolvePrototype, "draw 1. exile 1")}
}

type missionaryImplementation struct {
	cardImplementationBase
}

func (impl *missionaryImplementation) fullAction(u *Unit) []*FullAction {
	resolvePrototype := func(a Action) ActionResolveFunc {
		u := a.Source().(*Unit)
		target := a.Targets().sel[0].(*Unit)
		return func(s *State) {
			faith, found := target.States[UnitMarks.Faith]
			if !found {
				target.States[UnitMarks.Faith] = 2
			} else {
				target.States[UnitMarks.Faith] = faith + 2
				if faith+2 > target.Card().BuyCost {
					target.controller = u.Controller()
				}
			}
		}
	}
	return []*FullAction{NewFullAction(u, resolvePrototype, "put faith ...")}
}

type swordImplementation struct {
	cardImplementationBase
}

func (*swordImplementation) onPile(p Permanent) {
	if u, ok := p.(*Unit); ok && !INVALID_ATTACK(u.Attack) {
		u.Attack.attacks[0] += 1
	}
}

func (*swordImplementation) onDrop(p Permanent) {
	if u, ok := p.(*Unit); ok && !INVALID_ATTACK(u.Attack) {
		u.Attack.attacks[0] -= 1
	}
}

func init() {
	cardImplementations = map[string]cardImplementation{
		"base/advisor":    &advisorImplementation{},
		"base/missionary": &missionaryImplementation{},
		"base/sword":      &swordImplementation{},

		"misc/farmer": &farmerImplementation{},
	}
}