1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Stu\Module\Ship\Action\DropBuoy; |
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\Component\Ship\System\ShipSystemTypeEnum; |
15
|
|
|
use Stu\Orm\Repository\CommodityRepositoryInterface; |
16
|
|
|
use Stu\Module\Commodity\CommodityTypeEnum; |
17
|
|
|
|
18
|
|
|
|
19
|
|
|
|
20
|
|
|
final class DropBuoy implements ActionControllerInterface |
21
|
|
|
{ |
22
|
|
|
public const ACTION_IDENTIFIER = 'B_DROP_BOUY'; |
23
|
|
|
|
24
|
|
|
private ShipLoaderInterface $shipLoader; |
25
|
|
|
private BuoyRepositoryInterface $buoyRepository; |
26
|
|
|
private CommodityRepositoryInterface $commodityRepository; |
27
|
|
|
private ShipStorageManagerInterface $shipStorageManager; |
28
|
|
|
|
29
|
|
|
public function __construct( |
30
|
|
|
ShipLoaderInterface $shipLoader, |
31
|
|
|
BuoyRepositoryInterface $buoyRepository, |
32
|
|
|
CommodityRepositoryInterface $commodityRepository, |
33
|
|
|
ShipStorageManagerInterface $shipStorageManager |
34
|
|
|
) { |
35
|
|
|
$this->shipLoader = $shipLoader; |
36
|
|
|
$this->buoyRepository = $buoyRepository; |
37
|
|
|
$this->commodityRepository = $commodityRepository; |
38
|
|
|
$this->shipStorageManager = $shipStorageManager; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function handle(GameControllerInterface $game): void |
42
|
|
|
{ |
43
|
|
|
$game->setView(ShowShip::VIEW_IDENTIFIER); |
44
|
|
|
$userId = $game->getUser()->getId(); |
45
|
|
|
$wrapper = $this->shipLoader->getWrapperByIdAndUser( |
46
|
|
|
request::indInt('id'), |
47
|
|
|
$userId |
48
|
|
|
); |
49
|
|
|
$ship = $wrapper->get(); |
50
|
|
|
|
51
|
|
|
if (!$ship->isSystemHealthy(ShipSystemTypeEnum::SYSTEM_TORPEDO)) { |
52
|
|
|
$game->addInformation(_("Die Torpedorampe ist zerstört")); |
53
|
|
|
return; |
54
|
|
|
} |
55
|
|
|
$epsSystem = $wrapper->getEpsSystemData(); |
56
|
|
|
if ($epsSystem === null || $epsSystem->getEps() == 0) { |
57
|
|
|
$game->addInformation(_("Keine Energie vorhanden")); |
58
|
|
|
return; |
59
|
|
|
} |
60
|
|
|
if ($ship->getCloakState()) { |
61
|
|
|
$game->addInformation(_("Die Tarnung ist aktiviert")); |
62
|
|
|
return; |
63
|
|
|
} |
64
|
|
|
if ($ship->getWarpState()) { |
65
|
|
|
$game->addInformation(_("Der Warpantrieb ist aktiviert")); |
66
|
|
|
return; |
67
|
|
|
} |
68
|
|
|
if ($ship->getShieldState()) { |
69
|
|
|
$game->addInformation(_("Die Schilde sind aktiviert")); |
70
|
|
|
return; |
71
|
|
|
} |
72
|
|
|
if (count($this->buoyRepository->findByUserId($userId)) >= 16) { |
73
|
|
|
$game->addInformation(_("Es können nicht mehr als 16 Bojen platziert werden")); |
74
|
|
|
return; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
$text = request::postString('text'); |
78
|
|
|
|
79
|
|
|
if ($text === false || mb_strlen($text) > 60) { |
|
|
|
|
80
|
|
|
$game->addInformation(_("Der Text darf nicht länger als 60 Zeichen sein")); |
81
|
|
|
return; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
if (empty($text)) { |
85
|
|
|
$game->addInformation(_("Der Text darf nicht leer sein")); |
86
|
|
|
return; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
$storage = $ship->getStorage(); |
90
|
|
|
|
91
|
|
|
$commodity = $this->commodityRepository->find(CommodityTypeEnum::BASE_ID_BUOY); |
92
|
|
|
if ($commodity !== null && !$storage->containsKey($commodity->getId())) { |
93
|
|
|
$game->addInformationf( |
94
|
|
|
_('Es wird eine Boje benötigt') |
95
|
|
|
); |
96
|
|
|
return; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
if ($epsSystem->getEps() < 1) { |
100
|
|
|
$game->addInformation(_('Es wird 1 Energie für den Start der Boje benötigt')); |
101
|
|
|
return; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
if ($commodity !== null) { |
105
|
|
|
$this->shipStorageManager->lowerStorage( |
106
|
|
|
$ship, |
107
|
|
|
$commodity, |
108
|
|
|
1 |
109
|
|
|
); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
$buoy = $this->buoyRepository->prototype(); |
113
|
|
|
$buoy->setUser($game->getUser()); |
114
|
|
|
$buoy->setText($text); |
115
|
|
|
|
116
|
|
|
|
117
|
|
|
if ($ship->getStarsystemMap() !== null) { |
118
|
|
|
$buoy->setSystemMap($ship->getStarsystemMap()); |
119
|
|
|
} else { |
120
|
|
|
$buoy->setMap($ship->getMap()); |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
|
124
|
|
|
$this->buoyRepository->save($buoy); |
125
|
|
|
$epsSystem->lowerEps(1)->update(); |
126
|
|
|
|
127
|
|
|
$game->addInformation(_('Die Boje wurde erfolgreich platziert')); |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
public function performSessionCheck(): bool |
131
|
|
|
{ |
132
|
|
|
return true; |
133
|
|
|
} |
134
|
|
|
} |