|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Stu\Module\Colony\View\ShowSectorScan; |
|
6
|
|
|
|
|
7
|
|
|
use request; |
|
8
|
|
|
use Stu\Component\Ship\FlightSignatureVisibilityEnum; |
|
9
|
|
|
use Stu\Lib\SignatureWrapper; |
|
10
|
|
|
use Stu\Module\Colony\Lib\ColonyLoaderInterface; |
|
11
|
|
|
use Stu\Module\Control\GameControllerInterface; |
|
12
|
|
|
use Stu\Module\Control\ViewControllerInterface; |
|
13
|
|
|
use Stu\Orm\Repository\FlightSignatureRepositoryInterface; |
|
14
|
|
|
use Stu\Orm\Repository\StarSystemMapRepositoryInterface; |
|
15
|
|
|
|
|
16
|
|
|
final class ShowSectorScan implements ViewControllerInterface |
|
17
|
|
|
{ |
|
18
|
|
|
public const VIEW_IDENTIFIER = 'SHOW_SECTOR_SCAN'; |
|
19
|
|
|
|
|
20
|
|
|
private ColonyLoaderInterface $colonyLoader; |
|
21
|
|
|
|
|
22
|
|
|
private StarSystemMapRepositoryInterface $mapRepository; |
|
23
|
|
|
|
|
24
|
|
|
private FlightSignatureRepositoryInterface $flightSignatureRepository; |
|
25
|
|
|
|
|
26
|
|
|
private $fadedSignaturesUncloaked = []; |
|
27
|
|
|
private $fadedSignaturesCloaked = []; |
|
28
|
|
|
|
|
29
|
|
|
public function __construct( |
|
30
|
|
|
ColonyLoaderInterface $colonyLoader, |
|
31
|
|
|
StarSystemMapRepositoryInterface $mapRepository, |
|
32
|
|
|
FlightSignatureRepositoryInterface $flightSignatureRepository |
|
33
|
|
|
) { |
|
34
|
|
|
$this->colonyLoader = $colonyLoader; |
|
35
|
|
|
$this->mapRepository = $mapRepository; |
|
36
|
|
|
$this->flightSignatureRepository = $flightSignatureRepository; |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
public function handle(GameControllerInterface $game): void |
|
40
|
|
|
{ |
|
41
|
|
|
$userId = $game->getUser()->getId(); |
|
42
|
|
|
|
|
43
|
|
|
$colony = $this->colonyLoader->byIdAndUser( |
|
44
|
|
|
request::indInt('id'), |
|
45
|
|
|
$userId, |
|
46
|
|
|
false |
|
47
|
|
|
); |
|
48
|
|
|
|
|
49
|
|
|
$game->setPageTitle("Sektor Scan"); |
|
50
|
|
|
$game->setMacroInAjaxWindow('html/colonymacros.xhtml/sectorscan'); |
|
51
|
|
|
|
|
52
|
|
|
$game->setTemplateVar('ERROR', true); |
|
53
|
|
|
|
|
54
|
|
|
$mapField = $this->mapRepository->getByCoordinates( |
|
55
|
|
|
$colony->getSystem()->getId(), |
|
56
|
|
|
$colony->getSx(), |
|
57
|
|
|
$colony->getSy() |
|
58
|
|
|
); |
|
59
|
|
|
|
|
60
|
|
|
$game->setTemplateVar('SIGNATURES', $this->getSignatures($mapField, true, $userId)); |
|
61
|
|
|
$game->setTemplateVar('OTHER_SIG_COUNT', empty($this->fadedSignaturesUncloaked) ? null : count($this->fadedSignaturesUncloaked)); |
|
62
|
|
|
$game->setTemplateVar('OTHER_CLOAKED_COUNT', empty($this->fadedSignaturesCloaked) ? null : count($this->fadedSignaturesCloaked)); |
|
63
|
|
|
$game->setTemplateVar('ERROR', false); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
private function getSignatures($field, $isSystem, $ignoreId) |
|
67
|
|
|
{ |
|
68
|
|
|
$allSigs = $this->flightSignatureRepository->getVisibleSignatures((int) $field->getId(), $isSystem, $ignoreId); |
|
69
|
|
|
|
|
70
|
|
|
$filteredSigs = []; |
|
71
|
|
|
|
|
72
|
|
|
foreach ($allSigs as $sig) { |
|
73
|
|
|
$id = $sig->getShipId(); |
|
74
|
|
|
$name = $sig->getShipName(); |
|
75
|
|
|
|
|
76
|
|
|
if (!array_key_exists($id, $filteredSigs)) { |
|
77
|
|
|
$wrapper = new SignatureWrapper($sig); |
|
78
|
|
|
|
|
79
|
|
|
if ($wrapper->getRump() === null) { |
|
80
|
|
|
if ($sig->isCloaked()) { |
|
81
|
|
|
if ($sig->getTime() > (time() - FlightSignatureVisibilityEnum::SIG_VISIBILITY_CLOAKED)) { |
|
82
|
|
|
$this->fadedSignaturesCloaked[$id] = $id; |
|
83
|
|
|
} |
|
84
|
|
|
} else { |
|
85
|
|
|
$this->fadedSignaturesUncloaked[$id] = $id; |
|
86
|
|
|
} |
|
87
|
|
|
} else { |
|
88
|
|
|
$filteredSigs[$id] = $wrapper; |
|
89
|
|
|
} |
|
90
|
|
|
} else { |
|
91
|
|
|
$existingSig = $filteredSigs[$id]; |
|
92
|
|
|
if ($existingSig->getShipName() !== $name) { |
|
93
|
|
|
$wrapper = new SignatureWrapper($sig); |
|
94
|
|
|
$filteredSigs[$id] = $wrapper; |
|
95
|
|
|
} |
|
96
|
|
|
} |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
return $filteredSigs; |
|
100
|
|
|
} |
|
101
|
|
|
} |
|
102
|
|
|
|