|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Stu\Module\Spacecraft\Lib\CloseCombat; |
|
4
|
|
|
|
|
5
|
|
|
use Override; |
|
|
|
|
|
|
6
|
|
|
use Stu\Module\Control\StuRandom; |
|
7
|
|
|
use Stu\Module\Spacecraft\Lib\Auxiliary\ShipShutdownInterface; |
|
8
|
|
|
use Stu\Module\Spacecraft\Lib\Message\MessageCollectionInterface; |
|
9
|
|
|
use Stu\Module\Spacecraft\Lib\Message\MessageFactoryInterface; |
|
10
|
|
|
use Stu\Module\Spacecraft\Lib\SpacecraftWrapperInterface; |
|
11
|
|
|
use Stu\Orm\Entity\CrewAssignmentInterface; |
|
12
|
|
|
use Stu\Orm\Repository\CrewAssignmentRepositoryInterface; |
|
13
|
|
|
use Stu\Orm\Repository\CrewRepositoryInterface; |
|
14
|
|
|
|
|
15
|
|
|
class BoardShipUtil implements BoardShipUtilInterface |
|
16
|
|
|
{ |
|
17
|
1 |
|
public function __construct( |
|
18
|
|
|
private CrewRepositoryInterface $crewRepository, |
|
19
|
|
|
private CrewAssignmentRepositoryInterface $crewAssignmentRepository, |
|
20
|
|
|
private CloseCombatUtilInterface $closeCombatUtil, |
|
21
|
|
|
private ShipShutdownInterface $shipShutdown, |
|
22
|
|
|
private MessageFactoryInterface $messageFactory, |
|
23
|
|
|
private StuRandom $stuRandom |
|
24
|
1 |
|
) {} |
|
25
|
|
|
|
|
26
|
|
|
#[Override] |
|
27
|
|
|
public function cycleKillRound( |
|
28
|
|
|
array &$attackers, |
|
29
|
|
|
array &$defenders, |
|
30
|
|
|
SpacecraftWrapperInterface $wrapper, |
|
31
|
|
|
SpacecraftWrapperInterface $targetWrapper, |
|
32
|
|
|
MessageCollectionInterface $messages |
|
33
|
|
|
): void { |
|
34
|
|
|
|
|
35
|
|
|
$ship = $wrapper->get(); |
|
36
|
|
|
$target = $targetWrapper->get(); |
|
37
|
|
|
|
|
38
|
|
|
$combatValueAttacker = $this->closeCombatUtil->getCombatValue($attackers, $ship->getUser()->getFaction()); |
|
39
|
|
|
$combatValueDefender = $this->closeCombatUtil->getCombatValue($defenders, $target->getUser()->getFaction()); |
|
40
|
|
|
|
|
41
|
|
|
$rand = $this->stuRandom->rand( |
|
42
|
|
|
0, |
|
43
|
|
|
$combatValueAttacker + $combatValueDefender |
|
44
|
|
|
); |
|
45
|
|
|
|
|
46
|
|
|
$isDeathOnDefenderSide = $rand <= $combatValueAttacker; |
|
47
|
|
|
if ($isDeathOnDefenderSide) { |
|
48
|
|
|
$killedCrewAssignment = $this->getKilledCrew($defenders, $targetWrapper); |
|
49
|
|
|
} else { |
|
50
|
|
|
$killedCrewAssignment = $this->getKilledCrew($attackers, $wrapper); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
$message = $this->messageFactory->createMessage($ship->getUser()->getId(), $killedCrewAssignment->getUser()->getId()); |
|
54
|
|
|
$message->add(sprintf( |
|
55
|
|
|
'%s %s des Spielers %s von der %s wurde im Kampf getötet.', |
|
56
|
|
|
$killedCrewAssignment->getCrew()->getTypeDescription(), |
|
57
|
|
|
$killedCrewAssignment->getCrew()->getName(), |
|
58
|
|
|
$isDeathOnDefenderSide ? $target->getUser()->getName() : $ship->getUser()->getName(), |
|
59
|
|
|
$isDeathOnDefenderSide ? $target->getName() : $ship->getName() |
|
60
|
|
|
)); |
|
61
|
|
|
$messages->add($message); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* @param array<int, CrewAssignmentInterface> &$combatGroup |
|
66
|
|
|
*/ |
|
67
|
|
|
private function getKilledCrew(array &$combatGroup, SpacecraftWrapperInterface $wrapper): CrewAssignmentInterface |
|
68
|
|
|
{ |
|
69
|
|
|
$keys = array_keys($combatGroup); |
|
70
|
|
|
shuffle($keys); |
|
71
|
|
|
|
|
72
|
|
|
$randomKey = current($keys); |
|
73
|
|
|
|
|
74
|
|
|
$killedCrewAssignment = $combatGroup[$randomKey]; |
|
75
|
|
|
unset($combatGroup[$randomKey]); |
|
76
|
|
|
|
|
77
|
|
|
$ship = $wrapper->get(); |
|
78
|
|
|
$ship->getCrewAssignments()->removeElement($killedCrewAssignment); |
|
79
|
|
|
$this->crewRepository->delete($killedCrewAssignment->getCrew()); |
|
80
|
|
|
$this->crewAssignmentRepository->delete($killedCrewAssignment); |
|
81
|
|
|
|
|
82
|
|
|
if ($ship->getCrewAssignments()->isEmpty()) { |
|
83
|
|
|
$this->shipShutdown->shutdown($wrapper, true); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
return $killedCrewAssignment; |
|
87
|
|
|
} |
|
88
|
|
|
} |
|
89
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths