1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Stu\Module\Admin\Action\Map\RegenerateSystem; |
6
|
|
|
|
7
|
|
|
use request; |
8
|
|
|
use RuntimeException; |
9
|
|
|
use Stu\Component\StarSystem\StarSystemCreationInterface; |
10
|
|
|
use Stu\Module\Admin\View\Map\ShowSystem\ShowSystem; |
11
|
|
|
use Stu\Module\Control\ActionControllerInterface; |
12
|
|
|
use Stu\Module\Control\GameControllerInterface; |
13
|
|
|
use Stu\Orm\Repository\StarSystemRepositoryInterface; |
14
|
|
|
|
15
|
|
|
final class RegenerateSystem implements ActionControllerInterface |
16
|
|
|
{ |
17
|
|
|
public const ACTION_IDENTIFIER = 'REGENERATE_SYSTEM'; |
18
|
|
|
|
19
|
|
|
private StarSystemRepositoryInterface $starSystemRepository; |
20
|
|
|
|
21
|
|
|
private StarSystemCreationInterface $starSystemCreation; |
22
|
|
|
|
23
|
|
|
public function __construct( |
24
|
|
|
StarSystemRepositoryInterface $starSystemRepository, |
25
|
|
|
StarSystemCreationInterface $starSystemCreation |
26
|
|
|
) { |
27
|
|
|
$this->starSystemRepository = $starSystemRepository; |
28
|
|
|
$this->starSystemCreation = $starSystemCreation; |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
public function handle(GameControllerInterface $game): void |
32
|
|
|
{ |
33
|
|
|
$game->setView(ShowSystem::VIEW_IDENTIFIER); |
34
|
|
|
|
35
|
|
|
$systemId = request::getInt('sysid'); |
36
|
|
|
|
37
|
|
|
$starSystem = $this->starSystemRepository->find($systemId); |
38
|
|
|
if ($starSystem === null) { |
39
|
|
|
return; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
$map = $starSystem->getMapField(); |
43
|
|
|
if ($map === null) { |
44
|
|
|
return; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
$systemName = current($this->starSystemRepository->getRandomFreeSystemNames(1)); |
48
|
|
|
if ($systemName === false) { |
49
|
|
|
throw new RuntimeException('no free system name available'); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
$this->starSystemCreation->recreateStarSystem($map, $systemName->getName()); |
53
|
|
|
|
54
|
|
|
$game->addInformation('Das System wurde neu generiert.'); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function performSessionCheck(): bool |
58
|
|
|
{ |
59
|
|
|
return false; |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|