summaryrefslogtreecommitdiff
path: root/engine/play/play.go
blob: 42d9fa3b96763e1e3bee321a19bc47fbe095e2a7 (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
package play

import (
	"sakura/engine"
	"sakura/engine/card"
	"sakura/engine/card/predicate"
)

func Card(g *engine.Game, p *engine.Player, anyCard engine.IsCard) {
	switch c := anyCard.(type) {
	case card.IsAttack:
		Attack(g, p, c)
	}
	g.Stack = append(g.Stack, anyCard)
}

func Attack(g *engine.Game, p *engine.Player, a card.IsAttack) {
	att := a.Attack()
	opp := p.Opponent(g)
	if !att.Unreactable && opp.Hand.Contains(predicate.ReactionApplicable) {
		reactions := opp.Hand.Filter(predicate.ReactionApplicable)
		acs := make([]engine.Action, len(reactions), len(reactions))
		for i, r := range reactions {
			acs[i] = &engine.PlayCard{
				BaseAction: &engine.BaseAction{
					User:       p,
					BaseSource: r,
				},
			}
		}
		g.May = engine.Interactions(acs...)
	}
	switch {
	case att.AuraDamage == card.Unselectable:
		opp.Life.Subtract(att.LifeDamage.Value())
	case att.LifeDamage == card.Unselectable:
		opp.Aura.Subtract(att.AuraDamage.Value())
	case att.AuraDamage.Value() > opp.Aura.Value:
		opp.Life.Subtract(att.LifeDamage.Value())
	default:
		g.Actions = engine.Interactions(&engine.DesignateDamage{
			Attacker:   p,
			Defender:   opp,
			SourceCard: a.Attack().Card,
		})
	}
}

func Vigor(g *engine.Game, p *engine.Player, a engine.VigorAction) {
	a.From(p).Subtract(1)
	a.To(p).Add(1)
}