|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Stu\Lib\Pirate\Behaviour; |
|
4
|
|
|
|
|
5
|
|
|
use Override; |
|
|
|
|
|
|
6
|
|
|
use Stu\Component\Game\ModuleEnum; |
|
7
|
|
|
use Stu\Component\Spacecraft\System\SpacecraftSystemManagerInterface; |
|
8
|
|
|
use Stu\Component\Spacecraft\System\SpacecraftSystemTypeEnum; |
|
9
|
|
|
use Stu\Lib\Information\InformationWrapper; |
|
10
|
|
|
use Stu\Lib\Map\DistanceCalculationInterface; |
|
11
|
|
|
use Stu\Lib\Pirate\Component\PirateNavigationInterface; |
|
12
|
|
|
use Stu\Lib\Pirate\PirateBehaviourEnum; |
|
13
|
|
|
use Stu\Lib\Pirate\PirateReactionInterface; |
|
14
|
|
|
use Stu\Lib\Pirate\PirateReactionMetadata; |
|
15
|
|
|
use Stu\Lib\Transfer\CommodityTransferInterface; |
|
16
|
|
|
use Stu\Module\Colony\Lib\ColonyLibFactoryInterface; |
|
17
|
|
|
use Stu\Module\Colony\View\ShowColony\ShowColony; |
|
18
|
|
|
use Stu\Module\Control\StuRandom; |
|
19
|
|
|
use Stu\Module\Logging\LoggerUtilFactoryInterface; |
|
20
|
|
|
use Stu\Module\Logging\PirateLoggerInterface; |
|
21
|
|
|
use Stu\Module\Message\Lib\PrivateMessageFolderTypeEnum; |
|
22
|
|
|
use Stu\Module\Message\Lib\PrivateMessageSenderInterface; |
|
23
|
|
|
use Stu\Module\Ship\Lib\FleetWrapperInterface; |
|
24
|
|
|
use Stu\Orm\Entity\Colony; |
|
25
|
|
|
use Stu\Orm\Entity\Spacecraft; |
|
26
|
|
|
use Stu\Orm\Entity\Storage; |
|
27
|
|
|
use Stu\Orm\Repository\ColonyRepositoryInterface; |
|
28
|
|
|
|
|
29
|
|
|
class RubColonyBehaviour implements PirateBehaviourInterface |
|
30
|
|
|
{ |
|
31
|
|
|
private PirateLoggerInterface $logger; |
|
32
|
|
|
|
|
33
|
1 |
|
public function __construct( |
|
34
|
|
|
private ColonyRepositoryInterface $colonyRepository, |
|
35
|
|
|
private DistanceCalculationInterface $distanceCalculation, |
|
36
|
|
|
private PirateNavigationInterface $pirateNavigation, |
|
37
|
|
|
private ColonyLibFactoryInterface $colonyLibFactory, |
|
38
|
|
|
private SpacecraftSystemManagerInterface $spacecraftSystemManager, |
|
39
|
|
|
private CommodityTransferInterface $commodityTransfer, |
|
40
|
|
|
private PrivateMessageSenderInterface $privateMessageSender, |
|
41
|
|
|
private StuRandom $stuRandom, |
|
42
|
|
|
LoggerUtilFactoryInterface $loggerUtilFactory |
|
43
|
|
|
) { |
|
44
|
1 |
|
$this->logger = $loggerUtilFactory->getPirateLogger(); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
#[Override] |
|
48
|
|
|
public function action( |
|
49
|
|
|
FleetWrapperInterface $fleet, |
|
50
|
|
|
PirateReactionInterface $pirateReaction, |
|
51
|
|
|
PirateReactionMetadata $reactionMetadata, |
|
52
|
|
|
?Spacecraft $triggerSpacecraft |
|
53
|
|
|
): ?PirateBehaviourEnum { |
|
54
|
|
|
|
|
55
|
|
|
$leadWrapper = $fleet->getLeadWrapper(); |
|
56
|
|
|
$leadShip = $leadWrapper->get(); |
|
57
|
|
|
|
|
58
|
|
|
$targets = $this->colonyRepository->getPirateTargets($leadWrapper); |
|
59
|
|
|
if ($targets === []) { |
|
60
|
|
|
$this->logger->log(' no colony targets in reach'); |
|
61
|
|
|
return PirateBehaviourEnum::FLY; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
usort($targets, fn(Colony $a, Colony $b): int => |
|
65
|
|
|
$this->distanceCalculation->spacecraftToColonyDistance($leadShip, $a) - $this->distanceCalculation->spacecraftToColonyDistance($leadShip, $b)); |
|
66
|
|
|
|
|
67
|
|
|
$closestColony = current($targets); |
|
68
|
|
|
|
|
69
|
|
|
if ($this->pirateNavigation->navigateToTarget($fleet, $closestColony->getStarsystemMap())) { |
|
70
|
|
|
$this->logger->logf( |
|
71
|
|
|
' reached colonyId %d at %s', |
|
72
|
|
|
$closestColony->getId(), |
|
73
|
|
|
$closestColony->getSectorString() |
|
74
|
|
|
); |
|
75
|
|
|
$this->rubColony($fleet, $closestColony); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
return null; |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
private function rubColony(FleetWrapperInterface $fleetWrapper, Colony $colony): void |
|
82
|
|
|
{ |
|
83
|
|
|
if ($this->colonyLibFactory->createColonyShieldingManager($colony)->isShieldingEnabled()) { |
|
84
|
|
|
$this->logger->log(' colony has shield on'); |
|
85
|
|
|
return; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
$pirateUser = $fleetWrapper->get()->getUser(); |
|
89
|
|
|
|
|
90
|
|
|
$filteredColonyStorage = array_filter( |
|
91
|
|
|
$colony->getStorage()->toArray(), |
|
92
|
|
|
fn(Storage $storage): bool => $storage->getCommodity()->isBeamable($colony->getUser(), $pirateUser) |
|
93
|
|
|
); |
|
94
|
|
|
|
|
95
|
|
|
$allInformations = new InformationWrapper(); |
|
96
|
|
|
|
|
97
|
|
|
foreach ($fleetWrapper->getShipWrappers() as $wrapper) { |
|
98
|
|
|
|
|
99
|
|
|
if ($filteredColonyStorage === []) { |
|
100
|
|
|
$this->logger->log(' no beamable storage on colony'); |
|
101
|
|
|
return; |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
$this->spacecraftSystemManager->deactivate($wrapper, SpacecraftSystemTypeEnum::SHIELDS, true); |
|
105
|
|
|
|
|
106
|
|
|
$ship = $wrapper->get(); |
|
107
|
|
|
$randomCommodityId = array_rand($filteredColonyStorage); |
|
108
|
|
|
|
|
109
|
|
|
$informations = new InformationWrapper(); |
|
110
|
|
|
|
|
111
|
|
|
$hasStolen = $this->commodityTransfer->transferCommodity( |
|
112
|
|
|
$randomCommodityId, |
|
113
|
|
|
$this->stuRandom->rand(1, $wrapper->get()->getMaxStorage()), |
|
114
|
|
|
$wrapper, |
|
115
|
|
|
$colony, |
|
116
|
|
|
$wrapper->get(), |
|
117
|
|
|
$informations |
|
118
|
|
|
); |
|
119
|
|
|
|
|
120
|
|
|
if ($hasStolen) { |
|
121
|
|
|
$informations->addInformationArray([sprintf( |
|
122
|
|
|
_('Die %s hat folgende Waren von der Kolonie %s gestohlen'), |
|
123
|
|
|
$ship->getName(), |
|
124
|
|
|
$colony->getName() |
|
125
|
|
|
)], true); |
|
126
|
|
|
|
|
127
|
|
|
$this->spacecraftSystemManager->activate($wrapper, SpacecraftSystemTypeEnum::SHIELDS, true); |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
$allInformations->addInformationWrapper($informations); |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
|
|
$this->privateMessageSender->send( |
|
134
|
|
|
$pirateUser->getId(), |
|
135
|
|
|
$colony->getUser()->getId(), |
|
136
|
|
|
$allInformations, |
|
137
|
|
|
PrivateMessageFolderTypeEnum::SPECIAL_TRADE, |
|
138
|
|
|
sprintf( |
|
139
|
|
|
'%s?%s=1&id=%d', |
|
140
|
|
|
ModuleEnum::COLONY->getPhpPage(), |
|
141
|
|
|
ShowColony::VIEW_IDENTIFIER, |
|
142
|
|
|
$colony->getId() |
|
143
|
|
|
) |
|
144
|
|
|
); |
|
145
|
|
|
} |
|
146
|
|
|
} |
|
147
|
|
|
|
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