|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace AardsGerds\Game\Entity; |
|
6
|
|
|
|
|
7
|
|
|
use AardsGerds\Game\Build\Attribute\Etherum; |
|
8
|
|
|
use AardsGerds\Game\Build\Attribute\Health; |
|
9
|
|
|
use AardsGerds\Game\Build\Attribute\Initiative; |
|
10
|
|
|
use AardsGerds\Game\Build\Attribute\Strength; |
|
11
|
|
|
use AardsGerds\Game\Build\Talent\SecretKnowledge\Ascension; |
|
12
|
|
|
use AardsGerds\Game\Build\Talent\TalentCollection; |
|
13
|
|
|
use AardsGerds\Game\Build\Talent\WeaponMastery\WeaponMasteryLevel; |
|
14
|
|
|
use AardsGerds\Game\Fight\Fighter; |
|
15
|
|
|
use AardsGerds\Game\Inventory\Inventory; |
|
16
|
|
|
use AardsGerds\Game\Inventory\Weapon\Weapon; |
|
17
|
|
|
use AardsGerds\Game\Shared\IntegerValueException; |
|
18
|
|
|
|
|
19
|
|
|
abstract class Entity implements Fighter |
|
20
|
|
|
{ |
|
21
|
6 |
|
public function __construct( |
|
22
|
|
|
protected string $name, |
|
23
|
|
|
protected Health $health, |
|
24
|
|
|
protected Etherum $etherum, |
|
25
|
|
|
protected Strength $strength, |
|
26
|
|
|
protected Initiative $initiative, |
|
27
|
|
|
protected TalentCollection $talentCollection, |
|
28
|
|
|
protected Inventory $inventory, |
|
29
|
|
|
protected ?Weapon $weapon, |
|
30
|
|
|
protected bool $corrupted = false, // @todo: vo |
|
31
|
6 |
|
) {} |
|
32
|
|
|
|
|
33
|
6 |
|
public function getName(): string |
|
34
|
|
|
{ |
|
35
|
6 |
|
return $this->name; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
6 |
|
public function getHealth(): Health |
|
39
|
|
|
{ |
|
40
|
6 |
|
return $this->health; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
1 |
|
public function getEtherum(): Etherum |
|
44
|
|
|
{ |
|
45
|
1 |
|
return $this->etherum; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
6 |
|
public function getStrength(): Strength |
|
49
|
|
|
{ |
|
50
|
6 |
|
return $this->strength; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
6 |
|
public function getInitiative(): Initiative |
|
54
|
|
|
{ |
|
55
|
6 |
|
return $this->initiative; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
6 |
|
public function getTalents(): TalentCollection |
|
59
|
|
|
{ |
|
60
|
6 |
|
return $this->talentCollection; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
4 |
|
public function getWeaponMasteryLevel(): WeaponMasteryLevel |
|
64
|
|
|
{ |
|
65
|
4 |
|
if ($this->weapon === null) { |
|
66
|
2 |
|
return WeaponMasteryLevel::inexperienced(); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
4 |
|
$weaponMastery = $this->talentCollection->findWeaponMasteryForWeaponType($this->weapon->getType()); |
|
70
|
4 |
|
if ($weaponMastery === null) { |
|
71
|
|
|
return WeaponMasteryLevel::inexperienced(); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
4 |
|
return $weaponMastery->getLevel(); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
2 |
|
public function getInventory(): Inventory |
|
78
|
|
|
{ |
|
79
|
2 |
|
return $this->inventory; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
6 |
|
public function getWeapon(): ?Weapon |
|
83
|
|
|
{ |
|
84
|
6 |
|
return $this->weapon; |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
5 |
|
public function isCorrupted(): bool |
|
88
|
|
|
{ |
|
89
|
5 |
|
return $this->corrupted; |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
public function __toString(): string |
|
93
|
|
|
{ |
|
94
|
|
|
return $this->name; |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
3 |
|
protected function calculateCorruptionBoundary(): Etherum |
|
98
|
|
|
{ |
|
99
|
3 |
|
$ascension = $this->talentCollection->findSecretKnowledge()?->getAscension(); |
|
100
|
3 |
|
if ($ascension === null) { |
|
101
|
|
|
return new Etherum(2); |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
try { |
|
105
|
3 |
|
$nextAscensionEtherum = (new Ascension($ascension->get()))->increment()->getRequiredEtherum(); |
|
106
|
1 |
|
} catch (IntegerValueException) { |
|
107
|
|
|
// entity has 8th ascension |
|
108
|
1 |
|
$nextAscensionEtherum = new Etherum(Ascension::eighthAscension()->getRequiredEtherum()->get() * 2); |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
// etherum required by next ascension + 0.5 x etherum required by next ascension |
|
112
|
3 |
|
return $nextAscensionEtherum->increaseBy( |
|
113
|
3 |
|
new Etherum((int) ($nextAscensionEtherum->get() * 0.5)), |
|
114
|
|
|
); |
|
115
|
|
|
} |
|
116
|
|
|
} |
|
117
|
|
|
|