|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Stu\Component\Player\Relation; |
|
6
|
|
|
|
|
7
|
|
|
use Stu\Component\Alliance\AllianceEnum; |
|
8
|
|
|
use Stu\Orm\Entity\UserInterface; |
|
9
|
|
|
use Stu\Orm\Repository\AllianceRelationRepositoryInterface; |
|
10
|
|
|
use Stu\Orm\Repository\ContactRepositoryInterface; |
|
11
|
|
|
|
|
12
|
|
|
class EnemyDeterminator |
|
13
|
|
|
{ |
|
14
|
|
|
private AllianceRelationRepositoryInterface $allianceRelationRepository; |
|
15
|
|
|
|
|
16
|
|
|
private ContactRepositoryInterface $contactRepository; |
|
17
|
|
|
|
|
18
|
4 |
|
public function __construct( |
|
19
|
|
|
AllianceRelationRepositoryInterface $allianceRelationRepository, |
|
20
|
|
|
ContactRepositoryInterface $contactRepository |
|
21
|
|
|
) { |
|
22
|
4 |
|
$this->allianceRelationRepository = $allianceRelationRepository; |
|
23
|
4 |
|
$this->contactRepository = $contactRepository; |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
4 |
|
public function isEnemy(UserInterface $user, UserInterface $otherUser): PlayerRelationTypeEnum |
|
27
|
|
|
{ |
|
28
|
4 |
|
$alliance = $user->getAlliance(); |
|
29
|
|
|
|
|
30
|
4 |
|
$otherUserAlliance = $otherUser->getAlliance(); |
|
31
|
|
|
|
|
32
|
4 |
|
if ($alliance !== null && $otherUserAlliance !== null) { |
|
33
|
3 |
|
if ($alliance === $otherUserAlliance) { |
|
34
|
1 |
|
return PlayerRelationTypeEnum::NONE; |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
2 |
|
$result = $this->allianceRelationRepository->getActiveByTypeAndAlliancePair( |
|
38
|
2 |
|
[ |
|
39
|
2 |
|
AllianceEnum::ALLIANCE_RELATION_WAR, |
|
40
|
2 |
|
], |
|
41
|
2 |
|
$otherUserAlliance->getId(), |
|
42
|
2 |
|
$alliance->getId() |
|
43
|
2 |
|
); |
|
44
|
|
|
|
|
45
|
2 |
|
if ($result !== null) { |
|
46
|
1 |
|
return PlayerRelationTypeEnum::ALLY; |
|
47
|
|
|
} |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
2 |
|
$contact = $this->contactRepository->getByUserAndOpponent( |
|
51
|
2 |
|
$user->getId(), |
|
52
|
2 |
|
$otherUser->getId() |
|
53
|
2 |
|
); |
|
54
|
|
|
|
|
55
|
2 |
|
if ($contact !== null && $contact->isEnemy()) { |
|
56
|
1 |
|
return PlayerRelationTypeEnum::USER; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
1 |
|
return PlayerRelationTypeEnum::NONE; |
|
60
|
|
|
} |
|
61
|
|
|
} |
|
62
|
|
|
|