1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace Stratadox\CardGame\Match; |
4
|
|
|
|
5
|
|
|
use Stratadox\CardGame\DomainEventRecorder; |
6
|
|
|
use Stratadox\CardGame\DomainEventRecording; |
7
|
|
|
|
8
|
|
|
final class Card implements DomainEventRecorder |
9
|
|
|
{ |
10
|
|
|
use DomainEventRecording; |
11
|
|
|
|
12
|
|
|
private $location; |
13
|
|
|
private $template; |
14
|
|
|
|
15
|
|
|
private function __construct(Location $location, CardTemplate $template) |
16
|
|
|
{ |
17
|
|
|
$this->location = $location; |
18
|
|
|
$this->template = $template; |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
public static function inDeck(int $position, CardTemplate $template): self |
22
|
|
|
{ |
23
|
|
|
return new self(Location::inDeck($position), $template); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
public function isInDeck(): bool |
27
|
|
|
{ |
28
|
|
|
return $this->location->isInDeck(); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
public function isInHand(): bool |
32
|
|
|
{ |
33
|
|
|
return $this->location->isInHand(); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
public function isInPlay(): bool |
37
|
|
|
{ |
38
|
|
|
return $this->location->isInPlay(); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function isAttacking(): bool |
42
|
|
|
{ |
43
|
|
|
return $this->location->isAttacking(); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public function isDefending(): bool |
47
|
|
|
{ |
48
|
|
|
return $this->location->isDefending(); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function isAttackingThe(Card $defender): bool |
52
|
|
|
{ |
53
|
|
|
return $this->location->isAttackingThe($defender->location); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function hasHigherPositionThan(Card $other): bool |
57
|
|
|
{ |
58
|
|
|
return $this->location->hasHigherPositionThan($other->location); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
public function draw(MatchId $match, int $position, int $player): void |
62
|
|
|
{ |
63
|
|
|
$this->location = $this->location->toHand($position); |
64
|
|
|
$this->happened(...$this->template->drawingEvents($match, $player)); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
public function play(MatchId $match, int $position, int $player): void |
68
|
|
|
{ |
69
|
|
|
$this->location = $this->template->playingMove($position); |
70
|
|
|
$this->happened(...$this->template->playingEvents($match, $player)); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
public function sendToAttack(MatchId $match, int $position, int $player): void |
74
|
|
|
{ |
75
|
|
|
$this->location = $this->template->attackingMove($position); |
76
|
|
|
$this->happened(...$this->template->attackingEvents($match, $player)); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
public function sendToDefendAgainst(MatchId $match, int $position, int $player): void |
80
|
|
|
{ |
81
|
|
|
$this->location = $this->template->defendingMove($position); |
82
|
|
|
$this->happened(...$this->template->defendingEvents($match, $player)); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
public function counterAttack(MatchId $match, Card $attacker): void |
86
|
|
|
{ |
87
|
|
|
// kill 'm for now... @todo combat mechanics |
88
|
|
|
$attacker->location = Location::inVoid(); |
89
|
|
|
$this->happened(...$attacker->template->dyingEvents($match)); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
public function cost(): Mana |
93
|
|
|
{ |
94
|
|
|
return $this->template->cost(); |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
|