1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Stu\Module\Ship\Action\TholianWeb; |
6
|
|
|
|
7
|
|
|
use request; |
8
|
|
|
use Stu\Exception\SanityCheckException; |
9
|
|
|
use Stu\Module\Control\ActionControllerInterface; |
10
|
|
|
use Stu\Module\Control\GameControllerInterface; |
11
|
|
|
use Stu\Module\Logging\LoggerUtilFactoryInterface; |
12
|
|
|
use Stu\Module\Logging\LoggerUtilInterface; |
13
|
|
|
use Stu\Module\Ship\Lib\ShipLoaderInterface; |
14
|
|
|
use Stu\Module\Ship\Lib\Interaction\TholianWebUtilInterface; |
15
|
|
|
use Stu\Module\Ship\View\ShowShip\ShowShip; |
16
|
|
|
|
17
|
|
|
final class RemoveTholianWeb implements ActionControllerInterface |
18
|
|
|
{ |
19
|
|
|
public const ACTION_IDENTIFIER = 'B_REMOVE_WEB'; |
20
|
|
|
|
21
|
|
|
private ShipLoaderInterface $shipLoader; |
22
|
|
|
|
23
|
|
|
private TholianWebUtilInterface $tholianWebUtil; |
24
|
|
|
|
25
|
|
|
private LoggerUtilInterface $loggerUtil; |
26
|
|
|
|
27
|
|
|
public function __construct( |
28
|
|
|
ShipLoaderInterface $shipLoader, |
29
|
|
|
TholianWebUtilInterface $tholianWebUtil, |
30
|
|
|
LoggerUtilFactoryInterface $loggerUtilFactory |
31
|
|
|
) { |
32
|
|
|
$this->shipLoader = $shipLoader; |
33
|
|
|
$this->tholianWebUtil = $tholianWebUtil; |
34
|
|
|
$this->loggerUtil = $loggerUtilFactory->getLoggerUtil(); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public function handle(GameControllerInterface $game): void |
38
|
|
|
{ |
39
|
|
|
$game->setView(ShowShip::VIEW_IDENTIFIER); |
40
|
|
|
|
41
|
|
|
$userId = $game->getUser()->getId(); |
42
|
|
|
$shipId = request::indInt('id'); |
43
|
|
|
|
44
|
|
|
$wrapper = $this->shipLoader->getWrapperByIdAndUser( |
45
|
|
|
$shipId, |
46
|
|
|
$userId |
47
|
|
|
); |
48
|
|
|
|
49
|
|
|
$emitter = $wrapper->getWebEmitterSystemData(); |
50
|
|
|
|
51
|
|
|
$this->loggerUtil->log('1'); |
52
|
|
|
if ($emitter === null || $emitter->ownedWebId === null) { |
53
|
|
|
$this->loggerUtil->log('2'); |
54
|
|
|
throw new SanityCheckException('emitter = null or no owned web', self::ACTION_IDENTIFIER); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
$web = $emitter->getOwnedTholianWeb(); |
58
|
|
|
if ($web === null) { |
59
|
|
|
$this->loggerUtil->log('2'); |
60
|
|
|
throw new SanityCheckException('no own web', self::ACTION_IDENTIFIER); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
if (!$web->isFinished()) { |
64
|
|
|
$this->loggerUtil->log('2'); |
65
|
|
|
throw new SanityCheckException('web not finished', self::ACTION_IDENTIFIER); |
66
|
|
|
} |
67
|
|
|
$this->loggerUtil->log('3'); |
68
|
|
|
|
69
|
|
|
$ship = $wrapper->get(); |
70
|
|
|
//check if system healthy |
71
|
|
|
if (!$ship->isWebEmitterHealthy()) { |
72
|
|
|
throw new SanityCheckException('emitter not healthy', self::ACTION_IDENTIFIER); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
$this->loggerUtil->log('5'); |
76
|
|
|
|
77
|
|
|
|
78
|
|
|
$this->loggerUtil->log(sprintf('capturedSize: %d', count($web->getCapturedShips()))); |
79
|
|
|
$this->loggerUtil->log('6'); |
80
|
|
|
|
81
|
|
|
//unlink targets |
82
|
|
|
$this->tholianWebUtil->releaseAllShips($web, $wrapper->getShipWrapperFactory()); |
83
|
|
|
|
84
|
|
|
$game->addInformation("Das Energienetz wurde aufgelöst"); |
85
|
|
|
|
86
|
|
|
$this->loggerUtil->log('10'); |
87
|
|
|
|
88
|
|
|
$emitter->setOwnedWebId(null)->update(); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
|
92
|
|
|
public function performSessionCheck(): bool |
93
|
|
|
{ |
94
|
|
|
return true; |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
|