1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Stu\Module\Spacecraft\Lib\Battle\Provider; |
6
|
|
|
|
7
|
|
|
use Override; |
|
|
|
|
8
|
|
|
use RuntimeException; |
9
|
|
|
use Stu\Component\Spacecraft\System\SpacecraftSystemTypeEnum; |
10
|
|
|
use Stu\Module\Control\StuRandom; |
11
|
|
|
use Stu\Module\Spacecraft\Lib\Torpedo\ShipTorpedoManagerInterface; |
12
|
|
|
use Stu\Module\Spacecraft\Lib\SpacecraftWrapperInterface; |
13
|
|
|
use Stu\Orm\Entity\LocationInterface; |
14
|
|
|
use Stu\Orm\Entity\ModuleInterface; |
15
|
|
|
use Stu\Orm\Entity\SpacecraftInterface; |
16
|
|
|
use Stu\Orm\Entity\TorpedoTypeInterface; |
17
|
|
|
|
18
|
|
|
class SpacecraftAttacker extends AbstractEnergyAttacker implements ProjectileAttackerInterface |
19
|
|
|
{ |
20
|
25 |
|
public function __construct( |
21
|
|
|
private SpacecraftWrapperInterface $wrapper, |
22
|
|
|
private ShipTorpedoManagerInterface $shipTorpedoManager, |
23
|
|
|
private bool $isAttackingShieldsOnly, |
24
|
|
|
StuRandom $stuRandom |
25
|
|
|
) { |
26
|
25 |
|
parent::__construct($stuRandom); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
#[Override] |
30
|
|
|
public function isAvoidingHullHits(SpacecraftInterface $target): bool |
31
|
|
|
{ |
32
|
|
|
return $this->isAttackingShieldsOnly && !$target->isShielded(); |
33
|
|
|
} |
34
|
|
|
|
35
|
1 |
|
#[Override] |
36
|
|
|
public function getPhaserVolleys(): int |
37
|
|
|
{ |
38
|
1 |
|
return $this->get()->getRump()->getPhaserVolleys(); |
39
|
|
|
} |
40
|
|
|
|
41
|
1 |
|
#[Override] |
42
|
|
|
public function getPhaserState(): bool |
43
|
|
|
{ |
44
|
1 |
|
return $this->get()->getPhaserState(); |
45
|
|
|
} |
46
|
|
|
|
47
|
3 |
|
#[Override] |
48
|
|
|
public function hasSufficientEnergy(int $amount): bool |
49
|
|
|
{ |
50
|
3 |
|
$epsSystemData = $this->wrapper->getEpsSystemData(); |
51
|
3 |
|
if ($epsSystemData === null) { |
52
|
1 |
|
return false; |
53
|
|
|
} |
54
|
2 |
|
return $epsSystemData->getEps() >= $amount; |
55
|
|
|
} |
56
|
|
|
|
57
|
2 |
|
#[Override] |
58
|
|
|
public function getWeaponModule(): ModuleInterface |
59
|
|
|
{ |
60
|
2 |
|
if ($this->module === null) { |
61
|
2 |
|
$shipSystem = $this->get()->getSpacecraftSystem(SpacecraftSystemTypeEnum::PHASER); |
62
|
|
|
|
63
|
2 |
|
$module = $shipSystem->getModule(); |
64
|
2 |
|
if ($module === null) { |
65
|
1 |
|
throw new RuntimeException('weapon system should have a module'); |
66
|
|
|
} |
67
|
|
|
|
68
|
1 |
|
$this->module = $module; |
69
|
|
|
} |
70
|
|
|
|
71
|
1 |
|
return $this->module; |
|
|
|
|
72
|
|
|
} |
73
|
|
|
|
74
|
2 |
|
#[Override] |
75
|
|
|
public function getEnergyWeaponBaseDamage(): int |
76
|
|
|
{ |
77
|
2 |
|
$energyWeapon = $this->wrapper->getEnergyWeaponSystemData(); |
78
|
|
|
|
79
|
2 |
|
return $energyWeapon === null ? 0 : $energyWeapon->getBaseDamage(); |
80
|
|
|
} |
81
|
|
|
|
82
|
2 |
|
#[Override] |
83
|
|
|
public function reduceEps(int $amount): void |
84
|
|
|
{ |
85
|
2 |
|
$epsSystemData = $this->wrapper->getEpsSystemData(); |
86
|
2 |
|
if ($epsSystemData === null) { |
87
|
1 |
|
return; |
88
|
|
|
} |
89
|
1 |
|
$epsSystemData->lowerEps($amount)->update(); |
90
|
|
|
} |
91
|
|
|
|
92
|
1 |
|
#[Override] |
93
|
|
|
public function getName(): string |
94
|
|
|
{ |
95
|
1 |
|
return $this->get()->getName(); |
96
|
|
|
} |
97
|
|
|
|
98
|
1 |
|
#[Override] |
99
|
|
|
public function getUserId(): int |
100
|
|
|
{ |
101
|
1 |
|
return $this->get()->getUser()->getId(); |
102
|
|
|
} |
103
|
|
|
|
104
|
16 |
|
private function get(): SpacecraftInterface |
105
|
|
|
{ |
106
|
16 |
|
return $this->wrapper->get(); |
107
|
|
|
} |
108
|
|
|
|
109
|
1 |
|
#[Override] |
110
|
|
|
public function getHitChance(): int |
111
|
|
|
{ |
112
|
1 |
|
return $this->get()->getHitChance(); |
113
|
|
|
} |
114
|
|
|
|
115
|
1 |
|
#[Override] |
116
|
|
|
public function getPhaserShieldDamageFactor(): int |
117
|
|
|
{ |
118
|
1 |
|
return $this->get()->getRump()->getPhaserShieldDamageFactor(); |
119
|
|
|
} |
120
|
|
|
|
121
|
1 |
|
#[Override] |
122
|
|
|
public function getPhaserHullDamageFactor(): int |
123
|
|
|
{ |
124
|
1 |
|
return $this->get()->getRump()->getPhaserHullDamageFactor(); |
125
|
|
|
} |
126
|
|
|
|
127
|
1 |
|
#[Override] |
128
|
|
|
public function getTorpedoVolleys(): int |
129
|
|
|
{ |
130
|
1 |
|
return $this->get()->getRump()->getTorpedoVolleys(); |
131
|
|
|
} |
132
|
|
|
|
133
|
1 |
|
#[Override] |
134
|
|
|
public function getTorpedoState(): bool |
135
|
|
|
{ |
136
|
1 |
|
return $this->get()->getTorpedoState(); |
137
|
|
|
} |
138
|
|
|
|
139
|
1 |
|
#[Override] |
140
|
|
|
public function getTorpedoCount(): int |
141
|
|
|
{ |
142
|
1 |
|
return $this->get()->getTorpedoCount(); |
143
|
|
|
} |
144
|
|
|
|
145
|
4 |
|
#[Override] |
146
|
|
|
public function getTorpedo(): ?TorpedoTypeInterface |
147
|
|
|
{ |
148
|
4 |
|
return $this->get()->getTorpedo(); |
149
|
|
|
} |
150
|
|
|
|
151
|
1 |
|
#[Override] |
152
|
|
|
public function lowerTorpedoCount(int $amount): void |
153
|
|
|
{ |
154
|
1 |
|
$this->shipTorpedoManager->changeTorpedo($this->wrapper, -$amount); |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
#[Override] |
158
|
|
|
public function isShieldPenetration(): bool |
159
|
|
|
{ |
160
|
|
|
$systemData = $this->wrapper->getProjectileLauncherSystemData(); |
161
|
|
|
if ($systemData === null) { |
162
|
|
|
throw new RuntimeException('this should not happen'); |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
return $this->stuRandom->rand(1, 10000) <= $systemData->getShieldPenetration(); |
166
|
|
|
} |
167
|
|
|
|
168
|
3 |
|
#[Override] |
169
|
|
|
public function getProjectileWeaponDamage(bool $isCritical): int |
170
|
|
|
{ |
171
|
3 |
|
$torpedo = $this->getTorpedo(); |
172
|
3 |
|
if ($torpedo === null) { |
173
|
1 |
|
return 0; |
174
|
|
|
} |
175
|
|
|
|
176
|
2 |
|
$module = $this->get()->getSpacecraftSystem(SpacecraftSystemTypeEnum::TORPEDO)->getModule(); |
177
|
2 |
|
if ($module === null) { |
178
|
1 |
|
return 0; |
179
|
|
|
} |
180
|
|
|
|
181
|
1 |
|
$variance = (int) round($torpedo->getBaseDamage() / 100 * $torpedo->getVariance()); |
182
|
1 |
|
$basedamage = $torpedo->getBaseDamage(); |
183
|
1 |
|
$damage = random_int($basedamage - $variance, $basedamage + $variance); |
184
|
|
|
|
185
|
1 |
|
return $isCritical ? $damage * 2 : $damage; |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
#[Override] |
189
|
|
|
public function getLocation(): LocationInterface |
190
|
|
|
{ |
191
|
|
|
return $this->get()->getLocation(); |
192
|
|
|
} |
193
|
|
|
} |
194
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths