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