1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace Stratadox\CardGame\Match; |
4
|
|
|
|
5
|
|
|
// @todo remove reference to foreign context |
6
|
|
|
use Stratadox\CardGame\Deck\CardId; |
7
|
|
|
use Stratadox\CardGame\Match\Event\CardWasDrawn; |
8
|
|
|
use Stratadox\CardGame\Match\Event\UnitDied; |
9
|
|
|
use Stratadox\CardGame\Match\Event\UnitMovedIntoPlay; |
10
|
|
|
use Stratadox\CardGame\Match\Event\UnitMovedToAttack; |
11
|
|
|
use Stratadox\CardGame\Match\Event\UnitRegrouped; |
12
|
|
|
|
13
|
|
|
final class UnitTemplate implements CardTemplate |
14
|
|
|
{ |
15
|
|
|
private $card; |
16
|
|
|
private $cost; |
17
|
|
|
|
18
|
|
|
public function __construct(CardId $card, Mana $cost) |
19
|
|
|
{ |
20
|
|
|
$this->card = $card; |
21
|
|
|
$this->cost = $cost; |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
public function playingEvents( |
25
|
|
|
MatchId $match, |
26
|
|
|
int $player, |
27
|
|
|
int $offset |
28
|
|
|
): array { |
29
|
|
|
return [new UnitMovedIntoPlay($match, $this->card, $player, $offset)]; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
public function drawingEvents( |
33
|
|
|
MatchId $match, |
34
|
|
|
int $player, |
35
|
|
|
int $offset |
36
|
|
|
): array { |
37
|
|
|
return [new CardWasDrawn($match, $this->card, $player, $offset)]; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function attackingEvents( |
41
|
|
|
MatchId $match, |
42
|
|
|
int $player, |
43
|
|
|
int $offset |
44
|
|
|
): array { |
45
|
|
|
return [new UnitMovedToAttack($match, $player, $offset)]; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function defendingEvents( |
49
|
|
|
MatchId $match, |
50
|
|
|
int $player, |
51
|
|
|
int $offset |
52
|
|
|
): array { |
53
|
|
|
// @todo add UnitMovedToDefend? |
54
|
|
|
return []; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function dyingEvents( |
58
|
|
|
MatchId $match, |
59
|
|
|
int $player, |
60
|
|
|
int $offset |
61
|
|
|
): array { |
62
|
|
|
return [new UnitDied($match, $player, $offset)]; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
public function regroupingEvents( |
66
|
|
|
MatchId $match, |
67
|
|
|
int $player, |
68
|
|
|
int $offset |
69
|
|
|
): array { |
70
|
|
|
return [new UnitRegrouped($match, $player, $offset)]; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
public function playingMove(int $position): Location |
74
|
|
|
{ |
75
|
|
|
return Location::inPlay($position); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
public function attackingMove(int $position): Location |
79
|
|
|
{ |
80
|
|
|
return Location::attackingAt($position); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
public function defendingMove(int $position): Location |
84
|
|
|
{ |
85
|
|
|
return Location::defendingAgainst($position); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
public function regroupingMove(int $position): Location |
89
|
|
|
{ |
90
|
|
|
return Location::inPlay($position); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
public function cost(): Mana |
94
|
|
|
{ |
95
|
|
|
return $this->cost; |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
|