1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Stu\Module\Ship\Lib\Movement\Component\Consequence\Flight; |
6
|
|
|
|
7
|
|
|
use Stu\Component\Ship\System\ShipSystemManagerInterface; |
8
|
|
|
use Stu\Component\Ship\System\ShipSystemTypeEnum; |
9
|
|
|
use Stu\Component\Ship\System\Utility\TractorMassPayloadUtilInterface; |
10
|
|
|
use Stu\Lib\InformationWrapper; |
11
|
|
|
use Stu\Module\Ship\Lib\Message\Message; |
12
|
|
|
use Stu\Module\Ship\Lib\Message\MessageCollectionInterface; |
13
|
|
|
use Stu\Module\Ship\Lib\CancelColonyBlockOrDefendInterface; |
14
|
|
|
use Stu\Module\Ship\Lib\Movement\Component\Consequence\AbstractFlightConsequence; |
15
|
|
|
use Stu\Module\Ship\Lib\Movement\Route\FlightRouteInterface; |
16
|
|
|
use Stu\Module\Ship\Lib\ShipWrapperInterface; |
17
|
|
|
|
18
|
|
|
class TractorConsequence extends AbstractFlightConsequence |
19
|
|
|
{ |
20
|
|
|
private TractorMassPayloadUtilInterface $tractorMassPayloadUtil; |
21
|
|
|
|
22
|
|
|
private ShipSystemManagerInterface $shipSystemManager; |
23
|
|
|
|
24
|
|
|
private CancelColonyBlockOrDefendInterface $cancelColonyBlockOrDefend; |
25
|
|
|
|
26
|
5 |
|
public function __construct( |
27
|
|
|
TractorMassPayloadUtilInterface $tractorMassPayloadUtil, |
28
|
|
|
ShipSystemManagerInterface $shipSystemManager, |
29
|
|
|
CancelColonyBlockOrDefendInterface $cancelColonyBlockOrDefend |
30
|
|
|
) { |
31
|
5 |
|
$this->tractorMassPayloadUtil = $tractorMassPayloadUtil; |
32
|
5 |
|
$this->shipSystemManager = $shipSystemManager; |
33
|
5 |
|
$this->cancelColonyBlockOrDefend = $cancelColonyBlockOrDefend; |
34
|
|
|
} |
35
|
|
|
|
36
|
3 |
|
protected function triggerSpecific( |
37
|
|
|
ShipWrapperInterface $wrapper, |
38
|
|
|
FlightRouteInterface $flightRoute, |
39
|
|
|
MessageCollectionInterface $messages |
40
|
|
|
): void { |
41
|
|
|
|
42
|
3 |
|
$ship = $wrapper->get(); |
43
|
|
|
|
44
|
3 |
|
$tractoredShip = $ship->getTractoredShip(); |
45
|
3 |
|
if ($tractoredShip === null) { |
46
|
|
|
return; |
47
|
|
|
} |
48
|
|
|
|
49
|
3 |
|
$message = new Message(); |
50
|
3 |
|
$messages->add($message); |
51
|
|
|
|
52
|
3 |
|
$tractoredShipFleet = $tractoredShip->getFleet(); |
53
|
|
|
|
54
|
|
|
if ( |
55
|
3 |
|
$tractoredShipFleet !== null |
56
|
3 |
|
&& $tractoredShipFleet->getShipCount() > 1 |
57
|
|
|
) { |
58
|
1 |
|
$this->shipSystemManager->deactivate($wrapper, ShipSystemTypeEnum::SYSTEM_TRACTOR_BEAM, true); |
59
|
1 |
|
$message->add( |
60
|
1 |
|
sprintf( |
61
|
1 |
|
'Flottenschiffe können nicht mitgezogen werden - Der auf die %s gerichtete Traktorstrahl wurde deaktiviert', |
62
|
1 |
|
$tractoredShip->getName() |
63
|
1 |
|
) |
64
|
1 |
|
); |
65
|
|
|
|
66
|
1 |
|
return; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
//can tow tractored ship? |
70
|
2 |
|
$abortionMsg = $this->tractorMassPayloadUtil->tryToTow($wrapper, $tractoredShip); |
71
|
2 |
|
if ($abortionMsg !== null) { |
72
|
1 |
|
$this->shipSystemManager->deactivate($wrapper, ShipSystemTypeEnum::SYSTEM_TRACTOR_BEAM, true); |
73
|
1 |
|
$message->add($abortionMsg); |
74
|
|
|
|
75
|
1 |
|
return; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
// cancel colony block or defend of tractored ship fleet |
79
|
1 |
|
$informations = new InformationWrapper(); |
80
|
|
|
|
81
|
1 |
|
$this->cancelColonyBlockOrDefend->work($ship, $informations, true); |
82
|
|
|
|
83
|
1 |
|
$message->addMessageMerge($informations->getInformations()); |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|