1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Stu\Module\Spacecraft\Lib\Battle\Party; |
4
|
|
|
|
5
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
6
|
|
|
use Doctrine\Common\Collections\Collection; |
7
|
|
|
use Override; |
|
|
|
|
8
|
|
|
use RuntimeException; |
9
|
|
|
use Stu\Module\Message\Lib\PrivateMessageFolderTypeEnum; |
10
|
|
|
use Stu\Module\Spacecraft\Lib\SpacecraftWrapperInterface; |
11
|
|
|
use Stu\Orm\Entity\User; |
12
|
|
|
|
13
|
|
|
abstract class AbstractBattleParty implements BattlePartyInterface |
14
|
|
|
{ |
15
|
|
|
private bool $isStation; |
16
|
|
|
private User $user; |
17
|
|
|
|
18
|
|
|
/** @var Collection<int, covariant SpacecraftWrapperInterface> $members */ |
19
|
|
|
private ?Collection $members = null; |
20
|
|
|
|
21
|
21 |
|
public function __construct( |
22
|
|
|
protected SpacecraftWrapperInterface $leader, |
23
|
|
|
private bool $isAttackingShieldsOnly = false |
24
|
|
|
) { |
25
|
21 |
|
$this->isStation = $leader->get()->isStation(); |
26
|
21 |
|
$this->user = $leader->get()->getUser(); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @return Collection<int, covariant SpacecraftWrapperInterface> |
31
|
|
|
*/ |
32
|
|
|
abstract protected function initMembers(): Collection; |
33
|
|
|
|
34
|
|
|
#[Override] |
35
|
|
|
public function getUser(): User |
36
|
|
|
{ |
37
|
|
|
return $this->user; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
#[Override] |
41
|
|
|
public function getLeader(): SpacecraftWrapperInterface |
42
|
|
|
{ |
43
|
|
|
return $this->leader; |
44
|
|
|
} |
45
|
|
|
|
46
|
19 |
|
#[Override] |
47
|
|
|
public function getActiveMembers(bool $canFire = false, bool $filterDisabled = true): Collection |
48
|
|
|
{ |
49
|
19 |
|
if ($this->members === null) { |
50
|
19 |
|
$this->members = $this->initMembers(); |
51
|
|
|
} |
52
|
|
|
|
53
|
19 |
|
return $this->members->filter( |
|
|
|
|
54
|
19 |
|
fn(SpacecraftWrapperInterface $wrapper): bool => !$wrapper->get()->getCondition()->isDestroyed() |
55
|
17 |
|
&& (!$filterDisabled || !$wrapper->get()->getCondition()->isDisabled()) |
56
|
17 |
|
&& (!$canFire || $wrapper->canFire()) |
57
|
19 |
|
); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
#[Override] |
61
|
|
|
public function getRandomActiveMember(): SpacecraftWrapperInterface |
62
|
|
|
{ |
63
|
|
|
$activeMembers = $this->getActiveMembers(); |
64
|
|
|
$randomActiveMember = $activeMembers->get(array_rand($activeMembers->toArray())); |
|
|
|
|
65
|
|
|
if ($randomActiveMember === null) { |
66
|
|
|
throw new RuntimeException('isDefeated should be called first'); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
return $randomActiveMember; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
#[Override] |
73
|
|
|
public function isDefeated(): bool |
74
|
|
|
{ |
75
|
|
|
return $this->getActiveMembers()->isEmpty(); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
|
79
|
2 |
|
#[Override] |
80
|
|
|
public function isStation(): bool |
81
|
|
|
{ |
82
|
2 |
|
return $this->isStation; |
83
|
|
|
} |
84
|
|
|
|
85
|
2 |
|
#[Override] |
86
|
|
|
public function isAttackingShieldsOnly(): bool |
87
|
|
|
{ |
88
|
2 |
|
return $this->isAttackingShieldsOnly; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
#[Override] |
92
|
|
|
public function isActive(): bool |
93
|
|
|
{ |
94
|
|
|
return $this->getActiveMembers() |
95
|
|
|
->exists(fn(int $key, SpacecraftWrapperInterface $wrapper): bool => $wrapper->get()->hasEnoughCrew()); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* @return Collection<int, SpacecraftWrapperInterface> |
100
|
|
|
*/ |
101
|
7 |
|
protected function createSingleton(SpacecraftWrapperInterface $wrapper): Collection |
102
|
|
|
{ |
103
|
7 |
|
return new ArrayCollection([$wrapper->get()->getId() => $wrapper]); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
#[Override] |
107
|
|
|
public function count(): int |
108
|
|
|
{ |
109
|
|
|
return $this->getActiveMembers()->count(); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
#[Override] |
113
|
|
|
public function getPrivateMessageType(): PrivateMessageFolderTypeEnum |
114
|
|
|
{ |
115
|
|
|
return $this->isStation() |
116
|
|
|
? PrivateMessageFolderTypeEnum::SPECIAL_STATION |
117
|
|
|
: PrivateMessageFolderTypeEnum::SPECIAL_SHIP; |
118
|
|
|
} |
119
|
|
|
} |
120
|
|
|
|
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