1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Stu\Module\Ship\Action\StopTakeover; |
6
|
|
|
|
7
|
|
|
use request; |
8
|
|
|
use Stu\Module\Control\ActionControllerInterface; |
9
|
|
|
use Stu\Module\Control\GameControllerInterface; |
10
|
|
|
use Stu\Module\Ship\Lib\Interaction\ShipTakeoverManagerInterface; |
11
|
|
|
use Stu\Module\Ship\Lib\ShipLoaderInterface; |
12
|
|
|
use Stu\Module\Ship\View\ShowShip\ShowShip; |
13
|
|
|
|
14
|
|
|
final class StopTakeover implements ActionControllerInterface |
15
|
|
|
{ |
16
|
|
|
public const ACTION_IDENTIFIER = 'B_STOP_TAKEOVER'; |
17
|
|
|
|
18
|
|
|
private ShipLoaderInterface $shipLoader; |
19
|
|
|
|
20
|
|
|
private ShipTakeoverManagerInterface $shipTakeoverManager; |
21
|
|
|
|
22
|
|
|
public function __construct( |
23
|
|
|
ShipLoaderInterface $shipLoader, |
24
|
|
|
ShipTakeoverManagerInterface $shipTakeoverManager |
25
|
|
|
) { |
26
|
|
|
$this->shipLoader = $shipLoader; |
27
|
|
|
$this->shipTakeoverManager = $shipTakeoverManager; |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function handle(GameControllerInterface $game): void |
31
|
|
|
{ |
32
|
|
|
$game->setView(ShowShip::VIEW_IDENTIFIER); |
33
|
|
|
|
34
|
|
|
$user = $game->getUser(); |
35
|
|
|
$userId = $user->getId(); |
36
|
|
|
|
37
|
|
|
$shipId = request::getIntFatal('id'); |
38
|
|
|
|
39
|
|
|
$wrapper = $this->shipLoader->getWrapperByIdAndUser( |
40
|
|
|
$shipId, |
41
|
|
|
$userId |
42
|
|
|
); |
43
|
|
|
|
44
|
|
|
$ship = $wrapper->get(); |
45
|
|
|
|
46
|
|
|
$takeover = $ship->getTakeoverActive(); |
47
|
|
|
if ($takeover === null) { |
48
|
|
|
return; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
$this->shipTakeoverManager->cancelTakeover($takeover); |
52
|
|
|
|
53
|
|
|
$game->addInformationf( |
54
|
|
|
'Übernahme der %s wurde abgebrochen', |
55
|
|
|
$takeover->getTargetShip()->getName() |
56
|
|
|
); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public function performSessionCheck(): bool |
60
|
|
|
{ |
61
|
|
|
return true; |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|