|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Stu\Module\Tick\Spacecraft\Handler; |
|
4
|
|
|
|
|
5
|
|
|
use Stu\Component\Spacecraft\System\SpacecraftSystemTypeEnum; |
|
6
|
|
|
use Stu\Lib\Information\InformationInterface; |
|
7
|
|
|
use Stu\Lib\Transfer\Storage\StorageManagerInterface; |
|
8
|
|
|
use Stu\Module\Control\StuRandom; |
|
9
|
|
|
use Stu\Module\Ship\Lib\ShipWrapperInterface; |
|
10
|
|
|
use Stu\Module\Spacecraft\Lib\SpacecraftWrapperInterface; |
|
11
|
|
|
use Stu\Orm\Repository\LocationMiningRepositoryInterface; |
|
12
|
|
|
|
|
13
|
|
|
class BussardCollectorHandler implements SpacecraftTickHandlerInterface |
|
14
|
|
|
{ |
|
15
|
1 |
|
public function __construct( |
|
16
|
|
|
private readonly LocationMiningRepositoryInterface $locationMiningRepository, |
|
17
|
|
|
private readonly StorageManagerInterface $storageManager, |
|
18
|
|
|
private readonly StuRandom $stuRandom |
|
19
|
1 |
|
) {} |
|
20
|
|
|
|
|
21
|
|
|
#[\Override] |
|
22
|
|
|
public function handleSpacecraftTick( |
|
23
|
|
|
SpacecraftWrapperInterface $wrapper, |
|
24
|
|
|
InformationInterface $information |
|
25
|
|
|
): void { |
|
26
|
|
|
|
|
27
|
|
|
if (!$wrapper instanceof ShipWrapperInterface) { |
|
28
|
|
|
return; |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
$ship = $wrapper->get(); |
|
32
|
|
|
$bussard = $wrapper->getBussardCollectorSystemData(); |
|
33
|
|
|
$miningqueue = $ship->getMiningQueue(); |
|
34
|
|
|
|
|
35
|
|
|
if ($bussard === null) { |
|
36
|
|
|
return; |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
if ($miningqueue == null) { |
|
40
|
|
|
return; |
|
41
|
|
|
} else { |
|
42
|
|
|
$locationmining = $miningqueue->getLocationMining(); |
|
43
|
|
|
$actualAmount = $locationmining->getActualAmount(); |
|
44
|
|
|
$freeStorage = $ship->getMaxStorage() - $ship->getStorageSum(); |
|
45
|
|
|
$module = $ship->getSpacecraftSystem(SpacecraftSystemTypeEnum::BUSSARD_COLLECTOR)->getModule(); |
|
46
|
|
|
$gathercount = 0; |
|
47
|
|
|
|
|
48
|
|
|
if ($module !== null) { |
|
49
|
|
|
if ($module->getFactionId() == null) { |
|
50
|
|
|
$gathercount = (int) min(min(round($this->stuRandom->rand(95, 105)), $actualAmount), $freeStorage); |
|
51
|
|
|
} else { |
|
52
|
|
|
$gathercount = (int) min(min(round($this->stuRandom->rand(190, 220)), $actualAmount), $freeStorage); |
|
53
|
|
|
} |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
$newAmount = $actualAmount - $gathercount; |
|
57
|
|
|
if ($gathercount > 0 && $locationmining->getDepletedAt() !== null) { |
|
58
|
|
|
$locationmining->setDepletedAt(null); |
|
59
|
|
|
} |
|
60
|
|
|
if ($newAmount == 0 && $actualAmount > 0) { |
|
61
|
|
|
$locationmining->setDepletedAt(time()); |
|
62
|
|
|
$information->addInformationf( |
|
63
|
|
|
'Es sind keine %s bei den Koordinaten %s|%s vorhanden!', |
|
64
|
|
|
$locationmining->getCommodity()->getName(), |
|
65
|
|
|
(string)$locationmining->getLocation()->getCx(), |
|
66
|
|
|
(string)$locationmining->getLocation()->getCy() |
|
67
|
|
|
); |
|
68
|
|
|
} |
|
69
|
|
|
$locationmining->setActualAmount($newAmount); |
|
70
|
|
|
|
|
71
|
|
|
$this->locationMiningRepository->save($locationmining); |
|
72
|
|
|
if ($gathercount + $ship->getStorageSum() >= $ship->getMaxStorage()) { |
|
73
|
|
|
$information->addInformationf('Der Lagerraum des Schiffes wurde beim Sammeln von %s voll!', $locationmining->getCommodity()->getName()); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
if ($gathercount > 0) { |
|
77
|
|
|
$this->storageManager->upperStorage( |
|
78
|
|
|
$ship, |
|
79
|
|
|
$locationmining->getCommodity(), |
|
80
|
|
|
$gathercount |
|
81
|
|
|
); |
|
82
|
|
|
} |
|
83
|
|
|
} |
|
84
|
|
|
} |
|
85
|
|
|
} |
|
86
|
|
|
|