|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Stu\Module\Tick\Colony\Component; |
|
4
|
|
|
|
|
5
|
|
|
use Stu\Lib\Information\InformationInterface; |
|
6
|
|
|
use Stu\Lib\Transfer\Storage\StorageManagerInterface; |
|
7
|
|
|
use Stu\Module\Commodity\Lib\CommodityCacheInterface; |
|
8
|
|
|
use Stu\Orm\Entity\ColonyInterface; |
|
9
|
|
|
use Stu\Orm\Repository\ColonyDepositMiningRepositoryInterface; |
|
10
|
|
|
|
|
11
|
|
|
class ProceedStorage implements ColonyTickComponentInterface |
|
12
|
|
|
{ |
|
13
|
1 |
|
public function __construct( |
|
14
|
|
|
private readonly ColonyDepositMiningRepositoryInterface $colonyDepositMiningRepository, |
|
15
|
|
|
private readonly CommodityCacheInterface $commodityCache, |
|
16
|
|
|
private readonly StorageManagerInterface $storageManager |
|
17
|
1 |
|
) {} |
|
18
|
|
|
|
|
19
|
|
|
public function work(ColonyInterface $colony, array &$production, InformationInterface $information): void |
|
20
|
|
|
{ |
|
21
|
|
|
$sum = $colony->getStorageSum(); |
|
22
|
|
|
|
|
23
|
|
|
//DECREASE |
|
24
|
|
|
foreach ($production as $commodityId => $obj) { |
|
25
|
|
|
$amount = $obj->getProduction(); |
|
26
|
|
|
$commodity = $this->commodityCache->get($commodityId); |
|
27
|
|
|
|
|
28
|
|
|
if ($amount < 0) { |
|
29
|
|
|
$amount = abs($amount); |
|
30
|
|
|
|
|
31
|
|
|
if ($commodity->isSaveable()) { |
|
32
|
|
|
// STANDARD |
|
33
|
|
|
$this->storageManager->lowerStorage( |
|
34
|
|
|
$colony, |
|
35
|
|
|
$this->commodityCache->get($commodityId), |
|
36
|
|
|
$amount |
|
|
|
|
|
|
37
|
|
|
); |
|
38
|
|
|
$sum -= $amount; |
|
39
|
|
|
} else { |
|
40
|
|
|
// EFFECTS |
|
41
|
|
|
$depositMining = $this->colonyDepositMiningRepository->getCurrentUserDepositMinings($colony)[$commodityId]; |
|
42
|
|
|
|
|
43
|
|
|
$depositMining->setAmountLeft($depositMining->getAmountLeft() - $amount); |
|
|
|
|
|
|
44
|
|
|
$this->colonyDepositMiningRepository->save($depositMining); |
|
45
|
|
|
} |
|
46
|
|
|
} |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
foreach ($production as $commodityId => $obj) { |
|
50
|
|
|
|
|
51
|
|
|
$commodity = $this->commodityCache->get($commodityId); |
|
52
|
|
|
if ($obj->getProduction() <= 0 || !$commodity->isSaveable()) { |
|
53
|
|
|
continue; |
|
54
|
|
|
} |
|
55
|
|
|
if ($sum >= $colony->getMaxStorage()) { |
|
56
|
|
|
if ($colony->getUser()->isStorageNotification()) { |
|
57
|
|
|
$information->addInformation('Das Lager der Kolonie ist voll'); |
|
58
|
|
|
} |
|
59
|
|
|
break; |
|
60
|
|
|
} |
|
61
|
|
|
if ($sum + $obj->getProduction() > $colony->getMaxStorage()) { |
|
62
|
|
|
$this->storageManager->upperStorage( |
|
63
|
|
|
$colony, |
|
64
|
|
|
$commodity, |
|
65
|
|
|
$colony->getMaxStorage() - $sum |
|
66
|
|
|
); |
|
67
|
|
|
if ($colony->getUser()->isStorageNotification()) { |
|
68
|
|
|
$information->addInformation('Das Lager der Kolonie ist voll'); |
|
69
|
|
|
} |
|
70
|
|
|
break; |
|
71
|
|
|
} |
|
72
|
|
|
$this->storageManager->upperStorage( |
|
73
|
|
|
$colony, |
|
74
|
|
|
$commodity, |
|
75
|
|
|
$obj->getProduction() |
|
76
|
|
|
); |
|
77
|
|
|
$sum += $obj->getProduction(); |
|
78
|
|
|
} |
|
79
|
|
|
} |
|
80
|
|
|
} |
|
81
|
|
|
|