1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Stu\Module\Ship\Action\TakeBuoy; |
6
|
|
|
|
7
|
|
|
use request; |
8
|
|
|
use Stu\Module\Control\ActionControllerInterface; |
9
|
|
|
use Stu\Module\Control\GameControllerInterface; |
10
|
|
|
use Stu\Orm\Repository\BuoyRepositoryInterface; |
11
|
|
|
use Stu\Module\Ship\Lib\ShipLoaderInterface; |
12
|
|
|
use Stu\Module\Ship\View\ShowShip\ShowShip; |
13
|
|
|
use Stu\Component\Ship\Storage\ShipStorageManagerInterface; |
14
|
|
|
use Stu\Module\Message\Lib\PrivateMessageFolderSpecialEnum; |
15
|
|
|
use Stu\Orm\Repository\CommodityRepositoryInterface; |
16
|
|
|
use Stu\Module\Commodity\CommodityTypeEnum; |
17
|
|
|
use Stu\Module\Message\Lib\PrivateMessageSenderInterface; |
18
|
|
|
|
19
|
|
|
|
20
|
|
|
|
21
|
|
|
final class TakeBuoy implements ActionControllerInterface |
22
|
|
|
{ |
23
|
|
|
public const ACTION_IDENTIFIER = 'B_TAKE_BUOY'; |
24
|
|
|
|
25
|
|
|
private ShipLoaderInterface $shipLoader; |
26
|
|
|
private BuoyRepositoryInterface $buoyRepository; |
27
|
|
|
private CommodityRepositoryInterface $commodityRepository; |
28
|
|
|
private ShipStorageManagerInterface $shipStorageManager; |
29
|
|
|
private PrivateMessageSenderInterface $privateMessageSender; |
30
|
|
|
|
31
|
|
|
public function __construct( |
32
|
|
|
ShipLoaderInterface $shipLoader, |
33
|
|
|
BuoyRepositoryInterface $buoyRepository, |
34
|
|
|
CommodityRepositoryInterface $commodityRepository, |
35
|
|
|
ShipStorageManagerInterface $shipStorageManager, |
36
|
|
|
PrivateMessageSenderInterface $privateMessageSender |
37
|
|
|
) { |
38
|
|
|
$this->shipLoader = $shipLoader; |
39
|
|
|
$this->buoyRepository = $buoyRepository; |
40
|
|
|
$this->commodityRepository = $commodityRepository; |
41
|
|
|
$this->shipStorageManager = $shipStorageManager; |
42
|
|
|
$this->privateMessageSender = $privateMessageSender; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public function handle(GameControllerInterface $game): void |
46
|
|
|
{ |
47
|
|
|
$game->setView(ShowShip::VIEW_IDENTIFIER); |
48
|
|
|
$userId = $game->getUser()->getId(); |
49
|
|
|
$wrapper = $this->shipLoader->getWrapperByIdAndUser( |
50
|
|
|
request::indInt('id'), |
51
|
|
|
$userId |
52
|
|
|
); |
53
|
|
|
$ship = $wrapper->get(); |
54
|
|
|
$buoyId = request::indInt('buoy_id'); |
55
|
|
|
$epsSystem = $wrapper->getEpsSystemData(); |
56
|
|
|
|
57
|
|
|
if ($epsSystem === null || $epsSystem->getEps() == 0) { |
58
|
|
|
$game->addInformation(_("Keine Energie vorhanden")); |
59
|
|
|
return; |
60
|
|
|
} |
61
|
|
|
if ($ship->getCloakState()) { |
62
|
|
|
$game->addInformation(_("Die Tarnung ist aktiviert")); |
63
|
|
|
return; |
64
|
|
|
} |
65
|
|
|
if ($ship->getWarpState()) { |
66
|
|
|
$game->addInformation(_("Der Warpantrieb ist aktiviert")); |
67
|
|
|
return; |
68
|
|
|
} |
69
|
|
|
if ($ship->getShieldState()) { |
70
|
|
|
$game->addInformation(_("Die Schilde sind aktiviert")); |
71
|
|
|
return; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
if ($epsSystem->getEps() < 1) { |
75
|
|
|
$game->addInformation(_('Es wird 1 Energie für den Start der Boje benötigt')); |
76
|
|
|
return; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
$commodity = $this->commodityRepository->find(CommodityTypeEnum::BASE_ID_BUOY); |
80
|
|
|
|
81
|
|
|
if ($commodity !== null) { |
82
|
|
|
$this->shipStorageManager->upperStorage( |
83
|
|
|
$ship, |
84
|
|
|
$commodity, |
85
|
|
|
1 |
86
|
|
|
); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
$buoy = $this->buoyRepository->find($buoyId); |
90
|
|
|
if ($buoy === null) { |
91
|
|
|
$game->addInformation(_("Die Boje existiert nicht")); |
92
|
|
|
return; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
if ($buoy->getUserId() !== $userId) { |
96
|
|
|
$this->privateMessageSender->send( |
97
|
|
|
$game->getUser()->getId(), |
98
|
|
|
$buoy->getUserId(), |
99
|
|
|
sprintf( |
100
|
|
|
_('Deine Boje %s wurde von der %s bei %s aufgebracht.'), |
101
|
|
|
$buoy->getText(), |
102
|
|
|
$ship->getName(), |
103
|
|
|
$ship->getSectorString() |
104
|
|
|
), |
105
|
|
|
PrivateMessageFolderSpecialEnum::PM_SPECIAL_SHIP, |
106
|
|
|
null |
107
|
|
|
); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
$this->buoyRepository->delete($buoy); |
111
|
|
|
|
112
|
|
|
$epsSystem->lowerEps(1)->update(); |
113
|
|
|
|
114
|
|
|
$game->addInformation(_('Die Boje wurde erfolgreich eingesammelt')); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
public function performSessionCheck(): bool |
118
|
|
|
{ |
119
|
|
|
return true; |
120
|
|
|
} |
121
|
|
|
} |