|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Obblm\Core\Helper; |
|
4
|
|
|
|
|
5
|
|
|
use Obblm\Core\Entity\Team; |
|
6
|
|
|
use Obblm\Core\Entity\TeamVersion; |
|
7
|
|
|
use Obblm\Core\Contracts\RuleHelperInterface; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* Class TeamHelper |
|
11
|
|
|
* @package Obblm\Core\Helper |
|
12
|
|
|
*/ |
|
13
|
|
|
class TeamHelper |
|
14
|
|
|
{ |
|
15
|
|
|
private $ruleHelper; |
|
16
|
|
|
|
|
17
|
|
|
public function __construct(RuleHelper $ruleHelper) |
|
18
|
|
|
{ |
|
19
|
|
|
$this->ruleHelper = $ruleHelper; |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @param Team $team |
|
24
|
|
|
* @return RuleHelperInterface |
|
25
|
|
|
* @throws \Exception |
|
26
|
|
|
*/ |
|
27
|
|
|
public function getRuleHelper(Team $team):RuleHelperInterface |
|
28
|
|
|
{ |
|
29
|
|
|
if (!$team->getRule()) { |
|
30
|
|
|
throw new \Exception('This team does not have a rule'); |
|
31
|
|
|
} |
|
32
|
|
|
return $this->ruleHelper->getHelper($team->getRule()); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
public static function getLastVersion(Team $team):TeamVersion |
|
36
|
|
|
{ |
|
37
|
|
|
$versions = $team->getVersions(); |
|
38
|
|
|
/** @var TeamVersion $last */ |
|
39
|
|
|
$last = $versions->first(); |
|
40
|
|
|
if ($last) { |
|
|
|
|
|
|
41
|
|
|
return $last; |
|
42
|
|
|
} |
|
43
|
|
|
$version = new TeamVersion(); |
|
44
|
|
|
$team->addVersion($version); |
|
45
|
|
|
return $version; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/********************** |
|
49
|
|
|
* TEAM HELPER METHODS |
|
50
|
|
|
**********************/ |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* @param TeamVersion $version |
|
54
|
|
|
* @return int |
|
55
|
|
|
* @throws \Exception |
|
56
|
|
|
*/ |
|
57
|
|
|
public function calculateTeamValue(TeamVersion $version):int |
|
58
|
|
|
{ |
|
59
|
|
|
return $this->getRuleHelper($version->getTeam()) |
|
|
|
|
|
|
60
|
|
|
->calculateTeamValue($version); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* @param TeamVersion $version |
|
65
|
|
|
* @return int |
|
66
|
|
|
* @throws \Exception |
|
67
|
|
|
*/ |
|
68
|
|
|
public function calculateTeamRate(TeamVersion $version):int |
|
69
|
|
|
{ |
|
70
|
|
|
return $this->getRuleHelper($version->getTeam()) |
|
|
|
|
|
|
71
|
|
|
->calculateTeamRate($version); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* @param Team $team |
|
76
|
|
|
* @return TeamVersion |
|
77
|
|
|
* @throws \Psr\Cache\InvalidArgumentException |
|
78
|
|
|
*/ |
|
79
|
|
|
public function createNewTeamVersion(Team $team):TeamVersion |
|
80
|
|
|
{ |
|
81
|
|
|
return (TeamHelper::getLastVersion($team)) |
|
82
|
|
|
->setTreasure($this->ruleHelper->getHelper($team->getRule())->getMaxTeamCost()); |
|
83
|
|
|
} |
|
84
|
|
|
public function destructTeamVersion(Team $team):TeamVersion |
|
|
|
|
|
|
85
|
|
|
{ |
|
86
|
|
|
} |
|
|
|
|
|
|
87
|
|
|
|
|
88
|
|
|
/**************************** |
|
89
|
|
|
* TEAM INFORMATION METHODS |
|
90
|
|
|
***************************/ |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* @param Team $team |
|
94
|
|
|
* @return int |
|
95
|
|
|
* @throws \Exception |
|
96
|
|
|
*/ |
|
97
|
|
|
public function getRerollCost(Team $team):int |
|
98
|
|
|
{ |
|
99
|
|
|
return (int) $this->getRuleHelper($team)->getRerollCost($team); |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
/** |
|
103
|
|
|
* @param Team $team |
|
104
|
|
|
* @return int |
|
105
|
|
|
* @throws \Exception |
|
106
|
|
|
*/ |
|
107
|
|
|
public function getApothecaryCost(Team $team):int |
|
108
|
|
|
{ |
|
109
|
|
|
return (int) $this->getRuleHelper($team)->getApothecaryCost($team); |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
/** |
|
113
|
|
|
* @param Team $team |
|
114
|
|
|
* @return int |
|
115
|
|
|
* @throws \Exception |
|
116
|
|
|
*/ |
|
117
|
|
|
public function getCheerleadersCost(Team $team):int |
|
118
|
|
|
{ |
|
119
|
|
|
return (int) $this->getRuleHelper($team)->getCheerleadersCost($team); |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
/** |
|
123
|
|
|
* @param Team $team |
|
124
|
|
|
* @return int |
|
125
|
|
|
* @throws \Exception |
|
126
|
|
|
*/ |
|
127
|
|
|
public function getAssistantsCost(Team $team):int |
|
128
|
|
|
{ |
|
129
|
|
|
return (int) $this->getRuleHelper($team)->getAssistantsCost($team); |
|
130
|
|
|
} |
|
131
|
|
|
|
|
132
|
|
|
/** |
|
133
|
|
|
* @param Team $team |
|
134
|
|
|
* @return int |
|
135
|
|
|
* @throws \Exception |
|
136
|
|
|
*/ |
|
137
|
|
|
public function getPopularityCost(Team $team):int |
|
138
|
|
|
{ |
|
139
|
|
|
return (int) $this->getRuleHelper($team)->getPopularityCost($team); |
|
140
|
|
|
} |
|
141
|
|
|
|
|
142
|
|
|
/** |
|
143
|
|
|
* @param Team $team |
|
144
|
|
|
* @return bool |
|
145
|
|
|
* @throws \Exception |
|
146
|
|
|
*/ |
|
147
|
|
|
public function couldHaveApothecary(Team $team):bool |
|
148
|
|
|
{ |
|
149
|
|
|
if (!$team->getRule()) { |
|
150
|
|
|
throw new \Exception('This team does not have a rule'); |
|
151
|
|
|
} |
|
152
|
|
|
return (bool) $this->getRuleHelper($team)->couldHaveApothecary($team); |
|
153
|
|
|
} |
|
154
|
|
|
} |
|
155
|
|
|
|