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