1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Stu\Component\Spacecraft\Module; |
6
|
|
|
|
7
|
|
|
use Override; |
|
|
|
|
8
|
|
|
use Stu\Lib\Information\InformationInterface; |
9
|
|
|
use Stu\Lib\Transfer\EntityWithStorageInterface; |
10
|
|
|
use Stu\Lib\Transfer\Storage\StorageManagerInterface; |
11
|
|
|
use Stu\Module\Control\StuRandom; |
12
|
|
|
use Stu\Orm\Entity\ModuleInterface; |
13
|
|
|
use Stu\Orm\Entity\SpacecraftInterface; |
14
|
|
|
|
15
|
|
|
class ModuleRecycling implements ModuleRecyclingInterface |
16
|
|
|
{ |
17
|
5 |
|
public function __construct( |
18
|
|
|
private StorageManagerInterface $storageManager, |
19
|
|
|
private StuRandom $stuRandom |
20
|
5 |
|
) {} |
21
|
|
|
|
22
|
4 |
|
#[Override] |
23
|
|
|
public function retrieveSomeModules( |
24
|
|
|
SpacecraftInterface $spacecraft, |
25
|
|
|
EntityWithStorageInterface $entity, |
26
|
|
|
InformationInterface $information, |
27
|
|
|
int $recyclingChance = 50 |
28
|
|
|
): void { |
29
|
|
|
|
30
|
|
|
/** @var array<int, array{0: ModuleInterface, 1: int, 2: int}> */ |
31
|
4 |
|
$recycledModuleChances = []; |
32
|
|
|
|
33
|
4 |
|
$buildplan = $spacecraft->getBuildplan(); |
34
|
4 |
|
if ($buildplan === null) { |
35
|
1 |
|
return; |
36
|
|
|
} |
37
|
|
|
|
38
|
3 |
|
$buildplanModules = $buildplan->getModules(); |
39
|
|
|
|
40
|
|
|
// recycle installed systems based on health |
41
|
3 |
|
foreach ($spacecraft->getSystems() as $system) { |
42
|
|
|
|
43
|
1 |
|
$module = $system->getModule(); |
44
|
1 |
|
if ($module !== null) { |
45
|
1 |
|
if (!array_key_exists($module->getId(), $recycledModuleChances)) { |
46
|
|
|
|
47
|
1 |
|
$buildplanModule = $buildplanModules->get($module->getId()); |
48
|
1 |
|
$amount = $buildplanModule === null ? 1 : $buildplanModule->getModuleCount(); |
49
|
1 |
|
$chance = (int)ceil($recyclingChance * $system->getStatus() / 100); |
50
|
|
|
|
51
|
1 |
|
$recycledModuleChances[$module->getId()] = [$module, $amount, $chance]; |
52
|
|
|
} |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
// recycle buildplan modules |
57
|
3 |
|
foreach ($buildplanModules as $buildplanModule) { |
58
|
|
|
|
59
|
3 |
|
$module = $buildplanModule->getModule(); |
60
|
3 |
|
if (!array_key_exists($module->getId(), $recycledModuleChances)) { |
61
|
2 |
|
$moduleCount = $buildplanModule->getModuleCount(); |
62
|
|
|
|
63
|
2 |
|
$recycledModuleChances[$module->getId()] = [ |
64
|
2 |
|
$module, |
65
|
2 |
|
$this->stuRandom->rand(1, $moduleCount, true, (int)ceil($moduleCount / 2)), |
66
|
2 |
|
intdiv($recyclingChance, 2) |
67
|
2 |
|
]; |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|
71
|
3 |
|
$maxStorage = $entity->getMaxStorage(); |
72
|
|
|
|
73
|
3 |
|
foreach ($recycledModuleChances as [$module, $amount, $recyclingChance]) { |
74
|
|
|
|
75
|
3 |
|
if ($entity->getStorageSum() >= $maxStorage) { |
76
|
1 |
|
$information->addInformation('Kein Lagerraum frei um Module zu recyclen!'); |
77
|
1 |
|
break; |
78
|
|
|
} |
79
|
|
|
|
80
|
2 |
|
if ($this->stuRandom->rand(1, 100) > $recyclingChance) { |
81
|
1 |
|
continue; |
82
|
|
|
} |
83
|
|
|
|
84
|
2 |
|
$this->storageManager->upperStorage( |
85
|
2 |
|
$entity, |
86
|
2 |
|
$module->getCommodity(), |
87
|
2 |
|
$amount |
88
|
2 |
|
); |
89
|
|
|
|
90
|
2 |
|
$information->addInformationf('Folgendes Modul konnte recycelt werden: %s, Anzahl: %d', $module->getName(), $amount); |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
|
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