1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Stu\Lib\Transfer\Strategy; |
6
|
|
|
|
7
|
|
|
use Override; |
|
|
|
|
8
|
|
|
use request; |
9
|
|
|
use Stu\Component\Spacecraft\Crew\SpacecraftCrewCalculatorInterface; |
10
|
|
|
use Stu\Lib\Information\InformationInterface; |
11
|
|
|
use Stu\Lib\Transfer\Wrapper\StorageEntityWrapperInterface; |
12
|
|
|
use Stu\Module\Control\GameControllerInterface; |
13
|
|
|
use Stu\Module\Spacecraft\Lib\Crew\TroopTransferUtilityInterface; |
14
|
|
|
use Stu\Orm\Entity\CrewAssignmentInterface; |
15
|
|
|
use Stu\Orm\Entity\ShipInterface; |
16
|
|
|
use Stu\Orm\Entity\UserInterface; |
17
|
|
|
|
18
|
|
|
class TroopTransferStrategy implements TransferStrategyInterface |
19
|
|
|
{ |
20
|
1 |
|
public function __construct( |
21
|
|
|
private SpacecraftCrewCalculatorInterface $shipCrewCalculator, |
22
|
|
|
private TroopTransferUtilityInterface $troopTransferUtility, |
23
|
1 |
|
) {} |
24
|
|
|
|
25
|
4 |
|
#[Override] |
26
|
|
|
public function setTemplateVariables( |
27
|
|
|
bool $isUnload, |
28
|
|
|
StorageEntityWrapperInterface $source, |
29
|
|
|
StorageEntityWrapperInterface $target, |
30
|
|
|
GameControllerInterface $game |
31
|
|
|
): void { |
32
|
|
|
|
33
|
4 |
|
$user = $game->getUser(); |
34
|
4 |
|
$targetEntity = $target->get(); |
35
|
|
|
|
36
|
|
|
if ( |
37
|
4 |
|
$targetEntity instanceof ShipInterface |
38
|
4 |
|
&& $targetEntity->getBuildplan() !== null |
39
|
|
|
) { |
40
|
2 |
|
$game->setTemplateVar('SHOW_TARGET_CREW', true); |
41
|
2 |
|
$game->setTemplateVar('ACTUAL_TARGET_CREW', $targetEntity->getCrewCount()); |
42
|
2 |
|
$game->setTemplateVar('MINIMUM_TARGET_CREW', $targetEntity->getBuildplan()->getCrew()); |
43
|
2 |
|
$game->setTemplateVar( |
44
|
2 |
|
'MAXIMUM_TARGET_CREW', |
45
|
2 |
|
$this->shipCrewCalculator->getMaxCrewCountByShip($targetEntity) |
46
|
2 |
|
); |
47
|
|
|
} |
48
|
|
|
|
49
|
4 |
|
$game->setTemplateVar('MAXIMUM', $this->getMaxTransferrableCrew($source, $target, $user, $isUnload)); |
50
|
|
|
} |
51
|
|
|
|
52
|
4 |
|
private function getMaxTransferrableCrew( |
53
|
|
|
StorageEntityWrapperInterface $source, |
54
|
|
|
StorageEntityWrapperInterface $target, |
55
|
|
|
UserInterface $user, |
56
|
|
|
bool $isUnload |
57
|
|
|
): int { |
58
|
4 |
|
return min( |
59
|
4 |
|
$isUnload ? $source->getMaxTransferrableCrew(false, $user) : $target->getMaxTransferrableCrew(true, $user), |
60
|
4 |
|
$isUnload ? $target->getFreeCrewSpace($user) : $source->getFreeCrewSpace($user) |
61
|
4 |
|
); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
#[Override] |
65
|
|
|
public function transfer( |
66
|
|
|
bool $isUnload, |
67
|
|
|
StorageEntityWrapperInterface $source, |
68
|
|
|
StorageEntityWrapperInterface $target, |
69
|
|
|
InformationInterface $information |
70
|
|
|
): void { |
71
|
|
|
|
72
|
|
|
$user = $source->getUser(); |
73
|
|
|
|
74
|
|
|
$amount = min( |
75
|
|
|
request::postInt('crewcount'), |
76
|
|
|
$this->getMaxTransferrableCrew($source, $target, $user, $isUnload) |
77
|
|
|
); |
78
|
|
|
|
79
|
|
|
if ($amount < 1) { |
80
|
|
|
$information->addInformation('Es konnten keine Crewman transferiert werden'); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
if (!$source->checkCrewStorage($amount, $isUnload, $information)) { |
84
|
|
|
return; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
if ($isUnload && !$target->acceptsCrewFrom($amount, $user, $information)) { |
88
|
|
|
return; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
$destination = $isUnload ? $target : $source; |
92
|
|
|
$crewAssignments = $isUnload ? $source->get()->getCrewAssignments() : $target->get()->getCrewAssignments(); |
93
|
|
|
$filteredByUser = $crewAssignments->filter(fn(CrewAssignmentInterface $crewAssignment): bool => $crewAssignment->getCrew()->getUser() === $source->getUser())->toArray(); |
94
|
|
|
$slice = array_slice($filteredByUser, 0, $amount); |
95
|
|
|
|
96
|
|
|
foreach ($slice as $crewAssignment) { |
97
|
|
|
$this->troopTransferUtility->assignCrew($crewAssignment, $destination->get()); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
$information->addInformation( |
101
|
|
|
sprintf( |
102
|
|
|
_('Die %s hat %d Crewman %s der %s transferiert'), |
103
|
|
|
$source->getName(), |
104
|
|
|
$amount, |
105
|
|
|
$isUnload ? 'zu' : 'von', |
106
|
|
|
$target->getName() |
107
|
|
|
) |
108
|
|
|
); |
109
|
|
|
|
110
|
|
|
$foreignCrewChangeAmount = $source->getUser() !== $target->getUser() |
111
|
|
|
? ($isUnload ? $amount : -$amount) |
112
|
|
|
: 0; |
113
|
|
|
|
114
|
|
|
$source->postCrewTransfer($foreignCrewChangeAmount, $target, $information); |
115
|
|
|
$target->postCrewTransfer($foreignCrewChangeAmount, $source, $information); |
116
|
|
|
} |
117
|
|
|
} |
118
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths