1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Stu\Module\Ship\Lib\Interaction; |
6
|
|
|
|
7
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
8
|
|
|
use Doctrine\Common\Collections\Collection; |
9
|
|
|
use Doctrine\ORM\EntityManagerInterface; |
10
|
|
|
use Override; |
|
|
|
|
11
|
|
|
use Stu\Component\Ship\System\Exception\AlreadyOffException; |
12
|
|
|
use Stu\Component\Ship\System\ShipSystemManagerInterface; |
13
|
|
|
use Stu\Component\Ship\System\ShipSystemTypeEnum; |
14
|
|
|
use Stu\Lib\Information\InformationInterface; |
15
|
|
|
use Stu\Module\Message\Lib\PrivateMessageFolderTypeEnum; |
16
|
|
|
use Stu\Module\Message\Lib\PrivateMessageSenderInterface; |
17
|
|
|
use Stu\Module\Ship\Lib\Battle\AlertDetection\AlertReactionFacadeInterface; |
18
|
|
|
use Stu\Module\Ship\Lib\ShipWrapperInterface; |
19
|
|
|
use Stu\Module\Ship\View\ShowShip\ShowShip; |
|
|
|
|
20
|
|
|
use Stu\Orm\Repository\ShipRepositoryInterface; |
21
|
|
|
|
22
|
|
|
final class InterceptShipCore implements InterceptShipCoreInterface |
23
|
|
|
{ |
24
|
1 |
|
public function __construct( |
25
|
|
|
private ShipRepositoryInterface $shipRepository, |
26
|
|
|
private ShipSystemManagerInterface $shipSystemManager, |
27
|
|
|
private AlertReactionFacadeInterface $alertReactionFacade, |
28
|
|
|
private PrivateMessageSenderInterface $privateMessageSender, |
29
|
|
|
private EntityManagerInterface $entityManager |
30
|
1 |
|
) {} |
31
|
|
|
|
32
|
1 |
|
#[Override] |
33
|
|
|
public function intercept( |
34
|
|
|
ShipWrapperInterface $wrapper, |
35
|
|
|
ShipWrapperInterface $targetWrapper, |
36
|
|
|
InformationInterface $informations |
37
|
|
|
): void { |
38
|
|
|
|
39
|
1 |
|
$ship = $wrapper->get(); |
40
|
1 |
|
$target = $targetWrapper->get(); |
41
|
1 |
|
$userId = $ship->getUser()->getId(); |
42
|
|
|
|
43
|
1 |
|
$wrappersToToggleAlertReaction = new ArrayCollection([$targetWrapper]); |
44
|
|
|
|
45
|
1 |
|
$targetFleetWrapper = $targetWrapper->getFleetWrapper(); |
46
|
1 |
|
if ($targetFleetWrapper !== null) { |
47
|
|
|
foreach ($targetFleetWrapper->getShipWrappers() as $fleetWrapper) { |
48
|
|
|
$this->deactivateWarpdrive($fleetWrapper, $wrappersToToggleAlertReaction); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
$informations->addInformationf("Die Flotte %s wurde abgefangen", $targetFleetWrapper->get()->getName()); |
52
|
|
|
$pm = "Die Flotte " . $targetFleetWrapper->get()->getName() . " wurde von der " . $ship->getName() . " abgefangen"; |
53
|
|
|
} else { |
54
|
1 |
|
$this->deactivateWarpdrive($targetWrapper, $wrappersToToggleAlertReaction); |
55
|
|
|
|
56
|
1 |
|
$informations->addInformationf("Die %s wurde abgefangen", $target->getName()); |
57
|
1 |
|
$pm = "Die " . $target->getName() . " wurde von der " . $ship->getName() . " abgefangen"; |
58
|
|
|
} |
59
|
|
|
|
60
|
1 |
|
$href = sprintf('ship.php?%s=1&id=%d', ShowShip::VIEW_IDENTIFIER, $target->getId()); |
61
|
|
|
|
62
|
1 |
|
$this->privateMessageSender->send( |
63
|
1 |
|
$userId, |
64
|
1 |
|
$target->getUser()->getId(), |
65
|
1 |
|
$pm, |
66
|
1 |
|
PrivateMessageFolderTypeEnum::SPECIAL_SHIP, |
67
|
1 |
|
$href |
68
|
1 |
|
); |
69
|
|
|
|
70
|
1 |
|
$fleetWrapper = $wrapper->getFleetWrapper(); |
71
|
1 |
|
if ($fleetWrapper !== null) { |
72
|
|
|
foreach ($fleetWrapper->getShipWrappers() as $fleetWrapper) { |
73
|
|
|
$this->deactivateWarpdrive($fleetWrapper, $wrappersToToggleAlertReaction); |
74
|
|
|
} |
75
|
|
|
} else { |
76
|
1 |
|
$this->deactivateWarpdrive($wrapper, $wrappersToToggleAlertReaction, true); |
77
|
|
|
} |
78
|
1 |
|
$this->entityManager->flush(); |
79
|
|
|
|
80
|
|
|
// alert reaction check |
81
|
1 |
|
foreach ($wrappersToToggleAlertReaction as $wrapper) { |
82
|
1 |
|
$this->alertReactionFacade->doItAll($wrapper, $informations); |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** @param ArrayCollection<int, ShipWrapperInterface> $wrappersToToggleAlertReaction */ |
87
|
1 |
|
private function deactivateWarpdrive(ShipWrapperInterface $wrapper, Collection $wrappersToToggleAlertReaction, bool $addSelfAsToggle = false): void |
88
|
|
|
{ |
89
|
|
|
try { |
90
|
1 |
|
$this->shipSystemManager->deactivate($wrapper, ShipSystemTypeEnum::SYSTEM_WARPDRIVE); |
91
|
1 |
|
$this->shipRepository->save($wrapper->get()); |
92
|
|
|
|
93
|
1 |
|
$tractoredWrapper = $wrapper->getTractoredShipWrapper(); |
94
|
1 |
|
if ($tractoredWrapper !== null) { |
95
|
1 |
|
$wrappersToToggleAlertReaction->add($tractoredWrapper); |
96
|
|
|
} |
97
|
1 |
|
if ($addSelfAsToggle) { |
98
|
1 |
|
$wrappersToToggleAlertReaction->add($wrapper); |
99
|
|
|
} |
100
|
|
|
} catch (AlreadyOffException) { |
|
|
|
|
101
|
|
|
} |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
|
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