1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace Stratadox\CardGame\Match\Command; |
4
|
|
|
|
5
|
|
|
use function assert; |
6
|
|
|
use Stratadox\CardGame\CorrelationId; |
7
|
|
|
use Stratadox\CardGame\Match\MatchId; |
8
|
|
|
|
9
|
|
|
final class Block |
10
|
|
|
{ |
11
|
|
|
/** @var int|null */ |
12
|
|
|
private $attacker; |
13
|
|
|
/** @var int|null */ |
14
|
|
|
private $defender; |
15
|
|
|
/** @var int|null */ |
16
|
|
|
private $player; |
17
|
|
|
/** @var MatchId|null */ |
18
|
|
|
private $match; |
19
|
|
|
/** @var CorrelationId|null */ |
20
|
|
|
private $correlationId; |
21
|
|
|
|
22
|
|
|
private function __construct( |
23
|
|
|
?int $attacker, |
24
|
|
|
?int $defender, |
25
|
|
|
?int $player, |
26
|
|
|
?MatchId $match, |
27
|
|
|
?CorrelationId $correlationId |
28
|
|
|
) { |
29
|
|
|
$this->attacker = $attacker; |
30
|
|
|
$this->defender = $defender; |
31
|
|
|
$this->player = $player; |
32
|
|
|
$this->match = $match; |
33
|
|
|
$this->correlationId = $correlationId; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
public static function theAttack(): self |
37
|
|
|
{ |
38
|
|
|
return new self(null, null, null, null, null); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function ofAttacker(int $attacker): self |
42
|
|
|
{ |
43
|
|
|
$clone = clone $this; |
44
|
|
|
$clone->attacker = $attacker; |
45
|
|
|
return $clone; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function withDefender(int $defender): self |
49
|
|
|
{ |
50
|
|
|
$clone = clone $this; |
51
|
|
|
$clone->defender = $defender; |
52
|
|
|
return $clone; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function as(int $player): self |
56
|
|
|
{ |
57
|
|
|
$clone = clone $this; |
58
|
|
|
$clone->player = $player; |
59
|
|
|
return $clone; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public function in(MatchId $match): self |
63
|
|
|
{ |
64
|
|
|
$clone = clone $this; |
65
|
|
|
$clone->match = $match; |
66
|
|
|
return $clone; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
public function trackedWith(CorrelationId $correlationId): self |
70
|
|
|
{ |
71
|
|
|
$clone = clone $this; |
72
|
|
|
$clone->correlationId = $correlationId; |
73
|
|
|
return $clone; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
public function go(): BlockTheAttacker |
77
|
|
|
{ |
78
|
|
|
assert($this->attacker !== null); |
79
|
|
|
assert($this->defender !== null); |
80
|
|
|
assert($this->player !== null); |
81
|
|
|
assert($this->match !== null); |
82
|
|
|
assert($this->correlationId !== null); |
83
|
|
|
return BlockTheAttacker::number( |
84
|
|
|
$this->attacker, |
85
|
|
|
$this->defender, |
86
|
|
|
$this->player, |
87
|
|
|
$this->match, |
88
|
|
|
$this->correlationId |
89
|
|
|
); |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
|