aboutsummaryrefslogtreecommitdiff
path: root/go/game/areaEffect.go
blob: ea97b31c1323fec35b217f46ad9c6fb8597a78fe (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
package game

type areaEffect interface {
	onEntering(Permanent)
	onLeaving(Permanent)
}

type dynamicAreaEffect struct {
	_onEntering func(Permanent)
	_onLeaving  func(Permanent)
}

func newDynamicAreaEffect(enter func(Permanent), leave func(Permanent)) *dynamicAreaEffect {
	return &dynamicAreaEffect{enter, leave}
}

func (e *dynamicAreaEffect) onEntering(p Permanent) {
	if e._onEntering != nil {
		e._onEntering(p)
	}
}

func (e *dynamicAreaEffect) onLeaving(p Permanent) {
	if e._onLeaving != nil {
		e._onLeaving(p)
	}
}

func newGrantFullActionEffect(cardPath string, f ActionFuncPrototype, desc, tag string,
) *dynamicAreaEffect {
	onEntering := func(p Permanent) {
		if p.Card().Path() != cardPath {
			return
		}

		u := p.(*Unit)
		fa := newFullAction(u, f, desc)
		fa.tag = tag
		u.FullActions = append(u.FullActions, fa)
	}

	onLeaving := func(p Permanent) {
		if p.Card().Path() != cardPath {
			return
		}
		u := p.(*Unit)
		u.removeFullAction(tag)
	}

	return newDynamicAreaEffect(onEntering, onLeaving)
}