1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Obblm\Core\Helper\Rule\Traits; |
4
|
|
|
|
5
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
6
|
|
|
use Obblm\Core\Entity\PlayerVersion; |
7
|
|
|
use Obblm\Core\Entity\Team; |
8
|
|
|
use Obblm\Core\Entity\TeamVersion; |
9
|
|
|
use Obblm\Core\Exception\InvalidArgumentException; |
10
|
|
|
use Obblm\Core\Exception\NotFoundRuleKeyExcepion; |
11
|
|
|
use Obblm\Core\Exception\NoVersionException; |
12
|
|
|
use Obblm\Core\Helper\PlayerHelper; |
13
|
|
|
use Obblm\Core\Helper\Rule\Roster\Roster; |
14
|
|
|
use Obblm\Core\Validator\Constraints\TeamValue; |
15
|
|
|
|
16
|
|
|
/**************************** |
17
|
|
|
* TEAM INFORMATION METHODS |
18
|
|
|
***************************/ |
19
|
|
|
trait AbstractTeamRuleTrait |
20
|
|
|
{ |
21
|
|
|
public function getAvailableRosters(): ArrayCollection |
22
|
|
|
{ |
23
|
|
|
return $this->getRosters(); |
|
|
|
|
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @return int |
28
|
|
|
*/ |
29
|
|
|
public function getMaxTeamCost():int |
30
|
|
|
{ |
31
|
|
|
return ($this->rule['max_team_cost']) ? $this->rule['max_team_cost'] : TeamValue::LIMIT; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @param Team $team |
36
|
|
|
* @return array |
37
|
|
|
*/ |
38
|
|
|
public function getTeamAvailablePlayerTypes(Team $team) |
39
|
|
|
{ |
40
|
|
|
return $this->getAvailablePlayerTypes($team->getRoster()); |
|
|
|
|
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @param Team $team |
45
|
|
|
* @return int |
46
|
|
|
* @throws \Exception |
47
|
|
|
*/ |
48
|
|
|
public function getRerollCost(Team $team):int |
49
|
|
|
{ |
50
|
|
|
/** @var Roster $roster */ |
51
|
|
|
$roster = $this->getRosters()->get($team->getRoster()); |
52
|
|
|
return (int) $roster->getRerollCost(); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @param Team $team |
57
|
|
|
* @return int |
58
|
|
|
*/ |
59
|
|
|
public function getApothecaryCost(Team $team):int |
|
|
|
|
60
|
|
|
{ |
61
|
|
|
return (int) $this->rule['sidelines_cost']['apothecary']; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @param Team $team |
66
|
|
|
* @return int |
67
|
|
|
*/ |
68
|
|
|
public function getCheerleadersCost(Team $team):int |
|
|
|
|
69
|
|
|
{ |
70
|
|
|
return (int) $this->rule['sidelines_cost']['cheerleaders']; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @param Team $team |
75
|
|
|
* @return int |
76
|
|
|
*/ |
77
|
|
|
public function getAssistantsCost(Team $team):int |
|
|
|
|
78
|
|
|
{ |
79
|
|
|
return (int) $this->rule['sidelines_cost']['assistants']; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @param Team $team |
84
|
|
|
* @return int |
85
|
|
|
*/ |
86
|
|
|
public function getPopularityCost(Team $team):int |
|
|
|
|
87
|
|
|
{ |
88
|
|
|
return (int) $this->rule['sidelines_cost']['popularity']; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @param Team $team |
93
|
|
|
* @return bool |
94
|
|
|
* @throws \Exception |
95
|
|
|
*/ |
96
|
|
|
public function couldHaveApothecary(Team $team):bool |
97
|
|
|
{ |
98
|
|
|
/** @var Roster $roster */ |
99
|
|
|
$roster = $this->getRosters()->get($team->getRoster()); |
100
|
|
|
return (bool) $roster->canHaveApothecary(); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
public function calculateTeamRate(TeamVersion $version):?int |
104
|
|
|
{ |
105
|
|
|
return $this->calculateTeamValue($version) / 10000; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
public function calculateTeamValue(TeamVersion $version, bool $excludeDisposable = false):int |
109
|
|
|
{ |
110
|
|
|
if (!$version->getTeam()) { |
111
|
|
|
throw new InvalidArgumentException(); |
112
|
|
|
} |
113
|
|
|
$value = 0; |
114
|
|
|
// Players |
115
|
|
|
// TODO: Bug => players are not version's one (because od dead players) |
116
|
|
|
foreach ($version->getTeam()->getAvailablePlayers() as $player) { |
117
|
|
|
if ($player->getType()) { |
118
|
|
|
try { |
119
|
|
|
$playerVersion = PlayerHelper::getLastVersion($player); |
120
|
|
|
} catch (NoVersionException $e) { // It's a new player ! |
121
|
|
|
$playerVersion = (new PlayerVersion()); |
122
|
|
|
$player->addVersion($playerVersion); |
123
|
|
|
$version->addPlayerVersion($playerVersion); |
124
|
|
|
$this->setPlayerDefaultValues($playerVersion); |
125
|
|
|
} |
126
|
|
|
if (!$playerVersion->isMissingNextGame() && !($this->playerIsDisposable($playerVersion) && $excludeDisposable)) { |
127
|
|
|
$value += $playerVersion->getValue(); |
128
|
|
|
} |
129
|
|
|
} |
130
|
|
|
} |
131
|
|
|
// Sidelines |
132
|
|
|
$value += $version->getRerolls() * $this->getRerollCost($version->getTeam()); |
133
|
|
|
$value += $version->getAssistants() * $this->getAssistantsCost($version->getTeam()); |
134
|
|
|
$value += $version->getCheerleaders() * $this->getCheerleadersCost($version->getTeam()); |
135
|
|
|
$value += $version->getPopularity() * $this->getPopularityCost($version->getTeam()); |
136
|
|
|
$value += ($version->getApothecary()) ? $this->getApothecaryCost($version->getTeam()) : 0; |
137
|
|
|
|
138
|
|
|
return $value; |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
abstract public function setPlayerDefaultValues(PlayerVersion $version): ?PlayerVersion; |
142
|
|
|
abstract public function playerIsDisposable(PlayerVersion $version):bool; |
143
|
|
|
|
144
|
|
|
/** |
145
|
|
|
* @return array |
146
|
|
|
*/ |
147
|
|
|
public function getInjuriesTable():array |
148
|
|
|
{ |
149
|
|
|
return $this->getInjuries(); |
|
|
|
|
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
public function getMaxPlayersByType($rosterKey, $typeKey): int |
153
|
|
|
{ |
154
|
|
|
/** @var Roster $roster */ |
155
|
|
|
$roster = $this->getRosters()->get($rosterKey); |
156
|
|
|
if (!$type = $roster->getPlayerTypes()[$typeKey]) { |
157
|
|
|
throw new NotFoundRuleKeyExcepion($typeKey, 'toto'); |
|
|
|
|
158
|
|
|
} |
159
|
|
|
return (int) $type['max']; |
160
|
|
|
} |
161
|
|
|
} |
162
|
|
|
|