|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace AardsGerds\Game\Player; |
|
6
|
|
|
|
|
7
|
|
|
use AardsGerds\Game\Build\Attribute\AttributePoints; |
|
8
|
|
|
use AardsGerds\Game\Build\Attribute\Etherum; |
|
9
|
|
|
use AardsGerds\Game\Build\Attribute\Health; |
|
10
|
|
|
use AardsGerds\Game\Build\Attribute\Strength; |
|
11
|
|
|
use AardsGerds\Game\Build\Experience; |
|
12
|
|
|
use AardsGerds\Game\Build\LevelProgress; |
|
13
|
|
|
use AardsGerds\Game\Build\Talent\SecretKnowledge\Ascension; |
|
14
|
|
|
use AardsGerds\Game\Build\Talent\TalentCollection; |
|
15
|
|
|
use AardsGerds\Game\Build\Talent\TalentPoints; |
|
16
|
|
|
use AardsGerds\Game\Entity\Entity; |
|
17
|
|
|
use AardsGerds\Game\Inventory\Inventory; |
|
18
|
|
|
use AardsGerds\Game\Inventory\Weapon\Weapon; |
|
19
|
|
|
|
|
20
|
|
|
final class Player extends Entity |
|
21
|
|
|
{ |
|
22
|
|
|
public function __construct( |
|
23
|
|
|
string $name, |
|
24
|
|
|
Health $health, |
|
25
|
|
|
Etherum $etherum, |
|
26
|
|
|
Strength $strength, |
|
27
|
|
|
TalentCollection $talentCollection, |
|
28
|
|
|
Inventory $inventory, |
|
29
|
|
|
?Weapon $weapon, |
|
30
|
|
|
bool $corrupted, |
|
31
|
|
|
private LevelProgress $levelProgress, |
|
32
|
|
|
private AttributePoints $attributePoints, |
|
33
|
|
|
private TalentPoints $talentPoints, |
|
34
|
|
|
) { |
|
35
|
|
|
parent::__construct( |
|
36
|
|
|
$name, |
|
37
|
|
|
$health, |
|
38
|
|
|
$etherum, |
|
39
|
|
|
$strength, |
|
40
|
|
|
$talentCollection, |
|
41
|
|
|
$inventory, |
|
42
|
|
|
$weapon, |
|
43
|
|
|
$corrupted, |
|
44
|
|
|
); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
public function getLevelProgress(): LevelProgress |
|
48
|
|
|
{ |
|
49
|
|
|
return $this->levelProgress; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
public function increaseExperience(Experience $experience): void |
|
53
|
|
|
{ |
|
54
|
|
|
$this->levelProgress->increase($experience, $this); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* @throws PlayerException |
|
59
|
|
|
*/ |
|
60
|
|
|
public function increaseEtherum(Etherum $etherum): void |
|
61
|
|
|
{ |
|
62
|
|
|
$this->etherum->increaseBy($etherum); |
|
63
|
|
|
|
|
64
|
|
|
if ($this->isCorrupted()) { |
|
65
|
|
|
return; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
$playerAscension = $this->talentCollection->findSecretKnowledge()?->getAscension() |
|
69
|
|
|
?? throw PlayerException::etherumOverdose(); |
|
70
|
|
|
|
|
71
|
|
|
$corruptionBoundary = $this->calculateCorruptionBoundary(); |
|
72
|
|
|
|
|
73
|
|
|
if (!$this->isCorrupted() && $this->etherum->isGreaterThanOrEqual($corruptionBoundary)) { |
|
74
|
|
|
if ($playerAscension->isLowerThan(Ascension::sixthAscension())) { |
|
75
|
|
|
throw PlayerException::etherumOverdose(); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
$this->corrupted = true; |
|
79
|
|
|
} |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
public function getAttributePoints(): AttributePoints |
|
83
|
|
|
{ |
|
84
|
|
|
return $this->attributePoints; |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
public function getTalentPoints(): TalentPoints |
|
88
|
|
|
{ |
|
89
|
|
|
return $this->talentPoints; |
|
90
|
|
|
} |
|
91
|
|
|
} |
|
92
|
|
|
|