|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Stu\Module\Ship\Action\InterceptShip; |
|
6
|
|
|
|
|
7
|
|
|
use request; |
|
8
|
|
|
use Stu\Lib\Pirate\PirateReactionInterface; |
|
9
|
|
|
use Stu\Lib\Pirate\PirateReactionTriggerEnum; |
|
10
|
|
|
use Stu\Module\Control\ActionControllerInterface; |
|
11
|
|
|
use Stu\Module\Control\GameControllerInterface; |
|
12
|
|
|
use Stu\Module\Ship\Lib\Interaction\InteractionCheckerInterface; |
|
13
|
|
|
use Stu\Module\Ship\Lib\Interaction\InterceptShipCoreInterface; |
|
14
|
|
|
use Stu\Module\Ship\Lib\ShipLoaderInterface; |
|
15
|
|
|
use Stu\Module\Ship\View\ShowShip\ShowShip; |
|
16
|
|
|
|
|
17
|
|
|
final class InterceptShip implements ActionControllerInterface |
|
18
|
|
|
{ |
|
19
|
|
|
public const ACTION_IDENTIFIER = 'B_INTERCEPT'; |
|
20
|
|
|
|
|
21
|
|
|
public function __construct( |
|
22
|
|
|
private ShipLoaderInterface $shipLoader, |
|
23
|
|
|
private InterceptShipCoreInterface $interceptShipCore, |
|
24
|
|
|
private InteractionCheckerInterface $interactionChecker, |
|
25
|
|
|
private PirateReactionInterface $pirateReaction |
|
26
|
|
|
) { |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
public function handle(GameControllerInterface $game): void |
|
30
|
|
|
{ |
|
31
|
|
|
$game->setView(ShowShip::VIEW_IDENTIFIER); |
|
32
|
|
|
|
|
33
|
|
|
$userId = $game->getUser()->getId(); |
|
34
|
|
|
|
|
35
|
|
|
$shipId = request::indInt('id'); |
|
36
|
|
|
$targetId = request::indInt('target'); |
|
37
|
|
|
|
|
38
|
|
|
$wrappers = $this->shipLoader->getWrappersBySourceAndUserAndTarget( |
|
39
|
|
|
$shipId, |
|
40
|
|
|
$userId, |
|
41
|
|
|
$targetId |
|
42
|
|
|
); |
|
43
|
|
|
|
|
44
|
|
|
$wrapper = $wrappers->getSource(); |
|
45
|
|
|
$ship = $wrapper->get(); |
|
46
|
|
|
|
|
47
|
|
|
$targetWrapper = $wrappers->getTarget(); |
|
48
|
|
|
if ($targetWrapper === null) { |
|
49
|
|
|
return; |
|
50
|
|
|
} |
|
51
|
|
|
$target = $targetWrapper->get(); |
|
52
|
|
|
|
|
53
|
|
|
if (!$this->interactionChecker->checkPosition($target, $ship)) { |
|
54
|
|
|
return; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
if (!$ship->hasEnoughCrew($game)) { |
|
58
|
|
|
return; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
if (!$target->getWarpState()) { |
|
62
|
|
|
return; |
|
63
|
|
|
} |
|
64
|
|
|
if (!$ship->canIntercept()) { |
|
65
|
|
|
return; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
$this->interceptShipCore->intercept($ship, $target, $game); |
|
69
|
|
|
|
|
70
|
|
|
$this->pirateReaction->checkForPirateReaction( |
|
71
|
|
|
$target, |
|
72
|
|
|
PirateReactionTriggerEnum::ON_INTERCEPTION, |
|
73
|
|
|
$ship |
|
74
|
|
|
); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
public function performSessionCheck(): bool |
|
78
|
|
|
{ |
|
79
|
|
|
return true; |
|
80
|
|
|
} |
|
81
|
|
|
} |
|
82
|
|
|
|