1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Stu\Lib\Transfer\Strategy; |
6
|
|
|
|
7
|
|
|
use Override; |
|
|
|
|
8
|
|
|
use request; |
9
|
|
|
use RuntimeException; |
10
|
|
|
use Stu\Lib\Information\InformationInterface; |
11
|
|
|
use Stu\Lib\Transfer\Wrapper\StorageEntityWrapperInterface; |
12
|
|
|
use Stu\Module\Control\GameControllerInterface; |
13
|
|
|
use Stu\Orm\Entity\Colony; |
14
|
|
|
|
15
|
|
|
class TorpedoTransferStrategy implements TransferStrategyInterface |
16
|
|
|
{ |
17
|
|
|
#[Override] |
18
|
|
|
public function setTemplateVariables( |
19
|
|
|
bool $isUnload, |
20
|
|
|
StorageEntityWrapperInterface $source, |
21
|
|
|
StorageEntityWrapperInterface $target, |
22
|
|
|
GameControllerInterface $game |
23
|
|
|
): void { |
24
|
|
|
|
25
|
|
|
if ($target instanceof Colony) { |
26
|
|
|
throw new RuntimeException('this should not happen'); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
if ($isUnload) { |
30
|
|
|
$max = min( |
31
|
|
|
$target->getMaxTorpedos(), |
32
|
|
|
$source->getTorpedoCount() |
33
|
|
|
); |
34
|
|
|
$commodityId = $source->getTorpedo() === null ? null : $source->getTorpedo()->getCommodityId(); |
35
|
|
|
} else { |
36
|
|
|
$max = $target->getTorpedoCount(); |
37
|
|
|
$commodityId = $target->getTorpedo() === null ? null : $target->getTorpedo()->getCommodityId(); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
$game->setTemplateVar('MAXIMUM', $max); |
41
|
|
|
$game->setTemplateVar('COMMODITY_ID', $commodityId); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
#[Override] |
45
|
|
|
public function transfer( |
46
|
|
|
bool $isUnload, |
47
|
|
|
StorageEntityWrapperInterface $source, |
48
|
|
|
StorageEntityWrapperInterface $target, |
49
|
|
|
InformationInterface $information |
50
|
|
|
): void { |
51
|
|
|
|
52
|
|
|
$torpedoType = $isUnload ? $source->getTorpedo() : $target->getTorpedo(); |
53
|
|
|
if ($torpedoType === null) { |
54
|
|
|
throw new RuntimeException('this should not happen'); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
if (!$source->canTransferTorpedos($information)) { |
58
|
|
|
return; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
$destination = $isUnload ? $target : $source; |
62
|
|
|
if (!$destination->canStoreTorpedoType($torpedoType, $information)) { |
63
|
|
|
return; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
//TODO use energy to transfer |
67
|
|
|
$requestedTransferCount = request::postInt('tcount'); |
68
|
|
|
|
69
|
|
|
$amount = min( |
70
|
|
|
$requestedTransferCount, |
71
|
|
|
$isUnload ? $source->getTorpedoCount() : $target->getTorpedoCount(), |
72
|
|
|
$isUnload ? $target->getMaxTorpedos() - $target->getTorpedoCount() : $source->getMaxTorpedos() - $source->getTorpedoCount() |
73
|
|
|
); |
74
|
|
|
|
75
|
|
|
if ($amount < 1) { |
76
|
|
|
$information->addInformation('Es konnten keine Torpedos transferiert werden'); |
77
|
|
|
return; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
$target->changeTorpedo($isUnload ? $amount : -$amount, $torpedoType); |
81
|
|
|
$source->changeTorpedo($isUnload ? -$amount : $amount, $torpedoType); |
82
|
|
|
|
83
|
|
|
$information->addInformation( |
84
|
|
|
sprintf( |
85
|
|
|
'Die %s hat in Sektor %s %d Torpedos %s %s transferiert', |
86
|
|
|
$source->getName(), |
87
|
|
|
$source->getLocation()->getSectorString(), |
88
|
|
|
$amount, |
89
|
|
|
$isUnload ? 'zur' : 'von der', |
90
|
|
|
$target->getName() |
91
|
|
|
), |
92
|
|
|
); |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
|
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