|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Stu\Module\Ship\Lib\Battle\Weapon; |
|
6
|
|
|
|
|
7
|
|
|
use Stu\Component\Building\BuildingManagerInterface; |
|
8
|
|
|
use Stu\Component\Ship\System\ShipSystemManagerInterface; |
|
9
|
|
|
use Stu\Module\Control\StuRandom; |
|
10
|
|
|
use Stu\Module\History\Lib\EntryCreatorInterface; |
|
11
|
|
|
use Stu\Module\Logging\LoggerUtilFactoryInterface; |
|
12
|
|
|
use Stu\Module\Logging\LoggerUtilInterface; |
|
13
|
|
|
use Stu\Module\Message\Lib\PrivateMessageSenderInterface; |
|
14
|
|
|
use Stu\Module\PlayerSetting\Lib\UserEnum; |
|
15
|
|
|
use Stu\Module\Prestige\Lib\CreatePrestigeLogInterface; |
|
16
|
|
|
use Stu\Module\Ship\Lib\Damage\ApplyDamageInterface; |
|
17
|
|
|
use Stu\Module\Ship\Lib\ModuleValueCalculatorInterface; |
|
18
|
|
|
use Stu\Module\Ship\Lib\ShipRemoverInterface; |
|
19
|
|
|
use Stu\Orm\Entity\ModuleInterface; |
|
20
|
|
|
use Stu\Orm\Entity\ShipInterface; |
|
21
|
|
|
use Stu\Orm\Entity\UserInterface; |
|
22
|
|
|
use Stu\Orm\Repository\WeaponRepositoryInterface; |
|
23
|
|
|
|
|
24
|
|
|
abstract class AbstractWeaponPhase |
|
25
|
|
|
{ |
|
26
|
|
|
protected ShipSystemManagerInterface $shipSystemManager; |
|
27
|
|
|
|
|
28
|
|
|
protected WeaponRepositoryInterface $weaponRepository; |
|
29
|
|
|
|
|
30
|
|
|
protected EntryCreatorInterface $entryCreator; |
|
31
|
|
|
|
|
32
|
|
|
protected ShipRemoverInterface $shipRemover; |
|
33
|
|
|
|
|
34
|
|
|
protected ApplyDamageInterface $applyDamage; |
|
35
|
|
|
|
|
36
|
|
|
protected ModuleValueCalculatorInterface $moduleValueCalculator; |
|
37
|
|
|
|
|
38
|
|
|
protected BuildingManagerInterface $buildingManager; |
|
39
|
|
|
|
|
40
|
|
|
protected StuRandom $stuRandom; |
|
41
|
|
|
|
|
42
|
|
|
protected LoggerUtilInterface $loggerUtil; |
|
43
|
|
|
|
|
44
|
|
|
private CreatePrestigeLogInterface $createPrestigeLog; |
|
45
|
|
|
|
|
46
|
|
|
private PrivateMessageSenderInterface $privateMessageSender; |
|
47
|
|
|
|
|
48
|
|
|
|
|
49
|
1 |
|
public function __construct( |
|
50
|
|
|
ShipSystemManagerInterface $shipSystemManager, |
|
51
|
|
|
WeaponRepositoryInterface $weaponRepository, |
|
52
|
|
|
EntryCreatorInterface $entryCreator, |
|
53
|
|
|
ShipRemoverInterface $shipRemover, |
|
54
|
|
|
ApplyDamageInterface $applyDamage, |
|
55
|
|
|
ModuleValueCalculatorInterface $moduleValueCalculator, |
|
56
|
|
|
BuildingManagerInterface $buildingManager, |
|
57
|
|
|
CreatePrestigeLogInterface $createPrestigeLog, |
|
58
|
|
|
PrivateMessageSenderInterface $privateMessageSender, |
|
59
|
|
|
StuRandom $stuRandom, |
|
60
|
|
|
LoggerUtilFactoryInterface $loggerUtilFactory |
|
61
|
|
|
) { |
|
62
|
1 |
|
$this->shipSystemManager = $shipSystemManager; |
|
63
|
1 |
|
$this->weaponRepository = $weaponRepository; |
|
64
|
1 |
|
$this->entryCreator = $entryCreator; |
|
65
|
1 |
|
$this->shipRemover = $shipRemover; |
|
66
|
1 |
|
$this->applyDamage = $applyDamage; |
|
67
|
1 |
|
$this->moduleValueCalculator = $moduleValueCalculator; |
|
68
|
1 |
|
$this->buildingManager = $buildingManager; |
|
69
|
1 |
|
$this->createPrestigeLog = $createPrestigeLog; |
|
70
|
1 |
|
$this->privateMessageSender = $privateMessageSender; |
|
71
|
1 |
|
$this->stuRandom = $stuRandom; |
|
72
|
1 |
|
$this->loggerUtil = $loggerUtilFactory->getLoggerUtil(); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
1 |
|
public function checkForPrestige(UserInterface $destroyer, ShipInterface $target): void |
|
76
|
|
|
{ |
|
77
|
1 |
|
$rump = $target->getRump(); |
|
78
|
1 |
|
$amount = $rump->getPrestige(); |
|
79
|
|
|
|
|
80
|
|
|
// nothing to do |
|
81
|
1 |
|
if ($amount === 0) { |
|
82
|
1 |
|
return; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
// empty escape pods to five times negative prestige |
|
86
|
|
|
if ($rump->isEscapePods() && $target->getCrewCount() === 0) { |
|
87
|
|
|
$amount *= 5; |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
$description = sprintf( |
|
91
|
|
|
'%s%d%s Prestige erhalten für die Zerstörung von: %s', |
|
92
|
|
|
$amount < 0 ? '[b][color=red]' : '', |
|
93
|
|
|
$amount, |
|
94
|
|
|
$amount < 0 ? '[/color][/b]' : '', |
|
95
|
|
|
$rump->getName() |
|
96
|
|
|
); |
|
97
|
|
|
|
|
98
|
|
|
$this->createPrestigeLog->createLog($amount, $description, $destroyer, time()); |
|
99
|
|
|
|
|
100
|
|
|
// system pm only for negative prestige |
|
101
|
|
|
if ($amount < 0) { |
|
102
|
|
|
$this->sendSystemMessage($description, $destroyer->getId()); |
|
103
|
|
|
} |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
private function sendSystemMessage(string $description, int $userId): void |
|
107
|
|
|
{ |
|
108
|
|
|
$this->privateMessageSender->send( |
|
109
|
|
|
UserEnum::USER_NOONE, |
|
110
|
|
|
$userId, |
|
111
|
|
|
$description |
|
112
|
|
|
); |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
1 |
|
protected function getModule(ShipInterface $ship, int $moduleType): ?ModuleInterface |
|
116
|
|
|
{ |
|
117
|
1 |
|
$buildplan = $ship->getBuildplan(); |
|
118
|
1 |
|
if ($buildplan === null) { |
|
119
|
1 |
|
return null; |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
$buildplanModule = current($buildplan->getModulesByType($moduleType)); |
|
123
|
|
|
if (!$buildplanModule) { |
|
124
|
|
|
return null; |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
return $buildplanModule->getModule(); |
|
128
|
|
|
} |
|
129
|
|
|
} |
|
130
|
|
|
|