|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Stu\Module\Ship\Lib\Battle\AlertDetection; |
|
4
|
|
|
|
|
5
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
|
6
|
|
|
use Stu\Lib\Information\InformationInterface; |
|
7
|
|
|
use Stu\Module\Ship\Lib\Battle\Party\AlertStateBattleParty; |
|
8
|
|
|
use Stu\Module\Ship\Lib\Battle\Party\BattlePartyFactoryInterface; |
|
9
|
|
|
use Stu\Orm\Entity\ShipInterface; |
|
10
|
|
|
|
|
11
|
|
|
class AlertDetection implements AlertDetectionInterface |
|
12
|
|
|
{ |
|
13
|
2 |
|
public function __construct( |
|
14
|
|
|
private AlertedShipsDetectionInterface $alertedShipsDetection, |
|
15
|
|
|
private SkipDetectionInterface $skipDetection, |
|
16
|
|
|
private BattlePartyFactoryInterface $battlePartyFactory, |
|
17
|
|
|
private TrojanHorseNotifierInterface $trojanHorseNotifier, |
|
18
|
|
|
private AlertedShipInformationInterface $alertedShipInformation |
|
19
|
|
|
) { |
|
20
|
2 |
|
} |
|
21
|
|
|
|
|
22
|
2 |
|
public function detectAlertedBattleParties( |
|
23
|
|
|
ShipInterface $incomingShip, |
|
24
|
|
|
InformationInterface $informations, |
|
25
|
|
|
?ShipInterface $tractoringShip = null |
|
26
|
|
|
): array { |
|
27
|
|
|
|
|
28
|
2 |
|
$alertedWrappers = $this->alertedShipsDetection->getAlertedShipsOnLocation($incomingShip); |
|
29
|
2 |
|
if ($alertedWrappers->isEmpty()) { |
|
30
|
1 |
|
return []; |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
/** @var array<int, AlertStateBattleParty> */ |
|
34
|
1 |
|
$battleParties = []; |
|
35
|
1 |
|
$usersToInformAboutTrojanHorse = new ArrayCollection(); |
|
36
|
|
|
|
|
37
|
1 |
|
foreach ($alertedWrappers as $alertedWrapper) { |
|
38
|
|
|
|
|
39
|
1 |
|
$alertedShip = $alertedWrapper->get(); |
|
40
|
|
|
|
|
41
|
1 |
|
if ($this->skipDetection->isSkipped($incomingShip, $alertedShip, $tractoringShip, $usersToInformAboutTrojanHorse)) { |
|
42
|
1 |
|
continue; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
1 |
|
$battleParties[$alertedShip->getId()] = $this->battlePartyFactory->createAlertStateBattleParty($alertedWrapper); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
1 |
|
$this->trojanHorseNotifier->informUsersAboutTrojanHorse( |
|
49
|
1 |
|
$incomingShip, |
|
50
|
1 |
|
$tractoringShip, |
|
51
|
1 |
|
$usersToInformAboutTrojanHorse |
|
52
|
1 |
|
); |
|
53
|
|
|
|
|
54
|
1 |
|
$this->alertedShipInformation->addAlertedShipsInfo( |
|
55
|
1 |
|
$incomingShip, |
|
56
|
1 |
|
$battleParties, |
|
57
|
1 |
|
$informations |
|
58
|
1 |
|
); |
|
59
|
|
|
|
|
60
|
1 |
|
return $battleParties; |
|
61
|
|
|
} |
|
62
|
|
|
} |
|
63
|
|
|
|