1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Stu\Module\Spacecraft\Lib\Damage; |
6
|
|
|
|
7
|
|
|
use Override; |
|
|
|
|
8
|
|
|
use Stu\Component\Spacecraft\System\SpacecraftSystemManagerInterface; |
9
|
|
|
use Stu\Component\Spacecraft\System\SpacecraftSystemModeEnum; |
10
|
|
|
use Stu\Lib\Damage\DamageWrapper; |
11
|
|
|
use Stu\Lib\Information\InformationInterface; |
12
|
|
|
use Stu\Module\Spacecraft\Lib\SpacecraftWrapperInterface; |
13
|
|
|
use Stu\Orm\Entity\SpacecraftSystem; |
14
|
|
|
|
15
|
|
|
//TODO unit tests and move to Lib/Damage |
16
|
|
|
final class SystemDamage implements SystemDamageInterface |
17
|
|
|
{ |
18
|
1 |
|
public function __construct( |
19
|
|
|
private SpacecraftSystemManagerInterface $spacecraftSystemManager |
20
|
1 |
|
) {} |
21
|
|
|
|
22
|
1 |
|
#[Override] |
23
|
|
|
public function checkForDamagedShipSystems( |
24
|
|
|
SpacecraftWrapperInterface $wrapper, |
25
|
|
|
DamageWrapper $damageWrapper, |
26
|
|
|
int $huelleVorher, |
27
|
|
|
InformationInterface $informations |
28
|
|
|
): bool { |
29
|
1 |
|
$ship = $wrapper->get(); |
30
|
1 |
|
$systemsToDamage = ceil($huelleVorher * 6 / $ship->getMaxHull()) - |
31
|
1 |
|
ceil($ship->getCondition()->getHull() * 6 / $ship->getMaxHull()); |
32
|
|
|
|
33
|
1 |
|
if ($systemsToDamage == 0) { |
34
|
1 |
|
return false; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
for ($i = 1; $i <= $systemsToDamage; $i++) { |
38
|
|
|
$this->damageRandomShipSystem($wrapper, $damageWrapper, $informations); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
return true; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
#[Override] |
45
|
|
|
public function destroyRandomShipSystem(SpacecraftWrapperInterface $wrapper, DamageWrapper $damageWrapper): ?string |
46
|
|
|
{ |
47
|
|
|
$healthySystems = $this->getHealthySystems($wrapper, $damageWrapper); |
48
|
|
|
shuffle($healthySystems); |
49
|
|
|
|
50
|
|
|
if ($healthySystems === []) { |
51
|
|
|
return null; |
52
|
|
|
} |
53
|
|
|
$system = $healthySystems[0]; |
54
|
|
|
$system->setStatus(0); |
55
|
|
|
$system->setMode(SpacecraftSystemModeEnum::MODE_OFF); |
56
|
|
|
$this->spacecraftSystemManager->handleDestroyedSystem($wrapper, $healthySystems[0]->getSystemType()); |
57
|
|
|
|
58
|
|
|
return $healthySystems[0]->getSystemType()->getDescription(); |
59
|
|
|
} |
60
|
|
|
|
61
|
1 |
|
#[Override] |
62
|
|
|
public function damageRandomShipSystem( |
63
|
|
|
SpacecraftWrapperInterface $wrapper, |
64
|
|
|
DamageWrapper $damageWrapper, |
65
|
|
|
InformationInterface $informations, |
66
|
|
|
?int $percent = null |
67
|
|
|
): void { |
68
|
1 |
|
$healthySystems = $this->getHealthySystems($wrapper, $damageWrapper); |
69
|
1 |
|
shuffle($healthySystems); |
70
|
|
|
|
71
|
1 |
|
if ($healthySystems !== []) { |
72
|
1 |
|
$system = $healthySystems[0]; |
73
|
|
|
|
74
|
1 |
|
$this->damageShipSystem($wrapper, $system, $percent ?? random_int(1, 70), $informations); |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** @return array<SpacecraftSystem> */ |
79
|
1 |
|
private function getHealthySystems(SpacecraftWrapperInterface $wrapper, DamageWrapper $damageWrapper): array |
80
|
|
|
{ |
81
|
1 |
|
return $wrapper->get()->getSystems() |
82
|
1 |
|
->filter(fn(SpacecraftSystem $system): bool => $damageWrapper->canDamageSystem($system->getSystemType())) |
83
|
1 |
|
->filter(fn(SpacecraftSystem $system): bool => $system->getStatus() > 0) |
84
|
1 |
|
->filter(fn(SpacecraftSystem $system): bool => $system->getSystemType()->canBeDamaged()) |
85
|
1 |
|
->toArray(); |
86
|
|
|
} |
87
|
|
|
|
88
|
1 |
|
#[Override] |
89
|
|
|
public function damageShipSystem( |
90
|
|
|
SpacecraftWrapperInterface $wrapper, |
91
|
|
|
SpacecraftSystem $system, |
92
|
|
|
int $dmg, |
93
|
|
|
InformationInterface $informations |
94
|
|
|
): bool { |
95
|
1 |
|
$status = $system->getStatus(); |
96
|
1 |
|
$systemName = $system->getSystemType()->getDescription(); |
97
|
|
|
|
98
|
1 |
|
if ($status > $dmg) { |
99
|
1 |
|
$system->setStatus($status - $dmg); |
100
|
1 |
|
$this->spacecraftSystemManager->handleDamagedSystem($wrapper, $system->getSystemType()); |
101
|
1 |
|
$informations->addInformation("- Folgendes System wurde beschädigt: " . $systemName); |
102
|
|
|
|
103
|
1 |
|
return false; |
104
|
|
|
} else { |
105
|
1 |
|
$system->setStatus(0); |
106
|
1 |
|
$system->setMode(SpacecraftSystemModeEnum::MODE_OFF); |
107
|
1 |
|
$this->spacecraftSystemManager->handleDestroyedSystem($wrapper, $system->getSystemType()); |
108
|
1 |
|
$informations->addInformation("- Der Schaden zerstört folgendes System: " . $systemName); |
109
|
|
|
|
110
|
1 |
|
return true; |
111
|
|
|
} |
112
|
|
|
} |
113
|
|
|
} |
114
|
|
|
|
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