Skip to content

Commit 8d75cc7

Browse files
committed
crew cheat
1 parent e601d41 commit 8d75cc7

File tree

5 files changed

+145
-0
lines changed

5 files changed

+145
-0
lines changed
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Stu\Module\Admin\Action;
6+
7+
use InvalidArgumentException;
8+
use Override;
9+
use request;
10+
use Stu\Module\Admin\View\Scripts\ShowScripts;
11+
use Stu\Module\Control\ActionControllerInterface;
12+
use Stu\Module\Control\GameControllerInterface;
13+
use Stu\Module\Crew\Lib\CrewCreatorInterface;
14+
use Stu\Orm\Repository\ColonyRepositoryInterface;
15+
use Stu\Orm\Repository\SpacecraftRepositoryInterface;
16+
17+
final class CreateCrew implements ActionControllerInterface
18+
{
19+
public const string ACTION_IDENTIFIER = 'B_CREATE_CREW';
20+
21+
public function __construct(
22+
private CrewCreatorInterface $crewCreator,
23+
private SpacecraftRepositoryInterface $spacecraftRepository,
24+
private ColonyRepositoryInterface $colonyRepository
25+
) {}
26+
27+
#[Override]
28+
public function handle(GameControllerInterface $game): void
29+
{
30+
$game->setView(ShowScripts::VIEW_IDENTIFIER);
31+
32+
if (!$game->isAdmin()) {
33+
$game->getInfo()->addInformation(_('[b][color=#ff2626]Aktion nicht möglich, Spieler ist kein Admin![/color][/b]'));
34+
return;
35+
}
36+
37+
$spacecraftId = request::postInt('spacecraft_id');
38+
$colonyId = request::postInt('colony_id');
39+
$amount = request::postIntFatal('crew_amount');
40+
41+
if ($amount <= 0) {
42+
$game->getInfo()->addInformation('Anzahl muss größer als 0 sein');
43+
return;
44+
}
45+
46+
if ($spacecraftId > 0 && $colonyId > 0) {
47+
$game->getInfo()->addInformation('Nur Spacecraft-ID ODER Kolonie-ID angeben');
48+
return;
49+
}
50+
51+
if ($spacecraftId === 0 && $colonyId === 0) {
52+
$game->getInfo()->addInformation('Spacecraft-ID oder Kolonie-ID angeben');
53+
return;
54+
}
55+
56+
if ($spacecraftId > 0) {
57+
$this->createCrewForSpacecraft($spacecraftId, $amount, $game);
58+
} else {
59+
$this->createCrewForColony($colonyId, $amount, $game);
60+
}
61+
}
62+
63+
private function createCrewForSpacecraft(int $spacecraftId, int $amount, GameControllerInterface $game): void
64+
{
65+
$spacecraft = $this->spacecraftRepository->find($spacecraftId);
66+
if ($spacecraft === null) {
67+
throw new InvalidArgumentException(sprintf('spacecraftId %d does not exist', $spacecraftId));
68+
}
69+
70+
$user = $spacecraft->getUser();
71+
72+
for ($i = 0; $i < $amount; $i++) {
73+
$crewAssignment = $this->crewCreator->create($user->getId());
74+
75+
$crewAssignment->setSpacecraft($spacecraft);
76+
$crewAssignment->setColony(null);
77+
$crewAssignment->setTradepost(null);
78+
79+
$spacecraft->getCrewAssignments()->add($crewAssignment);
80+
}
81+
82+
$this->spacecraftRepository->save($spacecraft);
83+
84+
$game->getInfo()->addInformation(sprintf(
85+
'%d Crew wurde für das Raumschiff %s (ID: %d) von Spieler %s erstellt',
86+
$amount,
87+
$spacecraft->getName(),
88+
$spacecraftId,
89+
$user->getName()
90+
));
91+
}
92+
93+
private function createCrewForColony(int $colonyId, int $amount, GameControllerInterface $game): void
94+
{
95+
$colony = $this->colonyRepository->find($colonyId);
96+
if ($colony === null) {
97+
throw new InvalidArgumentException(sprintf('colonyId %d does not exist', $colonyId));
98+
}
99+
100+
$user = $colony->getUser();
101+
102+
for ($i = 0; $i < $amount; $i++) {
103+
$this->crewCreator->create($user->getId(), $colony);
104+
}
105+
106+
$game->getInfo()->addInformation(sprintf(
107+
'%d Crew wurde für die Kolonie %s (ID: %d) von Spieler %s erstellt',
108+
$amount,
109+
$colony->getName(),
110+
$colonyId,
111+
$user->getName()
112+
));
113+
}
114+
115+
#[Override]
116+
public function performSessionCheck(): bool
117+
{
118+
return true;
119+
}
120+
}

src/Module/Admin/services.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use Stu\Module\Admin\Action\BlockUser;
88
use Stu\Module\Admin\Action\ClearFaultyBBCodes;
9+
use Stu\Module\Admin\Action\CreateCrew;
910
use Stu\Module\Admin\Action\CreateMissingUserWards;
1011
use Stu\Module\Admin\Action\LockUser;
1112
use Stu\Module\Admin\Action\PostNews;
@@ -112,6 +113,7 @@
112113
CreateInfluenceAreas::ACTION_IDENTIFIER => autowire(CreateInfluenceAreas::class),
113114
ClearFaultyBBCodes::ACTION_IDENTIFIER => autowire(ClearFaultyBBCodes::class),
114115
SendMassMail::ACTION_IDENTIFIER => autowire(SendMassMail::class),
116+
CreateCrew::ACTION_IDENTIFIER => autowire(CreateCrew::class),
115117
LockUser::ACTION_IDENTIFIER => autowire(LockUser::class),
116118
UnlockUser::ACTION_IDENTIFIER => autowire(UnlockUser::class),
117119
BlockUser::ACTION_IDENTIFIER => autowire(BlockUser::class),

src/Module/NPC/Action/CreateShip.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Stu\Module\NPC\Action;
66

7+
78
use InvalidArgumentException;
89
use Override;
910
use request;

src/html/admin/scripts.twig

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,17 @@
7070
</div>
7171
</div>
7272
<br />
73+
<div class="divhead">Crew</div>
74+
<div class="divbody">
75+
<div>
76+
Spacecraft-ID:<input type="text" size="8" name="spacecraft_id" id="spacecraft_id" />
77+
ODER Kolonie-ID:<input type="text" size="8" name="colony_id" id="colony_id" />
78+
<br /><br />
79+
Anzahl:<input type="text" size="5" name="crew_amount" id="crew_amount" value="1" />
80+
<input type="submit" class="button" name="B_CREATE_CREW" value="Crew erstellen" id="createcrewbutton" />
81+
</div>
82+
</div>
83+
<br />
7384
<div class="divhead">Anderes</div>
7485
<div class="divbody">
7586
Faction-ID:<input type="text" size="5" value="1" name="factionid" />

tests/inttest/html/__snapshots__/AllViewControllerTest--ADMIN_VIEWS-SHOW_SCRIPTS.html

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,17 @@
172172
</div>
173173
</div>
174174
<br>
175+
<div class="divhead">Crew</div>
176+
<div class="divbody">
177+
<div>
178+
Spacecraft-ID:<input type="text" size="8" name="spacecraft_id" id="spacecraft_id">
179+
ODER Kolonie-ID:<input type="text" size="8" name="colony_id" id="colony_id">
180+
<br><br>
181+
Anzahl:<input type="text" size="5" name="crew_amount" id="crew_amount" value="1">
182+
<input type="submit" class="button" name="B_CREATE_CREW" value="Crew erstellen" id="createcrewbutton">
183+
</div>
184+
</div>
185+
<br>
175186
<div class="divhead">Anderes</div>
176187
<div class="divbody">
177188
Faction-ID:<input type="text" size="5" value="1" name="factionid">

0 commit comments

Comments
 (0)