1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Created by Gorlum 12.10.2017 15:19 |
4
|
|
|
*/ |
5
|
|
|
|
6
|
|
|
use Core\GlobalContainer; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Class General |
10
|
|
|
* |
11
|
|
|
* Wrapper for /includes/general.php |
12
|
|
|
* Will make unit testing easier |
13
|
|
|
* |
14
|
|
|
*/ |
15
|
|
|
class General { |
16
|
|
|
/** |
17
|
|
|
* @var GlobalContainer $gc |
18
|
|
|
*/ |
19
|
|
|
protected $gc; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @var \Bonus\ValueStorage $valueStorage |
23
|
|
|
*/ |
24
|
|
|
protected $valueStorage; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* General constructor. |
28
|
|
|
* |
29
|
|
|
* @param GlobalContainer $gc |
30
|
|
|
*/ |
31
|
|
|
public function __construct(GlobalContainer $gc) { |
32
|
|
|
$this->gc = $gc; |
33
|
|
|
$this->valueStorage = $this->gc->valueStorage; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @param string|string[] $groupNameList |
38
|
|
|
* |
39
|
|
|
* @return array|array[] |
40
|
|
|
*/ |
41
|
|
|
public function getGroupsByName($groupNameList) { |
42
|
|
|
return sn_get_groups($groupNameList); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @param int|string|array $groupIdList |
47
|
|
|
* |
48
|
|
|
* @return array|array[] |
49
|
|
|
*/ |
50
|
|
|
public function getGroupsById($groupIdList) { |
51
|
|
|
if (!is_array($groupIdList)) { |
52
|
|
|
$groupIdList = [$groupIdList]; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
$idToName = $this->getGroupsByName(GROUP_GROUP_ID_TO_NAMES); |
56
|
|
|
foreach ($groupIdList as &$groupId) { |
57
|
|
|
if (!empty($idToName[$groupId])) { |
58
|
|
|
$groupId = $idToName[$groupId]; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
return $this->getGroupsByName($groupIdList); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @return float|int |
68
|
|
|
*/ |
69
|
|
|
public function fleetNoobPoints() { |
70
|
|
|
return $this->valueStorage->getValue(UNIT_SERVER_FLEET_NOOB_POINTS) * game_resource_multiplier(true); |
|
|
|
|
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Is player qualified as "noob" aka "New Inexpirienced player" |
75
|
|
|
* |
76
|
|
|
* @param float $playerTotalPoints |
77
|
|
|
* |
78
|
|
|
* @return bool |
79
|
|
|
*/ |
80
|
|
|
public function playerIsNoobByPoints($playerTotalPoints) { |
81
|
|
|
return $playerTotalPoints <= $this->fleetNoobPoints(); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Is player 1 stronger then player 2 counting game noob factor? |
86
|
|
|
* |
87
|
|
|
* @param float $player1TotalPoints |
88
|
|
|
* @param float $player2TotalPoints |
89
|
|
|
* |
90
|
|
|
* @return bool |
91
|
|
|
*/ |
92
|
|
|
public function playerIs1stStrongerThen2nd($player1TotalPoints, $player2TotalPoints) { |
93
|
|
|
$gameNoobFactor = $this->valueStorage->getValue(UNIT_SERVER_FLEET_NOOB_FACTOR); |
|
|
|
|
94
|
|
|
|
95
|
|
|
return $gameNoobFactor && $player1TotalPoints > $player2TotalPoints * $gameNoobFactor; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
} |
99
|
|
|
|