|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Stu\Lib\SpacecraftManagement\Manager; |
|
6
|
|
|
|
|
7
|
|
|
use Override; |
|
|
|
|
|
|
8
|
|
|
use RuntimeException; |
|
9
|
|
|
use Stu\Lib\SpacecraftManagement\Provider\ManagerProviderInterface; |
|
10
|
|
|
use Stu\Component\Player\Relation\PlayerRelationDeterminatorInterface; |
|
11
|
|
|
use Stu\Module\Commodity\Lib\CommodityCacheInterface; |
|
12
|
|
|
use Stu\Module\Spacecraft\Lib\ReactorUtilInterface; |
|
13
|
|
|
use Stu\Module\Spacecraft\Lib\ReactorWrapperInterface; |
|
14
|
|
|
use Stu\Module\Spacecraft\Lib\SpacecraftWrapperInterface; |
|
15
|
|
|
use Stu\Orm\Entity\ShipInterface; |
|
16
|
|
|
use Stu\Orm\Entity\SpacecraftInterface; |
|
17
|
|
|
|
|
18
|
|
|
class ManageReactor implements ManagerInterface |
|
19
|
|
|
{ |
|
20
|
|
|
public function __construct(private ReactorUtilInterface $reactorUtil, private CommodityCacheInterface $commodityCache, private PlayerRelationDeterminatorInterface $playerRelationDeterminator) {} |
|
21
|
|
|
|
|
22
|
|
|
#[Override] |
|
23
|
|
|
public function manage(SpacecraftWrapperInterface $wrapper, array $values, ManagerProviderInterface $managerProvider): array |
|
24
|
|
|
{ |
|
25
|
|
|
$values = $values['reactor'] ?? null; |
|
26
|
|
|
if ($values === null) { |
|
27
|
|
|
throw new RuntimeException('value array not existent'); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
$ship = $wrapper->get(); |
|
31
|
|
|
|
|
32
|
|
|
if (!array_key_exists($ship->getId(), $values)) { |
|
33
|
|
|
return []; |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
if ($values[$ship->getId()] === '' || $values[$ship->getId()] < 1) { |
|
37
|
|
|
return []; |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
$reactor = $wrapper->getReactorWrapper(); |
|
41
|
|
|
if ($reactor === null) { |
|
42
|
|
|
return []; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
if ($ship->getShieldState() && !$this->playerRelationDeterminator->isFriend($ship->getUser(), $managerProvider->getUser())) { |
|
46
|
|
|
$msg[] = sprintf( |
|
|
|
|
|
|
47
|
|
|
_('%s: Warpkern konnte wegen aktivierter Schilde nicht aufgeladen werden.'), |
|
48
|
|
|
$ship->getName() |
|
49
|
|
|
); |
|
50
|
|
|
return $msg; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
$storage = $managerProvider->getStorage(); |
|
54
|
|
|
|
|
55
|
|
|
if ($this->reactorUtil->storageContainsNeededCommodities($storage, $reactor)) { |
|
56
|
|
|
$load = $values[$ship->getId()] == 'm' ? PHP_INT_MAX : (int)$values[$ship->getId()]; |
|
57
|
|
|
$loadMessage = $this->reactorUtil->loadReactor($ship, $load, $managerProvider, $reactor); |
|
58
|
|
|
|
|
59
|
|
|
if ($loadMessage !== null) { |
|
60
|
|
|
return [$loadMessage]; |
|
61
|
|
|
} |
|
62
|
|
|
} else { |
|
63
|
|
|
return $this->createMissingCommoditiesMessage($ship, $reactor); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
return []; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* @return array<string> |
|
71
|
|
|
*/ |
|
72
|
|
|
private function createMissingCommoditiesMessage(SpacecraftInterface $spacecraft, ReactorWrapperInterface $reactor): array |
|
73
|
|
|
{ |
|
74
|
|
|
$msg = []; |
|
75
|
|
|
|
|
76
|
|
|
$msg[] = sprintf( |
|
77
|
|
|
_('%s: Es werden mindestens folgende Waren zum Aufladen des %ss benötigt:'), |
|
78
|
|
|
$spacecraft->getName(), |
|
79
|
|
|
$reactor->get()->getSystemType()->getDescription() |
|
80
|
|
|
); |
|
81
|
|
|
|
|
82
|
|
|
foreach ($reactor->get()->getLoadCost() as $commodityId => $loadCost) { |
|
83
|
|
|
$commodity = $this->commodityCache->get($commodityId); |
|
84
|
|
|
$msg[] = sprintf(_('%d %s'), $loadCost, $commodity->getName()); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
return $msg; |
|
88
|
|
|
} |
|
89
|
|
|
} |
|
90
|
|
|
|
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