|
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\Experience; |
|
9
|
|
|
use AardsGerds\Game\Build\Level; |
|
10
|
|
|
use AardsGerds\Game\Build\LevelProgress; |
|
11
|
|
|
use AardsGerds\Game\Build\Talent\TalentPoints; |
|
12
|
|
|
|
|
13
|
|
|
final class Player |
|
14
|
|
|
{ |
|
15
|
|
|
public function __construct( |
|
16
|
|
|
private string $name, |
|
17
|
|
|
private LevelProgress $levelProgress, |
|
18
|
|
|
private AttributePoints $attributePoints, |
|
19
|
|
|
private TalentPoints $talentPoints, |
|
20
|
|
|
) {} |
|
21
|
|
|
|
|
22
|
|
|
public static function unserialize(array $data): self |
|
23
|
|
|
{ |
|
24
|
|
|
return new self( |
|
25
|
|
|
$data['name'], |
|
26
|
|
|
new LevelProgress( |
|
27
|
|
|
new Level($data['level']), |
|
28
|
|
|
new Experience($data['current_experience']), |
|
29
|
|
|
), |
|
30
|
|
|
new AttributePoints($data['attribute_points']), |
|
31
|
|
|
new TalentPoints($data['talent_points']), |
|
32
|
|
|
); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
public function serialize(): array |
|
36
|
|
|
{ |
|
37
|
|
|
return [ |
|
38
|
|
|
'name' => $this->name, |
|
39
|
|
|
'level' => $this->levelProgress->getLevel()->get(), |
|
40
|
|
|
'current_experience' => $this->levelProgress->getCurrentExperience()->get(), |
|
41
|
|
|
'attribute_points' => $this->attributePoints->get(), |
|
42
|
|
|
'talent_points' => $this->talentPoints->get(), |
|
43
|
|
|
]; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
public function increaseExperience(Experience $experience): void |
|
47
|
|
|
{ |
|
48
|
|
|
$this->levelProgress->increase($experience, $this); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
public function getAttributePoints(): AttributePoints |
|
52
|
|
|
{ |
|
53
|
|
|
return $this->attributePoints; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
public function getTalentPoints(): TalentPoints |
|
57
|
|
|
{ |
|
58
|
|
|
return $this->talentPoints; |
|
59
|
|
|
} |
|
60
|
|
|
} |
|
61
|
|
|
|