1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Stu\Module\Tick\Pirate; |
4
|
|
|
|
5
|
|
|
use Override; |
|
|
|
|
6
|
|
|
use Stu\Lib\Pirate\Behaviour\PirateBehaviourInterface; |
7
|
|
|
use Stu\Lib\Pirate\Component\ReloadMinimalEpsInterface; |
8
|
|
|
use Stu\Lib\Pirate\PirateBehaviourEnum; |
9
|
|
|
use Stu\Lib\Pirate\PirateCreationInterface; |
10
|
|
|
use Stu\Lib\Pirate\PirateReactionInterface; |
11
|
|
|
use Stu\Lib\Pirate\PirateReactionMetadata; |
12
|
|
|
use Stu\Module\Control\StuRandom; |
13
|
|
|
use Stu\Module\Logging\LoggerUtilFactoryInterface; |
14
|
|
|
use Stu\Module\Logging\PirateLoggerInterface; |
15
|
|
|
use Stu\Module\Spacecraft\Lib\SpacecraftWrapperFactoryInterface; |
16
|
|
|
|
17
|
|
|
final class PirateTick implements PirateTickInterface |
18
|
|
|
{ |
19
|
|
|
private PirateLoggerInterface $logger; |
20
|
|
|
|
21
|
|
|
/** @param array<int, PirateBehaviourInterface> $behaviours */ |
22
|
1 |
|
public function __construct( |
23
|
|
|
private PirateCreationInterface $pirateCreation, |
24
|
|
|
private PirateReactionInterface $pirateReaction, |
25
|
|
|
private SpacecraftWrapperFactoryInterface $spacecraftWrapperFactory, |
26
|
|
|
private ReloadMinimalEpsInterface $reloadMinimalEps, |
27
|
|
|
private StuRandom $stuRandom, |
28
|
|
|
LoggerUtilFactoryInterface $loggerUtilFactory, |
29
|
|
|
private array $behaviours |
30
|
|
|
) { |
31
|
1 |
|
$this->logger = $loggerUtilFactory->getPirateLogger(); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
#[Override] |
35
|
|
|
public function work(): void |
36
|
|
|
{ |
37
|
|
|
$this->logger->log('PIRATE TICK:'); |
38
|
|
|
|
39
|
|
|
// create new pirates (max 5 fleets) |
40
|
|
|
$pirateFleets = $this->pirateCreation->createPirateFleetsIfNeeded(); |
41
|
|
|
|
42
|
|
|
// process pirate fleets |
43
|
|
|
foreach ($pirateFleets as $fleet) { |
44
|
|
|
$behaviourType = $this->getRandomBehaviourType(); |
45
|
|
|
|
46
|
|
|
if ($behaviourType === PirateBehaviourEnum::DO_NOTHING) { |
47
|
|
|
continue; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
$this->logger->log(sprintf('pirateFleetId %d does %s', $fleet->getId(), $behaviourType->name)); |
|
|
|
|
51
|
|
|
|
52
|
|
|
$fleetWrapper = $this->spacecraftWrapperFactory->wrapFleet($fleet); |
53
|
|
|
|
54
|
|
|
$this->behaviours[$behaviourType->value]->action( |
55
|
|
|
$fleetWrapper, |
56
|
|
|
$this->pirateReaction, |
57
|
|
|
new PirateReactionMetadata(), |
58
|
|
|
null |
59
|
|
|
); |
60
|
|
|
|
61
|
|
|
$this->reloadMinimalEps->reload($fleetWrapper); |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
private function getRandomBehaviourType(): PirateBehaviourEnum |
66
|
|
|
{ |
67
|
|
|
$value = $this->stuRandom->randomKeyOfProbabilities(PirateBehaviourEnum::getBehaviourProbabilities()); |
68
|
|
|
|
69
|
|
|
return PirateBehaviourEnum::from($value); |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|
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