1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Stu\Module\Ship\View\ShowSectorScan; |
6
|
|
|
|
7
|
|
|
use request; |
8
|
|
|
use Stu\Component\Map\EncodedMapInterface; |
9
|
|
|
use Stu\Component\Ship\FlightSignatureVisibilityEnum; |
10
|
|
|
use Stu\Lib\SignatureWrapper; |
11
|
|
|
use Stu\Module\Control\GameControllerInterface; |
12
|
|
|
use Stu\Module\Control\ViewControllerInterface; |
13
|
|
|
use Stu\Module\Ship\Lib\ShipLoaderInterface; |
14
|
|
|
use Stu\Orm\Entity\MapInterface; |
15
|
|
|
use Stu\Orm\Entity\ShipInterface; |
16
|
|
|
use Stu\Orm\Repository\FlightSignatureRepositoryInterface; |
17
|
|
|
use Stu\Orm\Repository\BuoyRepositoryInterface; |
18
|
|
|
|
19
|
|
|
final class ShowSectorScan implements ViewControllerInterface |
20
|
|
|
{ |
21
|
|
|
public const VIEW_IDENTIFIER = 'SHOW_SECTOR_SCAN'; |
22
|
|
|
|
23
|
|
|
private ShipLoaderInterface $shipLoader; |
24
|
|
|
|
25
|
|
|
private FlightSignatureRepositoryInterface $flightSignatureRepository; |
26
|
|
|
|
27
|
|
|
private EncodedMapInterface $encodedMap; |
28
|
|
|
|
29
|
|
|
private BuoyRepositoryInterface $buoyRepository; |
30
|
|
|
|
31
|
|
|
/** @var array<int> */ |
32
|
|
|
private array $fadedSignaturesUncloaked = []; |
33
|
|
|
|
34
|
|
|
/** @var array<int> */ |
35
|
|
|
private array $fadedSignaturesCloaked = []; |
36
|
|
|
|
37
|
|
|
public function __construct( |
38
|
|
|
ShipLoaderInterface $shipLoader, |
39
|
|
|
FlightSignatureRepositoryInterface $flightSignatureRepository, |
40
|
|
|
EncodedMapInterface $encodedMap, |
41
|
|
|
BuoyRepositoryInterface $buoyRepository |
42
|
|
|
) { |
43
|
|
|
$this->shipLoader = $shipLoader; |
44
|
|
|
$this->flightSignatureRepository = $flightSignatureRepository; |
45
|
|
|
$this->encodedMap = $encodedMap; |
46
|
|
|
$this->buoyRepository = $buoyRepository; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function handle(GameControllerInterface $game): void |
50
|
|
|
{ |
51
|
|
|
$userId = $game->getUser()->getId(); |
52
|
|
|
|
53
|
|
|
$buoy = null; |
54
|
|
|
|
55
|
|
|
$game->setPageTitle("Sektor Scan"); |
56
|
|
|
$game->setMacroInAjaxWindow('html/shipmacros.xhtml/sectorscan'); |
57
|
|
|
$game->setTemplateVar('ERROR', true); |
58
|
|
|
|
59
|
|
|
$wrapper = $this->shipLoader->getWrapperByIdAndUser( |
60
|
|
|
request::indInt('id'), |
61
|
|
|
$userId, |
62
|
|
|
true |
63
|
|
|
); |
64
|
|
|
$ship = $wrapper->get(); |
65
|
|
|
|
66
|
|
|
if (!$ship->getNbs()) { |
67
|
|
|
$game->addInformation("Die Nahbereichssensoren sind nicht aktiv"); |
68
|
|
|
return; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
$epsSystem = $wrapper->getEpsSystemData(); |
72
|
|
|
if ($epsSystem === null || $epsSystem->getEps() < 1) { |
73
|
|
|
$game->addInformation("Nicht genügend Energie vorhanden (1 benötigt)"); |
74
|
|
|
return; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
$epsSystem->lowerEps(1)->update(); |
78
|
|
|
|
79
|
|
|
$mapField = $ship->getCurrentMapField(); |
80
|
|
|
|
81
|
|
|
$colonyClass = $mapField->getFieldType()->getColonyClass(); |
82
|
|
|
if ($colonyClass !== null) { |
83
|
|
|
$game->checkDatabaseItem($colonyClass->getDatabaseId()); |
84
|
|
|
} |
85
|
|
|
if ($mapField->getSystem() !== null && $mapField->getFieldType()->getIsSystem()) { |
86
|
|
|
$game->checkDatabaseItem($mapField->getSystem()->getSystemType()->getDatabaseEntryId()); |
87
|
|
|
} |
88
|
|
|
if ($ship->getStarsystemMap() !== null) { |
89
|
|
|
$buoy = $this->buoyRepository->findBySysMapId($ship->getStarsystemMap()->getId()); |
90
|
|
|
} |
91
|
|
|
if ($ship->getMap() !== null) { |
92
|
|
|
$buoy = $this->buoyRepository->findByMapId($ship->getMap()->getId()); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
$game->setTemplateVar('SIGNATURES', $this->getSignatures($mapField->getId(), $ship->getSystem() !== null, $userId)); |
96
|
|
|
$game->setTemplateVar('OTHER_SIG_COUNT', empty($this->fadedSignaturesUncloaked) ? null : count($this->fadedSignaturesUncloaked)); |
97
|
|
|
$game->setTemplateVar('OTHER_CLOAKED_COUNT', empty($this->fadedSignaturesCloaked) ? null : count($this->fadedSignaturesCloaked)); |
98
|
|
|
$game->setTemplateVar('SHIP', $ship); |
99
|
|
|
$game->setTemplateVar('MAP_PATH', $this->getMapPath($ship)); |
100
|
|
|
$game->setTemplateVar('BUOY', $buoy); |
101
|
|
|
|
102
|
|
|
$game->setTemplateVar('ERROR', false); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* @return array<int, SignatureWrapper> |
107
|
|
|
*/ |
108
|
|
|
private function getSignatures(int $fieldId, bool $isSystem, int $ignoreId): array |
109
|
|
|
{ |
110
|
|
|
$allSigs = $this->flightSignatureRepository->getVisibleSignatures($fieldId, $isSystem, $ignoreId); |
111
|
|
|
|
112
|
|
|
$filteredSigs = []; |
113
|
|
|
|
114
|
|
|
foreach ($allSigs as $sig) { |
115
|
|
|
$id = $sig->getShipId(); |
116
|
|
|
$name = $sig->getShipName(); |
117
|
|
|
|
118
|
|
|
if (!array_key_exists($id . '_' . $name, $filteredSigs)) { |
119
|
|
|
$wrapper = new SignatureWrapper($sig); |
120
|
|
|
|
121
|
|
|
if ($wrapper->getRump() === null) { |
122
|
|
|
if ($sig->isCloaked()) { |
123
|
|
|
if ($sig->getTime() > (time() - FlightSignatureVisibilityEnum::SIG_VISIBILITY_CLOAKED)) { |
124
|
|
|
$this->fadedSignaturesCloaked[$id] = $id; |
125
|
|
|
} |
126
|
|
|
} else { |
127
|
|
|
$this->fadedSignaturesUncloaked[$id] = $id; |
128
|
|
|
} |
129
|
|
|
} else { |
130
|
|
|
$filteredSigs[$id . '_' . $name] = $wrapper; |
131
|
|
|
} |
132
|
|
|
} |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
return $filteredSigs; |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
private function getMapPath(ShipInterface $ship): string |
139
|
|
|
{ |
140
|
|
|
$currentMapField = $ship->getCurrentMapField(); |
141
|
|
|
|
142
|
|
|
if ($currentMapField instanceof MapInterface) { |
143
|
|
|
return $this->encodedMap->getEncodedMapPath($currentMapField->getFieldId(), $currentMapField->getLayer()); |
144
|
|
|
} else { |
145
|
|
|
return sprintf('%d.png', $currentMapField->getFieldId()); |
146
|
|
|
} |
147
|
|
|
} |
148
|
|
|
} |