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\UnitMovedToDefend; |
12
|
|
|
use Stratadox\CardGame\Match\Event\UnitRegrouped; |
13
|
|
|
|
14
|
|
|
final class UnitTemplate implements CardTemplate |
15
|
|
|
{ |
16
|
|
|
private $card; |
17
|
|
|
private $cost; |
18
|
|
|
|
19
|
|
|
public function __construct(CardId $card, Mana $cost) |
20
|
|
|
{ |
21
|
|
|
$this->card = $card; |
22
|
|
|
$this->cost = $cost; |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
public function playingEvents( |
26
|
|
|
MatchId $match, |
27
|
|
|
int $player, |
28
|
|
|
int $offset |
29
|
|
|
): array { |
30
|
|
|
return [new UnitMovedIntoPlay($match, $this->card, $player, $offset)]; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
public function drawingEvents( |
34
|
|
|
MatchId $match, |
35
|
|
|
int $player, |
36
|
|
|
int $offset |
37
|
|
|
): array { |
38
|
|
|
return [new CardWasDrawn($match, $this->card, $player, $offset)]; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function attackingEvents( |
42
|
|
|
MatchId $match, |
43
|
|
|
int $player, |
44
|
|
|
int $offset |
45
|
|
|
): array { |
46
|
|
|
return [new UnitMovedToAttack($match, $player, $offset)]; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function defendingEvents( |
50
|
|
|
MatchId $match, |
51
|
|
|
int $player, |
52
|
|
|
int $offset |
53
|
|
|
): array { |
54
|
|
|
return [new UnitMovedToDefend($match, $player, $offset)]; |
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
|
|
|
|