|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Stu\Component\Event\Strategy; |
|
4
|
|
|
|
|
5
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
|
6
|
|
|
use Doctrine\Common\Collections\Collection; |
|
7
|
|
|
use JsonMapper\JsonMapperInterface; |
|
8
|
|
|
use Stu\Component\Event\Payload\PayloadWithIdAndTurn; |
|
9
|
|
|
use Stu\Module\Tick\Ship\ManagerComponent\RepairActions; |
|
10
|
|
|
use Stu\Orm\Entity\ColonyShipRepairInterface; |
|
11
|
|
|
use Stu\Orm\Entity\EventInterface; |
|
12
|
|
|
use Stu\Orm\Repository\ColonyShipRepairRepositoryInterface; |
|
13
|
|
|
|
|
14
|
|
|
class ColonyShipRepairEventStrategy implements EventStrategyInterface |
|
15
|
|
|
{ |
|
16
|
|
|
public function __construct( |
|
17
|
|
|
private ColonyShipRepairRepositoryInterface $colonyShipRepairRepository, |
|
18
|
|
|
private RepairActions $repairActions, |
|
19
|
|
|
private JsonMapperInterface $jsonMapper |
|
20
|
|
|
) { |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
public function getEntitiesToLock(EventInterface $event): Collection |
|
24
|
|
|
{ |
|
25
|
|
|
$result = []; |
|
26
|
|
|
|
|
27
|
|
|
$colonyShipRepair = $this->getShipRepair($event); |
|
28
|
|
|
if ($colonyShipRepair !== null) { |
|
29
|
|
|
$colonyUser = $colonyShipRepair->getColony()->getUser(); |
|
30
|
|
|
$shipUser = $colonyShipRepair->getShip()->getUser(); |
|
31
|
|
|
|
|
32
|
|
|
$result[$colonyUser->getId()] = $colonyUser; |
|
33
|
|
|
$result[$shipUser->getId()] = $shipUser; |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
return new ArrayCollection($result); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
public function processEvent(EventInterface $event): void |
|
40
|
|
|
{ |
|
41
|
|
|
$shipRepair = $this->getShipRepair($event); |
|
42
|
|
|
if ($shipRepair !== null) { |
|
43
|
|
|
$this->repairActions->repairShipOnColony($shipRepair); |
|
44
|
|
|
} |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
private function getShipRepair(EventInterface $event): ?ColonyShipRepairInterface |
|
48
|
|
|
{ |
|
49
|
|
|
/** @var PayloadWithIdAndTurn */ |
|
50
|
|
|
$payload = $event->getPayloadAsObject($this->jsonMapper); |
|
51
|
|
|
|
|
52
|
|
|
return $this->colonyShipRepairRepository->find($payload->id); |
|
53
|
|
|
} |
|
54
|
|
|
} |
|
55
|
|
|
|