|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Stu\Module\Ship\Lib\Movement\Route; |
|
6
|
|
|
|
|
7
|
|
|
use Override; |
|
|
|
|
|
|
8
|
|
|
use RuntimeException; |
|
9
|
|
|
use Stu\Exception\SanityCheckException; |
|
10
|
|
|
use Stu\Orm\Entity\MapInterface; |
|
11
|
|
|
use Stu\Orm\Entity\ShipInterface; |
|
12
|
|
|
use Stu\Orm\Entity\StarSystemMapInterface; |
|
13
|
|
|
use Stu\Orm\Repository\MapRepositoryInterface; |
|
14
|
|
|
use Stu\Orm\Repository\StarSystemMapRepositoryInterface; |
|
15
|
|
|
|
|
16
|
|
|
final class CheckDestination implements CheckDestinationInterface |
|
17
|
|
|
{ |
|
18
|
14 |
|
public function __construct(private MapRepositoryInterface $mapRepository, private StarSystemMapRepositoryInterface $starSystemMapRepository) |
|
19
|
|
|
{ |
|
20
|
14 |
|
} |
|
21
|
|
|
|
|
22
|
14 |
|
#[Override] |
|
23
|
|
|
public function validate( |
|
24
|
|
|
ShipInterface $ship, |
|
25
|
|
|
int $destinationX, |
|
26
|
|
|
int $destinationY |
|
27
|
|
|
): MapInterface|StarSystemMapInterface { |
|
28
|
14 |
|
$start = $ship->getCurrentMapField(); |
|
29
|
|
|
|
|
30
|
14 |
|
if ($start->getX() !== $destinationX && $start->getY() !== $destinationY) { |
|
31
|
2 |
|
throw new SanityCheckException( |
|
32
|
2 |
|
sprintf( |
|
33
|
2 |
|
'userId %d tried to navigate from %s to invalid position %d|%d', |
|
34
|
2 |
|
$ship->getUser()->getId(), |
|
35
|
2 |
|
$start->getSectorString(), |
|
36
|
2 |
|
$destinationX, |
|
37
|
2 |
|
$destinationY |
|
38
|
2 |
|
) |
|
39
|
2 |
|
); |
|
40
|
|
|
} |
|
41
|
12 |
|
if ($destinationX < 1) { |
|
42
|
|
|
$destinationX = 1; |
|
43
|
|
|
} |
|
44
|
12 |
|
if ($destinationY < 1) { |
|
45
|
|
|
$destinationY = 1; |
|
46
|
|
|
} |
|
47
|
12 |
|
if ($start instanceof StarSystemMapInterface) { |
|
48
|
|
|
|
|
49
|
6 |
|
$system = $start->getSystem(); |
|
50
|
6 |
|
if ($destinationX > $system->getMaxX()) { |
|
51
|
1 |
|
$destinationX = $system->getMaxX(); |
|
52
|
|
|
} |
|
53
|
6 |
|
if ($destinationY > $system->getMaxY()) { |
|
54
|
1 |
|
$destinationY = $system->getMaxY(); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
6 |
|
$result = $this->starSystemMapRepository->getByCoordinates($system->getId(), $destinationX, $destinationY); |
|
58
|
|
|
} else { |
|
59
|
6 |
|
$layer = $start->getLayer(); |
|
60
|
6 |
|
if ($layer === null) { |
|
61
|
|
|
throw new RuntimeException('this should not happen'); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
6 |
|
if ($destinationX > $layer->getWidth()) { |
|
65
|
1 |
|
$destinationX = $layer->getWidth(); |
|
66
|
|
|
} |
|
67
|
6 |
|
if ($destinationY > $layer->getHeight()) { |
|
68
|
1 |
|
$destinationY = $layer->getHeight(); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
6 |
|
$result = $this->mapRepository->getByCoordinates($layer, $destinationX, $destinationY); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
12 |
|
if ($result === null) { |
|
75
|
2 |
|
throw new RuntimeException(sprintf('destination %d|%d does not exist', $destinationX, $destinationY)); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
10 |
|
return $result; |
|
79
|
|
|
} |
|
80
|
|
|
} |
|
81
|
|
|
|
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