1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Stu\Module\Colony\Lib\Gui\Component; |
4
|
|
|
|
5
|
|
|
use RuntimeException; |
6
|
|
|
use Stu\Component\Colony\OrbitShipListRetrieverInterface; |
7
|
|
|
use Stu\Lib\Colony\PlanetFieldHostInterface; |
8
|
|
|
use Stu\Lib\Colony\PlanetFieldHostProviderInterface; |
9
|
|
|
use Stu\Module\Colony\Lib\ColonyLibFactoryInterface; |
10
|
|
|
use Stu\Module\Control\GameControllerInterface; |
11
|
|
|
use Stu\Module\Ship\Lib\ShipWrapperFactoryInterface; |
12
|
|
|
use Stu\Orm\Entity\ColonyInterface; |
13
|
|
|
use Stu\Orm\Entity\ShipInterface; |
14
|
|
|
use Stu\Orm\Repository\ShipRumpBuildingFunctionRepositoryInterface; |
15
|
|
|
|
16
|
|
|
final class ShipRepairProvider implements GuiComponentProviderInterface |
17
|
|
|
{ |
18
|
|
|
private ShipRumpBuildingFunctionRepositoryInterface $shipRumpBuildingFunctionRepository; |
19
|
|
|
|
20
|
|
|
private PlanetFieldHostProviderInterface $planetFieldHostProvider; |
21
|
|
|
|
22
|
|
|
private ColonyLibFactoryInterface $colonyLibFactory; |
23
|
|
|
|
24
|
|
|
private ShipWrapperFactoryInterface $shipWrapperFactory; |
25
|
|
|
|
26
|
|
|
private OrbitShipListRetrieverInterface $orbitShipListRetriever; |
27
|
|
|
|
28
|
|
|
public function __construct( |
29
|
|
|
ShipRumpBuildingFunctionRepositoryInterface $shipRumpBuildingFunctionRepository, |
30
|
|
|
PlanetFieldHostProviderInterface $planetFieldHostProvider, |
31
|
|
|
ColonyLibFactoryInterface $colonyLibFactory, |
32
|
|
|
OrbitShipListRetrieverInterface $orbitShipListRetriever, |
33
|
|
|
ShipWrapperFactoryInterface $shipWrapperFactory |
34
|
|
|
) { |
35
|
|
|
$this->shipRumpBuildingFunctionRepository = $shipRumpBuildingFunctionRepository; |
36
|
|
|
$this->planetFieldHostProvider = $planetFieldHostProvider; |
37
|
|
|
$this->colonyLibFactory = $colonyLibFactory; |
38
|
|
|
$this->shipWrapperFactory = $shipWrapperFactory; |
39
|
|
|
$this->orbitShipListRetriever = $orbitShipListRetriever; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** @param ColonyInterface $host */ |
43
|
|
|
public function setTemplateVariables( |
44
|
|
|
PlanetFieldHostInterface $host, |
45
|
|
|
GameControllerInterface $game |
46
|
|
|
): void { |
47
|
|
|
$field = $this->planetFieldHostProvider->loadFieldViaRequestParameter($game->getUser()); |
48
|
|
|
|
49
|
|
|
$building = $field->getBuilding(); |
50
|
|
|
if ($building === null) { |
51
|
|
|
throw new RuntimeException('building is null'); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
$fieldFunctions = $building->getFunctions()->toArray(); |
55
|
|
|
$colonySurface = $this->colonyLibFactory->createColonySurface($host); |
56
|
|
|
|
57
|
|
|
if ($colonySurface->hasShipyard()) { |
58
|
|
|
$repairableShips = []; |
59
|
|
|
foreach ($this->orbitShipListRetriever->retrieve($host) as $fleet) { |
60
|
|
|
/** @var ShipInterface $ship */ |
61
|
|
|
foreach ($fleet['ships'] as $ship) { |
62
|
|
|
$wrapper = $this->shipWrapperFactory->wrapShip($ship); |
63
|
|
|
|
64
|
|
|
if ( |
65
|
|
|
!$wrapper->canBeRepaired() || $ship->isUnderRepair() |
66
|
|
|
) { |
67
|
|
|
continue; |
68
|
|
|
} |
69
|
|
|
foreach ($this->shipRumpBuildingFunctionRepository->getByShipRump($ship->getRump()) as $rump_rel) { |
70
|
|
|
if (array_key_exists($rump_rel->getBuildingFunction(), $fieldFunctions)) { |
71
|
|
|
$repairableShips[$ship->getId()] = $wrapper; |
72
|
|
|
break; |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
$game->setTemplateVar('REPAIRABLE_SHIP_LIST', $repairableShips); |
79
|
|
|
$game->setTemplateVar('FIELD', $field); |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|