Skip to content

Commit 022373a

Browse files
committed
fix ticket 995
1 parent 95b21f6 commit 022373a

File tree

17 files changed

+177
-48
lines changed

17 files changed

+177
-48
lines changed

src/Lib/Map/VisualPanel/Layer/Data/SpacecraftCountData.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ class SpacecraftCountData extends AbstractData
1515
private int $spacecraftcount = 0;
1616
#[Column(type: 'integer')]
1717
private int $cloakcount = 0;
18+
#[Column(type: 'integer', nullable: true)]
19+
private ?int $system_id = null;
1820

1921
public function getSpacecraftCount(): int
2022
{
@@ -37,4 +39,9 @@ public function isDubious(): bool
3739
return $this->effects !== null
3840
&& in_array(FieldTypeEffectEnum::DUBIOUS_SPACECRAFT_COUNT->value, $this->effects);
3941
}
42+
43+
public function getSystemId(): ?int
44+
{
45+
return $this->system_id;
46+
}
4047
}

src/Lib/Map/VisualPanel/Layer/DataProvider/Spacecraftcount/AbstractShipcountDataProvider.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,6 @@ protected function addFieldResults(ResultSetMapping $rsm): void
2222
$rsm->addFieldResult('d', 'spacecraftcount', 'spacecraftcount');
2323
$rsm->addFieldResult('d', 'cloakcount', 'cloakcount');
2424
$rsm->addFieldResult('d', 'effects', 'effects');
25+
$rsm->addFieldResult('d', 'system_id', 'system_id');
2526
}
2627
}

src/Lib/Map/VisualPanel/Layer/PanelLayerCreation.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
use Stu\Orm\Entity\Layer;
2727
use Stu\Orm\Entity\Location;
2828
use Stu\Orm\Entity\Spacecraft;
29+
use Stu\Orm\Repository\StarSystemRepositoryInterface;
30+
2931

3032
final class PanelLayerCreation implements PanelLayerCreationInterface
3133
{
@@ -45,6 +47,7 @@ public function __construct(
4547
private readonly SpacecraftCountDataProviderFactoryInterface $shipcountDataProviderFactory,
4648
private readonly SubspaceDataProviderFactoryInterface $subspaceDataProviderFactory,
4749
private readonly LssBlockadeGridFactory $lssBlockadeGridFactory,
50+
private readonly StarSystemRepositoryInterface $starSystemRepository,
4851
private readonly array $dataProviders
4952
) {}
5053

@@ -96,9 +99,8 @@ public function addShipCountLayer(
9699
SpacecraftCountLayerTypeEnum $type,
97100
int $id
98101
): PanelLayerCreationInterface {
99-
$this->layers[PanelLayerEnum::SPACECRAFT_COUNT->value] = new SpacecraftCountLayerRenderer($showCloakedEverywhere, $currentSpacecraft);
102+
$this->layers[PanelLayerEnum::SPACECRAFT_COUNT->value] = new SpacecraftCountLayerRenderer($showCloakedEverywhere, $currentSpacecraft, $this->starSystemRepository);
100103
$this->specialDataProviders[PanelLayerEnum::SPACECRAFT_COUNT->value] = $this->shipcountDataProviderFactory->getDataProvider($id, $type);
101-
102104
return $this;
103105
}
104106

src/Lib/Map/VisualPanel/Layer/Render/SpacecraftCountLayerRenderer.php

Lines changed: 92 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,21 @@
44

55
namespace Stu\Lib\Map\VisualPanel\Layer\Render;
66

7+
use Stu\Component\Spacecraft\SpacecraftRumpRoleEnum;
78
use Stu\Lib\Map\VisualPanel\Layer\Data\CellDataInterface;
89
use Stu\Lib\Map\VisualPanel\Layer\Data\SpacecraftCountData;
910
use Stu\Lib\Map\VisualPanel\Layer\PanelLayerEnum;
1011
use Stu\Lib\Map\VisualPanel\PanelAttributesInterface;
1112
use Stu\Orm\Entity\Spacecraft;
13+
use Stu\Orm\Repository\StarSystemRepositoryInterface;
1214

1315
final class SpacecraftCountLayerRenderer implements LayerRendererInterface
1416
{
15-
public function __construct(private bool $showCloakedEverywhere, private ?Spacecraft $currentSpacecraft) {}
17+
public function __construct(
18+
private bool $showCloakedEverywhere,
19+
private ?Spacecraft $currentSpacecraft,
20+
private StarSystemRepositoryInterface $starSystemRepository
21+
) {}
1622

1723
/** @param SpacecraftCountData $data */
1824
#[\Override]
@@ -38,30 +44,108 @@ private function getDisplayCount(SpacecraftCountData $data): ?string
3844
}
3945

4046
$spacecraftCount = $data->getSpacecraftCount();
47+
4148
if ($spacecraftCount > 0) {
4249
return $data->isDubious() ? '!' : (string) $spacecraftCount;
4350
}
51+
4452
if ($data->hasCloakedShips()) {
4553
if ($this->showCloakedEverywhere) {
4654
return $data->isDubious() ? '!' : "?";
4755
}
4856

4957
$currentSpacecraft = $this->currentSpacecraft;
5058

51-
if (
52-
$currentSpacecraft !== null
53-
&& $currentSpacecraft->getTachyonState()
54-
&& abs($data->getPosX() - $currentSpacecraft->getPosX()) <= $this->getTachyonRange($currentSpacecraft)
55-
&& abs($data->getPosY() - $currentSpacecraft->getPosY()) <= $this->getTachyonRange($currentSpacecraft)
56-
) {
57-
return $data->isDubious() ? '!' : "?";
59+
if ($currentSpacecraft !== null && $currentSpacecraft->getTachyonState()) {
60+
$rump = $currentSpacecraft->getRump();
61+
62+
if (
63+
$rump->getRoleId() === SpacecraftRumpRoleEnum::SENSOR
64+
|| $rump->getRoleId() === SpacecraftRumpRoleEnum::BASE
65+
) {
66+
$spacecraftX = $this->getRelevantXCoordinate($currentSpacecraft, $data);
67+
$spacecraftY = $this->getRelevantYCoordinate($currentSpacecraft, $data);
68+
$dataX = $this->getRelevantDataXCoordinate($data);
69+
$dataY = $this->getRelevantDataYCoordinate($data);
70+
71+
$distanceX = abs($dataX - $spacecraftX);
72+
$distanceY = abs($dataY - $spacecraftY);
73+
$range = $this->getTachyonRange($currentSpacecraft);
74+
75+
if ($distanceX <= $range && $distanceY <= $range) {
76+
return $data->isDubious() ? '!' : "?";
77+
}
78+
} elseif (
79+
abs($data->getPosX() - $currentSpacecraft->getPosX()) <= $this->getTachyonRange($currentSpacecraft)
80+
&& abs($data->getPosY() - $currentSpacecraft->getPosY()) <= $this->getTachyonRange($currentSpacecraft)
81+
) {
82+
return $data->isDubious() ? '!' : "?";
83+
}
5884
}
5985
}
6086
return null;
6187
}
6288

89+
6390
private function getTachyonRange(Spacecraft $spacecraft): int
6491
{
6592
return $spacecraft->isStation() ? 7 : 3;
6693
}
94+
95+
private function getRelevantXCoordinate(Spacecraft $spacecraft, SpacecraftCountData $data): int
96+
{
97+
$spacecraftSystemMap = $spacecraft->getStarsystemMap();
98+
99+
if ($spacecraftSystemMap !== null) {
100+
return $spacecraftSystemMap->getSystem()->getCx() ?? $spacecraft->getPosX();
101+
}
102+
103+
return $spacecraft->getPosX();
104+
}
105+
106+
private function getRelevantYCoordinate(Spacecraft $spacecraft, SpacecraftCountData $data): int
107+
{
108+
$spacecraftSystemMap = $spacecraft->getStarsystemMap();
109+
110+
if ($spacecraftSystemMap !== null) {
111+
return $spacecraftSystemMap->getSystem()->getCy() ?? $spacecraft->getPosY();
112+
}
113+
114+
return $spacecraft->getPosY();
115+
}
116+
117+
private function getRelevantDataXCoordinate(SpacecraftCountData $data): int
118+
{
119+
$dataSystemId = $data->getSystemId();
120+
if ($dataSystemId !== null) {
121+
$dataSystem = $this->starSystemRepository->find($dataSystemId);
122+
123+
if ($dataSystem !== null) {
124+
$cx = $dataSystem->getCx();
125+
if ($cx !== null) {
126+
return $cx;
127+
}
128+
}
129+
}
130+
131+
$posX = $data->getPosX();
132+
133+
return $posX;
134+
}
135+
private function getRelevantDataYCoordinate(SpacecraftCountData $data): int
136+
{
137+
$dataSystemId = $data->getSystemId();
138+
139+
if ($dataSystemId !== null) {
140+
$dataSystem = $this->starSystemRepository->find($dataSystemId);
141+
if ($dataSystem !== null) {
142+
$cy = $dataSystem->getCy();
143+
if ($cy !== null) {
144+
return $cy;
145+
}
146+
}
147+
}
148+
149+
return $data->getPosY();
150+
}
67151
}

src/Module/Communication/View/ShowQuestList/ShowQuestList.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
use Stu\Orm\Entity\NPCQuest;
1414
use Stu\Orm\Entity\SpacecraftBuildplan;
1515
use Stu\Orm\Entity\Commodity;
16-
use Stu\Component\Quest\QuestUserModeEnum;
1716

1817
final class ShowQuestList implements ViewControllerInterface
1918
{

src/Module/Spacecraft/View/ShowSpacecraft/ShowSpacecraft.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ public function handle(GameControllerInterface $game): void
176176
);
177177

178178
$game->addExecuteJS(sprintf("setSpacecraftIdAndSstr(%d, '%s');", $spacecraft->getId(), $game->getSessionString()));
179+
$game->addExecuteJS(sprintf("setTachyonFresh(%s);", $tachyonFresh ? 'true' : 'false'));
179180
$this->addWarpcoreSplitJavascript($wrapper, $game);
180181

181182
$this->loggerUtil->log(sprintf('ShowShip.handle-end, timestamp: %F', microtime(true)));
@@ -225,8 +226,10 @@ private function addWarpcoreSplitJavascript(SpacecraftWrapperInterface $wrapper,
225226
$warpDriveSystem?->getWarpDrive() ?? 0,
226227
$warpDriveSystem?->getMaxWarpdrive() ?? 0
227228
), JavascriptExecutionTypeEnum::AFTER_RENDER);
228-
$game->addExecuteJS('updateReactorValues();',
229-
JavascriptExecutionTypeEnum::AFTER_RENDER);
229+
$game->addExecuteJS(
230+
'updateReactorValues();',
231+
JavascriptExecutionTypeEnum::AFTER_RENDER
232+
);
230233
}
231234
}
232235

src/Module/Station/Lib/StationUiFactory.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,16 @@ public function createSystemScanPanel(
3333
SpacecraftWrapperInterface $currentWrapper,
3434
User $user,
3535
LoggerUtilInterface $loggerUtil,
36-
StarSystem $system
36+
StarSystem $system,
37+
bool $tachyonFresh
3738
): SystemScanPanel {
3839
return new SystemScanPanel(
3940
$this->panelLayerCreation,
4041
$currentWrapper,
4142
$system,
4243
$user,
43-
$loggerUtil
44+
$loggerUtil,
45+
$tachyonFresh
4446
);
4547
}
4648

src/Module/Station/Lib/StationUiFactoryInterface.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ public function createSystemScanPanel(
1616
SpacecraftWrapperInterface $currentWrapper,
1717
User $user,
1818
LoggerUtilInterface $loggerUtil,
19-
StarSystem $system
19+
StarSystem $system,
20+
bool $tachyonFresh
2021
): SystemScanPanel;
2122

2223
public function createDockingPrivilegeItem(

src/Module/Station/Lib/SystemScanPanel.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ public function __construct(
2222
private SpacecraftWrapperInterface $currentWrapper,
2323
private StarSystem $system,
2424
private User $user,
25-
LoggerUtilInterface $loggerUtil
25+
LoggerUtilInterface $loggerUtil,
26+
private bool $tachyonFresh = false
2627
) {
2728
parent::__construct($panelLayerCreation, $loggerUtil);
2829
}
@@ -39,7 +40,7 @@ protected function loadLayers(): void
3940
$currentSpacecraft = $this->currentWrapper->get();
4041

4142
$panelLayerCreation = $this->panelLayerCreation
42-
->addShipCountLayer($currentSpacecraft->getTachyonState(), null, SpacecraftCountLayerTypeEnum::ALL, 0)
43+
->addShipCountLayer($this->tachyonFresh, $currentSpacecraft, SpacecraftCountLayerTypeEnum::ALL, 0)
4344
->addBorderLayer($this->currentWrapper, $this->system === $currentSpacecraft->getSystem())
4445
->addAnomalyLayer()
4546
->addSystemLayer()

src/Module/Station/View/ShowSystemSensorScan/ShowSystemSensorScan.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,14 @@ public function handle(GameControllerInterface $game): void
7272
return;
7373
}
7474

75+
$tachyonFresh = request::getInt('tf') === 1;
76+
7577
$game->setTemplateVar('VISUAL_PANEL', $this->stationUiFactory->createSystemScanPanel(
7678
$wrapper,
7779
$game->getUser(),
7880
$this->loggerUtilFactory->getLoggerUtil(),
79-
$system
81+
$system,
82+
$tachyonFresh
8083
));
8184

8285
$game->setTemplateVar('SHIP', $station);

0 commit comments

Comments
 (0)