|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Stu\Component\Player; |
|
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
|
|
|
/** |
|
13
|
|
|
* Some locations require to determine if a certain user is friendly towards the player |
|
14
|
|
|
*/ |
|
15
|
|
|
final class PlayerRelationDeterminator implements PlayerRelationDeterminatorInterface |
|
16
|
|
|
{ |
|
17
|
|
|
private AllianceRelationRepositoryInterface $allianceRelationRepository; |
|
18
|
|
|
|
|
19
|
|
|
private ContactRepositoryInterface $contactRepository; |
|
20
|
|
|
|
|
21
|
8 |
|
public function __construct( |
|
22
|
|
|
AllianceRelationRepositoryInterface $allianceRelationRepository, |
|
23
|
|
|
ContactRepositoryInterface $contactRepository |
|
24
|
|
|
) { |
|
25
|
8 |
|
$this->allianceRelationRepository = $allianceRelationRepository; |
|
26
|
8 |
|
$this->contactRepository = $contactRepository; |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
4 |
|
public function isFriend(UserInterface $user, UserInterface $otherUser): bool |
|
30
|
|
|
{ |
|
31
|
4 |
|
$alliance = $user->getAlliance(); |
|
32
|
|
|
|
|
33
|
4 |
|
$otherUserAlliance = $otherUser->getAlliance(); |
|
34
|
|
|
|
|
35
|
4 |
|
if ($alliance !== null && $otherUserAlliance !== null) { |
|
36
|
3 |
|
if ($alliance === $otherUserAlliance) { |
|
37
|
1 |
|
return true; |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
2 |
|
$result = $this->allianceRelationRepository->getActiveByTypeAndAlliancePair( |
|
41
|
2 |
|
[ |
|
42
|
2 |
|
AllianceEnum::ALLIANCE_RELATION_FRIENDS, |
|
43
|
2 |
|
AllianceEnum::ALLIANCE_RELATION_ALLIED, |
|
44
|
2 |
|
AllianceEnum::ALLIANCE_RELATION_VASSAL |
|
45
|
2 |
|
], |
|
46
|
2 |
|
$otherUserAlliance->getId(), |
|
47
|
2 |
|
$alliance->getId() |
|
48
|
2 |
|
); |
|
49
|
|
|
|
|
50
|
2 |
|
if ($result !== null) { |
|
51
|
1 |
|
return true; |
|
52
|
|
|
} |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
2 |
|
$contact = $this->contactRepository->getByUserAndOpponent( |
|
56
|
2 |
|
$user->getId(), |
|
57
|
2 |
|
$otherUser->getId() |
|
58
|
2 |
|
); |
|
59
|
|
|
|
|
60
|
2 |
|
return $contact !== null && $contact->isFriendly(); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
4 |
|
public function isEnemy(UserInterface $user, UserInterface $otherUser): bool |
|
64
|
|
|
{ |
|
65
|
4 |
|
$alliance = $user->getAlliance(); |
|
66
|
|
|
|
|
67
|
4 |
|
$otherUserAlliance = $otherUser->getAlliance(); |
|
68
|
|
|
|
|
69
|
4 |
|
if ($alliance !== null && $otherUserAlliance !== null) { |
|
70
|
3 |
|
if ($alliance === $otherUserAlliance) { |
|
71
|
1 |
|
return false; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
2 |
|
$result = $this->allianceRelationRepository->getActiveByTypeAndAlliancePair( |
|
75
|
2 |
|
[ |
|
76
|
2 |
|
AllianceEnum::ALLIANCE_RELATION_WAR, |
|
77
|
2 |
|
], |
|
78
|
2 |
|
$otherUserAlliance->getId(), |
|
79
|
2 |
|
$alliance->getId() |
|
80
|
2 |
|
); |
|
81
|
|
|
|
|
82
|
2 |
|
if ($result !== null) { |
|
83
|
1 |
|
return true; |
|
84
|
|
|
} |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
2 |
|
$contact = $this->contactRepository->getByUserAndOpponent( |
|
88
|
2 |
|
$user->getId(), |
|
89
|
2 |
|
$otherUser->getId() |
|
90
|
2 |
|
); |
|
91
|
|
|
|
|
92
|
2 |
|
return $contact !== null && $contact->isEnemy(); |
|
93
|
|
|
} |
|
94
|
|
|
} |
|
95
|
|
|
|